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
149 if ! n="$(get "/env?foo+bar%3d5" | grep GEMINI_SEARCH_STRING)"; then
150 echo "failed to get /env"
151 return 1
152 fi
154 if [ "$n" != "GEMINI_SEARCH_STRING=foo bar=5" ]; then
155 echo "wrong value for GEMINI_SEARCH_STRING"
156 echo "want : foo bar=5"
157 echo "got : $n"
158 return 1
159 fi
162 test_custom_index() {
163 setup_simple_test '' 'index "foo.gmi"'
165 fetch /dir/
166 check_reply "20 text/gemini" "# hello world"
169 test_custom_index_default_type_per_location() {
170 setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
172 fetch /dir/
173 check_reply "20 text/plain" "$(cat hello)"
176 test_auto_index() {
177 setup_simple_test '' 'location "/dir/*" { auto index on }'
179 fetch /
180 check_reply "20 text/gemini" "# hello world" || return 1
182 fetch_hdr /dir
183 check_reply "30 /dir/" || return 1
185 fetch_hdr /dir/
186 check_reply "20 text/gemini" || return 1
188 get /dir/ > listing || return 1
189 cat <<EOF > listing.expected
190 # Index of /dir/
192 => ./../
193 => ./current%20date
194 => ./foo.gmi
195 => ./hello
196 EOF
198 cmp -s listing.expected listing
199 ret=$?
200 if [ $ret -ne 0 ]; then
201 echo 'unexpected dir content:'
202 diff -u listing.expected listing
203 fi
204 rm listing listing.expected
206 return $ret
209 test_block() {
210 setup_simple_test '' 'location "*" { block }'
212 fetch /
213 check_reply "40 temporary failure" || return 1
215 fetch /nonexists
216 check_reply "40 temporary failure" || return 1
219 test_block_return_fmt() {
220 setup_simple_test '' '
221 location "/dir" {
222 strip 1
223 block return 40 "%% %p %q %P %N test"
225 location "*" {
226 strip 99
227 block return 40 "%% %p %q %P %N test"
228 }'
230 fetch_hdr /dir/foo.gmi
231 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
233 fetch_hdr /bigfile
234 check_reply "40 % / 10965 localhost test" || return 1
237 test_entrypoint() {
238 setup_simple_test '' 'entrypoint "/env"'
240 fetch_hdr /foo/bar
241 check_reply "20 text/plain; lang=en" || return 1
243 # TODO: test something similar with plain cgi too
245 body="$(get /foo/bar|grep PATH_INFO)"
246 if [ $? -ne 0 ]; then
247 echo "failed to get /foo/bar"
248 return 1
249 fi
251 if [ "$body" != "PATH_INFO=/foo/bar" ]; then
252 echo "Invalid PATH_INFO generated"
253 echo "want : PATH_INFO=/foo/bar"
254 echo "got : $body"
255 return 1
256 fi
259 test_require_client_ca() {
260 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
262 fetch /
263 check_reply "60 client certificate required" || return 1
265 ggflags="-C valid.crt -K valid.key"
266 fetch_hdr /
267 check_reply "20 text/gemini" || return 1
269 ggflags="-C invalid.cert.pem -K invalid.key.pem"
270 fetch_hdr /
271 check_reply "61 certificate not authorised" || return 1
274 test_root_inside_location() {
275 setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
277 fetch /foo
278 check_reply "51 not found" || return 1
280 fetch_hdr /foo/
281 check_reply "20 text/gemini"
284 test_root_inside_location_with_redirect() {
285 setup_simple_test '' '
286 location "/foo" { block return 31 "%p/" }
287 location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
289 fetch /foo
290 check_reply "31 /foo/" || return 1
292 fetch_hdr /foo/
293 check_reply "20 text/gemini"
296 test_fastcgi() {
297 # XXX: prefork 1 for testing
298 setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
300 fetch /
301 check_reply "20 text/gemini" "# Hello, world!"
304 test_macro_expansion() {
305 cat <<EOF > reg.conf
306 pwd = "$PWD"
307 $config_common
309 server "localhost" {
310 # the quoting of \$ is for sh
311 cert \$pwd "/cert.pem"
312 key \$pwd "/key.pem"
313 root \$pwd "/testdata"
315 EOF
317 if ! checkconf; then
318 echo "failed to parse the config"
319 return 1
320 fi
322 run
324 fetch /
325 check_reply "20 text/gemini" "# hello world"
328 # 1.7.4 bugfix: check_for_cgi goes out-of-bound processing a string
329 # that doesn't contain a '/'
330 test_174_bugfix() {
331 setup_simple_test '' 'cgi "*"'
333 # thanks cage :)
334 for i in 0 1 2 3 4 5 6 7 8 9; do
335 fetch /favicon.txt
336 check_reply "51 not found" || return 1
337 done
340 test_proxy_relay_to() {
341 gen_config '' ''
342 set_proxy ''
344 run
346 ggflags="-P localhost:$port -H localhost.local"
348 fetch /
349 check_reply "20 text/gemini" "# hello world"
352 test_proxy_with_certs() {
353 ggflags="-P localhost:$port -H localhost.local"
355 # first test using the valid keys
357 gen_config '' 'require client ca "'$PWD'/testca.pem"'
358 set_proxy "
359 cert \"$PWD/valid.crt\"
360 key \"$PWD/valid.key\"
362 run
364 fetch /
365 check_reply "20 text/gemini" "# hello world" || return 1
367 # then using some invalid keys
369 gen_config '' 'require client ca "'$PWD'/testca.pem"'
370 set_proxy "
371 cert \"$PWD/invalid.cert.pem\"
372 key \"$PWD/invalid.key.pem\"
374 run
376 fetch /
377 check_reply "61 certificate not authorised" || return 1
379 # and finally without keys
381 gen_config '' 'require client ca "'$PWD'/testca.pem"'
382 set_proxy ''
383 run
385 fetch /
386 check_reply "60 client certificate required" || return 1
389 test_unknown_host() {
390 setup_simple_test '' ''
392 ggflags="-N -H foobar"
393 fetch /
394 check_reply '59 Wrong/malformed host or missing SNI'
397 test_include_mime() {
398 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
400 fetch_hdr /
401 check_reply '20 text/gemini' || return 1
403 fetch_hdr /test.m3u8
404 check_reply '20 application/vnd.apple.mpegurl' || return 1
406 fetch_hdr /foo.1
407 check_reply '20 text/x-mandoc' || return 1