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 42235e3f 2024-04-04 op test_dump_config() {
12 42235e3f 2024-04-04 op dont_check_server_alive=yes
13 42235e3f 2024-04-04 op gen_config '' ''
15 42235e3f 2024-04-04 op exp="$(mktemp)"
16 42235e3f 2024-04-04 op got="$(mktemp)"
17 42235e3f 2024-04-04 op cat <<EOF >$exp
20 42235e3f 2024-04-04 op server "localhost" {
21 42235e3f 2024-04-04 op cert "$PWD/localhost.pem"
22 42235e3f 2024-04-04 op key "$PWD/localhost.key"
26 42235e3f 2024-04-04 op $gmid -nn -c reg.conf > $got 2>/dev/null
29 42235e3f 2024-04-04 op if ! cmp -s "$exp" "$got"; then
30 42235e3f 2024-04-04 op echo "config differs!" >&2
31 42235e3f 2024-04-04 op diff -u "$exp" "$got" >&2
35 42235e3f 2024-04-04 op rm "$exp" "$got"
39 471a5250 2023-07-25 op test_gemexp() {
40 a721c233 2021-12-09 op dont_check_server_alive=yes
42 471a5250 2023-07-25 op $gemexp -p $port -d . testdata &
48 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
51 176179b2 2021-10-04 op test_static_files() {
52 176179b2 2021-10-04 op setup_simple_test
55 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
58 176179b2 2021-10-04 op check_reply "51 not found" || return 1
60 176179b2 2021-10-04 op fetch /dir/foo.gmi
61 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
64 176179b2 2021-10-04 op test_directory_redirect() {
65 176179b2 2021-10-04 op setup_simple_test
68 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
71 176179b2 2021-10-04 op check_reply "51 not found" || return 1
74 176179b2 2021-10-04 op test_serve_big_files() {
75 176179b2 2021-10-04 op setup_simple_test
77 176179b2 2021-10-04 op hdr="$(head /bigfile)"
78 176179b2 2021-10-04 op get /bigfile > bigfile
80 611dffe8 2023-06-13 op want="20 application/octet-stream"
81 611dffe8 2023-06-13 op if [ "$hdr" != "$want" ]; then
82 611dffe8 2023-06-13 op echo "Header mismatch" >&2
83 611dffe8 2023-06-13 op echo "wants : $want" >&2
84 611dffe8 2023-06-13 op echo "got : $hdr" >&2
88 611dffe8 2023-06-13 op if ! cmp -s bigfile testdata/bigfile; then
89 611dffe8 2023-06-13 op echo "received bigfile is not as expected"
90 611dffe8 2023-06-13 op cmp bigfile testdata/bigfile
95 176179b2 2021-10-04 op test_dont_execute_scripts() {
96 176179b2 2021-10-04 op setup_simple_test
98 176179b2 2021-10-04 op fetch_hdr /hello
99 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "" || return 1
102 176179b2 2021-10-04 op test_custom_mime() {
103 9448a01f 2022-04-07 op setup_simple_test '
105 9448a01f 2022-04-07 op text/x-funny gmi
110 176179b2 2021-10-04 op check_reply "20 text/x-funny"
113 176179b2 2021-10-04 op test_default_type() {
114 176179b2 2021-10-04 op setup_simple_test '' 'default type "application/x-foo"'
116 176179b2 2021-10-04 op fetch_hdr /hello
117 176179b2 2021-10-04 op check_reply "20 application/x-foo"
120 176179b2 2021-10-04 op test_custom_lang() {
121 176179b2 2021-10-04 op setup_simple_test '' 'lang it'
124 176179b2 2021-10-04 op check_reply "20 text/gemini;lang=it"
127 176179b2 2021-10-04 op test_parse_custom_lang_per_location() {
128 176179b2 2021-10-04 op setup_simple_test '' \
129 176179b2 2021-10-04 op 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
130 176179b2 2021-10-04 op # can parse multiple locations
133 176179b2 2021-10-04 op test_custom_index() {
134 176179b2 2021-10-04 op setup_simple_test '' 'index "foo.gmi"'
137 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
140 176179b2 2021-10-04 op test_custom_index_default_type_per_location() {
141 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
144 176179b2 2021-10-04 op check_reply "20 text/plain" "$(cat hello)"
147 176179b2 2021-10-04 op test_auto_index() {
148 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { auto index on }'
151 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
153 176179b2 2021-10-04 op fetch_hdr /dir
154 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
156 176179b2 2021-10-04 op fetch_hdr /dir/
157 475205fa 2022-07-04 op check_reply "20 text/gemini" || return 1
159 475205fa 2022-07-04 op get /dir/ > listing || return 1
160 475205fa 2022-07-04 op cat <<EOF > listing.expected
161 475205fa 2022-07-04 op # Index of /dir/
164 475205fa 2022-07-04 op => ./current%20date
169 475205fa 2022-07-04 op cmp -s listing.expected listing
171 475205fa 2022-07-04 op if [ $ret -ne 0 ]; then
172 475205fa 2022-07-04 op echo 'unexpected dir content:'
173 475205fa 2022-07-04 op diff -u listing.expected listing
175 475205fa 2022-07-04 op rm listing listing.expected
180 176179b2 2021-10-04 op test_block() {
181 176179b2 2021-10-04 op setup_simple_test '' 'location "*" { block }'
184 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
186 176179b2 2021-10-04 op fetch /nonexists
187 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
190 176179b2 2021-10-04 op test_block_return_fmt() {
191 176179b2 2021-10-04 op setup_simple_test '' '
192 176179b2 2021-10-04 op location "/dir" {
194 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
196 176179b2 2021-10-04 op location "*" {
198 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
201 176179b2 2021-10-04 op fetch_hdr /dir/foo.gmi
202 176179b2 2021-10-04 op check_reply "40 % /foo.gmi 10965 localhost test" || return 1
204 176179b2 2021-10-04 op fetch_hdr /bigfile
205 176179b2 2021-10-04 op check_reply "40 % / 10965 localhost test" || return 1
208 176179b2 2021-10-04 op test_require_client_ca() {
209 176179b2 2021-10-04 op setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
212 176179b2 2021-10-04 op check_reply "60 client certificate required" || return 1
214 176179b2 2021-10-04 op ggflags="-C valid.crt -K valid.key"
216 176179b2 2021-10-04 op check_reply "20 text/gemini" || return 1
218 80745f04 2023-08-29 op ggflags="-C invalid.pem -K invalid.key"
220 176179b2 2021-10-04 op check_reply "61 certificate not authorised" || return 1
223 176179b2 2021-10-04 op test_root_inside_location() {
224 176179b2 2021-10-04 op setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
227 176179b2 2021-10-04 op check_reply "51 not found" || return 1
229 176179b2 2021-10-04 op fetch_hdr /foo/
230 176179b2 2021-10-04 op check_reply "20 text/gemini"
233 176179b2 2021-10-04 op test_root_inside_location_with_redirect() {
234 176179b2 2021-10-04 op setup_simple_test '' '
235 176179b2 2021-10-04 op location "/foo" { block return 31 "%p/" }
236 176179b2 2021-10-04 op location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
239 176179b2 2021-10-04 op check_reply "31 /foo/" || return 1
241 176179b2 2021-10-04 op fetch_hdr /foo/
242 176179b2 2021-10-04 op check_reply "20 text/gemini"
245 176179b2 2021-10-04 op test_fastcgi() {
246 9adeb265 2023-06-09 op ./fcgi-test fcgi.sock &
249 fdd67729 2023-07-23 op setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"'
251 2247b668 2023-07-01 op msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
254 9adeb265 2023-06-09 op while [ $i -lt 10 ]; do
256 2247b668 2023-07-01 op check_reply "20 text/gemini" "$msg"
257 9adeb265 2023-06-09 op if [ $? -ne 0 ]; then
258 9adeb265 2023-06-09 op kill $fcgi_pid
262 9adeb265 2023-06-09 op i=$(($i + 1))
265 60f4107d 2023-07-23 op kill $fcgi_pid
269 60f4107d 2023-07-23 op test_fastcgi_inside_location() {
270 60f4107d 2023-07-23 op ./fcgi-test fcgi.sock &
273 60f4107d 2023-07-23 op setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"
274 60f4107d 2023-07-23 op location "/dir/*" {
278 60f4107d 2023-07-23 op msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
280 60f4107d 2023-07-23 op if ! check_reply "20 text/gemini" "$msg"; then
281 60f4107d 2023-07-23 op kill $fcgi_pid
285 60f4107d 2023-07-23 op fetch /dir/foo.gmi
286 60f4107d 2023-07-23 op if ! check_reply "20 text/gemini" "# hello world"; then
287 60f4107d 2023-07-23 op kill $fcgi_pid
291 fdd67729 2023-07-23 op kill $fcgi_pid
295 fdd67729 2023-07-23 op test_fastcgi_deprecated_syntax() {
296 fdd67729 2023-07-23 op ./fcgi-test fcgi.sock &
299 fdd67729 2023-07-23 op # the old syntax will eventually go away, but check that the
300 fdd67729 2023-07-23 op # backward compatibility works.
301 fdd67729 2023-07-23 op setup_simple_test 'prefork 1' 'fastcgi "'$PWD'/fcgi.sock"'
303 fdd67729 2023-07-23 op msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
305 fdd67729 2023-07-23 op check_reply "20 text/gemini" "$msg"
306 fdd67729 2023-07-23 op if [ $? -ne 0 ]; then
307 fdd67729 2023-07-23 op kill $fcgi_pid
311 9adeb265 2023-06-09 op kill $fcgi_pid
315 176179b2 2021-10-04 op test_macro_expansion() {
316 176179b2 2021-10-04 op cat <<EOF > reg.conf
318 bb5a25d2 2024-01-30 op common = "lang it; auto index on"
320 176179b2 2021-10-04 op server "localhost" {
321 176179b2 2021-10-04 op # the quoting of \$ is for sh
322 80745f04 2023-08-29 op cert \$pwd "/localhost.pem"
323 80745f04 2023-08-29 op key \$pwd "/localhost.key"
324 176179b2 2021-10-04 op root \$pwd "/testdata"
325 5a345722 2023-06-23 op listen on $REGRESS_HOST port $port
330 176179b2 2021-10-04 op if ! checkconf; then
331 176179b2 2021-10-04 op echo "failed to parse the config"
338 3524375a 2024-01-26 op check_reply "20 text/gemini;lang=it" "# hello world"
341 4b5b1e82 2021-12-29 op test_proxy_relay_to() {
342 4b5b1e82 2021-12-29 op gen_config '' ''
347 c064f3de 2022-01-01 op ggflags="-P localhost:$port -H localhost.local"
350 c064f3de 2022-01-01 op check_reply "20 text/gemini" "# hello world"
353 c064f3de 2022-01-01 op test_proxy_with_certs() {
354 92a9f41d 2022-01-03 op ggflags="-P localhost:$port -H localhost.local"
356 92a9f41d 2022-01-03 op # first test using the valid keys
358 c064f3de 2022-01-01 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
360 92a9f41d 2022-01-03 op cert \"$PWD/valid.crt\"
361 92a9f41d 2022-01-03 op key \"$PWD/valid.key\"
366 92a9f41d 2022-01-03 op check_reply "20 text/gemini" "# hello world" || return 1
368 92a9f41d 2022-01-03 op # then using some invalid keys
370 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
372 80745f04 2023-08-29 op cert \"$PWD/invalid.pem\"
373 80745f04 2023-08-29 op key \"$PWD/invalid.key\"
378 92a9f41d 2022-01-03 op check_reply "61 certificate not authorised" || return 1
380 92a9f41d 2022-01-03 op # and finally without keys
382 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
387 92a9f41d 2022-01-03 op check_reply "60 client certificate required" || return 1
390 901905e0 2022-01-05 op test_unknown_host() {
391 901905e0 2022-01-05 op setup_simple_test '' ''
393 901905e0 2022-01-05 op ggflags="-N -H foobar"
395 901905e0 2022-01-05 op check_reply '59 Wrong/malformed host or missing SNI'
398 fb121226 2022-02-26 op test_include_mime() {
399 fb121226 2022-02-26 op setup_simple_test "types { include '$PWD/example.mime.types' }" ""
402 91971201 2022-03-26 op check_reply '20 text/gemini' || return 1
404 fb121226 2022-02-26 op fetch_hdr /test.m3u8
405 91971201 2022-03-26 op check_reply '20 application/vnd.apple.mpegurl' || return 1
407 fb121226 2022-02-26 op fetch_hdr /foo.1
408 91971201 2022-03-26 op check_reply '20 text/x-mandoc' || return 1
411 60b4efa1 2023-07-24 op test_log_file() {
412 60b4efa1 2023-07-24 op rm -f log log.edited
413 56054fe1 2023-08-03 op setup_simple_test '
414 56054fe1 2023-08-03 op log access "'$PWD'/log"
415 56054fe1 2023-08-03 op log style legacy'
418 60b4efa1 2023-07-24 op check_reply '20 text/gemini'
420 56054fe1 2023-08-03 op # remove the ip
421 56054fe1 2023-08-03 op awk '{$1 = ""; print substr($0, 2)}' log > log.edited
423 56054fe1 2023-08-03 op printf '%s\n' 'GET gemini://localhost/ 20 text/gemini' \
424 abd261d2 2023-07-25 op | cmp -s - log.edited
425 60b4efa1 2023-07-24 op if [ $? -ne 0 ]; then
426 60b4efa1 2023-07-24 op # keep the log for post-mortem analysis
430 60b4efa1 2023-07-24 op rm -f log log.edited