2 dont_check_server_alive=yes
7 dont_check_server_alive=yes
12 dont_check_server_alive=yes
14 $gemexp -p $port -d . testdata &
20 check_reply "20 text/gemini" "# hello world" || return 1
27 check_reply "20 text/gemini" "# hello world" || return 1
30 check_reply "51 not found" || return 1
33 check_reply "20 text/gemini" "# hello world" || return 1
36 test_directory_redirect() {
40 check_reply "30 /dir/" || return 1
43 check_reply "51 not found" || return 1
46 test_serve_big_files() {
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
60 if ! cmp -s bigfile testdata/bigfile; then
61 echo "received bigfile is not as expected"
62 cmp bigfile testdata/bigfile
67 test_dont_execute_scripts() {
71 check_reply "20 application/octet-stream" "" || return 1
82 check_reply "20 text/x-funny"
86 setup_simple_test '' 'default type "application/x-foo"'
89 check_reply "20 application/x-foo"
93 setup_simple_test '' 'lang it'
96 check_reply "20 text/gemini;lang=it"
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"'
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" }'
116 check_reply "20 text/plain" "$(cat hello)"
120 setup_simple_test '' 'location "/dir/*" { auto index on }'
123 check_reply "20 text/gemini" "# hello world" || return 1
126 check_reply "30 /dir/" || return 1
129 check_reply "20 text/gemini" || return 1
131 get /dir/ > listing || return 1
132 cat <<EOF > listing.expected
141 cmp -s listing.expected listing
143 if [ $ret -ne 0 ]; then
144 echo 'unexpected dir content:'
145 diff -u listing.expected listing
147 rm listing listing.expected
153 setup_simple_test '' 'location "*" { block }'
156 check_reply "40 temporary failure" || return 1
159 check_reply "40 temporary failure" || return 1
162 test_block_return_fmt() {
163 setup_simple_test '' '
166 block return 40 "%% %p %q %P %N test"
170 block return 40 "%% %p %q %P %N test"
173 fetch_hdr /dir/foo.gmi
174 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
177 check_reply "40 % / 10965 localhost test" || return 1
180 test_require_client_ca() {
181 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
184 check_reply "60 client certificate required" || return 1
186 ggflags="-C valid.crt -K valid.key"
188 check_reply "20 text/gemini" || return 1
190 ggflags="-C invalid.pem -K invalid.key"
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 }'
199 check_reply "51 not found" || return 1
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 }'
211 check_reply "31 /foo/" || return 1
214 check_reply "20 text/gemini"
218 ./fcgi-test fcgi.sock &
221 setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"'
223 msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
226 while [ $i -lt 10 ]; do
228 check_reply "20 text/gemini" "$msg"
229 if [ $? -ne 0 ]; then
241 test_fastcgi_inside_location() {
242 ./fcgi-test fcgi.sock &
245 setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"
250 msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
252 if ! check_reply "20 text/gemini" "$msg"; then
258 if ! check_reply "20 text/gemini" "# hello world"; then
267 test_fastcgi_deprecated_syntax() {
268 ./fcgi-test fcgi.sock &
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...")
277 check_reply "20 text/gemini" "$msg"
278 if [ $? -ne 0 ]; then
287 test_macro_expansion() {
290 common = "lang it; auto index on"
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
303 echo "failed to parse the config"
310 check_reply "20 text/gemini;lang=it" "# hello world"
313 test_proxy_relay_to() {
319 ggflags="-P localhost:$port -H localhost.local"
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"'
332 cert \"$PWD/valid.crt\"
333 key \"$PWD/valid.key\"
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"'
344 cert \"$PWD/invalid.pem\"
345 key \"$PWD/invalid.key\"
350 check_reply "61 certificate not authorised" || return 1
352 # and finally without keys
354 gen_config '' 'require client ca "'$PWD'/testca.pem"'
359 check_reply "60 client certificate required" || return 1
362 test_unknown_host() {
363 setup_simple_test '' ''
365 ggflags="-N -H foobar"
367 check_reply '59 Wrong/malformed host or missing SNI'
370 test_include_mime() {
371 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
374 check_reply '20 text/gemini' || return 1
377 check_reply '20 application/vnd.apple.mpegurl' || return 1
380 check_reply '20 text/x-mandoc' || return 1
386 log access "'$PWD'/log"
390 check_reply '20 text/gemini'
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