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
51 6e0f14d5 2021-10-04 op ./sha bigfile bigfile.sha
52 176179b2 2021-10-04 op body="$(cat bigfile.sha)"
54 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
57 176179b2 2021-10-04 op test_dont_execute_scripts() {
58 176179b2 2021-10-04 op setup_simple_test
60 176179b2 2021-10-04 op fetch_hdr /hello
61 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "" || return 1
64 176179b2 2021-10-04 op test_custom_mime() {
65 9448a01f 2022-04-07 op setup_simple_test '
67 9448a01f 2022-04-07 op text/x-funny gmi
72 176179b2 2021-10-04 op check_reply "20 text/x-funny"
75 176179b2 2021-10-04 op test_default_type() {
76 176179b2 2021-10-04 op setup_simple_test '' 'default type "application/x-foo"'
78 176179b2 2021-10-04 op fetch_hdr /hello
79 176179b2 2021-10-04 op check_reply "20 application/x-foo"
82 176179b2 2021-10-04 op test_custom_lang() {
83 176179b2 2021-10-04 op setup_simple_test '' 'lang it'
86 176179b2 2021-10-04 op check_reply "20 text/gemini;lang=it"
89 176179b2 2021-10-04 op test_parse_custom_lang_per_location() {
90 176179b2 2021-10-04 op setup_simple_test '' \
91 176179b2 2021-10-04 op 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
92 176179b2 2021-10-04 op # can parse multiple locations
95 176179b2 2021-10-04 op test_custom_index() {
96 176179b2 2021-10-04 op setup_simple_test '' 'index "foo.gmi"'
99 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
102 176179b2 2021-10-04 op test_custom_index_default_type_per_location() {
103 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
106 176179b2 2021-10-04 op check_reply "20 text/plain" "$(cat hello)"
109 176179b2 2021-10-04 op test_auto_index() {
110 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { auto index on }'
113 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
115 176179b2 2021-10-04 op fetch_hdr /dir
116 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
118 176179b2 2021-10-04 op fetch_hdr /dir/
119 475205fa 2022-07-04 op check_reply "20 text/gemini" || return 1
121 475205fa 2022-07-04 op get /dir/ > listing || return 1
122 475205fa 2022-07-04 op cat <<EOF > listing.expected
123 475205fa 2022-07-04 op # Index of /dir/
126 475205fa 2022-07-04 op => ./current%20date
131 475205fa 2022-07-04 op cmp -s listing.expected listing
133 475205fa 2022-07-04 op if [ $ret -ne 0 ]; then
134 475205fa 2022-07-04 op echo 'unexpected dir content:'
135 475205fa 2022-07-04 op diff -u listing.expected listing
137 475205fa 2022-07-04 op rm listing listing.expected
142 176179b2 2021-10-04 op test_block() {
143 176179b2 2021-10-04 op setup_simple_test '' 'location "*" { block }'
146 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
148 176179b2 2021-10-04 op fetch /nonexists
149 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
152 176179b2 2021-10-04 op test_block_return_fmt() {
153 176179b2 2021-10-04 op setup_simple_test '' '
154 176179b2 2021-10-04 op location "/dir" {
156 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
158 176179b2 2021-10-04 op location "*" {
160 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
163 176179b2 2021-10-04 op fetch_hdr /dir/foo.gmi
164 176179b2 2021-10-04 op check_reply "40 % /foo.gmi 10965 localhost test" || return 1
166 176179b2 2021-10-04 op fetch_hdr /bigfile
167 176179b2 2021-10-04 op check_reply "40 % / 10965 localhost test" || return 1
170 176179b2 2021-10-04 op test_require_client_ca() {
171 176179b2 2021-10-04 op setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
174 176179b2 2021-10-04 op check_reply "60 client certificate required" || return 1
176 176179b2 2021-10-04 op ggflags="-C valid.crt -K valid.key"
178 176179b2 2021-10-04 op check_reply "20 text/gemini" || return 1
180 176179b2 2021-10-04 op ggflags="-C invalid.cert.pem -K invalid.key.pem"
182 176179b2 2021-10-04 op check_reply "61 certificate not authorised" || return 1
185 176179b2 2021-10-04 op test_root_inside_location() {
186 176179b2 2021-10-04 op setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
189 176179b2 2021-10-04 op check_reply "51 not found" || return 1
191 176179b2 2021-10-04 op fetch_hdr /foo/
192 176179b2 2021-10-04 op check_reply "20 text/gemini"
195 176179b2 2021-10-04 op test_root_inside_location_with_redirect() {
196 176179b2 2021-10-04 op setup_simple_test '' '
197 176179b2 2021-10-04 op location "/foo" { block return 31 "%p/" }
198 176179b2 2021-10-04 op location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
201 176179b2 2021-10-04 op check_reply "31 /foo/" || return 1
203 176179b2 2021-10-04 op fetch_hdr /foo/
204 176179b2 2021-10-04 op check_reply "20 text/gemini"
207 176179b2 2021-10-04 op test_fastcgi() {
208 176179b2 2021-10-04 op # XXX: prefork 1 for testing
209 176179b2 2021-10-04 op setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
212 176179b2 2021-10-04 op check_reply "20 text/gemini" "# Hello, world!"
215 176179b2 2021-10-04 op test_macro_expansion() {
216 176179b2 2021-10-04 op cat <<EOF > reg.conf
218 176179b2 2021-10-04 op $config_common
220 176179b2 2021-10-04 op server "localhost" {
221 176179b2 2021-10-04 op # the quoting of \$ is for sh
222 176179b2 2021-10-04 op cert \$pwd "/cert.pem"
223 176179b2 2021-10-04 op key \$pwd "/key.pem"
224 176179b2 2021-10-04 op root \$pwd "/testdata"
228 176179b2 2021-10-04 op if ! checkconf; then
229 176179b2 2021-10-04 op echo "failed to parse the config"
236 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
239 4b5b1e82 2021-12-29 op test_proxy_relay_to() {
240 4b5b1e82 2021-12-29 op gen_config '' ''
245 c064f3de 2022-01-01 op ggflags="-P localhost:$port -H localhost.local"
248 c064f3de 2022-01-01 op check_reply "20 text/gemini" "# hello world"
251 c064f3de 2022-01-01 op test_proxy_with_certs() {
252 92a9f41d 2022-01-03 op ggflags="-P localhost:$port -H localhost.local"
254 92a9f41d 2022-01-03 op # first test using the valid keys
256 c064f3de 2022-01-01 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
258 92a9f41d 2022-01-03 op cert \"$PWD/valid.crt\"
259 92a9f41d 2022-01-03 op key \"$PWD/valid.key\"
264 92a9f41d 2022-01-03 op check_reply "20 text/gemini" "# hello world" || return 1
266 92a9f41d 2022-01-03 op # then using some invalid keys
268 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
270 92a9f41d 2022-01-03 op cert \"$PWD/invalid.cert.pem\"
271 92a9f41d 2022-01-03 op key \"$PWD/invalid.key.pem\"
276 92a9f41d 2022-01-03 op check_reply "61 certificate not authorised" || return 1
278 92a9f41d 2022-01-03 op # and finally without keys
280 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
285 92a9f41d 2022-01-03 op check_reply "60 client certificate required" || return 1
288 901905e0 2022-01-05 op test_unknown_host() {
289 901905e0 2022-01-05 op setup_simple_test '' ''
291 901905e0 2022-01-05 op ggflags="-N -H foobar"
293 901905e0 2022-01-05 op check_reply '59 Wrong/malformed host or missing SNI'
296 fb121226 2022-02-26 op test_include_mime() {
297 fb121226 2022-02-26 op setup_simple_test "types { include '$PWD/example.mime.types' }" ""
300 91971201 2022-03-26 op check_reply '20 text/gemini' || return 1
302 fb121226 2022-02-26 op fetch_hdr /test.m3u8
303 91971201 2022-03-26 op check_reply '20 application/vnd.apple.mpegurl' || return 1
305 fb121226 2022-02-26 op fetch_hdr /foo.1
306 91971201 2022-03-26 op check_reply '20 text/x-mandoc' || return 1