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
12 a721c233 2021-12-09 op dont_check_server_alive=yes
14 a5fb2593 2022-09-08 op $ge -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 9adeb265 2023-06-09 op setup_simple_test 'prefork 1' 'fastcgi "'$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 9adeb265 2023-06-09 op kill $fcgi_pid
241 176179b2 2021-10-04 op test_macro_expansion() {
242 176179b2 2021-10-04 op cat <<EOF > reg.conf
245 176179b2 2021-10-04 op server "localhost" {
246 176179b2 2021-10-04 op # the quoting of \$ is for sh
247 176179b2 2021-10-04 op cert \$pwd "/cert.pem"
248 176179b2 2021-10-04 op key \$pwd "/key.pem"
249 176179b2 2021-10-04 op root \$pwd "/testdata"
250 5a345722 2023-06-23 op listen on $REGRESS_HOST port $port
254 176179b2 2021-10-04 op if ! checkconf; then
255 176179b2 2021-10-04 op echo "failed to parse the config"
262 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
265 4b5b1e82 2021-12-29 op test_proxy_relay_to() {
266 4b5b1e82 2021-12-29 op gen_config '' ''
271 c064f3de 2022-01-01 op ggflags="-P localhost:$port -H localhost.local"
274 c064f3de 2022-01-01 op check_reply "20 text/gemini" "# hello world"
277 c064f3de 2022-01-01 op test_proxy_with_certs() {
278 92a9f41d 2022-01-03 op ggflags="-P localhost:$port -H localhost.local"
280 92a9f41d 2022-01-03 op # first test using the valid keys
282 c064f3de 2022-01-01 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
284 92a9f41d 2022-01-03 op cert \"$PWD/valid.crt\"
285 92a9f41d 2022-01-03 op key \"$PWD/valid.key\"
290 92a9f41d 2022-01-03 op check_reply "20 text/gemini" "# hello world" || return 1
292 92a9f41d 2022-01-03 op # then using some invalid keys
294 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
296 92a9f41d 2022-01-03 op cert \"$PWD/invalid.cert.pem\"
297 92a9f41d 2022-01-03 op key \"$PWD/invalid.key.pem\"
302 92a9f41d 2022-01-03 op check_reply "61 certificate not authorised" || return 1
304 92a9f41d 2022-01-03 op # and finally without keys
306 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
311 92a9f41d 2022-01-03 op check_reply "60 client certificate required" || return 1
314 901905e0 2022-01-05 op test_unknown_host() {
315 901905e0 2022-01-05 op setup_simple_test '' ''
317 901905e0 2022-01-05 op ggflags="-N -H foobar"
319 901905e0 2022-01-05 op check_reply '59 Wrong/malformed host or missing SNI'
322 fb121226 2022-02-26 op test_include_mime() {
323 fb121226 2022-02-26 op setup_simple_test "types { include '$PWD/example.mime.types' }" ""
326 91971201 2022-03-26 op check_reply '20 text/gemini' || return 1
328 fb121226 2022-02-26 op fetch_hdr /test.m3u8
329 91971201 2022-03-26 op check_reply '20 application/vnd.apple.mpegurl' || return 1
331 fb121226 2022-02-26 op fetch_hdr /foo.1
332 91971201 2022-03-26 op check_reply '20 text/x-mandoc' || return 1