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_configless_mode() {
12 dont_check_server_alive=yes
14 $gmid -p $port -H localhost -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
51 ./sha bigfile bigfile.sha
52 body="$(cat bigfile.sha)"
54 check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
55 }
57 test_dont_execute_scripts() {
58 setup_simple_test
60 fetch_hdr /hello
61 check_reply "20 application/octet-stream" "" || return 1
62 }
64 test_custom_mime() {
65 setup_simple_test 'map "text/x-funny" to-ext "gmi"' ''
67 fetch_hdr /
68 check_reply "20 text/x-funny"
69 }
71 test_default_type() {
72 setup_simple_test '' 'default type "application/x-foo"'
74 fetch_hdr /hello
75 check_reply "20 application/x-foo"
76 }
78 test_custom_lang() {
79 setup_simple_test '' 'lang it'
81 fetch_hdr /
82 check_reply "20 text/gemini;lang=it"
83 }
85 test_parse_custom_lang_per_location() {
86 setup_simple_test '' \
87 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
88 # can parse multiple locations
89 }
91 test_cgi_scripts() {
92 setup_simple_test '' 'cgi "*"'
94 fetch /hello
95 check_reply "20 text/gemini" "# hello world" || return 1
97 fetch /slow
98 check_reply "20 text/gemini" "# hello world" || return 1
100 fetch /err
101 check_reply "42 CGI error" || return 1
103 fetch /invalid
104 check_reply "42 CGI error" || return 1
107 test_cgi_big_replies() {
108 setup_simple_test '' 'cgi "*"'
110 hdr="$(head /serve-bigfile)"
111 get /bigfile > bigfile
112 ./sha bigfile bigfile.sha
113 body="$(cat bigfile.sha)"
114 check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
117 test_cgi_split_query() {
118 setup_simple_test '' 'cgi "*"'
120 for s in "1" "2 ?foo" "3 ?foo+bar" "1 ?foo+bar=5" "3 ?foo+bar%3d5"; do
121 exp="$(echo $s | sed 's/ .*//')"
122 qry="$(echo $s | sed 's/^..//')"
124 if [ "$exp" = "$qry" ]; then
125 # the "1" case yields exp == qry
126 qry=''
127 fi
129 url="/env$qry"
131 n="$(get "$url" | awk /^-/ | count)"
132 if [ $? -ne 0 ]; then
133 echo "failed to get /$url"
134 return 1
135 fi
137 if [ "$n" -ne $exp ]; then
138 echo "Unexpected number of args"
139 echo "want : $exp"
140 echo "got : $n"
141 return 1
142 fi
143 done
146 test_custom_index() {
147 setup_simple_test '' 'index "foo.gmi"'
149 fetch /dir/
150 check_reply "20 text/gemini" "# hello world"
153 test_custom_index_default_type_per_location() {
154 setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
156 fetch /dir/
157 check_reply "20 text/plain" "$(cat hello)"
160 test_auto_index() {
161 setup_simple_test '' 'location "/dir/*" { auto index on }'
163 fetch /
164 check_reply "20 text/gemini" "# hello world" || return 1
166 fetch_hdr /dir
167 check_reply "30 /dir/" || return 1
169 fetch_hdr /dir/
170 check_reply "20 text/gemini"
172 # we expect 5 lines from the auto index
174 body="$(get /dir/ | count)"
175 if [ $? -ne 0 ]; then
176 echo 'failed to get /dir/'
177 return 1
178 fi
180 if [ "$body" -ne 5 ]; then
181 echo "expected five lines from the auto index, got $body"
182 return 1
183 fi
186 test_block() {
187 setup_simple_test '' 'location "*" { block }'
189 fetch /
190 check_reply "40 temporary failure" || return 1
192 fetch /nonexists
193 check_reply "40 temporary failure" || return 1
196 test_block_return_fmt() {
197 setup_simple_test '' '
198 location "/dir" {
199 strip 1
200 block return 40 "%% %p %q %P %N test"
202 location "*" {
203 strip 99
204 block return 40 "%% %p %q %P %N test"
205 }'
207 fetch_hdr /dir/foo.gmi
208 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
210 fetch_hdr /bigfile
211 check_reply "40 % / 10965 localhost test" || return 1
214 test_entrypoint() {
215 setup_simple_test '' 'entrypoint "/env"'
217 fetch_hdr /foo/bar
218 check_reply "20 text/plain; lang=en" || return 1
220 # TODO: test something similar with plain cgi too
222 body="$(get /foo/bar|grep PATH_INFO)"
223 if [ $? -ne 0 ]; then
224 echo "failed to get /foo/bar"
225 return 1
226 fi
228 if [ "$body" != "PATH_INFO=/foo/bar" ]; then
229 echo "Invalid PATH_INFO generated"
230 echo "want : PATH_INFO=/foo/bar"
231 echo "got : $body"
232 return 1
233 fi
236 test_require_client_ca() {
237 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
239 fetch /
240 check_reply "60 client certificate required" || return 1
242 ggflags="-C valid.crt -K valid.key"
243 fetch_hdr /
244 check_reply "20 text/gemini" || return 1
246 ggflags="-C invalid.cert.pem -K invalid.key.pem"
247 fetch_hdr /
248 check_reply "61 certificate not authorised" || return 1
251 test_root_inside_location() {
252 setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
254 fetch /foo
255 check_reply "51 not found" || return 1
257 fetch_hdr /foo/
258 check_reply "20 text/gemini"
261 test_root_inside_location_with_redirect() {
262 setup_simple_test '' '
263 location "/foo" { block return 31 "%p/" }
264 location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
266 fetch /foo
267 check_reply "31 /foo/" || return 1
269 fetch_hdr /foo/
270 check_reply "20 text/gemini"
273 test_fastcgi() {
274 # XXX: prefork 1 for testing
275 setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
277 fetch /
278 check_reply "20 text/gemini" "# Hello, world!"
281 test_macro_expansion() {
282 cat <<EOF > reg.conf
283 pwd = "$PWD"
284 $config_common
286 server "localhost" {
287 # the quoting of \$ is for sh
288 cert \$pwd "/cert.pem"
289 key \$pwd "/key.pem"
290 root \$pwd "/testdata"
292 EOF
294 if ! checkconf; then
295 echo "failed to parse the config"
296 return 1
297 fi
299 run
301 fetch /
302 check_reply "20 text/gemini" "# hello world"
305 # 1.7.4 bugfix: check_for_cgi goes out-of-bound processing a string
306 # that doesn't contain a '/'
307 test_174_bugfix() {
308 setup_simple_test '' 'cgi "*"'
310 # thanks cage :)
311 for i in 0 1 2 3 4 5 6 7 8 9; do
312 fetch /favicon.txt
313 check_reply "51 not found" || return 1
314 done
317 test_proxy_relay_to() {
318 gen_config '' ''
319 set_proxy ''
321 run
323 ggflags="-P localhost:$port -H localhost.local"
325 fetch /
326 check_reply "20 text/gemini" "# hello world"
329 test_proxy_with_certs() {
330 ggflags="-P localhost:$port -H localhost.local"
332 # first test using the valid keys
334 gen_config '' 'require client ca "'$PWD'/testca.pem"'
335 set_proxy "
336 cert \"$PWD/valid.crt\"
337 key \"$PWD/valid.key\"
339 run
341 fetch /
342 check_reply "20 text/gemini" "# hello world" || return 1
344 # then using some invalid keys
346 gen_config '' 'require client ca "'$PWD'/testca.pem"'
347 set_proxy "
348 cert \"$PWD/invalid.cert.pem\"
349 key \"$PWD/invalid.key.pem\"
351 run
353 fetch /
354 check_reply "61 certificate not authorised" || return 1
356 # and finally without keys
358 gen_config '' 'require client ca "'$PWD'/testca.pem"'
359 set_proxy ''
360 run
362 fetch /
363 check_reply "60 client certificate required" || return 1
366 test_unknown_host() {
367 setup_simple_test '' ''
369 ggflags="-N -H foobar"
370 fetch /
371 check_reply '59 Wrong/malformed host or missing SNI'