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_gemexp() {
12 dont_check_server_alive=yes
14 $gemexp -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
52 want="20 application/octet-stream"
53 if [ "$hdr" != "$want" ]; then
54 echo "Header mismatch" >&2
55 echo "wants : $want" >&2
56 echo "got : $hdr" >&2
57 return 1
58 fi
60 if ! cmp -s bigfile testdata/bigfile; then
61 echo "received bigfile is not as expected"
62 cmp bigfile testdata/bigfile
63 return 1
64 fi
65 }
67 test_dont_execute_scripts() {
68 setup_simple_test
70 fetch_hdr /hello
71 check_reply "20 application/octet-stream" "" || return 1
72 }
74 test_custom_mime() {
75 setup_simple_test '
76 types {
77 text/x-funny gmi
78 }
79 ' ''
81 fetch_hdr /
82 check_reply "20 text/x-funny"
83 }
85 test_default_type() {
86 setup_simple_test '' 'default type "application/x-foo"'
88 fetch_hdr /hello
89 check_reply "20 application/x-foo"
90 }
92 test_custom_lang() {
93 setup_simple_test '' 'lang it'
95 fetch_hdr /
96 check_reply "20 text/gemini;lang=it"
97 }
99 test_parse_custom_lang_per_location() {
100 setup_simple_test '' \
101 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
102 # can parse multiple locations
105 test_custom_index() {
106 setup_simple_test '' 'index "foo.gmi"'
108 fetch /dir/
109 check_reply "20 text/gemini" "# hello world"
112 test_custom_index_default_type_per_location() {
113 setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
115 fetch /dir/
116 check_reply "20 text/plain" "$(cat hello)"
119 test_auto_index() {
120 setup_simple_test '' 'location "/dir/*" { auto index on }'
122 fetch /
123 check_reply "20 text/gemini" "# hello world" || return 1
125 fetch_hdr /dir
126 check_reply "30 /dir/" || return 1
128 fetch_hdr /dir/
129 check_reply "20 text/gemini" || return 1
131 get /dir/ > listing || return 1
132 cat <<EOF > listing.expected
133 # Index of /dir/
135 => ./../
136 => ./current%20date
137 => ./foo.gmi
138 => ./hello
139 EOF
141 cmp -s listing.expected listing
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 echo 'unexpected dir content:'
145 diff -u listing.expected listing
146 fi
147 rm listing listing.expected
149 return $ret
152 test_block() {
153 setup_simple_test '' 'location "*" { block }'
155 fetch /
156 check_reply "40 temporary failure" || return 1
158 fetch /nonexists
159 check_reply "40 temporary failure" || return 1
162 test_block_return_fmt() {
163 setup_simple_test '' '
164 location "/dir" {
165 strip 1
166 block return 40 "%% %p %q %P %N test"
168 location "*" {
169 strip 99
170 block return 40 "%% %p %q %P %N test"
171 }'
173 fetch_hdr /dir/foo.gmi
174 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
176 fetch_hdr /bigfile
177 check_reply "40 % / 10965 localhost test" || return 1
180 test_require_client_ca() {
181 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
183 fetch /
184 check_reply "60 client certificate required" || return 1
186 ggflags="-C valid.crt -K valid.key"
187 fetch_hdr /
188 check_reply "20 text/gemini" || return 1
190 ggflags="-C invalid.pem -K invalid.key"
191 fetch_hdr /
192 check_reply "61 certificate not authorised" || return 1
195 test_root_inside_location() {
196 setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
198 fetch /foo
199 check_reply "51 not found" || return 1
201 fetch_hdr /foo/
202 check_reply "20 text/gemini"
205 test_root_inside_location_with_redirect() {
206 setup_simple_test '' '
207 location "/foo" { block return 31 "%p/" }
208 location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
210 fetch /foo
211 check_reply "31 /foo/" || return 1
213 fetch_hdr /foo/
214 check_reply "20 text/gemini"
217 test_fastcgi() {
218 ./fcgi-test fcgi.sock &
219 fcgi_pid=$!
221 setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"'
223 msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
225 i=0
226 while [ $i -lt 10 ]; do
227 fetch /
228 check_reply "20 text/gemini" "$msg"
229 if [ $? -ne 0 ]; then
230 kill $fcgi_pid
231 return 1
232 fi
234 i=$(($i + 1))
235 done
237 kill $fcgi_pid
238 return 0
241 test_fastcgi_inside_location() {
242 ./fcgi-test fcgi.sock &
243 fcgi_pid=$!
245 setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"
246 location "/dir/*" {
247 fastcgi off
248 }'
250 msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
251 fetch /foo
252 if ! check_reply "20 text/gemini" "$msg"; then
253 kill $fcgi_pid
254 return 1
255 fi
257 fetch /dir/foo.gmi
258 if ! check_reply "20 text/gemini" "# hello world"; then
259 kill $fcgi_pid
260 return 1
261 fi
263 kill $fcgi_pid
264 return 0
267 test_fastcgi_deprecated_syntax() {
268 ./fcgi-test fcgi.sock &
269 fcgi_pid=$!
271 # the old syntax will eventually go away, but check that the
272 # backward compatibility works.
273 setup_simple_test 'prefork 1' 'fastcgi "'$PWD'/fcgi.sock"'
275 msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
276 fetch /
277 check_reply "20 text/gemini" "$msg"
278 if [ $? -ne 0 ]; then
279 kill $fcgi_pid
280 return 1
281 fi
283 kill $fcgi_pid
284 return 0
287 test_macro_expansion() {
288 cat <<EOF > reg.conf
289 pwd = "$PWD"
290 common = "lang it; auto index on"
292 server "localhost" {
293 # the quoting of \$ is for sh
294 cert \$pwd "/localhost.pem"
295 key \$pwd "/localhost.key"
296 root \$pwd "/testdata"
297 listen on $REGRESS_HOST port $port
298 @common
300 EOF
302 if ! checkconf; then
303 echo "failed to parse the config"
304 return 1
305 fi
307 run
309 fetch /
310 check_reply "20 text/gemini;lang=it" "# hello world"
313 test_proxy_relay_to() {
314 gen_config '' ''
315 set_proxy ''
317 run
319 ggflags="-P localhost:$port -H localhost.local"
321 fetch /
322 check_reply "20 text/gemini" "# hello world"
325 test_proxy_with_certs() {
326 ggflags="-P localhost:$port -H localhost.local"
328 # first test using the valid keys
330 gen_config '' 'require client ca "'$PWD'/testca.pem"'
331 set_proxy "
332 cert \"$PWD/valid.crt\"
333 key \"$PWD/valid.key\"
335 run
337 fetch /
338 check_reply "20 text/gemini" "# hello world" || return 1
340 # then using some invalid keys
342 gen_config '' 'require client ca "'$PWD'/testca.pem"'
343 set_proxy "
344 cert \"$PWD/invalid.pem\"
345 key \"$PWD/invalid.key\"
347 run
349 fetch /
350 check_reply "61 certificate not authorised" || return 1
352 # and finally without keys
354 gen_config '' 'require client ca "'$PWD'/testca.pem"'
355 set_proxy ''
356 run
358 fetch /
359 check_reply "60 client certificate required" || return 1
362 test_unknown_host() {
363 setup_simple_test '' ''
365 ggflags="-N -H foobar"
366 fetch /
367 check_reply '59 Wrong/malformed host or missing SNI'
370 test_include_mime() {
371 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
373 fetch_hdr /
374 check_reply '20 text/gemini' || return 1
376 fetch_hdr /test.m3u8
377 check_reply '20 application/vnd.apple.mpegurl' || return 1
379 fetch_hdr /foo.1
380 check_reply '20 text/x-mandoc' || return 1
383 test_log_file() {
384 rm -f log log.edited
385 setup_simple_test '
386 log access "'$PWD'/log"
387 log style legacy'
389 fetch_hdr /
390 check_reply '20 text/gemini'
392 # remove the ip
393 awk '{$1 = ""; print substr($0, 2)}' log > log.edited
395 printf '%s\n' 'GET gemini://localhost/ 20 text/gemini' \
396 | cmp -s - log.edited
397 if [ $? -ne 0 ]; then
398 # keep the log for post-mortem analysis
399 return 1
400 fi
402 rm -f log log.edited
403 return 0