1 5741561d 2021-12-09 op test_punycode() {
2 a721c233 2021-12-09 op dont_check_server_alive=yes
7 a721c233 2021-12-09 op dont_check_server_alive=yes
11 471a5250 2023-07-25 op test_gemexp() {
12 a721c233 2021-12-09 op dont_check_server_alive=yes
14 471a5250 2023-07-25 op $gemexp -p $port -d . testdata &
20 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
23 176179b2 2021-10-04 op test_static_files() {
24 176179b2 2021-10-04 op setup_simple_test
27 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
30 176179b2 2021-10-04 op check_reply "51 not found" || return 1
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
36 176179b2 2021-10-04 op test_directory_redirect() {
37 176179b2 2021-10-04 op setup_simple_test
40 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
43 176179b2 2021-10-04 op check_reply "51 not found" || return 1
46 176179b2 2021-10-04 op test_serve_big_files() {
47 176179b2 2021-10-04 op setup_simple_test
49 176179b2 2021-10-04 op hdr="$(head /bigfile)"
50 176179b2 2021-10-04 op get /bigfile > bigfile
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
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
67 176179b2 2021-10-04 op test_dont_execute_scripts() {
68 176179b2 2021-10-04 op setup_simple_test
70 176179b2 2021-10-04 op fetch_hdr /hello
71 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "" || return 1
74 176179b2 2021-10-04 op test_custom_mime() {
75 9448a01f 2022-04-07 op setup_simple_test '
77 9448a01f 2022-04-07 op text/x-funny gmi
82 176179b2 2021-10-04 op check_reply "20 text/x-funny"
85 176179b2 2021-10-04 op test_default_type() {
86 176179b2 2021-10-04 op setup_simple_test '' 'default type "application/x-foo"'
88 176179b2 2021-10-04 op fetch_hdr /hello
89 176179b2 2021-10-04 op check_reply "20 application/x-foo"
92 176179b2 2021-10-04 op test_custom_lang() {
93 176179b2 2021-10-04 op setup_simple_test '' 'lang it'
96 176179b2 2021-10-04 op check_reply "20 text/gemini;lang=it"
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
105 176179b2 2021-10-04 op test_custom_index() {
106 176179b2 2021-10-04 op setup_simple_test '' 'index "foo.gmi"'
109 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
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" }'
116 176179b2 2021-10-04 op check_reply "20 text/plain" "$(cat hello)"
119 176179b2 2021-10-04 op test_auto_index() {
120 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { auto index on }'
123 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
125 176179b2 2021-10-04 op fetch_hdr /dir
126 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
128 176179b2 2021-10-04 op fetch_hdr /dir/
129 475205fa 2022-07-04 op check_reply "20 text/gemini" || return 1
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/
136 475205fa 2022-07-04 op => ./current%20date
141 475205fa 2022-07-04 op cmp -s listing.expected listing
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
147 475205fa 2022-07-04 op rm listing listing.expected
152 176179b2 2021-10-04 op test_block() {
153 176179b2 2021-10-04 op setup_simple_test '' 'location "*" { block }'
156 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
158 176179b2 2021-10-04 op fetch /nonexists
159 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
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" {
166 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
168 176179b2 2021-10-04 op location "*" {
170 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
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
176 176179b2 2021-10-04 op fetch_hdr /bigfile
177 176179b2 2021-10-04 op check_reply "40 % / 10965 localhost test" || return 1
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"'
184 176179b2 2021-10-04 op check_reply "60 client certificate required" || return 1
186 176179b2 2021-10-04 op ggflags="-C valid.crt -K valid.key"
188 176179b2 2021-10-04 op check_reply "20 text/gemini" || return 1
190 176179b2 2021-10-04 op ggflags="-C invalid.cert.pem -K invalid.key.pem"
192 176179b2 2021-10-04 op check_reply "61 certificate not authorised" || return 1
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 }'
199 176179b2 2021-10-04 op check_reply "51 not found" || return 1
201 176179b2 2021-10-04 op fetch_hdr /foo/
202 176179b2 2021-10-04 op check_reply "20 text/gemini"
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 }'
211 176179b2 2021-10-04 op check_reply "31 /foo/" || return 1
213 176179b2 2021-10-04 op fetch_hdr /foo/
214 176179b2 2021-10-04 op check_reply "20 text/gemini"
217 176179b2 2021-10-04 op test_fastcgi() {
218 9adeb265 2023-06-09 op ./fcgi-test fcgi.sock &
221 fdd67729 2023-07-23 op setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"'
223 2247b668 2023-07-01 op msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
226 9adeb265 2023-06-09 op while [ $i -lt 10 ]; do
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
234 9adeb265 2023-06-09 op i=$(($i + 1))
237 60f4107d 2023-07-23 op kill $fcgi_pid
241 60f4107d 2023-07-23 op test_fastcgi_inside_location() {
242 60f4107d 2023-07-23 op ./fcgi-test fcgi.sock &
245 60f4107d 2023-07-23 op setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"
246 60f4107d 2023-07-23 op location "/dir/*" {
250 60f4107d 2023-07-23 op msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
252 60f4107d 2023-07-23 op if ! check_reply "20 text/gemini" "$msg"; then
253 60f4107d 2023-07-23 op kill $fcgi_pid
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
263 fdd67729 2023-07-23 op kill $fcgi_pid
267 fdd67729 2023-07-23 op test_fastcgi_deprecated_syntax() {
268 fdd67729 2023-07-23 op ./fcgi-test fcgi.sock &
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"'
275 fdd67729 2023-07-23 op msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
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
283 9adeb265 2023-06-09 op kill $fcgi_pid
287 176179b2 2021-10-04 op test_macro_expansion() {
288 176179b2 2021-10-04 op cat <<EOF > reg.conf
291 176179b2 2021-10-04 op server "localhost" {
292 176179b2 2021-10-04 op # the quoting of \$ is for sh
293 176179b2 2021-10-04 op cert \$pwd "/cert.pem"
294 176179b2 2021-10-04 op key \$pwd "/key.pem"
295 176179b2 2021-10-04 op root \$pwd "/testdata"
296 5a345722 2023-06-23 op listen on $REGRESS_HOST port $port
300 176179b2 2021-10-04 op if ! checkconf; then
301 176179b2 2021-10-04 op echo "failed to parse the config"
308 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
311 4b5b1e82 2021-12-29 op test_proxy_relay_to() {
312 4b5b1e82 2021-12-29 op gen_config '' ''
317 c064f3de 2022-01-01 op ggflags="-P localhost:$port -H localhost.local"
320 c064f3de 2022-01-01 op check_reply "20 text/gemini" "# hello world"
323 c064f3de 2022-01-01 op test_proxy_with_certs() {
324 92a9f41d 2022-01-03 op ggflags="-P localhost:$port -H localhost.local"
326 92a9f41d 2022-01-03 op # first test using the valid keys
328 c064f3de 2022-01-01 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
330 92a9f41d 2022-01-03 op cert \"$PWD/valid.crt\"
331 92a9f41d 2022-01-03 op key \"$PWD/valid.key\"
336 92a9f41d 2022-01-03 op check_reply "20 text/gemini" "# hello world" || return 1
338 92a9f41d 2022-01-03 op # then using some invalid keys
340 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
342 92a9f41d 2022-01-03 op cert \"$PWD/invalid.cert.pem\"
343 92a9f41d 2022-01-03 op key \"$PWD/invalid.key.pem\"
348 92a9f41d 2022-01-03 op check_reply "61 certificate not authorised" || return 1
350 92a9f41d 2022-01-03 op # and finally without keys
352 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
357 92a9f41d 2022-01-03 op check_reply "60 client certificate required" || return 1
360 901905e0 2022-01-05 op test_unknown_host() {
361 901905e0 2022-01-05 op setup_simple_test '' ''
363 901905e0 2022-01-05 op ggflags="-N -H foobar"
365 901905e0 2022-01-05 op check_reply '59 Wrong/malformed host or missing SNI'
368 fb121226 2022-02-26 op test_include_mime() {
369 fb121226 2022-02-26 op setup_simple_test "types { include '$PWD/example.mime.types' }" ""
372 91971201 2022-03-26 op check_reply '20 text/gemini' || return 1
374 fb121226 2022-02-26 op fetch_hdr /test.m3u8
375 91971201 2022-03-26 op check_reply '20 application/vnd.apple.mpegurl' || return 1
377 fb121226 2022-02-26 op fetch_hdr /foo.1
378 91971201 2022-03-26 op check_reply '20 text/x-mandoc' || return 1
381 60b4efa1 2023-07-24 op test_log_file() {
382 60b4efa1 2023-07-24 op rm -f log log.edited
383 56054fe1 2023-08-03 op setup_simple_test '
384 56054fe1 2023-08-03 op log access "'$PWD'/log"
385 56054fe1 2023-08-03 op log style legacy'
388 60b4efa1 2023-07-24 op check_reply '20 text/gemini'
390 56054fe1 2023-08-03 op # remove the ip
391 56054fe1 2023-08-03 op awk '{$1 = ""; print substr($0, 2)}' log > log.edited
393 56054fe1 2023-08-03 op printf '%s\n' 'GET gemini://localhost/ 20 text/gemini' \
394 abd261d2 2023-07-25 op | cmp -s - log.edited
395 60b4efa1 2023-07-24 op if [ $? -ne 0 ]; then
396 60b4efa1 2023-07-24 op # keep the log for post-mortem analysis
400 60b4efa1 2023-07-24 op rm -f log log.edited