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" || return 1
176 get /dir/ > listing || return 1
177 cat <<EOF > listing.expected
178 # Index of /dir/
180 => ./../
181 => ./current%20date
182 => ./foo.gmi
183 => ./hello
184 EOF
186 cmp -s listing.expected listing
187 ret=$?
188 if [ $ret -ne 0 ]; then
189 echo 'unexpected dir content:'
190 diff -u listing.expected listing
191 fi
192 rm listing listing.expected
194 return $ret
197 test_block() {
198 setup_simple_test '' 'location "*" { block }'
200 fetch /
201 check_reply "40 temporary failure" || return 1
203 fetch /nonexists
204 check_reply "40 temporary failure" || return 1
207 test_block_return_fmt() {
208 setup_simple_test '' '
209 location "/dir" {
210 strip 1
211 block return 40 "%% %p %q %P %N test"
213 location "*" {
214 strip 99
215 block return 40 "%% %p %q %P %N test"
216 }'
218 fetch_hdr /dir/foo.gmi
219 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
221 fetch_hdr /bigfile
222 check_reply "40 % / 10965 localhost test" || return 1
225 test_entrypoint() {
226 setup_simple_test '' 'entrypoint "/env"'
228 fetch_hdr /foo/bar
229 check_reply "20 text/plain; lang=en" || return 1
231 # TODO: test something similar with plain cgi too
233 body="$(get /foo/bar|grep PATH_INFO)"
234 if [ $? -ne 0 ]; then
235 echo "failed to get /foo/bar"
236 return 1
237 fi
239 if [ "$body" != "PATH_INFO=/foo/bar" ]; then
240 echo "Invalid PATH_INFO generated"
241 echo "want : PATH_INFO=/foo/bar"
242 echo "got : $body"
243 return 1
244 fi
247 test_require_client_ca() {
248 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
250 fetch /
251 check_reply "60 client certificate required" || return 1
253 ggflags="-C valid.crt -K valid.key"
254 fetch_hdr /
255 check_reply "20 text/gemini" || return 1
257 ggflags="-C invalid.cert.pem -K invalid.key.pem"
258 fetch_hdr /
259 check_reply "61 certificate not authorised" || return 1
262 test_root_inside_location() {
263 setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
265 fetch /foo
266 check_reply "51 not found" || return 1
268 fetch_hdr /foo/
269 check_reply "20 text/gemini"
272 test_root_inside_location_with_redirect() {
273 setup_simple_test '' '
274 location "/foo" { block return 31 "%p/" }
275 location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
277 fetch /foo
278 check_reply "31 /foo/" || return 1
280 fetch_hdr /foo/
281 check_reply "20 text/gemini"
284 test_fastcgi() {
285 # XXX: prefork 1 for testing
286 setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
288 fetch /
289 check_reply "20 text/gemini" "# Hello, world!"
292 test_macro_expansion() {
293 cat <<EOF > reg.conf
294 pwd = "$PWD"
295 $config_common
297 server "localhost" {
298 # the quoting of \$ is for sh
299 cert \$pwd "/cert.pem"
300 key \$pwd "/key.pem"
301 root \$pwd "/testdata"
303 EOF
305 if ! checkconf; then
306 echo "failed to parse the config"
307 return 1
308 fi
310 run
312 fetch /
313 check_reply "20 text/gemini" "# hello world"
316 # 1.7.4 bugfix: check_for_cgi goes out-of-bound processing a string
317 # that doesn't contain a '/'
318 test_174_bugfix() {
319 setup_simple_test '' 'cgi "*"'
321 # thanks cage :)
322 for i in 0 1 2 3 4 5 6 7 8 9; do
323 fetch /favicon.txt
324 check_reply "51 not found" || return 1
325 done
328 test_proxy_relay_to() {
329 gen_config '' ''
330 set_proxy ''
332 run
334 ggflags="-P localhost:$port -H localhost.local"
336 fetch /
337 check_reply "20 text/gemini" "# hello world"
340 test_proxy_with_certs() {
341 ggflags="-P localhost:$port -H localhost.local"
343 # first test using the valid keys
345 gen_config '' 'require client ca "'$PWD'/testca.pem"'
346 set_proxy "
347 cert \"$PWD/valid.crt\"
348 key \"$PWD/valid.key\"
350 run
352 fetch /
353 check_reply "20 text/gemini" "# hello world" || return 1
355 # then using some invalid keys
357 gen_config '' 'require client ca "'$PWD'/testca.pem"'
358 set_proxy "
359 cert \"$PWD/invalid.cert.pem\"
360 key \"$PWD/invalid.key.pem\"
362 run
364 fetch /
365 check_reply "61 certificate not authorised" || return 1
367 # and finally without keys
369 gen_config '' 'require client ca "'$PWD'/testca.pem"'
370 set_proxy ''
371 run
373 fetch /
374 check_reply "60 client certificate required" || return 1
377 test_unknown_host() {
378 setup_simple_test '' ''
380 ggflags="-N -H foobar"
381 fetch /
382 check_reply '59 Wrong/malformed host or missing SNI'
385 test_include_mime() {
386 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
388 fetch_hdr /
389 check_reply '20 text/gemini' || return 1
391 fetch_hdr /test.m3u8
392 check_reply '20 application/vnd.apple.mpegurl' || return 1
394 fetch_hdr /foo.1
395 check_reply '20 text/x-mandoc' || return 1