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 176179b2 2021-10-04 op test_configless_mode() {
12 a721c233 2021-12-09 op dont_check_server_alive=yes
14 176179b2 2021-10-04 op $gmid -p $port -H localhost -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_cgi_scripts() {
96 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
99 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
102 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
105 176179b2 2021-10-04 op check_reply "42 CGI error" || return 1
107 176179b2 2021-10-04 op fetch /invalid
108 176179b2 2021-10-04 op check_reply "42 CGI error" || return 1
111 176179b2 2021-10-04 op test_cgi_big_replies() {
112 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
114 176179b2 2021-10-04 op hdr="$(head /serve-bigfile)"
115 176179b2 2021-10-04 op get /bigfile > bigfile
116 6e0f14d5 2021-10-04 op ./sha bigfile bigfile.sha
117 176179b2 2021-10-04 op body="$(cat bigfile.sha)"
118 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
121 176179b2 2021-10-04 op test_cgi_split_query() {
122 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
124 176179b2 2021-10-04 op for s in "1" "2 ?foo" "3 ?foo+bar" "1 ?foo+bar=5" "3 ?foo+bar%3d5"; do
125 176179b2 2021-10-04 op exp="$(echo $s | sed 's/ .*//')"
126 176179b2 2021-10-04 op qry="$(echo $s | sed 's/^..//')"
128 176179b2 2021-10-04 op if [ "$exp" = "$qry" ]; then
129 176179b2 2021-10-04 op # the "1" case yields exp == qry
133 176179b2 2021-10-04 op url="/env$qry"
135 176179b2 2021-10-04 op n="$(get "$url" | awk /^-/ | count)"
136 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
137 176179b2 2021-10-04 op echo "failed to get /$url"
141 176179b2 2021-10-04 op if [ "$n" -ne $exp ]; then
142 176179b2 2021-10-04 op echo "Unexpected number of args"
143 176179b2 2021-10-04 op echo "want : $exp"
144 176179b2 2021-10-04 op echo "got : $n"
150 176179b2 2021-10-04 op test_custom_index() {
151 176179b2 2021-10-04 op setup_simple_test '' 'index "foo.gmi"'
154 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
157 176179b2 2021-10-04 op test_custom_index_default_type_per_location() {
158 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
161 176179b2 2021-10-04 op check_reply "20 text/plain" "$(cat hello)"
164 176179b2 2021-10-04 op test_auto_index() {
165 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { auto index on }'
168 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
170 176179b2 2021-10-04 op fetch_hdr /dir
171 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
173 176179b2 2021-10-04 op fetch_hdr /dir/
174 176179b2 2021-10-04 op check_reply "20 text/gemini"
176 176179b2 2021-10-04 op # we expect 5 lines from the auto index
178 176179b2 2021-10-04 op body="$(get /dir/ | count)"
179 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
180 176179b2 2021-10-04 op echo 'failed to get /dir/'
184 176179b2 2021-10-04 op if [ "$body" -ne 5 ]; then
185 176179b2 2021-10-04 op echo "expected five lines from the auto index, got $body"
190 176179b2 2021-10-04 op test_block() {
191 176179b2 2021-10-04 op setup_simple_test '' 'location "*" { block }'
194 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
196 176179b2 2021-10-04 op fetch /nonexists
197 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
200 176179b2 2021-10-04 op test_block_return_fmt() {
201 176179b2 2021-10-04 op setup_simple_test '' '
202 176179b2 2021-10-04 op location "/dir" {
204 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
206 176179b2 2021-10-04 op location "*" {
208 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
211 176179b2 2021-10-04 op fetch_hdr /dir/foo.gmi
212 176179b2 2021-10-04 op check_reply "40 % /foo.gmi 10965 localhost test" || return 1
214 176179b2 2021-10-04 op fetch_hdr /bigfile
215 176179b2 2021-10-04 op check_reply "40 % / 10965 localhost test" || return 1
218 176179b2 2021-10-04 op test_entrypoint() {
219 176179b2 2021-10-04 op setup_simple_test '' 'entrypoint "/env"'
221 176179b2 2021-10-04 op fetch_hdr /foo/bar
222 176179b2 2021-10-04 op check_reply "20 text/plain; lang=en" || return 1
224 176179b2 2021-10-04 op # TODO: test something similar with plain cgi too
226 176179b2 2021-10-04 op body="$(get /foo/bar|grep PATH_INFO)"
227 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
228 176179b2 2021-10-04 op echo "failed to get /foo/bar"
232 176179b2 2021-10-04 op if [ "$body" != "PATH_INFO=/foo/bar" ]; then
233 176179b2 2021-10-04 op echo "Invalid PATH_INFO generated"
234 176179b2 2021-10-04 op echo "want : PATH_INFO=/foo/bar"
235 176179b2 2021-10-04 op echo "got : $body"
240 176179b2 2021-10-04 op test_require_client_ca() {
241 176179b2 2021-10-04 op setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
244 176179b2 2021-10-04 op check_reply "60 client certificate required" || return 1
246 176179b2 2021-10-04 op ggflags="-C valid.crt -K valid.key"
248 176179b2 2021-10-04 op check_reply "20 text/gemini" || return 1
250 176179b2 2021-10-04 op ggflags="-C invalid.cert.pem -K invalid.key.pem"
252 176179b2 2021-10-04 op check_reply "61 certificate not authorised" || return 1
255 176179b2 2021-10-04 op test_root_inside_location() {
256 176179b2 2021-10-04 op setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
259 176179b2 2021-10-04 op check_reply "51 not found" || return 1
261 176179b2 2021-10-04 op fetch_hdr /foo/
262 176179b2 2021-10-04 op check_reply "20 text/gemini"
265 176179b2 2021-10-04 op test_root_inside_location_with_redirect() {
266 176179b2 2021-10-04 op setup_simple_test '' '
267 176179b2 2021-10-04 op location "/foo" { block return 31 "%p/" }
268 176179b2 2021-10-04 op location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
271 176179b2 2021-10-04 op check_reply "31 /foo/" || return 1
273 176179b2 2021-10-04 op fetch_hdr /foo/
274 176179b2 2021-10-04 op check_reply "20 text/gemini"
277 176179b2 2021-10-04 op test_fastcgi() {
278 176179b2 2021-10-04 op # XXX: prefork 1 for testing
279 176179b2 2021-10-04 op setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
282 176179b2 2021-10-04 op check_reply "20 text/gemini" "# Hello, world!"
285 176179b2 2021-10-04 op test_macro_expansion() {
286 176179b2 2021-10-04 op cat <<EOF > reg.conf
288 176179b2 2021-10-04 op $config_common
290 176179b2 2021-10-04 op server "localhost" {
291 176179b2 2021-10-04 op # the quoting of \$ is for sh
292 176179b2 2021-10-04 op cert \$pwd "/cert.pem"
293 176179b2 2021-10-04 op key \$pwd "/key.pem"
294 176179b2 2021-10-04 op root \$pwd "/testdata"
298 176179b2 2021-10-04 op if ! checkconf; then
299 176179b2 2021-10-04 op echo "failed to parse the config"
306 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
309 176179b2 2021-10-04 op # 1.7.4 bugfix: check_for_cgi goes out-of-bound processing a string
310 176179b2 2021-10-04 op # that doesn't contain a '/'
311 176179b2 2021-10-04 op test_174_bugfix() {
312 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
314 176179b2 2021-10-04 op # thanks cage :)
315 176179b2 2021-10-04 op for i in 0 1 2 3 4 5 6 7 8 9; do
316 176179b2 2021-10-04 op fetch /favicon.txt
317 176179b2 2021-10-04 op check_reply "51 not found" || return 1
321 4b5b1e82 2021-12-29 op test_proxy_relay_to() {
322 4b5b1e82 2021-12-29 op gen_config '' ''
327 c064f3de 2021-01-01 op ggflags="-P localhost:$port -H localhost.local"
330 c064f3de 2021-01-01 op check_reply "20 text/gemini" "# hello world"
333 c064f3de 2021-01-01 op test_proxy_with_certs() {
334 92a9f41d 2022-01-03 op ggflags="-P localhost:$port -H localhost.local"
336 92a9f41d 2022-01-03 op # first test using the valid keys
338 c064f3de 2021-01-01 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
340 92a9f41d 2022-01-03 op cert \"$PWD/valid.crt\"
341 92a9f41d 2022-01-03 op key \"$PWD/valid.key\"
346 92a9f41d 2022-01-03 op check_reply "20 text/gemini" "# hello world" || return 1
348 92a9f41d 2022-01-03 op # then using some invalid keys
350 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
352 92a9f41d 2022-01-03 op cert \"$PWD/invalid.cert.pem\"
353 92a9f41d 2022-01-03 op key \"$PWD/invalid.key.pem\"
358 92a9f41d 2022-01-03 op check_reply "61 certificate not authorised" || return 1
360 92a9f41d 2022-01-03 op # and finally without keys
362 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
367 92a9f41d 2022-01-03 op check_reply "60 client certificate required" || return 1
370 901905e0 2022-01-05 op test_unknown_host() {
371 901905e0 2022-01-05 op setup_simple_test '' ''
373 901905e0 2022-01-05 op ggflags="-N -H foobar"
375 901905e0 2022-01-05 op check_reply '59 Wrong/malformed host or missing SNI'
378 fb121226 2022-02-26 op test_include_mime() {
379 fb121226 2022-02-26 op setup_simple_test "types { include '$PWD/example.mime.types' }" ""
382 91971201 2022-03-26 op check_reply '20 text/gemini' || return 1
384 fb121226 2022-02-26 op fetch_hdr /test.m3u8
385 91971201 2022-03-26 op check_reply '20 application/vnd.apple.mpegurl' || return 1
387 fb121226 2022-02-26 op fetch_hdr /foo.1
388 91971201 2022-03-26 op check_reply '20 text/x-mandoc' || return 1