2 dont_check_server_alive=yes
7 dont_check_server_alive=yes
12 dont_check_server_alive=yes
21 cert "$PWD/localhost.pem"
22 key "$PWD/localhost.key"
26 $gmid -nn -c reg.conf > $got 2>/dev/null
29 if ! cmp -s "$exp" "$got"; then
30 echo "config differs!" >&2
31 diff -u "$exp" "$got" >&2
40 dont_check_server_alive=yes
42 $gemexp -p $port -d . testdata &
48 check_reply "20 text/gemini" "# hello world" || return 1
55 check_reply "20 text/gemini" "# hello world" || return 1
58 check_reply "51 not found" || return 1
61 check_reply "20 text/gemini" "# hello world" || return 1
64 test_directory_redirect() {
68 check_reply "30 /dir/" || return 1
71 check_reply "51 not found" || return 1
74 test_serve_big_files() {
77 hdr="$(head /bigfile)"
78 get /bigfile > bigfile
80 want="20 application/octet-stream"
81 if [ "$hdr" != "$want" ]; then
82 echo "Header mismatch" >&2
83 echo "wants : $want" >&2
88 if ! cmp -s bigfile testdata/bigfile; then
89 echo "received bigfile is not as expected"
90 cmp bigfile testdata/bigfile
95 test_dont_execute_scripts() {
99 check_reply "20 application/octet-stream" "" || return 1
110 check_reply "20 text/x-funny"
113 test_default_type() {
114 setup_simple_test '' 'default type "application/x-foo"'
117 check_reply "20 application/x-foo"
121 setup_simple_test '' 'lang it'
124 check_reply "20 text/gemini;lang=it"
127 test_parse_custom_lang_per_location() {
128 setup_simple_test '' \
129 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
130 # can parse multiple locations
133 test_custom_index() {
134 setup_simple_test '' 'index "foo.gmi"'
137 check_reply "20 text/gemini" "# hello world"
140 test_custom_index_default_type_per_location() {
141 setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
144 check_reply "20 text/plain" "$(cat hello)"
148 setup_simple_test '' 'location "/dir/*" { auto index on }'
151 check_reply "20 text/gemini" "# hello world" || return 1
154 check_reply "30 /dir/" || return 1
157 check_reply "20 text/gemini" || return 1
159 get /dir/ > listing || return 1
160 cat <<EOF > listing.expected
169 cmp -s listing.expected listing
171 if [ $ret -ne 0 ]; then
172 echo 'unexpected dir content:'
173 diff -u listing.expected listing
175 rm listing listing.expected
181 setup_simple_test '' 'location "*" { block }'
184 check_reply "40 temporary failure" || return 1
187 check_reply "40 temporary failure" || return 1
190 test_block_return_fmt() {
191 setup_simple_test '' '
194 block return 40 "%% %p %q %P %N test"
198 block return 40 "%% %p %q %P %N test"
201 fetch_hdr /dir/foo.gmi
202 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
205 check_reply "40 % / 10965 localhost test" || return 1
208 test_require_client_ca() {
209 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
212 check_reply "60 client certificate required" || return 1
214 ggflags="-C valid.crt -K valid.key"
216 check_reply "20 text/gemini" || return 1
218 ggflags="-C invalid.pem -K invalid.key"
220 check_reply "61 certificate not authorised" || return 1
223 test_root_inside_location() {
224 setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
227 check_reply "51 not found" || return 1
230 check_reply "20 text/gemini"
233 test_root_inside_location_with_redirect() {
234 setup_simple_test '' '
235 location "/foo" { block return 31 "%p/" }
236 location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
239 check_reply "31 /foo/" || return 1
242 check_reply "20 text/gemini"
246 ./fcgi-test fcgi.sock &
249 setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"'
251 msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
254 while [ $i -lt 10 ]; do
256 check_reply "20 text/gemini" "$msg"
257 if [ $? -ne 0 ]; then
269 test_fastcgi_inside_location() {
270 ./fcgi-test fcgi.sock &
273 setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"
278 msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
280 if ! check_reply "20 text/gemini" "$msg"; then
286 if ! check_reply "20 text/gemini" "# hello world"; then
295 test_fastcgi_deprecated_syntax() {
296 ./fcgi-test fcgi.sock &
299 # the old syntax will eventually go away, but check that the
300 # backward compatibility works.
301 setup_simple_test 'prefork 1' 'fastcgi "'$PWD'/fcgi.sock"'
303 msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
305 check_reply "20 text/gemini" "$msg"
306 if [ $? -ne 0 ]; then
315 test_macro_expansion() {
318 common = "lang it; auto index on"
321 # the quoting of \$ is for sh
322 cert \$pwd "/localhost.pem"
323 key \$pwd "/localhost.key"
324 root \$pwd "/testdata"
325 listen on $REGRESS_HOST port $port
331 echo "failed to parse the config"
338 check_reply "20 text/gemini;lang=it" "# hello world"
341 test_proxy_relay_to() {
347 ggflags="-P localhost:$port -H localhost.local"
350 check_reply "20 text/gemini" "# hello world"
353 test_proxy_with_certs() {
354 ggflags="-P localhost:$port -H localhost.local"
356 # first test using the valid keys
358 gen_config '' 'require client ca "'$PWD'/testca.pem"'
360 cert \"$PWD/valid.crt\"
361 key \"$PWD/valid.key\"
366 check_reply "20 text/gemini" "# hello world" || return 1
368 # then using some invalid keys
370 gen_config '' 'require client ca "'$PWD'/testca.pem"'
372 cert \"$PWD/invalid.pem\"
373 key \"$PWD/invalid.key\"
378 check_reply "61 certificate not authorised" || return 1
380 # and finally without keys
382 gen_config '' 'require client ca "'$PWD'/testca.pem"'
387 check_reply "60 client certificate required" || return 1
390 test_unknown_host() {
391 setup_simple_test '' ''
393 ggflags="-N -H foobar"
395 check_reply '59 Wrong/malformed host or missing SNI'
398 test_include_mime() {
399 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
402 check_reply '20 text/gemini' || return 1
405 check_reply '20 application/vnd.apple.mpegurl' || return 1
408 check_reply '20 text/x-mandoc' || return 1
414 log access "'$PWD'/log"
418 check_reply '20 text/gemini'
421 awk '{$1 = ""; print substr($0, 2)}' log > log.edited
423 printf '%s\n' 'GET gemini://localhost/ 20 text/gemini' \
424 | cmp -s - log.edited
425 if [ $? -ne 0 ]; then
426 # keep the log for post-mortem analysis