2021-12-09 20:02:09 +01:00
|
|
|
test_punycode() {
|
2021-12-09 20:03:18 +01:00
|
|
|
dont_check_server_alive=yes
|
2021-12-09 20:02:09 +01:00
|
|
|
./puny-test
|
|
|
|
}
|
|
|
|
|
|
|
|
test_iri() {
|
2021-12-09 20:03:18 +01:00
|
|
|
dont_check_server_alive=yes
|
2021-12-09 20:02:09 +01:00
|
|
|
./iri_test
|
|
|
|
}
|
|
|
|
|
2024-04-04 15:07:09 +02:00
|
|
|
test_dump_config() {
|
|
|
|
dont_check_server_alive=yes
|
|
|
|
gen_config '' ''
|
|
|
|
|
|
|
|
exp="$(mktemp)"
|
|
|
|
got="$(mktemp)"
|
|
|
|
cat <<EOF >$exp
|
|
|
|
prefork 3
|
|
|
|
|
|
|
|
server "localhost" {
|
|
|
|
cert "$PWD/localhost.pem"
|
|
|
|
key "$PWD/localhost.key"
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
$gmid -nn -c reg.conf > $got 2>/dev/null
|
|
|
|
|
|
|
|
ret=0
|
|
|
|
if ! cmp -s "$exp" "$got"; then
|
|
|
|
echo "config differs!" >&2
|
|
|
|
diff -u "$exp" "$got" >&2
|
|
|
|
ret=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm "$exp" "$got"
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
2023-07-25 22:26:26 +02:00
|
|
|
test_gemexp() {
|
2021-12-09 20:03:18 +01:00
|
|
|
dont_check_server_alive=yes
|
2021-10-04 11:04:33 +02:00
|
|
|
|
2023-07-25 22:26:26 +02:00
|
|
|
$gemexp -p $port -d . testdata &
|
2021-10-04 11:04:33 +02:00
|
|
|
pid=$!
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
fetch /
|
|
|
|
kill $pid
|
|
|
|
check_reply "20 text/gemini" "# hello world" || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_static_files() {
|
|
|
|
setup_simple_test
|
|
|
|
|
|
|
|
fetch /
|
|
|
|
check_reply "20 text/gemini" "# hello world" || return 1
|
|
|
|
|
|
|
|
fetch /foo
|
|
|
|
check_reply "51 not found" || return 1
|
|
|
|
|
|
|
|
fetch /dir/foo.gmi
|
|
|
|
check_reply "20 text/gemini" "# hello world" || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_directory_redirect() {
|
|
|
|
setup_simple_test
|
|
|
|
|
|
|
|
fetch /dir
|
|
|
|
check_reply "30 /dir/" || return 1
|
|
|
|
|
|
|
|
fetch /dir/
|
|
|
|
check_reply "51 not found" || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_serve_big_files() {
|
|
|
|
setup_simple_test
|
|
|
|
|
|
|
|
hdr="$(head /bigfile)"
|
|
|
|
get /bigfile > bigfile
|
|
|
|
|
2023-06-13 12:59:50 +02:00
|
|
|
want="20 application/octet-stream"
|
|
|
|
if [ "$hdr" != "$want" ]; then
|
|
|
|
echo "Header mismatch" >&2
|
|
|
|
echo "wants : $want" >&2
|
|
|
|
echo "got : $hdr" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! cmp -s bigfile testdata/bigfile; then
|
|
|
|
echo "received bigfile is not as expected"
|
|
|
|
cmp bigfile testdata/bigfile
|
|
|
|
return 1
|
|
|
|
fi
|
2021-10-04 11:04:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
test_dont_execute_scripts() {
|
|
|
|
setup_simple_test
|
|
|
|
|
|
|
|
fetch_hdr /hello
|
|
|
|
check_reply "20 application/octet-stream" "" || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_custom_mime() {
|
2022-04-07 18:21:56 +02:00
|
|
|
setup_simple_test '
|
|
|
|
types {
|
|
|
|
text/x-funny gmi
|
|
|
|
}
|
|
|
|
' ''
|
2021-10-04 11:04:33 +02:00
|
|
|
|
|
|
|
fetch_hdr /
|
|
|
|
check_reply "20 text/x-funny"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_default_type() {
|
|
|
|
setup_simple_test '' 'default type "application/x-foo"'
|
|
|
|
|
|
|
|
fetch_hdr /hello
|
|
|
|
check_reply "20 application/x-foo"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_custom_lang() {
|
|
|
|
setup_simple_test '' 'lang it'
|
|
|
|
|
|
|
|
fetch_hdr /
|
|
|
|
check_reply "20 text/gemini;lang=it"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_parse_custom_lang_per_location() {
|
|
|
|
setup_simple_test '' \
|
|
|
|
'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
|
|
|
|
# can parse multiple locations
|
|
|
|
}
|
|
|
|
|
|
|
|
test_custom_index() {
|
|
|
|
setup_simple_test '' 'index "foo.gmi"'
|
|
|
|
|
|
|
|
fetch /dir/
|
|
|
|
check_reply "20 text/gemini" "# hello world"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_custom_index_default_type_per_location() {
|
|
|
|
setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
|
|
|
|
|
|
|
|
fetch /dir/
|
|
|
|
check_reply "20 text/plain" "$(cat hello)"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_auto_index() {
|
|
|
|
setup_simple_test '' 'location "/dir/*" { auto index on }'
|
|
|
|
|
|
|
|
fetch /
|
|
|
|
check_reply "20 text/gemini" "# hello world" || return 1
|
|
|
|
|
|
|
|
fetch_hdr /dir
|
|
|
|
check_reply "30 /dir/" || return 1
|
|
|
|
|
|
|
|
fetch_hdr /dir/
|
2022-07-04 11:36:31 +02:00
|
|
|
check_reply "20 text/gemini" || return 1
|
|
|
|
|
|
|
|
get /dir/ > listing || return 1
|
|
|
|
cat <<EOF > listing.expected
|
|
|
|
# Index of /dir/
|
|
|
|
|
2022-07-04 16:33:45 +02:00
|
|
|
=> ./../
|
2022-07-04 11:36:31 +02:00
|
|
|
=> ./current%20date
|
|
|
|
=> ./foo.gmi
|
|
|
|
=> ./hello
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cmp -s listing.expected listing
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ]; then
|
|
|
|
echo 'unexpected dir content:'
|
|
|
|
diff -u listing.expected listing
|
2021-10-04 11:04:33 +02:00
|
|
|
fi
|
2022-07-04 11:36:31 +02:00
|
|
|
rm listing listing.expected
|
2021-10-04 11:04:33 +02:00
|
|
|
|
2022-07-04 11:36:31 +02:00
|
|
|
return $ret
|
2021-10-04 11:04:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
test_block() {
|
|
|
|
setup_simple_test '' 'location "*" { block }'
|
|
|
|
|
|
|
|
fetch /
|
|
|
|
check_reply "40 temporary failure" || return 1
|
|
|
|
|
|
|
|
fetch /nonexists
|
|
|
|
check_reply "40 temporary failure" || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_block_return_fmt() {
|
|
|
|
setup_simple_test '' '
|
|
|
|
location "/dir" {
|
|
|
|
strip 1
|
|
|
|
block return 40 "%% %p %q %P %N test"
|
|
|
|
}
|
|
|
|
location "*" {
|
|
|
|
strip 99
|
|
|
|
block return 40 "%% %p %q %P %N test"
|
|
|
|
}'
|
|
|
|
|
|
|
|
fetch_hdr /dir/foo.gmi
|
|
|
|
check_reply "40 % /foo.gmi 10965 localhost test" || return 1
|
|
|
|
|
|
|
|
fetch_hdr /bigfile
|
|
|
|
check_reply "40 % / 10965 localhost test" || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_require_client_ca() {
|
|
|
|
setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
|
|
|
|
|
|
|
|
fetch /
|
|
|
|
check_reply "60 client certificate required" || return 1
|
|
|
|
|
|
|
|
ggflags="-C valid.crt -K valid.key"
|
|
|
|
fetch_hdr /
|
|
|
|
check_reply "20 text/gemini" || return 1
|
|
|
|
|
2023-08-29 11:30:28 +02:00
|
|
|
ggflags="-C invalid.pem -K invalid.key"
|
2021-10-04 11:04:33 +02:00
|
|
|
fetch_hdr /
|
|
|
|
check_reply "61 certificate not authorised" || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_root_inside_location() {
|
|
|
|
setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
|
|
|
|
|
|
|
|
fetch /foo
|
|
|
|
check_reply "51 not found" || return 1
|
|
|
|
|
|
|
|
fetch_hdr /foo/
|
|
|
|
check_reply "20 text/gemini"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_root_inside_location_with_redirect() {
|
|
|
|
setup_simple_test '' '
|
|
|
|
location "/foo" { block return 31 "%p/" }
|
|
|
|
location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
|
|
|
|
|
|
|
|
fetch /foo
|
|
|
|
check_reply "31 /foo/" || return 1
|
|
|
|
|
|
|
|
fetch_hdr /foo/
|
|
|
|
check_reply "20 text/gemini"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_fastcgi() {
|
2023-06-09 12:46:50 +02:00
|
|
|
./fcgi-test fcgi.sock &
|
|
|
|
fcgi_pid=$!
|
2021-10-04 11:04:33 +02:00
|
|
|
|
2023-07-23 20:45:43 +02:00
|
|
|
setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"'
|
2023-06-09 12:46:50 +02:00
|
|
|
|
2023-07-01 20:38:22 +02:00
|
|
|
msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
|
|
|
|
|
2023-06-09 12:46:50 +02:00
|
|
|
i=0
|
|
|
|
while [ $i -lt 10 ]; do
|
|
|
|
fetch /
|
2023-07-01 20:38:22 +02:00
|
|
|
check_reply "20 text/gemini" "$msg"
|
2023-06-09 12:46:50 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
kill $fcgi_pid
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
i=$(($i + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
kill $fcgi_pid
|
|
|
|
return 0
|
2021-10-04 11:04:33 +02:00
|
|
|
}
|
|
|
|
|
2023-07-23 21:04:53 +02:00
|
|
|
test_fastcgi_inside_location() {
|
|
|
|
./fcgi-test fcgi.sock &
|
|
|
|
fcgi_pid=$!
|
|
|
|
|
|
|
|
setup_simple_test 'prefork 1' 'fastcgi socket "'$PWD'/fcgi.sock"
|
|
|
|
location "/dir/*" {
|
|
|
|
fastcgi off
|
|
|
|
}'
|
|
|
|
|
|
|
|
msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
|
|
|
|
fetch /foo
|
|
|
|
if ! check_reply "20 text/gemini" "$msg"; then
|
|
|
|
kill $fcgi_pid
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
fetch /dir/foo.gmi
|
|
|
|
if ! check_reply "20 text/gemini" "# hello world"; then
|
|
|
|
kill $fcgi_pid
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
kill $fcgi_pid
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-06-03 18:14:40 +02:00
|
|
|
test_fastcgi_location_match() {
|
|
|
|
./fcgi-test fcgi.sock &
|
|
|
|
fcgi_pid=$!
|
|
|
|
|
|
|
|
setup_simple_test 'prefork 1' '
|
|
|
|
location "/dir/*" {
|
|
|
|
fastcgi off
|
|
|
|
}
|
|
|
|
location "/*" {
|
|
|
|
fastcgi socket "'$PWD'/fcgi.sock"
|
|
|
|
}'
|
|
|
|
|
|
|
|
msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
|
|
|
|
fetch /foo
|
|
|
|
if ! check_reply "20 text/gemini" "$msg"; then
|
|
|
|
kill $fcgi_pid
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
fetch /dir/foo.gmi
|
|
|
|
if ! check_reply "20 text/gemini" "# hello world"; then
|
|
|
|
kill $fcgi_pid
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
kill $fcgi_pid
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-07-23 20:45:43 +02:00
|
|
|
test_fastcgi_deprecated_syntax() {
|
|
|
|
./fcgi-test fcgi.sock &
|
|
|
|
fcgi_pid=$!
|
|
|
|
|
|
|
|
# the old syntax will eventually go away, but check that the
|
|
|
|
# backward compatibility works.
|
|
|
|
setup_simple_test 'prefork 1' 'fastcgi "'$PWD'/fcgi.sock"'
|
|
|
|
|
|
|
|
msg=$(printf "# hello from fastcgi!\nsome more content in the page...")
|
|
|
|
fetch /
|
|
|
|
check_reply "20 text/gemini" "$msg"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
kill $fcgi_pid
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
kill $fcgi_pid
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-10-04 11:04:33 +02:00
|
|
|
test_macro_expansion() {
|
|
|
|
cat <<EOF > reg.conf
|
|
|
|
pwd = "$PWD"
|
2024-01-30 10:31:09 +01:00
|
|
|
common = "lang it; auto index on"
|
2021-10-04 11:04:33 +02:00
|
|
|
|
|
|
|
server "localhost" {
|
|
|
|
# the quoting of \$ is for sh
|
2023-08-29 11:30:28 +02:00
|
|
|
cert \$pwd "/localhost.pem"
|
|
|
|
key \$pwd "/localhost.key"
|
2021-10-04 11:04:33 +02:00
|
|
|
root \$pwd "/testdata"
|
2024-05-29 10:33:36 +02:00
|
|
|
listen on $host port $port
|
2024-01-30 10:31:09 +01:00
|
|
|
@common
|
2021-10-04 11:04:33 +02:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
if ! checkconf; then
|
|
|
|
echo "failed to parse the config"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
run
|
|
|
|
|
|
|
|
fetch /
|
2024-01-26 16:34:46 +01:00
|
|
|
check_reply "20 text/gemini;lang=it" "# hello world"
|
2021-10-04 11:04:33 +02:00
|
|
|
}
|
|
|
|
|
2021-12-29 21:36:54 +01:00
|
|
|
test_proxy_relay_to() {
|
|
|
|
gen_config '' ''
|
2022-01-03 14:31:34 +01:00
|
|
|
set_proxy ''
|
|
|
|
|
2021-12-29 21:36:54 +01:00
|
|
|
run
|
|
|
|
|
2022-01-01 17:33:44 +01:00
|
|
|
ggflags="-P localhost:$port -H localhost.local"
|
2021-12-29 21:36:54 +01:00
|
|
|
|
|
|
|
fetch /
|
|
|
|
check_reply "20 text/gemini" "# hello world"
|
|
|
|
}
|
2022-01-01 17:33:44 +01:00
|
|
|
|
|
|
|
test_proxy_with_certs() {
|
2022-01-03 14:31:34 +01:00
|
|
|
ggflags="-P localhost:$port -H localhost.local"
|
|
|
|
|
|
|
|
# first test using the valid keys
|
|
|
|
|
2022-01-01 17:33:44 +01:00
|
|
|
gen_config '' 'require client ca "'$PWD'/testca.pem"'
|
2022-01-03 14:31:34 +01:00
|
|
|
set_proxy "
|
|
|
|
cert \"$PWD/valid.crt\"
|
|
|
|
key \"$PWD/valid.key\"
|
|
|
|
"
|
2022-01-01 17:33:44 +01:00
|
|
|
run
|
|
|
|
|
2022-01-03 14:31:34 +01:00
|
|
|
fetch /
|
|
|
|
check_reply "20 text/gemini" "# hello world" || return 1
|
|
|
|
|
|
|
|
# then using some invalid keys
|
|
|
|
|
|
|
|
gen_config '' 'require client ca "'$PWD'/testca.pem"'
|
|
|
|
set_proxy "
|
2023-08-29 11:30:28 +02:00
|
|
|
cert \"$PWD/invalid.pem\"
|
|
|
|
key \"$PWD/invalid.key\"
|
2022-01-03 14:31:34 +01:00
|
|
|
"
|
|
|
|
run
|
2022-01-01 17:33:44 +01:00
|
|
|
|
|
|
|
fetch /
|
2022-01-03 14:31:34 +01:00
|
|
|
check_reply "61 certificate not authorised" || return 1
|
|
|
|
|
|
|
|
# and finally without keys
|
|
|
|
|
|
|
|
gen_config '' 'require client ca "'$PWD'/testca.pem"'
|
|
|
|
set_proxy ''
|
|
|
|
run
|
|
|
|
|
|
|
|
fetch /
|
|
|
|
check_reply "60 client certificate required" || return 1
|
2022-01-01 17:33:44 +01:00
|
|
|
}
|
2022-01-05 19:58:01 +01:00
|
|
|
|
|
|
|
test_unknown_host() {
|
|
|
|
setup_simple_test '' ''
|
|
|
|
|
|
|
|
ggflags="-N -H foobar"
|
|
|
|
fetch /
|
|
|
|
check_reply '59 Wrong/malformed host or missing SNI'
|
|
|
|
}
|
2022-02-26 15:02:45 +01:00
|
|
|
|
|
|
|
test_include_mime() {
|
|
|
|
setup_simple_test "types { include '$PWD/example.mime.types' }" ""
|
|
|
|
|
|
|
|
fetch_hdr /
|
2022-03-26 11:56:06 +01:00
|
|
|
check_reply '20 text/gemini' || return 1
|
2022-02-26 15:02:45 +01:00
|
|
|
|
|
|
|
fetch_hdr /test.m3u8
|
2022-03-26 11:56:06 +01:00
|
|
|
check_reply '20 application/vnd.apple.mpegurl' || return 1
|
2022-02-26 15:02:45 +01:00
|
|
|
|
|
|
|
fetch_hdr /foo.1
|
2022-03-26 11:56:06 +01:00
|
|
|
check_reply '20 text/x-mandoc' || return 1
|
2022-02-26 15:02:45 +01:00
|
|
|
}
|
2023-07-24 10:51:35 +02:00
|
|
|
|
|
|
|
test_log_file() {
|
|
|
|
rm -f log log.edited
|
2023-08-04 00:37:05 +02:00
|
|
|
setup_simple_test '
|
|
|
|
log access "'$PWD'/log"
|
|
|
|
log style legacy'
|
2023-07-24 10:51:35 +02:00
|
|
|
|
|
|
|
fetch_hdr /
|
|
|
|
check_reply '20 text/gemini'
|
|
|
|
|
2023-08-04 00:37:05 +02:00
|
|
|
# remove the ip
|
|
|
|
awk '{$1 = ""; print substr($0, 2)}' log > log.edited
|
2023-07-24 10:51:35 +02:00
|
|
|
|
2023-08-04 00:37:05 +02:00
|
|
|
printf '%s\n' 'GET gemini://localhost/ 20 text/gemini' \
|
2023-07-25 22:07:26 +02:00
|
|
|
| cmp -s - log.edited
|
2023-07-24 10:51:35 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
# keep the log for post-mortem analysis
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f log log.edited
|
|
|
|
return 0
|
|
|
|
}
|
2024-05-29 09:54:03 +02:00
|
|
|
|
2024-05-29 10:56:10 +02:00
|
|
|
test_ipv4_addr() {
|
2024-05-29 09:54:03 +02:00
|
|
|
server_name="*"
|
2024-05-29 10:33:36 +02:00
|
|
|
host="127.0.0.1"
|
2024-05-29 09:54:03 +02:00
|
|
|
gghost=127.0.0.1
|
|
|
|
ggflags=-N
|
|
|
|
setup_simple_test
|
|
|
|
|
|
|
|
fetch /
|
|
|
|
check_reply "20 text/gemini" "# hello world" || return 1
|
|
|
|
}
|
2024-05-29 10:56:10 +02:00
|
|
|
|
|
|
|
test_ipv6_addr() {
|
|
|
|
server_name="*"
|
|
|
|
host="::1"
|
|
|
|
gghost="[::1]"
|
|
|
|
ggflags=-N
|
|
|
|
setup_simple_test
|
|
|
|
|
|
|
|
fetch /
|
|
|
|
check_reply "20 text/gemini" "# hello world" || return 1
|
|
|
|
}
|
2024-05-29 11:06:45 +02:00
|
|
|
|
|
|
|
test_ipv6_server() {
|
|
|
|
server_name="::1"
|
|
|
|
host="::1"
|
|
|
|
gghost="[::1]"
|
|
|
|
ggflags=-N
|
|
|
|
setup_simple_test
|
|
|
|
|
|
|
|
fetch /
|
|
|
|
check_reply "20 text/gemini" "# hello world" || return 1
|
|
|
|
}
|