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 176179b2 2021-10-04 op setup_simple_test 'map "text/x-funny" to-ext "gmi"' ''
68 176179b2 2021-10-04 op check_reply "20 text/x-funny"
71 176179b2 2021-10-04 op test_default_type() {
72 176179b2 2021-10-04 op setup_simple_test '' 'default type "application/x-foo"'
74 176179b2 2021-10-04 op fetch_hdr /hello
75 176179b2 2021-10-04 op check_reply "20 application/x-foo"
78 176179b2 2021-10-04 op test_custom_lang() {
79 176179b2 2021-10-04 op setup_simple_test '' 'lang it'
82 176179b2 2021-10-04 op check_reply "20 text/gemini;lang=it"
85 176179b2 2021-10-04 op test_parse_custom_lang_per_location() {
86 176179b2 2021-10-04 op setup_simple_test '' \
87 176179b2 2021-10-04 op 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
88 176179b2 2021-10-04 op # can parse multiple locations
91 176179b2 2021-10-04 op test_cgi_scripts() {
92 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
95 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
98 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
101 176179b2 2021-10-04 op check_reply "42 CGI error" || return 1
103 176179b2 2021-10-04 op fetch /invalid
104 176179b2 2021-10-04 op check_reply "42 CGI error" || return 1
107 176179b2 2021-10-04 op test_cgi_big_replies() {
108 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
110 176179b2 2021-10-04 op hdr="$(head /serve-bigfile)"
111 176179b2 2021-10-04 op get /bigfile > bigfile
112 6e0f14d5 2021-10-04 op ./sha bigfile bigfile.sha
113 176179b2 2021-10-04 op body="$(cat bigfile.sha)"
114 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
117 176179b2 2021-10-04 op test_cgi_split_query() {
118 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
120 176179b2 2021-10-04 op for s in "1" "2 ?foo" "3 ?foo+bar" "1 ?foo+bar=5" "3 ?foo+bar%3d5"; do
121 176179b2 2021-10-04 op exp="$(echo $s | sed 's/ .*//')"
122 176179b2 2021-10-04 op qry="$(echo $s | sed 's/^..//')"
124 176179b2 2021-10-04 op if [ "$exp" = "$qry" ]; then
125 176179b2 2021-10-04 op # the "1" case yields exp == qry
129 176179b2 2021-10-04 op url="/env$qry"
131 176179b2 2021-10-04 op n="$(get "$url" | awk /^-/ | count)"
132 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
133 176179b2 2021-10-04 op echo "failed to get /$url"
137 176179b2 2021-10-04 op if [ "$n" -ne $exp ]; then
138 176179b2 2021-10-04 op echo "Unexpected number of args"
139 176179b2 2021-10-04 op echo "want : $exp"
140 176179b2 2021-10-04 op echo "got : $n"
146 176179b2 2021-10-04 op test_custom_index() {
147 176179b2 2021-10-04 op setup_simple_test '' 'index "foo.gmi"'
150 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
153 176179b2 2021-10-04 op test_custom_index_default_type_per_location() {
154 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
157 176179b2 2021-10-04 op check_reply "20 text/plain" "$(cat hello)"
160 176179b2 2021-10-04 op test_auto_index() {
161 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { auto index on }'
164 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
166 176179b2 2021-10-04 op fetch_hdr /dir
167 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
169 176179b2 2021-10-04 op fetch_hdr /dir/
170 176179b2 2021-10-04 op check_reply "20 text/gemini"
172 176179b2 2021-10-04 op # we expect 5 lines from the auto index
174 176179b2 2021-10-04 op body="$(get /dir/ | count)"
175 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
176 176179b2 2021-10-04 op echo 'failed to get /dir/'
180 176179b2 2021-10-04 op if [ "$body" -ne 5 ]; then
181 176179b2 2021-10-04 op echo "expected five lines from the auto index, got $body"
186 176179b2 2021-10-04 op test_block() {
187 176179b2 2021-10-04 op setup_simple_test '' 'location "*" { block }'
190 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
192 176179b2 2021-10-04 op fetch /nonexists
193 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
196 176179b2 2021-10-04 op test_block_return_fmt() {
197 176179b2 2021-10-04 op setup_simple_test '' '
198 176179b2 2021-10-04 op location "/dir" {
200 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
202 176179b2 2021-10-04 op location "*" {
204 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
207 176179b2 2021-10-04 op fetch_hdr /dir/foo.gmi
208 176179b2 2021-10-04 op check_reply "40 % /foo.gmi 10965 localhost test" || return 1
210 176179b2 2021-10-04 op fetch_hdr /bigfile
211 176179b2 2021-10-04 op check_reply "40 % / 10965 localhost test" || return 1
214 176179b2 2021-10-04 op test_entrypoint() {
215 176179b2 2021-10-04 op setup_simple_test '' 'entrypoint "/env"'
217 176179b2 2021-10-04 op fetch_hdr /foo/bar
218 176179b2 2021-10-04 op check_reply "20 text/plain; lang=en" || return 1
220 176179b2 2021-10-04 op # TODO: test something similar with plain cgi too
222 176179b2 2021-10-04 op body="$(get /foo/bar|grep PATH_INFO)"
223 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
224 176179b2 2021-10-04 op echo "failed to get /foo/bar"
228 176179b2 2021-10-04 op if [ "$body" != "PATH_INFO=/foo/bar" ]; then
229 176179b2 2021-10-04 op echo "Invalid PATH_INFO generated"
230 176179b2 2021-10-04 op echo "want : PATH_INFO=/foo/bar"
231 176179b2 2021-10-04 op echo "got : $body"
236 176179b2 2021-10-04 op test_require_client_ca() {
237 176179b2 2021-10-04 op setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
240 176179b2 2021-10-04 op check_reply "60 client certificate required" || return 1
242 176179b2 2021-10-04 op ggflags="-C valid.crt -K valid.key"
244 176179b2 2021-10-04 op check_reply "20 text/gemini" || return 1
246 176179b2 2021-10-04 op ggflags="-C invalid.cert.pem -K invalid.key.pem"
248 176179b2 2021-10-04 op check_reply "61 certificate not authorised" || return 1
251 176179b2 2021-10-04 op test_root_inside_location() {
252 176179b2 2021-10-04 op setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
255 176179b2 2021-10-04 op check_reply "51 not found" || return 1
257 176179b2 2021-10-04 op fetch_hdr /foo/
258 176179b2 2021-10-04 op check_reply "20 text/gemini"
261 176179b2 2021-10-04 op test_root_inside_location_with_redirect() {
262 176179b2 2021-10-04 op setup_simple_test '' '
263 176179b2 2021-10-04 op location "/foo" { block return 31 "%p/" }
264 176179b2 2021-10-04 op location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
267 176179b2 2021-10-04 op check_reply "31 /foo/" || return 1
269 176179b2 2021-10-04 op fetch_hdr /foo/
270 176179b2 2021-10-04 op check_reply "20 text/gemini"
273 176179b2 2021-10-04 op test_fastcgi() {
274 176179b2 2021-10-04 op # XXX: prefork 1 for testing
275 176179b2 2021-10-04 op setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
278 176179b2 2021-10-04 op check_reply "20 text/gemini" "# Hello, world!"
281 176179b2 2021-10-04 op test_macro_expansion() {
282 176179b2 2021-10-04 op cat <<EOF > reg.conf
284 176179b2 2021-10-04 op $config_common
286 176179b2 2021-10-04 op server "localhost" {
287 176179b2 2021-10-04 op # the quoting of \$ is for sh
288 176179b2 2021-10-04 op cert \$pwd "/cert.pem"
289 176179b2 2021-10-04 op key \$pwd "/key.pem"
290 176179b2 2021-10-04 op root \$pwd "/testdata"
294 176179b2 2021-10-04 op if ! checkconf; then
295 176179b2 2021-10-04 op echo "failed to parse the config"
302 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
305 176179b2 2021-10-04 op # 1.7.4 bugfix: check_for_cgi goes out-of-bound processing a string
306 176179b2 2021-10-04 op # that doesn't contain a '/'
307 176179b2 2021-10-04 op test_174_bugfix() {
308 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
310 176179b2 2021-10-04 op # thanks cage :)
311 176179b2 2021-10-04 op for i in 0 1 2 3 4 5 6 7 8 9; do
312 176179b2 2021-10-04 op fetch /favicon.txt
313 176179b2 2021-10-04 op check_reply "51 not found" || return 1
317 4b5b1e82 2021-12-29 op test_proxy_relay_to() {
318 4b5b1e82 2021-12-29 op gen_config '' ''
323 c064f3de 2022-01-01 op ggflags="-P localhost:$port -H localhost.local"
326 c064f3de 2022-01-01 op check_reply "20 text/gemini" "# hello world"
329 c064f3de 2022-01-01 op test_proxy_with_certs() {
330 92a9f41d 2022-01-03 op ggflags="-P localhost:$port -H localhost.local"
332 92a9f41d 2022-01-03 op # first test using the valid keys
334 c064f3de 2022-01-01 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
336 92a9f41d 2022-01-03 op cert \"$PWD/valid.crt\"
337 92a9f41d 2022-01-03 op key \"$PWD/valid.key\"
342 92a9f41d 2022-01-03 op check_reply "20 text/gemini" "# hello world" || return 1
344 92a9f41d 2022-01-03 op # then using some invalid keys
346 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
348 92a9f41d 2022-01-03 op cert \"$PWD/invalid.cert.pem\"
349 92a9f41d 2022-01-03 op key \"$PWD/invalid.key.pem\"
354 92a9f41d 2022-01-03 op check_reply "61 certificate not authorised" || return 1
356 92a9f41d 2022-01-03 op # and finally without keys
358 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
363 92a9f41d 2022-01-03 op check_reply "60 client certificate required" || return 1
366 901905e0 2022-01-05 op test_unknown_host() {
367 901905e0 2022-01-05 op setup_simple_test '' ''
369 901905e0 2022-01-05 op ggflags="-N -H foobar"
371 901905e0 2022-01-05 op check_reply '59 Wrong/malformed host or missing SNI'