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
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 '
66 types {
67 text/x-funny gmi
68 }
69 ' ''
71 fetch_hdr /
72 check_reply "20 text/x-funny"
73 }
75 test_default_type() {
76 setup_simple_test '' 'default type "application/x-foo"'
78 fetch_hdr /hello
79 check_reply "20 application/x-foo"
80 }
82 test_custom_lang() {
83 setup_simple_test '' 'lang it'
85 fetch_hdr /
86 check_reply "20 text/gemini;lang=it"
87 }
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
93 }
95 test_custom_index() {
96 setup_simple_test '' 'index "foo.gmi"'
98 fetch /dir/
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" }'
105 fetch /dir/
106 check_reply "20 text/plain" "$(cat hello)"
109 test_auto_index() {
110 setup_simple_test '' 'location "/dir/*" { auto index on }'
112 fetch /
113 check_reply "20 text/gemini" "# hello world" || return 1
115 fetch_hdr /dir
116 check_reply "30 /dir/" || return 1
118 fetch_hdr /dir/
119 check_reply "20 text/gemini" || return 1
121 get /dir/ > listing || return 1
122 cat <<EOF > listing.expected
123 # Index of /dir/
125 => ./../
126 => ./current%20date
127 => ./foo.gmi
128 => ./hello
129 EOF
131 cmp -s listing.expected listing
132 ret=$?
133 if [ $ret -ne 0 ]; then
134 echo 'unexpected dir content:'
135 diff -u listing.expected listing
136 fi
137 rm listing listing.expected
139 return $ret
142 test_block() {
143 setup_simple_test '' 'location "*" { block }'
145 fetch /
146 check_reply "40 temporary failure" || return 1
148 fetch /nonexists
149 check_reply "40 temporary failure" || return 1
152 test_block_return_fmt() {
153 setup_simple_test '' '
154 location "/dir" {
155 strip 1
156 block return 40 "%% %p %q %P %N test"
158 location "*" {
159 strip 99
160 block return 40 "%% %p %q %P %N test"
161 }'
163 fetch_hdr /dir/foo.gmi
164 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
166 fetch_hdr /bigfile
167 check_reply "40 % / 10965 localhost test" || return 1
170 test_require_client_ca() {
171 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
173 fetch /
174 check_reply "60 client certificate required" || return 1
176 ggflags="-C valid.crt -K valid.key"
177 fetch_hdr /
178 check_reply "20 text/gemini" || return 1
180 ggflags="-C invalid.cert.pem -K invalid.key.pem"
181 fetch_hdr /
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 }'
188 fetch /foo
189 check_reply "51 not found" || return 1
191 fetch_hdr /foo/
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 }'
200 fetch /foo
201 check_reply "31 /foo/" || return 1
203 fetch_hdr /foo/
204 check_reply "20 text/gemini"
207 test_fastcgi() {
208 # XXX: prefork 1 for testing
209 setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
211 fetch /
212 check_reply "20 text/gemini" "# Hello, world!"
215 test_macro_expansion() {
216 cat <<EOF > reg.conf
217 pwd = "$PWD"
218 $config_common
220 server "localhost" {
221 # the quoting of \$ is for sh
222 cert \$pwd "/cert.pem"
223 key \$pwd "/key.pem"
224 root \$pwd "/testdata"
226 EOF
228 if ! checkconf; then
229 echo "failed to parse the config"
230 return 1
231 fi
233 run
235 fetch /
236 check_reply "20 text/gemini" "# hello world"
239 test_proxy_relay_to() {
240 gen_config '' ''
241 set_proxy ''
243 run
245 ggflags="-P localhost:$port -H localhost.local"
247 fetch /
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"'
257 set_proxy "
258 cert \"$PWD/valid.crt\"
259 key \"$PWD/valid.key\"
261 run
263 fetch /
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"'
269 set_proxy "
270 cert \"$PWD/invalid.cert.pem\"
271 key \"$PWD/invalid.key.pem\"
273 run
275 fetch /
276 check_reply "61 certificate not authorised" || return 1
278 # and finally without keys
280 gen_config '' 'require client ca "'$PWD'/testca.pem"'
281 set_proxy ''
282 run
284 fetch /
285 check_reply "60 client certificate required" || return 1
288 test_unknown_host() {
289 setup_simple_test '' ''
291 ggflags="-N -H foobar"
292 fetch /
293 check_reply '59 Wrong/malformed host or missing SNI'
296 test_include_mime() {
297 setup_simple_test "types { include '$PWD/example.mime.types' }" ""
299 fetch_hdr /
300 check_reply '20 text/gemini' || return 1
302 fetch_hdr /test.m3u8
303 check_reply '20 application/vnd.apple.mpegurl' || return 1
305 fetch_hdr /foo.1
306 check_reply '20 text/x-mandoc' || return 1