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 471a5250 2023-07-25 op test_gemexp() {
12 a721c233 2021-12-09 op dont_check_server_alive=yes
13 176179b2 2021-10-04 op
14 471a5250 2023-07-25 op $gemexp -p $port -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 176179b2 2021-10-04 op
52 611dffe8 2023-06-13 op want="20 application/octet-stream"
53 611dffe8 2023-06-13 op if [ "$hdr" != "$want" ]; then
54 611dffe8 2023-06-13 op echo "Header mismatch" >&2
55 611dffe8 2023-06-13 op echo "wants : $want" >&2
56 611dffe8 2023-06-13 op echo "got : $hdr" >&2
57 611dffe8 2023-06-13 op return 1
58 611dffe8 2023-06-13 op fi
59 611dffe8 2023-06-13 op
60 611dffe8 2023-06-13 op if ! cmp -s bigfile testdata/bigfile; then
61 611dffe8 2023-06-13 op echo "received bigfile is not as expected"
62 611dffe8 2023-06-13 op cmp bigfile testdata/bigfile
63 611dffe8 2023-06-13 op return 1
64 611dffe8 2023-06-13 op fi
65 176179b2 2021-10-04 op }
66 176179b2 2021-10-04 op
67 176179b2 2021-10-04 op test_dont_execute_scripts() {
68 176179b2 2021-10-04 op setup_simple_test
69 176179b2 2021-10-04 op
70 176179b2 2021-10-04 op fetch_hdr /hello
71 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "" || return 1
72 176179b2 2021-10-04 op }
73 176179b2 2021-10-04 op
74 176179b2 2021-10-04 op test_custom_mime() {
75 9448a01f 2022-04-07 op setup_simple_test '
76 9448a01f 2022-04-07 op types {
77 9448a01f 2022-04-07 op text/x-funny gmi
78 9448a01f 2022-04-07 op }
79 9448a01f 2022-04-07 op ' ''
80 176179b2 2021-10-04 op
81 176179b2 2021-10-04 op fetch_hdr /
82 176179b2 2021-10-04 op check_reply "20 text/x-funny"
83 176179b2 2021-10-04 op }
84 176179b2 2021-10-04 op
85 176179b2 2021-10-04 op test_default_type() {
86 176179b2 2021-10-04 op setup_simple_test '' 'default type "application/x-foo"'
87 176179b2 2021-10-04 op
88 176179b2 2021-10-04 op fetch_hdr /hello
89 176179b2 2021-10-04 op check_reply "20 application/x-foo"
90 176179b2 2021-10-04 op }
91 176179b2 2021-10-04 op
92 176179b2 2021-10-04 op test_custom_lang() {
93 176179b2 2021-10-04 op setup_simple_test '' 'lang it'
94 176179b2 2021-10-04 op
95 176179b2 2021-10-04 op fetch_hdr /
96 176179b2 2021-10-04 op check_reply "20 text/gemini;lang=it"
97 176179b2 2021-10-04 op }
98 176179b2 2021-10-04 op
99 176179b2 2021-10-04 op test_parse_custom_lang_per_location() {
100 176179b2 2021-10-04 op setup_simple_test '' \
101 176179b2 2021-10-04 op 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
102 176179b2 2021-10-04 op # can parse multiple locations
103 176179b2 2021-10-04 op }
104 176179b2 2021-10-04 op
105 176179b2 2021-10-04 op test_custom_index() {
106 176179b2 2021-10-04 op setup_simple_test '' 'index "foo.gmi"'
107 176179b2 2021-10-04 op
108 176179b2 2021-10-04 op fetch /dir/
109 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
110 176179b2 2021-10-04 op }
111 176179b2 2021-10-04 op
112 176179b2 2021-10-04 op test_custom_index_default_type_per_location() {
113 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
114 176179b2 2021-10-04 op
115 176179b2 2021-10-04 op fetch /dir/
116 176179b2 2021-10-04 op check_reply "20 text/plain" "$(cat hello)"
117 176179b2 2021-10-04 op }
118 176179b2 2021-10-04 op
119 176179b2 2021-10-04 op test_auto_index() {
120 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { auto index on }'
121 176179b2 2021-10-04 op
122 176179b2 2021-10-04 op fetch /
123 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
124 176179b2 2021-10-04 op
125 176179b2 2021-10-04 op fetch_hdr /dir
126 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
127 176179b2 2021-10-04 op
128 176179b2 2021-10-04 op fetch_hdr /dir/
129 475205fa 2022-07-04 op check_reply "20 text/gemini" || return 1
130 176179b2 2021-10-04 op
131 475205fa 2022-07-04 op get /dir/ > listing || return 1
132 475205fa 2022-07-04 op cat <<EOF > listing.expected
133 475205fa 2022-07-04 op # Index of /dir/
134 176179b2 2021-10-04 op
135 d45d5306 2022-07-04 op => ./../
136 475205fa 2022-07-04 op => ./current%20date
137 475205fa 2022-07-04 op => ./foo.gmi
138 475205fa 2022-07-04 op => ./hello
139 475205fa 2022-07-04 op EOF
140 176179b2 2021-10-04 op
141 475205fa 2022-07-04 op cmp -s listing.expected listing
142 475205fa 2022-07-04 op ret=$?
143 475205fa 2022-07-04 op if [ $ret -ne 0 ]; then
144 475205fa 2022-07-04 op echo 'unexpected dir content:'
145 475205fa 2022-07-04 op diff -u listing.expected listing
146 176179b2 2021-10-04 op fi
147 475205fa 2022-07-04 op rm listing listing.expected
148 475205fa 2022-07-04 op
149 475205fa 2022-07-04 op return $ret
150 176179b2 2021-10-04 op }
151 176179b2 2021-10-04 op
152 176179b2 2021-10-04 op test_block() {
153 176179b2 2021-10-04 op setup_simple_test '' 'location "*" { block }'
154 176179b2 2021-10-04 op
155 176179b2 2021-10-04 op fetch /
156 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
157 176179b2 2021-10-04 op
158 176179b2 2021-10-04 op fetch /nonexists
159 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
160 176179b2 2021-10-04 op }
161 176179b2 2021-10-04 op
162 176179b2 2021-10-04 op test_block_return_fmt() {
163 176179b2 2021-10-04 op setup_simple_test '' '
164 176179b2 2021-10-04 op location "/dir" {
165 176179b2 2021-10-04 op strip 1
166 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
167 176179b2 2021-10-04 op }
168 176179b2 2021-10-04 op location "*" {
169 176179b2 2021-10-04 op strip 99
170 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
171 176179b2 2021-10-04 op }'
172 176179b2 2021-10-04 op
173 176179b2 2021-10-04 op fetch_hdr /dir/foo.gmi
174 176179b2 2021-10-04 op check_reply "40 % /foo.gmi 10965 localhost test" || return 1
175 176179b2 2021-10-04 op
176 176179b2 2021-10-04 op fetch_hdr /bigfile
177 176179b2 2021-10-04 op check_reply "40 % / 10965 localhost test" || return 1
178 176179b2 2021-10-04 op }
179 176179b2 2021-10-04 op
180 176179b2 2021-10-04 op test_require_client_ca() {
181 176179b2 2021-10-04 op setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
182 176179b2 2021-10-04 op
183 176179b2 2021-10-04 op fetch /
184 176179b2 2021-10-04 op check_reply "60 client certificate required" || return 1
185 176179b2 2021-10-04 op
186 176179b2 2021-10-04 op ggflags="-C valid.crt -K valid.key"
187 176179b2 2021-10-04 op fetch_hdr /
188 176179b2 2021-10-04 op check_reply "20 text/gemini" || return 1
189 176179b2 2021-10-04 op
190 80745f04 2023-08-29 op ggflags="-C invalid.pem -K invalid.key"
191 176179b2 2021-10-04 op fetch_hdr /
192 176179b2 2021-10-04 op check_reply "61 certificate not authorised" || return 1
193 176179b2 2021-10-04 op }
194 176179b2 2021-10-04 op
195 176179b2 2021-10-04 op test_root_inside_location() {
196 176179b2 2021-10-04 op setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
197 176179b2 2021-10-04 op
198 176179b2 2021-10-04 op fetch /foo
199 176179b2 2021-10-04 op check_reply "51 not found" || return 1
200 176179b2 2021-10-04 op
201 176179b2 2021-10-04 op fetch_hdr /foo/
202 176179b2 2021-10-04 op check_reply "20 text/gemini"
203 176179b2 2021-10-04 op }
204 176179b2 2021-10-04 op
205 176179b2 2021-10-04 op test_root_inside_location_with_redirect() {
206 176179b2 2021-10-04 op setup_simple_test '' '
207 176179b2 2021-10-04 op location "/foo" { block return 31 "%p/" }
208 176179b2 2021-10-04 op location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
209 176179b2 2021-10-04 op
210 176179b2 2021-10-04 op fetch /foo
211 176179b2 2021-10-04 op check_reply "31 /foo/" || return 1
212 176179b2 2021-10-04 op
213 176179b2 2021-10-04 op fetch_hdr /foo/
214 176179b2 2021-10-04 op check_reply "20 text/gemini"
215 176179b2 2021-10-04 op }
216 176179b2 2021-10-04 op
217 176179b2 2021-10-04 op test_fastcgi() {
218 9adeb265 2023-06-09 op ./fcgi-test fcgi.sock &
219 9adeb265 2023-06-09 op fcgi_pid=$!
220 176179b2 2021-10-04 op
221 fdd67729 2023-07-23 op setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"'
222 2247b668 2023-07-01 op
223 2247b668 2023-07-01 op msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
224 9adeb265 2023-06-09 op
225 9adeb265 2023-06-09 op i=0
226 9adeb265 2023-06-09 op while [ $i -lt 10 ]; do
227 9adeb265 2023-06-09 op fetch /
228 2247b668 2023-07-01 op check_reply "20 text/gemini" "$msg"
229 9adeb265 2023-06-09 op if [ $? -ne 0 ]; then
230 9adeb265 2023-06-09 op kill $fcgi_pid
231 9adeb265 2023-06-09 op return 1
232 9adeb265 2023-06-09 op fi
233 9adeb265 2023-06-09 op
234 9adeb265 2023-06-09 op i=$(($i + 1))
235 9adeb265 2023-06-09 op done
236 60f4107d 2023-07-23 op
237 60f4107d 2023-07-23 op kill $fcgi_pid
238 60f4107d 2023-07-23 op return 0
239 60f4107d 2023-07-23 op }
240 60f4107d 2023-07-23 op
241 60f4107d 2023-07-23 op test_fastcgi_inside_location() {
242 60f4107d 2023-07-23 op ./fcgi-test fcgi.sock &
243 60f4107d 2023-07-23 op fcgi_pid=$!
244 60f4107d 2023-07-23 op
245 60f4107d 2023-07-23 op setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"
246 60f4107d 2023-07-23 op location "/dir/*" {
247 60f4107d 2023-07-23 op fastcgi off
248 60f4107d 2023-07-23 op }'
249 60f4107d 2023-07-23 op
250 60f4107d 2023-07-23 op msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
251 60f4107d 2023-07-23 op fetch /foo
252 60f4107d 2023-07-23 op if ! check_reply "20 text/gemini" "$msg"; then
253 60f4107d 2023-07-23 op kill $fcgi_pid
254 60f4107d 2023-07-23 op return 1
255 60f4107d 2023-07-23 op fi
256 fdd67729 2023-07-23 op
257 60f4107d 2023-07-23 op fetch /dir/foo.gmi
258 60f4107d 2023-07-23 op if ! check_reply "20 text/gemini" "# hello world"; then
259 60f4107d 2023-07-23 op kill $fcgi_pid
260 60f4107d 2023-07-23 op return 1
261 60f4107d 2023-07-23 op fi
262 60f4107d 2023-07-23 op
263 fdd67729 2023-07-23 op kill $fcgi_pid
264 fdd67729 2023-07-23 op return 0
265 fdd67729 2023-07-23 op }
266 fdd67729 2023-07-23 op
267 fdd67729 2023-07-23 op test_fastcgi_deprecated_syntax() {
268 fdd67729 2023-07-23 op ./fcgi-test fcgi.sock &
269 fdd67729 2023-07-23 op fcgi_pid=$!
270 fdd67729 2023-07-23 op
271 fdd67729 2023-07-23 op # the old syntax will eventually go away, but check that the
272 fdd67729 2023-07-23 op # backward compatibility works.
273 fdd67729 2023-07-23 op setup_simple_test 'prefork 1' 'fastcgi "'$PWD'/fcgi.sock"'
274 9adeb265 2023-06-09 op
275 fdd67729 2023-07-23 op msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
276 fdd67729 2023-07-23 op fetch /
277 fdd67729 2023-07-23 op check_reply "20 text/gemini" "$msg"
278 fdd67729 2023-07-23 op if [ $? -ne 0 ]; then
279 fdd67729 2023-07-23 op kill $fcgi_pid
280 fdd67729 2023-07-23 op return 1
281 fdd67729 2023-07-23 op fi
282 fdd67729 2023-07-23 op
283 9adeb265 2023-06-09 op kill $fcgi_pid
284 9adeb265 2023-06-09 op return 0
285 176179b2 2021-10-04 op }
286 176179b2 2021-10-04 op
287 176179b2 2021-10-04 op test_macro_expansion() {
288 176179b2 2021-10-04 op cat <<EOF > reg.conf
289 176179b2 2021-10-04 op pwd = "$PWD"
290 bb5a25d2 2024-01-30 op common = "lang it; auto index on"
291 176179b2 2021-10-04 op
292 176179b2 2021-10-04 op server "localhost" {
293 176179b2 2021-10-04 op # the quoting of \$ is for sh
294 80745f04 2023-08-29 op cert \$pwd "/localhost.pem"
295 80745f04 2023-08-29 op key \$pwd "/localhost.key"
296 176179b2 2021-10-04 op root \$pwd "/testdata"
297 5a345722 2023-06-23 op listen on $REGRESS_HOST port $port
298 bb5a25d2 2024-01-30 op @common
299 176179b2 2021-10-04 op }
300 176179b2 2021-10-04 op EOF
301 176179b2 2021-10-04 op
302 176179b2 2021-10-04 op if ! checkconf; then
303 176179b2 2021-10-04 op echo "failed to parse the config"
304 176179b2 2021-10-04 op return 1
305 176179b2 2021-10-04 op fi
306 176179b2 2021-10-04 op
307 176179b2 2021-10-04 op run
308 176179b2 2021-10-04 op
309 176179b2 2021-10-04 op fetch /
310 3524375a 2024-01-26 op check_reply "20 text/gemini;lang=it" "# hello world"
311 176179b2 2021-10-04 op }
312 176179b2 2021-10-04 op
313 4b5b1e82 2021-12-29 op test_proxy_relay_to() {
314 4b5b1e82 2021-12-29 op gen_config '' ''
315 92a9f41d 2022-01-03 op set_proxy ''
316 92a9f41d 2022-01-03 op
317 c064f3de 2021-01-01 op run
318 c064f3de 2021-01-01 op
319 c064f3de 2021-01-01 op ggflags="-P localhost:$port -H localhost.local"
320 c064f3de 2021-01-01 op
321 c064f3de 2021-01-01 op fetch /
322 c064f3de 2021-01-01 op check_reply "20 text/gemini" "# hello world"
323 c064f3de 2021-01-01 op }
324 c064f3de 2021-01-01 op
325 c064f3de 2021-01-01 op test_proxy_with_certs() {
326 92a9f41d 2022-01-03 op ggflags="-P localhost:$port -H localhost.local"
327 92a9f41d 2022-01-03 op
328 92a9f41d 2022-01-03 op # first test using the valid keys
329 92a9f41d 2022-01-03 op
330 c064f3de 2021-01-01 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
331 92a9f41d 2022-01-03 op set_proxy "
332 92a9f41d 2022-01-03 op cert \"$PWD/valid.crt\"
333 92a9f41d 2022-01-03 op key \"$PWD/valid.key\"
334 92a9f41d 2022-01-03 op "
335 4b5b1e82 2021-12-29 op run
336 4b5b1e82 2021-12-29 op
337 92a9f41d 2022-01-03 op fetch /
338 92a9f41d 2022-01-03 op check_reply "20 text/gemini" "# hello world" || return 1
339 4b5b1e82 2021-12-29 op
340 92a9f41d 2022-01-03 op # then using some invalid keys
341 92a9f41d 2022-01-03 op
342 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
343 92a9f41d 2022-01-03 op set_proxy "
344 80745f04 2023-08-29 op cert \"$PWD/invalid.pem\"
345 80745f04 2023-08-29 op key \"$PWD/invalid.key\"
346 92a9f41d 2022-01-03 op "
347 92a9f41d 2022-01-03 op run
348 92a9f41d 2022-01-03 op
349 4b5b1e82 2021-12-29 op fetch /
350 92a9f41d 2022-01-03 op check_reply "61 certificate not authorised" || return 1
351 92a9f41d 2022-01-03 op
352 92a9f41d 2022-01-03 op # and finally without keys
353 92a9f41d 2022-01-03 op
354 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
355 92a9f41d 2022-01-03 op set_proxy ''
356 92a9f41d 2022-01-03 op run
357 92a9f41d 2022-01-03 op
358 92a9f41d 2022-01-03 op fetch /
359 92a9f41d 2022-01-03 op check_reply "60 client certificate required" || return 1
360 901905e0 2022-01-05 op }
361 901905e0 2022-01-05 op
362 901905e0 2022-01-05 op test_unknown_host() {
363 901905e0 2022-01-05 op setup_simple_test '' ''
364 901905e0 2022-01-05 op
365 901905e0 2022-01-05 op ggflags="-N -H foobar"
366 901905e0 2022-01-05 op fetch /
367 901905e0 2022-01-05 op check_reply '59 Wrong/malformed host or missing SNI'
368 4b5b1e82 2021-12-29 op }
369 fb121226 2022-02-26 op
370 fb121226 2022-02-26 op test_include_mime() {
371 fb121226 2022-02-26 op setup_simple_test "types { include '$PWD/example.mime.types' }" ""
372 fb121226 2022-02-26 op
373 fb121226 2022-02-26 op fetch_hdr /
374 91971201 2022-03-26 op check_reply '20 text/gemini' || return 1
375 fb121226 2022-02-26 op
376 fb121226 2022-02-26 op fetch_hdr /test.m3u8
377 91971201 2022-03-26 op check_reply '20 application/vnd.apple.mpegurl' || return 1
378 fb121226 2022-02-26 op
379 fb121226 2022-02-26 op fetch_hdr /foo.1
380 91971201 2022-03-26 op check_reply '20 text/x-mandoc' || return 1
381 60b4efa1 2023-07-24 op }
382 60b4efa1 2023-07-24 op
383 60b4efa1 2023-07-24 op test_log_file() {
384 60b4efa1 2023-07-24 op rm -f log log.edited
385 56054fe1 2023-08-03 op setup_simple_test '
386 56054fe1 2023-08-03 op log access "'$PWD'/log"
387 56054fe1 2023-08-03 op log style legacy'
388 60b4efa1 2023-07-24 op
389 60b4efa1 2023-07-24 op fetch_hdr /
390 60b4efa1 2023-07-24 op check_reply '20 text/gemini'
391 60b4efa1 2023-07-24 op
392 56054fe1 2023-08-03 op # remove the ip
393 56054fe1 2023-08-03 op awk '{$1 = ""; print substr($0, 2)}' log > log.edited
394 60b4efa1 2023-07-24 op
395 56054fe1 2023-08-03 op printf '%s\n' 'GET gemini://localhost/ 20 text/gemini' \
396 abd261d2 2023-07-25 op | cmp -s - log.edited
397 60b4efa1 2023-07-24 op if [ $? -ne 0 ]; then
398 60b4efa1 2023-07-24 op # keep the log for post-mortem analysis
399 60b4efa1 2023-07-24 op return 1
400 60b4efa1 2023-07-24 op fi
401 60b4efa1 2023-07-24 op
402 60b4efa1 2023-07-24 op rm -f log log.edited
403 60b4efa1 2023-07-24 op return 0
404 fb121226 2022-02-26 op }