Blob


1 test_punycode() {
2 dont_check_server_alive=yes
3 ./puny-test
4 }
6 test_iri() {
7 dont_check_server_alive=yes
8 ./iri_test
9 }
11 test_ge() {
12 dont_check_server_alive=yes
14 $ge -p $port -d . testdata &
15 pid=$!
16 sleep 1
18 fetch /
19 kill $pid
20 check_reply "20 text/gemini" "# hello world" || return 1
21 }
23 test_static_files() {
24 setup_simple_test
26 fetch /
27 check_reply "20 text/gemini" "# hello world" || return 1
29 fetch /foo
30 check_reply "51 not found" || return 1
32 fetch /dir/foo.gmi
33 check_reply "20 text/gemini" "# hello world" || return 1
34 }
36 test_directory_redirect() {
37 setup_simple_test
39 fetch /dir
40 check_reply "30 /dir/" || return 1
42 fetch /dir/
43 check_reply "51 not found" || return 1
44 }
46 test_serve_big_files() {
47 setup_simple_test
49 hdr="$(head /bigfile)"
50 get /bigfile > bigfile
51 ./sha bigfile bigfile.sha
52 body="$(cat bigfile.sha)"
54 check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
55 }
57 test_dont_execute_scripts() {
58 setup_simple_test
60 fetch_hdr /hello
61 check_reply "20 application/octet-stream" "" || return 1
62 }
64 test_custom_mime() {
65 setup_simple_test '
66 types {
67 text/x-funny gmi
68 }
69 ' ''
71 fetch_hdr /
72 check_reply "20 text/x-funny"
73 }
75 test_default_type() {
76 setup_simple_test '' 'default type "application/x-foo"'
78 fetch_hdr /hello
79 check_reply "20 application/x-foo"
80 }
82 test_custom_lang() {
83 setup_simple_test '' 'lang it'
85 fetch_hdr /
86 check_reply "20 text/gemini;lang=it"
87 }
89 test_parse_custom_lang_per_location() {
90 setup_simple_test '' \
91 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
92 # can parse multiple locations
93 }
95 test_custom_index() {
96 setup_simple_test '' 'index "foo.gmi"'
98 fetch /dir/
99 check_reply "20 text/gemini" "# hello world"
102 test_custom_index_default_type_per_location() {
103 setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
105 fetch /dir/
106 check_reply "20 text/plain" "$(cat hello)"
109 test_auto_index() {
110 setup_simple_test '' 'location "/dir/*" { auto index on }'
112 fetch /
113 check_reply "20 text/gemini" "# hello world" || return 1
115 fetch_hdr /dir
116 check_reply "30 /dir/" || return 1
118 fetch_hdr /dir/
119 check_reply "20 text/gemini" || return 1
121 get /dir/ > listing || return 1
122 cat <<EOF > listing.expected
123 # Index of /dir/
125 => ./../
126 => ./current%20date
127 => ./foo.gmi
128 => ./hello
129 EOF
131 cmp -s listing.expected listing
132 ret=$?
133 if [ $ret -ne 0 ]; then
134 echo 'unexpected dir content:'
135 diff -u listing.expected listing
136 fi
137 rm listing listing.expected
139 return $ret
142 test_block() {
143 setup_simple_test '' 'location "*" { block }'
145 fetch /
146 check_reply "40 temporary failure" || return 1
148 fetch /nonexists
149 check_reply "40 temporary failure" || return 1
152 test_block_return_fmt() {
153 setup_simple_test '' '
154 location "/dir" {
155 strip 1
156 block return 40 "%% %p %q %P %N test"
158 location "*" {
159 strip 99
160 block return 40 "%% %p %q %P %N test"
161 }'
163 fetch_hdr /dir/foo.gmi
164 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
166 fetch_hdr /bigfile
167 check_reply "40 % / 10965 localhost test" || return 1
170 test_require_client_ca() {
171 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
173 fetch /
174 check_reply "60 client certificate required" || return 1
176 ggflags="-C valid.crt -K valid.key"
177 fetch_hdr /
178 check_reply "20 text/gemini" || return 1
180 ggflags="-C invalid.cert.pem -K invalid.key.pem"
181 fetch_hdr /
182 check_reply "61 certificate not authorised" || return 1
185 test_root_inside_location() {
186 setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
188 fetch /foo
189 check_reply "51 not found" || return 1
191 fetch_hdr /foo/
192 check_reply "20 text/gemini"
195 test_root_inside_location_with_redirect() {
196 setup_simple_test '' '
197 location "/foo" { block return 31 "%p/" }
198 location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
200 fetch /foo
201 check_reply "31 /foo/" || return 1
203 fetch_hdr /foo/
204 check_reply "20 text/gemini"
207 test_fastcgi() {
208 ./fcgi-test fcgi.sock &
209 fcgi_pid=$!
211 setup_simple_test 'prefork 1' 'fastcgi "'$PWD'/fcgi.sock"'
213 i=0
214 while [ $i -lt 10 ]; do
215 fetch /
216 check_reply "20 text/gemini" "# hello from fastcgi!"
217 if [ $? -ne 0 ]; then
218 kill $fcgi_pid
219 return 1
220 fi
222 i=$(($i + 1))
223 done
225 kill $fcgi_pid
226 return 0
229 test_macro_expansion() {
230 cat <<EOF > reg.conf
231 pwd = "$PWD"
232 $config_common
234 server "localhost" {
235 # the quoting of \$ is for sh
236 cert \$pwd "/cert.pem"
237 key \$pwd "/key.pem"
238 root \$pwd "/testdata"
240 EOF
242 if ! checkconf; then
243 echo "failed to parse the config"
244 return 1
245 fi
247 run
249 fetch /
250 check_reply "20 text/gemini" "# hello world"
253 test_proxy_relay_to() {
254 gen_config '' ''
255 set_proxy ''
257 run
259 ggflags="-P localhost:$port -H localhost.local"
261 fetch /
262 check_reply "20 text/gemini" "# hello world"
265 test_proxy_with_certs() {
266 ggflags="-P localhost:$port -H localhost.local"
268 # first test using the valid keys
270 gen_config '' 'require client ca "'$PWD'/testca.pem"'
271 set_proxy "
272 cert \"$PWD/valid.crt\"
273 key \"$PWD/valid.key\"
275 run
277 fetch /
278 check_reply "20 text/gemini" "# hello world" || return 1
280 # then using some invalid keys
282 gen_config '' 'require client ca "'$PWD'/testca.pem"'
283 set_proxy "
284 cert \"$PWD/invalid.cert.pem\"
285 key \"$PWD/invalid.key.pem\"
287 run
289 fetch /
290 check_reply "61 certificate not authorised" || return 1
292 # and finally without keys
294 gen_config '' 'require client ca "'$PWD'/testca.pem"'
295 set_proxy ''
296 run
298 fetch /
299 check_reply "60 client certificate required" || return 1
302 test_unknown_host() {
303 setup_simple_test '' ''
305 ggflags="-N -H foobar"
306 fetch /
307 check_reply '59 Wrong/malformed host or missing SNI'
310 test_include_mime() {
311 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
313 fetch_hdr /
314 check_reply '20 text/gemini' || return 1
316 fetch_hdr /test.m3u8
317 check_reply '20 application/vnd.apple.mpegurl' || return 1
319 fetch_hdr /foo.1
320 check_reply '20 text/x-mandoc' || return 1