Blame


1 5741561d 2021-12-09 op test_punycode() {
2 a721c233 2021-12-09 op dont_check_server_alive=yes
3 5741561d 2021-12-09 op ./puny-test
4 5741561d 2021-12-09 op }
5 5741561d 2021-12-09 op
6 5741561d 2021-12-09 op test_iri() {
7 a721c233 2021-12-09 op dont_check_server_alive=yes
8 5741561d 2021-12-09 op ./iri_test
9 5741561d 2021-12-09 op }
10 5741561d 2021-12-09 op
11 176179b2 2021-10-04 op test_configless_mode() {
12 a721c233 2021-12-09 op dont_check_server_alive=yes
13 176179b2 2021-10-04 op
14 176179b2 2021-10-04 op $gmid -p $port -H localhost -d . testdata &
15 176179b2 2021-10-04 op pid=$!
16 176179b2 2021-10-04 op sleep 1
17 176179b2 2021-10-04 op
18 176179b2 2021-10-04 op fetch /
19 176179b2 2021-10-04 op kill $pid
20 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
21 176179b2 2021-10-04 op }
22 176179b2 2021-10-04 op
23 176179b2 2021-10-04 op test_static_files() {
24 176179b2 2021-10-04 op setup_simple_test
25 176179b2 2021-10-04 op
26 176179b2 2021-10-04 op fetch /
27 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
28 176179b2 2021-10-04 op
29 176179b2 2021-10-04 op fetch /foo
30 176179b2 2021-10-04 op check_reply "51 not found" || return 1
31 176179b2 2021-10-04 op
32 176179b2 2021-10-04 op fetch /dir/foo.gmi
33 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
34 176179b2 2021-10-04 op }
35 176179b2 2021-10-04 op
36 176179b2 2021-10-04 op test_directory_redirect() {
37 176179b2 2021-10-04 op setup_simple_test
38 176179b2 2021-10-04 op
39 176179b2 2021-10-04 op fetch /dir
40 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
41 176179b2 2021-10-04 op
42 176179b2 2021-10-04 op fetch /dir/
43 176179b2 2021-10-04 op check_reply "51 not found" || return 1
44 176179b2 2021-10-04 op }
45 176179b2 2021-10-04 op
46 176179b2 2021-10-04 op test_serve_big_files() {
47 176179b2 2021-10-04 op setup_simple_test
48 176179b2 2021-10-04 op
49 176179b2 2021-10-04 op hdr="$(head /bigfile)"
50 176179b2 2021-10-04 op get /bigfile > bigfile
51 6e0f14d5 2021-10-04 op ./sha bigfile bigfile.sha
52 176179b2 2021-10-04 op body="$(cat bigfile.sha)"
53 176179b2 2021-10-04 op
54 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
55 176179b2 2021-10-04 op }
56 176179b2 2021-10-04 op
57 176179b2 2021-10-04 op test_dont_execute_scripts() {
58 176179b2 2021-10-04 op setup_simple_test
59 176179b2 2021-10-04 op
60 176179b2 2021-10-04 op fetch_hdr /hello
61 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "" || return 1
62 176179b2 2021-10-04 op }
63 176179b2 2021-10-04 op
64 176179b2 2021-10-04 op test_custom_mime() {
65 9448a01f 2022-04-07 op setup_simple_test '
66 9448a01f 2022-04-07 op types {
67 9448a01f 2022-04-07 op text/x-funny gmi
68 9448a01f 2022-04-07 op }
69 9448a01f 2022-04-07 op ' ''
70 176179b2 2021-10-04 op
71 176179b2 2021-10-04 op fetch_hdr /
72 176179b2 2021-10-04 op check_reply "20 text/x-funny"
73 176179b2 2021-10-04 op }
74 176179b2 2021-10-04 op
75 176179b2 2021-10-04 op test_default_type() {
76 176179b2 2021-10-04 op setup_simple_test '' 'default type "application/x-foo"'
77 176179b2 2021-10-04 op
78 176179b2 2021-10-04 op fetch_hdr /hello
79 176179b2 2021-10-04 op check_reply "20 application/x-foo"
80 176179b2 2021-10-04 op }
81 176179b2 2021-10-04 op
82 176179b2 2021-10-04 op test_custom_lang() {
83 176179b2 2021-10-04 op setup_simple_test '' 'lang it'
84 176179b2 2021-10-04 op
85 176179b2 2021-10-04 op fetch_hdr /
86 176179b2 2021-10-04 op check_reply "20 text/gemini;lang=it"
87 176179b2 2021-10-04 op }
88 176179b2 2021-10-04 op
89 176179b2 2021-10-04 op test_parse_custom_lang_per_location() {
90 176179b2 2021-10-04 op setup_simple_test '' \
91 176179b2 2021-10-04 op 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
92 176179b2 2021-10-04 op # can parse multiple locations
93 176179b2 2021-10-04 op }
94 176179b2 2021-10-04 op
95 176179b2 2021-10-04 op test_cgi_scripts() {
96 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
97 176179b2 2021-10-04 op
98 176179b2 2021-10-04 op fetch /hello
99 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
100 176179b2 2021-10-04 op
101 176179b2 2021-10-04 op fetch /slow
102 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
103 176179b2 2021-10-04 op
104 176179b2 2021-10-04 op fetch /err
105 176179b2 2021-10-04 op check_reply "42 CGI error" || return 1
106 176179b2 2021-10-04 op
107 176179b2 2021-10-04 op fetch /invalid
108 176179b2 2021-10-04 op check_reply "42 CGI error" || return 1
109 176179b2 2021-10-04 op }
110 176179b2 2021-10-04 op
111 176179b2 2021-10-04 op test_cgi_big_replies() {
112 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
113 176179b2 2021-10-04 op
114 176179b2 2021-10-04 op hdr="$(head /serve-bigfile)"
115 176179b2 2021-10-04 op get /bigfile > bigfile
116 6e0f14d5 2021-10-04 op ./sha bigfile bigfile.sha
117 176179b2 2021-10-04 op body="$(cat bigfile.sha)"
118 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
119 176179b2 2021-10-04 op }
120 176179b2 2021-10-04 op
121 176179b2 2021-10-04 op test_cgi_split_query() {
122 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
123 176179b2 2021-10-04 op
124 176179b2 2021-10-04 op for s in "1" "2 ?foo" "3 ?foo+bar" "1 ?foo+bar=5" "3 ?foo+bar%3d5"; do
125 176179b2 2021-10-04 op exp="$(echo $s | sed 's/ .*//')"
126 176179b2 2021-10-04 op qry="$(echo $s | sed 's/^..//')"
127 176179b2 2021-10-04 op
128 176179b2 2021-10-04 op if [ "$exp" = "$qry" ]; then
129 176179b2 2021-10-04 op # the "1" case yields exp == qry
130 176179b2 2021-10-04 op qry=''
131 176179b2 2021-10-04 op fi
132 176179b2 2021-10-04 op
133 176179b2 2021-10-04 op url="/env$qry"
134 176179b2 2021-10-04 op
135 176179b2 2021-10-04 op n="$(get "$url" | awk /^-/ | count)"
136 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
137 176179b2 2021-10-04 op echo "failed to get /$url"
138 176179b2 2021-10-04 op return 1
139 176179b2 2021-10-04 op fi
140 176179b2 2021-10-04 op
141 176179b2 2021-10-04 op if [ "$n" -ne $exp ]; then
142 176179b2 2021-10-04 op echo "Unexpected number of args"
143 176179b2 2021-10-04 op echo "want : $exp"
144 176179b2 2021-10-04 op echo "got : $n"
145 176179b2 2021-10-04 op return 1
146 176179b2 2021-10-04 op fi
147 176179b2 2021-10-04 op done
148 176179b2 2021-10-04 op }
149 176179b2 2021-10-04 op
150 176179b2 2021-10-04 op test_custom_index() {
151 176179b2 2021-10-04 op setup_simple_test '' 'index "foo.gmi"'
152 176179b2 2021-10-04 op
153 176179b2 2021-10-04 op fetch /dir/
154 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
155 176179b2 2021-10-04 op }
156 176179b2 2021-10-04 op
157 176179b2 2021-10-04 op test_custom_index_default_type_per_location() {
158 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
159 176179b2 2021-10-04 op
160 176179b2 2021-10-04 op fetch /dir/
161 176179b2 2021-10-04 op check_reply "20 text/plain" "$(cat hello)"
162 176179b2 2021-10-04 op }
163 176179b2 2021-10-04 op
164 176179b2 2021-10-04 op test_auto_index() {
165 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { auto index on }'
166 176179b2 2021-10-04 op
167 176179b2 2021-10-04 op fetch /
168 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
169 176179b2 2021-10-04 op
170 176179b2 2021-10-04 op fetch_hdr /dir
171 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
172 176179b2 2021-10-04 op
173 176179b2 2021-10-04 op fetch_hdr /dir/
174 475205fa 2022-07-04 op check_reply "20 text/gemini" || return 1
175 176179b2 2021-10-04 op
176 475205fa 2022-07-04 op get /dir/ > listing || return 1
177 475205fa 2022-07-04 op cat <<EOF > listing.expected
178 475205fa 2022-07-04 op # Index of /dir/
179 176179b2 2021-10-04 op
180 d45d5306 2022-07-04 op => ./../
181 475205fa 2022-07-04 op => ./current%20date
182 475205fa 2022-07-04 op => ./foo.gmi
183 475205fa 2022-07-04 op => ./hello
184 475205fa 2022-07-04 op EOF
185 176179b2 2021-10-04 op
186 475205fa 2022-07-04 op cmp -s listing.expected listing
187 475205fa 2022-07-04 op ret=$?
188 475205fa 2022-07-04 op if [ $ret -ne 0 ]; then
189 475205fa 2022-07-04 op echo 'unexpected dir content:'
190 475205fa 2022-07-04 op diff -u listing.expected listing
191 176179b2 2021-10-04 op fi
192 475205fa 2022-07-04 op rm listing listing.expected
193 475205fa 2022-07-04 op
194 475205fa 2022-07-04 op return $ret
195 176179b2 2021-10-04 op }
196 176179b2 2021-10-04 op
197 176179b2 2021-10-04 op test_block() {
198 176179b2 2021-10-04 op setup_simple_test '' 'location "*" { block }'
199 176179b2 2021-10-04 op
200 176179b2 2021-10-04 op fetch /
201 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
202 176179b2 2021-10-04 op
203 176179b2 2021-10-04 op fetch /nonexists
204 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
205 176179b2 2021-10-04 op }
206 176179b2 2021-10-04 op
207 176179b2 2021-10-04 op test_block_return_fmt() {
208 176179b2 2021-10-04 op setup_simple_test '' '
209 176179b2 2021-10-04 op location "/dir" {
210 176179b2 2021-10-04 op strip 1
211 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
212 176179b2 2021-10-04 op }
213 176179b2 2021-10-04 op location "*" {
214 176179b2 2021-10-04 op strip 99
215 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
216 176179b2 2021-10-04 op }'
217 176179b2 2021-10-04 op
218 176179b2 2021-10-04 op fetch_hdr /dir/foo.gmi
219 176179b2 2021-10-04 op check_reply "40 % /foo.gmi 10965 localhost test" || return 1
220 176179b2 2021-10-04 op
221 176179b2 2021-10-04 op fetch_hdr /bigfile
222 176179b2 2021-10-04 op check_reply "40 % / 10965 localhost test" || return 1
223 176179b2 2021-10-04 op }
224 176179b2 2021-10-04 op
225 176179b2 2021-10-04 op test_entrypoint() {
226 176179b2 2021-10-04 op setup_simple_test '' 'entrypoint "/env"'
227 176179b2 2021-10-04 op
228 176179b2 2021-10-04 op fetch_hdr /foo/bar
229 176179b2 2021-10-04 op check_reply "20 text/plain; lang=en" || return 1
230 176179b2 2021-10-04 op
231 176179b2 2021-10-04 op # TODO: test something similar with plain cgi too
232 176179b2 2021-10-04 op
233 176179b2 2021-10-04 op body="$(get /foo/bar|grep PATH_INFO)"
234 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
235 176179b2 2021-10-04 op echo "failed to get /foo/bar"
236 176179b2 2021-10-04 op return 1
237 176179b2 2021-10-04 op fi
238 176179b2 2021-10-04 op
239 176179b2 2021-10-04 op if [ "$body" != "PATH_INFO=/foo/bar" ]; then
240 176179b2 2021-10-04 op echo "Invalid PATH_INFO generated"
241 176179b2 2021-10-04 op echo "want : PATH_INFO=/foo/bar"
242 176179b2 2021-10-04 op echo "got : $body"
243 176179b2 2021-10-04 op return 1
244 176179b2 2021-10-04 op fi
245 176179b2 2021-10-04 op }
246 176179b2 2021-10-04 op
247 176179b2 2021-10-04 op test_require_client_ca() {
248 176179b2 2021-10-04 op setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
249 176179b2 2021-10-04 op
250 176179b2 2021-10-04 op fetch /
251 176179b2 2021-10-04 op check_reply "60 client certificate required" || return 1
252 176179b2 2021-10-04 op
253 176179b2 2021-10-04 op ggflags="-C valid.crt -K valid.key"
254 176179b2 2021-10-04 op fetch_hdr /
255 176179b2 2021-10-04 op check_reply "20 text/gemini" || return 1
256 176179b2 2021-10-04 op
257 176179b2 2021-10-04 op ggflags="-C invalid.cert.pem -K invalid.key.pem"
258 176179b2 2021-10-04 op fetch_hdr /
259 176179b2 2021-10-04 op check_reply "61 certificate not authorised" || return 1
260 176179b2 2021-10-04 op }
261 176179b2 2021-10-04 op
262 176179b2 2021-10-04 op test_root_inside_location() {
263 176179b2 2021-10-04 op setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
264 176179b2 2021-10-04 op
265 176179b2 2021-10-04 op fetch /foo
266 176179b2 2021-10-04 op check_reply "51 not found" || return 1
267 176179b2 2021-10-04 op
268 176179b2 2021-10-04 op fetch_hdr /foo/
269 176179b2 2021-10-04 op check_reply "20 text/gemini"
270 176179b2 2021-10-04 op }
271 176179b2 2021-10-04 op
272 176179b2 2021-10-04 op test_root_inside_location_with_redirect() {
273 176179b2 2021-10-04 op setup_simple_test '' '
274 176179b2 2021-10-04 op location "/foo" { block return 31 "%p/" }
275 176179b2 2021-10-04 op location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
276 176179b2 2021-10-04 op
277 176179b2 2021-10-04 op fetch /foo
278 176179b2 2021-10-04 op check_reply "31 /foo/" || return 1
279 176179b2 2021-10-04 op
280 176179b2 2021-10-04 op fetch_hdr /foo/
281 176179b2 2021-10-04 op check_reply "20 text/gemini"
282 176179b2 2021-10-04 op }
283 176179b2 2021-10-04 op
284 176179b2 2021-10-04 op test_fastcgi() {
285 176179b2 2021-10-04 op # XXX: prefork 1 for testing
286 176179b2 2021-10-04 op setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
287 176179b2 2021-10-04 op
288 176179b2 2021-10-04 op fetch /
289 176179b2 2021-10-04 op check_reply "20 text/gemini" "# Hello, world!"
290 176179b2 2021-10-04 op }
291 176179b2 2021-10-04 op
292 176179b2 2021-10-04 op test_macro_expansion() {
293 176179b2 2021-10-04 op cat <<EOF > reg.conf
294 176179b2 2021-10-04 op pwd = "$PWD"
295 176179b2 2021-10-04 op $config_common
296 176179b2 2021-10-04 op
297 176179b2 2021-10-04 op server "localhost" {
298 176179b2 2021-10-04 op # the quoting of \$ is for sh
299 176179b2 2021-10-04 op cert \$pwd "/cert.pem"
300 176179b2 2021-10-04 op key \$pwd "/key.pem"
301 176179b2 2021-10-04 op root \$pwd "/testdata"
302 176179b2 2021-10-04 op }
303 176179b2 2021-10-04 op EOF
304 176179b2 2021-10-04 op
305 176179b2 2021-10-04 op if ! checkconf; then
306 176179b2 2021-10-04 op echo "failed to parse the config"
307 176179b2 2021-10-04 op return 1
308 176179b2 2021-10-04 op fi
309 176179b2 2021-10-04 op
310 176179b2 2021-10-04 op run
311 176179b2 2021-10-04 op
312 176179b2 2021-10-04 op fetch /
313 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
314 176179b2 2021-10-04 op }
315 176179b2 2021-10-04 op
316 176179b2 2021-10-04 op # 1.7.4 bugfix: check_for_cgi goes out-of-bound processing a string
317 176179b2 2021-10-04 op # that doesn't contain a '/'
318 176179b2 2021-10-04 op test_174_bugfix() {
319 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
320 176179b2 2021-10-04 op
321 176179b2 2021-10-04 op # thanks cage :)
322 176179b2 2021-10-04 op for i in 0 1 2 3 4 5 6 7 8 9; do
323 176179b2 2021-10-04 op fetch /favicon.txt
324 176179b2 2021-10-04 op check_reply "51 not found" || return 1
325 176179b2 2021-10-04 op done
326 4b5b1e82 2021-12-29 op }
327 4b5b1e82 2021-12-29 op
328 4b5b1e82 2021-12-29 op test_proxy_relay_to() {
329 4b5b1e82 2021-12-29 op gen_config '' ''
330 92a9f41d 2022-01-03 op set_proxy ''
331 92a9f41d 2022-01-03 op
332 c064f3de 2021-01-01 op run
333 c064f3de 2021-01-01 op
334 c064f3de 2021-01-01 op ggflags="-P localhost:$port -H localhost.local"
335 c064f3de 2021-01-01 op
336 c064f3de 2021-01-01 op fetch /
337 c064f3de 2021-01-01 op check_reply "20 text/gemini" "# hello world"
338 c064f3de 2021-01-01 op }
339 c064f3de 2021-01-01 op
340 c064f3de 2021-01-01 op test_proxy_with_certs() {
341 92a9f41d 2022-01-03 op ggflags="-P localhost:$port -H localhost.local"
342 92a9f41d 2022-01-03 op
343 92a9f41d 2022-01-03 op # first test using the valid keys
344 92a9f41d 2022-01-03 op
345 c064f3de 2021-01-01 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
346 92a9f41d 2022-01-03 op set_proxy "
347 92a9f41d 2022-01-03 op cert \"$PWD/valid.crt\"
348 92a9f41d 2022-01-03 op key \"$PWD/valid.key\"
349 92a9f41d 2022-01-03 op "
350 4b5b1e82 2021-12-29 op run
351 4b5b1e82 2021-12-29 op
352 92a9f41d 2022-01-03 op fetch /
353 92a9f41d 2022-01-03 op check_reply "20 text/gemini" "# hello world" || return 1
354 4b5b1e82 2021-12-29 op
355 92a9f41d 2022-01-03 op # then using some invalid keys
356 92a9f41d 2022-01-03 op
357 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
358 92a9f41d 2022-01-03 op set_proxy "
359 92a9f41d 2022-01-03 op cert \"$PWD/invalid.cert.pem\"
360 92a9f41d 2022-01-03 op key \"$PWD/invalid.key.pem\"
361 92a9f41d 2022-01-03 op "
362 92a9f41d 2022-01-03 op run
363 92a9f41d 2022-01-03 op
364 4b5b1e82 2021-12-29 op fetch /
365 92a9f41d 2022-01-03 op check_reply "61 certificate not authorised" || return 1
366 92a9f41d 2022-01-03 op
367 92a9f41d 2022-01-03 op # and finally without keys
368 92a9f41d 2022-01-03 op
369 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
370 92a9f41d 2022-01-03 op set_proxy ''
371 92a9f41d 2022-01-03 op run
372 92a9f41d 2022-01-03 op
373 92a9f41d 2022-01-03 op fetch /
374 92a9f41d 2022-01-03 op check_reply "60 client certificate required" || return 1
375 901905e0 2022-01-05 op }
376 901905e0 2022-01-05 op
377 901905e0 2022-01-05 op test_unknown_host() {
378 901905e0 2022-01-05 op setup_simple_test '' ''
379 901905e0 2022-01-05 op
380 901905e0 2022-01-05 op ggflags="-N -H foobar"
381 901905e0 2022-01-05 op fetch /
382 901905e0 2022-01-05 op check_reply '59 Wrong/malformed host or missing SNI'
383 4b5b1e82 2021-12-29 op }
384 fb121226 2022-02-26 op
385 fb121226 2022-02-26 op test_include_mime() {
386 fb121226 2022-02-26 op setup_simple_test "types { include '$PWD/example.mime.types' }" ""
387 fb121226 2022-02-26 op
388 fb121226 2022-02-26 op fetch_hdr /
389 91971201 2022-03-26 op check_reply '20 text/gemini' || return 1
390 fb121226 2022-02-26 op
391 fb121226 2022-02-26 op fetch_hdr /test.m3u8
392 91971201 2022-03-26 op check_reply '20 application/vnd.apple.mpegurl' || return 1
393 fb121226 2022-02-26 op
394 fb121226 2022-02-26 op fetch_hdr /foo.1
395 91971201 2022-03-26 op check_reply '20 text/x-mandoc' || return 1
396 fb121226 2022-02-26 op }