1 test_configless_mode() {
4 $gmid -p $port -H localhost -d . testdata &
10 check_reply "20 text/gemini" "# hello world" || return 1
17 check_reply "20 text/gemini" "# hello world" || return 1
20 check_reply "51 not found" || return 1
23 check_reply "20 text/gemini" "# hello world" || return 1
26 test_directory_redirect() {
30 check_reply "30 /dir/" || return 1
33 check_reply "51 not found" || return 1
36 test_serve_big_files() {
39 hdr="$(head /bigfile)"
40 get /bigfile > bigfile
41 sha bigfile bigfile.sha
42 body="$(cat bigfile.sha)"
44 check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
47 test_dont_execute_scripts() {
51 check_reply "20 application/octet-stream" "" || return 1
55 setup_simple_test 'map "text/x-funny" to-ext "gmi"' ''
58 check_reply "20 text/x-funny"
62 setup_simple_test '' 'default type "application/x-foo"'
65 check_reply "20 application/x-foo"
69 setup_simple_test '' 'lang it'
72 check_reply "20 text/gemini;lang=it"
75 test_parse_custom_lang_per_location() {
76 setup_simple_test '' \
77 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
78 # can parse multiple locations
82 setup_simple_test '' 'cgi "*"'
85 check_reply "20 text/gemini" "# hello world" || return 1
88 check_reply "20 text/gemini" "# hello world" || return 1
91 check_reply "42 CGI error" || return 1
94 check_reply "42 CGI error" || return 1
97 test_cgi_big_replies() {
98 setup_simple_test '' 'cgi "*"'
100 hdr="$(head /serve-bigfile)"
101 get /bigfile > bigfile
102 sha bigfile bigfile.sha
103 body="$(cat bigfile.sha)"
104 check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
107 test_cgi_split_query() {
108 setup_simple_test '' 'cgi "*"'
110 for s in "1" "2 ?foo" "3 ?foo+bar" "1 ?foo+bar=5" "3 ?foo+bar%3d5"; do
111 exp="$(echo $s | sed 's/ .*//')"
112 qry="$(echo $s | sed 's/^..//')"
114 if [ "$exp" = "$qry" ]; then
115 # the "1" case yields exp == qry
121 n="$(get "$url" | awk /^-/ | count)"
122 if [ $? -ne 0 ]; then
123 echo "failed to get /$url"
127 if [ "$n" -ne $exp ]; then
128 echo "Unexpected number of args"
136 test_custom_index() {
137 setup_simple_test '' 'index "foo.gmi"'
140 check_reply "20 text/gemini" "# hello world"
143 test_custom_index_default_type_per_location() {
144 setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
147 check_reply "20 text/plain" "$(cat hello)"
151 setup_simple_test '' 'location "/dir/*" { auto index on }'
154 check_reply "20 text/gemini" "# hello world" || return 1
157 check_reply "30 /dir/" || return 1
160 check_reply "20 text/gemini"
162 # we expect 5 lines from the auto index
164 body="$(get /dir/ | count)"
165 if [ $? -ne 0 ]; then
166 echo 'failed to get /dir/'
170 if [ "$body" -ne 5 ]; then
171 echo "expected five lines from the auto index, got $body"
177 setup_simple_test '' 'location "*" { block }'
180 check_reply "40 temporary failure" || return 1
183 check_reply "40 temporary failure" || return 1
186 test_block_return_fmt() {
187 setup_simple_test '' '
190 block return 40 "%% %p %q %P %N test"
194 block return 40 "%% %p %q %P %N test"
197 fetch_hdr /dir/foo.gmi
198 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
201 check_reply "40 % / 10965 localhost test" || return 1
205 setup_simple_test '' 'entrypoint "/env"'
208 check_reply "20 text/plain; lang=en" || return 1
210 # TODO: test something similar with plain cgi too
212 body="$(get /foo/bar|grep PATH_INFO)"
213 if [ $? -ne 0 ]; then
214 echo "failed to get /foo/bar"
218 if [ "$body" != "PATH_INFO=/foo/bar" ]; then
219 echo "Invalid PATH_INFO generated"
220 echo "want : PATH_INFO=/foo/bar"
226 test_require_client_ca() {
227 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
230 check_reply "60 client certificate required" || return 1
232 ggflags="-C valid.crt -K valid.key"
234 check_reply "20 text/gemini" || return 1
236 ggflags="-C invalid.cert.pem -K invalid.key.pem"
238 check_reply "61 certificate not authorised" || return 1
241 test_root_inside_location() {
242 setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
245 check_reply "51 not found" || return 1
248 check_reply "20 text/gemini"
251 test_root_inside_location_with_redirect() {
252 setup_simple_test '' '
253 location "/foo" { block return 31 "%p/" }
254 location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
257 check_reply "31 /foo/" || return 1
260 check_reply "20 text/gemini"
264 # XXX: prefork 1 for testing
265 setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
268 check_reply "20 text/gemini" "# Hello, world!"
271 test_macro_expansion() {
277 # the quoting of \$ is for sh
278 cert \$pwd "/cert.pem"
280 root \$pwd "/testdata"
285 echo "failed to parse the config"
292 check_reply "20 text/gemini" "# hello world"
295 # 1.7.4 bugfix: check_for_cgi goes out-of-bound processing a string
296 # that doesn't contain a '/'
298 setup_simple_test '' 'cgi "*"'
301 for i in 0 1 2 3 4 5 6 7 8 9; do
303 check_reply "51 not found" || return 1