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_configless_mode() {
12 dont_check_server_alive=yes
14 $gmid -p $port -H localhost -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_cgi_scripts() {
96 setup_simple_test '' 'cgi "*"'
98 fetch /hello
99 check_reply "20 text/gemini" "# hello world" || return 1
101 fetch /slow
102 check_reply "20 text/gemini" "# hello world" || return 1
104 fetch /err
105 check_reply "42 CGI error" || return 1
107 fetch /invalid
108 check_reply "42 CGI error" || return 1
111 test_cgi_big_replies() {
112 setup_simple_test '' 'cgi "*"'
114 hdr="$(head /serve-bigfile)"
115 get /bigfile > bigfile
116 ./sha bigfile bigfile.sha
117 body="$(cat bigfile.sha)"
118 check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
121 test_cgi_split_query() {
122 setup_simple_test '' 'cgi "*"'
124 for s in "1" "2 ?foo" "3 ?foo+bar" "1 ?foo+bar=5" "3 ?foo+bar%3d5"; do
125 exp="$(echo $s | sed 's/ .*//')"
126 qry="$(echo $s | sed 's/^..//')"
128 if [ "$exp" = "$qry" ]; then
129 # the "1" case yields exp == qry
130 qry=''
131 fi
133 url="/env$qry"
135 n="$(get "$url" | awk /^-/ | count)"
136 if [ $? -ne 0 ]; then
137 echo "failed to get /$url"
138 return 1
139 fi
141 if [ "$n" -ne $exp ]; then
142 echo "Unexpected number of args"
143 echo "want : $exp"
144 echo "got : $n"
145 return 1
146 fi
147 done
150 test_custom_index() {
151 setup_simple_test '' 'index "foo.gmi"'
153 fetch /dir/
154 check_reply "20 text/gemini" "# hello world"
157 test_custom_index_default_type_per_location() {
158 setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
160 fetch /dir/
161 check_reply "20 text/plain" "$(cat hello)"
164 test_auto_index() {
165 setup_simple_test '' 'location "/dir/*" { auto index on }'
167 fetch /
168 check_reply "20 text/gemini" "# hello world" || return 1
170 fetch_hdr /dir
171 check_reply "30 /dir/" || return 1
173 fetch_hdr /dir/
174 check_reply "20 text/gemini"
176 # we expect 5 lines from the auto index
178 body="$(get /dir/ | count)"
179 if [ $? -ne 0 ]; then
180 echo 'failed to get /dir/'
181 return 1
182 fi
184 if [ "$body" -ne 5 ]; then
185 echo "expected five lines from the auto index, got $body"
186 return 1
187 fi
190 test_block() {
191 setup_simple_test '' 'location "*" { block }'
193 fetch /
194 check_reply "40 temporary failure" || return 1
196 fetch /nonexists
197 check_reply "40 temporary failure" || return 1
200 test_block_return_fmt() {
201 setup_simple_test '' '
202 location "/dir" {
203 strip 1
204 block return 40 "%% %p %q %P %N test"
206 location "*" {
207 strip 99
208 block return 40 "%% %p %q %P %N test"
209 }'
211 fetch_hdr /dir/foo.gmi
212 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
214 fetch_hdr /bigfile
215 check_reply "40 % / 10965 localhost test" || return 1
218 test_entrypoint() {
219 setup_simple_test '' 'entrypoint "/env"'
221 fetch_hdr /foo/bar
222 check_reply "20 text/plain; lang=en" || return 1
224 # TODO: test something similar with plain cgi too
226 body="$(get /foo/bar|grep PATH_INFO)"
227 if [ $? -ne 0 ]; then
228 echo "failed to get /foo/bar"
229 return 1
230 fi
232 if [ "$body" != "PATH_INFO=/foo/bar" ]; then
233 echo "Invalid PATH_INFO generated"
234 echo "want : PATH_INFO=/foo/bar"
235 echo "got : $body"
236 return 1
237 fi
240 test_require_client_ca() {
241 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
243 fetch /
244 check_reply "60 client certificate required" || return 1
246 ggflags="-C valid.crt -K valid.key"
247 fetch_hdr /
248 check_reply "20 text/gemini" || return 1
250 ggflags="-C invalid.cert.pem -K invalid.key.pem"
251 fetch_hdr /
252 check_reply "61 certificate not authorised" || return 1
255 test_root_inside_location() {
256 setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
258 fetch /foo
259 check_reply "51 not found" || return 1
261 fetch_hdr /foo/
262 check_reply "20 text/gemini"
265 test_root_inside_location_with_redirect() {
266 setup_simple_test '' '
267 location "/foo" { block return 31 "%p/" }
268 location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
270 fetch /foo
271 check_reply "31 /foo/" || return 1
273 fetch_hdr /foo/
274 check_reply "20 text/gemini"
277 test_fastcgi() {
278 # XXX: prefork 1 for testing
279 setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
281 fetch /
282 check_reply "20 text/gemini" "# Hello, world!"
285 test_macro_expansion() {
286 cat <<EOF > reg.conf
287 pwd = "$PWD"
288 $config_common
290 server "localhost" {
291 # the quoting of \$ is for sh
292 cert \$pwd "/cert.pem"
293 key \$pwd "/key.pem"
294 root \$pwd "/testdata"
296 EOF
298 if ! checkconf; then
299 echo "failed to parse the config"
300 return 1
301 fi
303 run
305 fetch /
306 check_reply "20 text/gemini" "# hello world"
309 # 1.7.4 bugfix: check_for_cgi goes out-of-bound processing a string
310 # that doesn't contain a '/'
311 test_174_bugfix() {
312 setup_simple_test '' 'cgi "*"'
314 # thanks cage :)
315 for i in 0 1 2 3 4 5 6 7 8 9; do
316 fetch /favicon.txt
317 check_reply "51 not found" || return 1
318 done
321 test_proxy_relay_to() {
322 gen_config '' ''
323 set_proxy ''
325 run
327 ggflags="-P localhost:$port -H localhost.local"
329 fetch /
330 check_reply "20 text/gemini" "# hello world"
333 test_proxy_with_certs() {
334 ggflags="-P localhost:$port -H localhost.local"
336 # first test using the valid keys
338 gen_config '' 'require client ca "'$PWD'/testca.pem"'
339 set_proxy "
340 cert \"$PWD/valid.crt\"
341 key \"$PWD/valid.key\"
343 run
345 fetch /
346 check_reply "20 text/gemini" "# hello world" || return 1
348 # then using some invalid keys
350 gen_config '' 'require client ca "'$PWD'/testca.pem"'
351 set_proxy "
352 cert \"$PWD/invalid.cert.pem\"
353 key \"$PWD/invalid.key.pem\"
355 run
357 fetch /
358 check_reply "61 certificate not authorised" || return 1
360 # and finally without keys
362 gen_config '' 'require client ca "'$PWD'/testca.pem"'
363 set_proxy ''
364 run
366 fetch /
367 check_reply "60 client certificate required" || return 1
370 test_unknown_host() {
371 setup_simple_test '' ''
373 ggflags="-N -H foobar"
374 fetch /
375 check_reply '59 Wrong/malformed host or missing SNI'
378 test_include_mime() {
379 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
381 fetch_hdr /
382 check_reply '20 text/gemini' || return 1
384 fetch_hdr /test.m3u8
385 check_reply '20 application/vnd.apple.mpegurl' || return 1
387 fetch_hdr /foo.1
388 check_reply '20 text/x-mandoc' || return 1