2 dont_check_server_alive=yes
7 dont_check_server_alive=yes
11 test_configless_mode() {
12 dont_check_server_alive=yes
14 $gmid -p $port -H localhost -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
51 ./sha bigfile bigfile.sha
52 body="$(cat bigfile.sha)"
54 check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
57 test_dont_execute_scripts() {
61 check_reply "20 application/octet-stream" "" || return 1
72 check_reply "20 text/x-funny"
76 setup_simple_test '' 'default type "application/x-foo"'
79 check_reply "20 application/x-foo"
83 setup_simple_test '' 'lang it'
86 check_reply "20 text/gemini;lang=it"
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
96 setup_simple_test '' 'index "foo.gmi"'
99 check_reply "20 text/gemini" "# hello world"
102 test_custom_index_default_type_per_location() {
103 setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
106 check_reply "20 text/plain" "$(cat hello)"
110 setup_simple_test '' 'location "/dir/*" { auto index on }'
113 check_reply "20 text/gemini" "# hello world" || return 1
116 check_reply "30 /dir/" || return 1
119 check_reply "20 text/gemini" || return 1
121 get /dir/ > listing || return 1
122 cat <<EOF > listing.expected
131 cmp -s listing.expected listing
133 if [ $ret -ne 0 ]; then
134 echo 'unexpected dir content:'
135 diff -u listing.expected listing
137 rm listing listing.expected
143 setup_simple_test '' 'location "*" { block }'
146 check_reply "40 temporary failure" || return 1
149 check_reply "40 temporary failure" || return 1
152 test_block_return_fmt() {
153 setup_simple_test '' '
156 block return 40 "%% %p %q %P %N test"
160 block return 40 "%% %p %q %P %N test"
163 fetch_hdr /dir/foo.gmi
164 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
167 check_reply "40 % / 10965 localhost test" || return 1
170 test_require_client_ca() {
171 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
174 check_reply "60 client certificate required" || return 1
176 ggflags="-C valid.crt -K valid.key"
178 check_reply "20 text/gemini" || return 1
180 ggflags="-C invalid.cert.pem -K invalid.key.pem"
182 check_reply "61 certificate not authorised" || return 1
185 test_root_inside_location() {
186 setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
189 check_reply "51 not found" || return 1
192 check_reply "20 text/gemini"
195 test_root_inside_location_with_redirect() {
196 setup_simple_test '' '
197 location "/foo" { block return 31 "%p/" }
198 location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
201 check_reply "31 /foo/" || return 1
204 check_reply "20 text/gemini"
208 # XXX: prefork 1 for testing
209 setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
212 check_reply "20 text/gemini" "# Hello, world!"
215 test_macro_expansion() {
221 # the quoting of \$ is for sh
222 cert \$pwd "/cert.pem"
224 root \$pwd "/testdata"
229 echo "failed to parse the config"
236 check_reply "20 text/gemini" "# hello world"
239 test_proxy_relay_to() {
245 ggflags="-P localhost:$port -H localhost.local"
248 check_reply "20 text/gemini" "# hello world"
251 test_proxy_with_certs() {
252 ggflags="-P localhost:$port -H localhost.local"
254 # first test using the valid keys
256 gen_config '' 'require client ca "'$PWD'/testca.pem"'
258 cert \"$PWD/valid.crt\"
259 key \"$PWD/valid.key\"
264 check_reply "20 text/gemini" "# hello world" || return 1
266 # then using some invalid keys
268 gen_config '' 'require client ca "'$PWD'/testca.pem"'
270 cert \"$PWD/invalid.cert.pem\"
271 key \"$PWD/invalid.key.pem\"
276 check_reply "61 certificate not authorised" || return 1
278 # and finally without keys
280 gen_config '' 'require client ca "'$PWD'/testca.pem"'
285 check_reply "60 client certificate required" || return 1
288 test_unknown_host() {
289 setup_simple_test '' ''
291 ggflags="-N -H foobar"
293 check_reply '59 Wrong/malformed host or missing SNI'
296 test_include_mime() {
297 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
300 check_reply '20 text/gemini' || return 1
303 check_reply '20 application/vnd.apple.mpegurl' || return 1
306 check_reply '20 text/x-mandoc' || return 1