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 '' 'cgi "*"'
99 check_reply "20 text/gemini" "# hello world" || return 1
102 check_reply "20 text/gemini" "# hello world" || return 1
105 check_reply "42 CGI error" || return 1
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
135 n="$(get "$url" | awk /^-/ | count)"
136 if [ $? -ne 0 ]; then
137 echo "failed to get /$url"
141 if [ "$n" -ne $exp ]; then
142 echo "Unexpected number of args"
150 test_custom_index() {
151 setup_simple_test '' 'index "foo.gmi"'
154 check_reply "20 text/gemini" "# hello world"
157 test_custom_index_default_type_per_location() {
158 setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
161 check_reply "20 text/plain" "$(cat hello)"
165 setup_simple_test '' 'location "/dir/*" { auto index on }'
168 check_reply "20 text/gemini" "# hello world" || return 1
171 check_reply "30 /dir/" || return 1
174 check_reply "20 text/gemini" || return 1
176 get /dir/ > listing || return 1
177 cat <<EOF > listing.expected
186 cmp -s listing.expected listing
188 if [ $ret -ne 0 ]; then
189 echo 'unexpected dir content:'
190 diff -u listing.expected listing
192 rm listing listing.expected
198 setup_simple_test '' 'location "*" { block }'
201 check_reply "40 temporary failure" || return 1
204 check_reply "40 temporary failure" || return 1
207 test_block_return_fmt() {
208 setup_simple_test '' '
211 block return 40 "%% %p %q %P %N test"
215 block return 40 "%% %p %q %P %N test"
218 fetch_hdr /dir/foo.gmi
219 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
222 check_reply "40 % / 10965 localhost test" || return 1
226 setup_simple_test '' 'entrypoint "/env"'
229 check_reply "20 text/plain; lang=en" || return 1
231 # TODO: test something similar with plain cgi too
233 body="$(get /foo/bar|grep PATH_INFO)"
234 if [ $? -ne 0 ]; then
235 echo "failed to get /foo/bar"
239 if [ "$body" != "PATH_INFO=/foo/bar" ]; then
240 echo "Invalid PATH_INFO generated"
241 echo "want : PATH_INFO=/foo/bar"
247 test_require_client_ca() {
248 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
251 check_reply "60 client certificate required" || return 1
253 ggflags="-C valid.crt -K valid.key"
255 check_reply "20 text/gemini" || return 1
257 ggflags="-C invalid.cert.pem -K invalid.key.pem"
259 check_reply "61 certificate not authorised" || return 1
262 test_root_inside_location() {
263 setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
266 check_reply "51 not found" || return 1
269 check_reply "20 text/gemini"
272 test_root_inside_location_with_redirect() {
273 setup_simple_test '' '
274 location "/foo" { block return 31 "%p/" }
275 location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
278 check_reply "31 /foo/" || return 1
281 check_reply "20 text/gemini"
285 # XXX: prefork 1 for testing
286 setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
289 check_reply "20 text/gemini" "# Hello, world!"
292 test_macro_expansion() {
298 # the quoting of \$ is for sh
299 cert \$pwd "/cert.pem"
301 root \$pwd "/testdata"
306 echo "failed to parse the config"
313 check_reply "20 text/gemini" "# hello world"
316 # 1.7.4 bugfix: check_for_cgi goes out-of-bound processing a string
317 # that doesn't contain a '/'
319 setup_simple_test '' 'cgi "*"'
322 for i in 0 1 2 3 4 5 6 7 8 9; do
324 check_reply "51 not found" || return 1
328 test_proxy_relay_to() {
334 ggflags="-P localhost:$port -H localhost.local"
337 check_reply "20 text/gemini" "# hello world"
340 test_proxy_with_certs() {
341 ggflags="-P localhost:$port -H localhost.local"
343 # first test using the valid keys
345 gen_config '' 'require client ca "'$PWD'/testca.pem"'
347 cert \"$PWD/valid.crt\"
348 key \"$PWD/valid.key\"
353 check_reply "20 text/gemini" "# hello world" || return 1
355 # then using some invalid keys
357 gen_config '' 'require client ca "'$PWD'/testca.pem"'
359 cert \"$PWD/invalid.cert.pem\"
360 key \"$PWD/invalid.key.pem\"
365 check_reply "61 certificate not authorised" || return 1
367 # and finally without keys
369 gen_config '' 'require client ca "'$PWD'/testca.pem"'
374 check_reply "60 client certificate required" || return 1
377 test_unknown_host() {
378 setup_simple_test '' ''
380 ggflags="-N -H foobar"
382 check_reply '59 Wrong/malformed host or missing SNI'
385 test_include_mime() {
386 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
389 check_reply '20 text/gemini' || return 1
392 check_reply '20 application/vnd.apple.mpegurl' || return 1
395 check_reply '20 text/x-mandoc' || return 1