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_ge() {
12 dont_check_server_alive=yes
14 $ge -p $port -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
52 want="20 application/octet-stream"
53 if [ "$hdr" != "$want" ]; then
54 echo "Header mismatch" >&2
55 echo "wants : $want" >&2
56 echo "got : $hdr" >&2
57 return 1
58 fi
60 if ! cmp -s bigfile testdata/bigfile; then
61 echo "received bigfile is not as expected"
62 cmp bigfile testdata/bigfile
63 return 1
64 fi
65 }
67 test_dont_execute_scripts() {
68 setup_simple_test
70 fetch_hdr /hello
71 check_reply "20 application/octet-stream" "" || return 1
72 }
74 test_custom_mime() {
75 setup_simple_test '
76 types {
77 text/x-funny gmi
78 }
79 ' ''
81 fetch_hdr /
82 check_reply "20 text/x-funny"
83 }
85 test_default_type() {
86 setup_simple_test '' 'default type "application/x-foo"'
88 fetch_hdr /hello
89 check_reply "20 application/x-foo"
90 }
92 test_custom_lang() {
93 setup_simple_test '' 'lang it'
95 fetch_hdr /
96 check_reply "20 text/gemini;lang=it"
97 }
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"'
108 fetch /dir/
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" }'
115 fetch /dir/
116 check_reply "20 text/plain" "$(cat hello)"
119 test_auto_index() {
120 setup_simple_test '' 'location "/dir/*" { auto index on }'
122 fetch /
123 check_reply "20 text/gemini" "# hello world" || return 1
125 fetch_hdr /dir
126 check_reply "30 /dir/" || return 1
128 fetch_hdr /dir/
129 check_reply "20 text/gemini" || return 1
131 get /dir/ > listing || return 1
132 cat <<EOF > listing.expected
133 # Index of /dir/
135 => ./../
136 => ./current%20date
137 => ./foo.gmi
138 => ./hello
139 EOF
141 cmp -s listing.expected listing
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 echo 'unexpected dir content:'
145 diff -u listing.expected listing
146 fi
147 rm listing listing.expected
149 return $ret
152 test_block() {
153 setup_simple_test '' 'location "*" { block }'
155 fetch /
156 check_reply "40 temporary failure" || return 1
158 fetch /nonexists
159 check_reply "40 temporary failure" || return 1
162 test_block_return_fmt() {
163 setup_simple_test '' '
164 location "/dir" {
165 strip 1
166 block return 40 "%% %p %q %P %N test"
168 location "*" {
169 strip 99
170 block return 40 "%% %p %q %P %N test"
171 }'
173 fetch_hdr /dir/foo.gmi
174 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
176 fetch_hdr /bigfile
177 check_reply "40 % / 10965 localhost test" || return 1
180 test_require_client_ca() {
181 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
183 fetch /
184 check_reply "60 client certificate required" || return 1
186 ggflags="-C valid.crt -K valid.key"
187 fetch_hdr /
188 check_reply "20 text/gemini" || return 1
190 ggflags="-C invalid.cert.pem -K invalid.key.pem"
191 fetch_hdr /
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 }'
198 fetch /foo
199 check_reply "51 not found" || return 1
201 fetch_hdr /foo/
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 }'
210 fetch /foo
211 check_reply "31 /foo/" || return 1
213 fetch_hdr /foo/
214 check_reply "20 text/gemini"
217 test_fastcgi() {
218 ./fcgi-test fcgi.sock &
219 fcgi_pid=$!
221 setup_simple_test 'prefork 1' 'fastcgi "'$PWD'/fcgi.sock"'
223 i=0
224 while [ $i -lt 10 ]; do
225 fetch /
226 check_reply "20 text/gemini" "# hello from fastcgi!"
227 if [ $? -ne 0 ]; then
228 kill $fcgi_pid
229 return 1
230 fi
232 i=$(($i + 1))
233 done
235 kill $fcgi_pid
236 return 0
239 test_macro_expansion() {
240 cat <<EOF > reg.conf
241 pwd = "$PWD"
243 server "localhost" {
244 # the quoting of \$ is for sh
245 cert \$pwd "/cert.pem"
246 key \$pwd "/key.pem"
247 root \$pwd "/testdata"
248 listen on localhost port $port
250 EOF
252 if ! checkconf; then
253 echo "failed to parse the config"
254 return 1
255 fi
257 run
259 fetch /
260 check_reply "20 text/gemini" "# hello world"
263 test_proxy_relay_to() {
264 gen_config '' ''
265 set_proxy ''
267 run
269 ggflags="-P localhost:$port -H localhost.local"
271 fetch /
272 check_reply "20 text/gemini" "# hello world"
275 test_proxy_with_certs() {
276 ggflags="-P localhost:$port -H localhost.local"
278 # first test using the valid keys
280 gen_config '' 'require client ca "'$PWD'/testca.pem"'
281 set_proxy "
282 cert \"$PWD/valid.crt\"
283 key \"$PWD/valid.key\"
285 run
287 fetch /
288 check_reply "20 text/gemini" "# hello world" || return 1
290 # then using some invalid keys
292 gen_config '' 'require client ca "'$PWD'/testca.pem"'
293 set_proxy "
294 cert \"$PWD/invalid.cert.pem\"
295 key \"$PWD/invalid.key.pem\"
297 run
299 fetch /
300 check_reply "61 certificate not authorised" || return 1
302 # and finally without keys
304 gen_config '' 'require client ca "'$PWD'/testca.pem"'
305 set_proxy ''
306 run
308 fetch /
309 check_reply "60 client certificate required" || return 1
312 test_unknown_host() {
313 setup_simple_test '' ''
315 ggflags="-N -H foobar"
316 fetch /
317 check_reply '59 Wrong/malformed host or missing SNI'
320 test_include_mime() {
321 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
323 fetch_hdr /
324 check_reply '20 text/gemini' || return 1
326 fetch_hdr /test.m3u8
327 check_reply '20 application/vnd.apple.mpegurl' || return 1
329 fetch_hdr /foo.1
330 check_reply '20 text/x-mandoc' || return 1