Blob


1 test_configless_mode() {
2 dont_check=yes
4 $gmid -p $port -H localhost -d . testdata &
5 pid=$!
6 sleep 1
8 fetch /
9 kill $pid
10 check_reply "20 text/gemini" "# hello world" || return 1
11 }
13 test_static_files() {
14 setup_simple_test
16 fetch /
17 check_reply "20 text/gemini" "# hello world" || return 1
19 fetch /foo
20 check_reply "51 not found" || return 1
22 fetch /dir/foo.gmi
23 check_reply "20 text/gemini" "# hello world" || return 1
24 }
26 test_directory_redirect() {
27 setup_simple_test
29 fetch /dir
30 check_reply "30 /dir/" || return 1
32 fetch /dir/
33 check_reply "51 not found" || return 1
34 }
36 test_serve_big_files() {
37 setup_simple_test
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)"
45 }
47 test_dont_execute_scripts() {
48 setup_simple_test
50 fetch_hdr /hello
51 check_reply "20 application/octet-stream" "" || return 1
52 }
54 test_custom_mime() {
55 setup_simple_test 'map "text/x-funny" to-ext "gmi"' ''
57 fetch_hdr /
58 check_reply "20 text/x-funny"
59 }
61 test_default_type() {
62 setup_simple_test '' 'default type "application/x-foo"'
64 fetch_hdr /hello
65 check_reply "20 application/x-foo"
66 }
68 test_custom_lang() {
69 setup_simple_test '' 'lang it'
71 fetch_hdr /
72 check_reply "20 text/gemini;lang=it"
73 }
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
79 }
81 test_cgi_scripts() {
82 setup_simple_test '' 'cgi "*"'
84 fetch /hello
85 check_reply "20 text/gemini" "# hello world" || return 1
87 fetch /slow
88 check_reply "20 text/gemini" "# hello world" || return 1
90 fetch /err
91 check_reply "42 CGI error" || return 1
93 fetch /invalid
94 check_reply "42 CGI error" || return 1
95 }
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
116 qry=''
117 fi
119 url="/env$qry"
121 n="$(get "$url" | awk /^-/ | count)"
122 if [ $? -ne 0 ]; then
123 echo "failed to get /$url"
124 return 1
125 fi
127 if [ "$n" -ne $exp ]; then
128 echo "Unexpected number of args"
129 echo "want : $exp"
130 echo "got : $n"
131 return 1
132 fi
133 done
136 test_custom_index() {
137 setup_simple_test '' 'index "foo.gmi"'
139 fetch /dir/
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" }'
146 fetch /dir/
147 check_reply "20 text/plain" "$(cat hello)"
150 test_auto_index() {
151 setup_simple_test '' 'location "/dir/*" { auto index on }'
153 fetch /
154 check_reply "20 text/gemini" "# hello world" || return 1
156 fetch_hdr /dir
157 check_reply "30 /dir/" || return 1
159 fetch_hdr /dir/
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/'
167 return 1
168 fi
170 if [ "$body" -ne 5 ]; then
171 echo "expected five lines from the auto index, got $body"
172 return 1
173 fi
176 test_block() {
177 setup_simple_test '' 'location "*" { block }'
179 fetch /
180 check_reply "40 temporary failure" || return 1
182 fetch /nonexists
183 check_reply "40 temporary failure" || return 1
186 test_block_return_fmt() {
187 setup_simple_test '' '
188 location "/dir" {
189 strip 1
190 block return 40 "%% %p %q %P %N test"
192 location "*" {
193 strip 99
194 block return 40 "%% %p %q %P %N test"
195 }'
197 fetch_hdr /dir/foo.gmi
198 check_reply "40 % /foo.gmi 10965 localhost test" || return 1
200 fetch_hdr /bigfile
201 check_reply "40 % / 10965 localhost test" || return 1
204 test_entrypoint() {
205 setup_simple_test '' 'entrypoint "/env"'
207 fetch_hdr /foo/bar
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"
215 return 1
216 fi
218 if [ "$body" != "PATH_INFO=/foo/bar" ]; then
219 echo "Invalid PATH_INFO generated"
220 echo "want : PATH_INFO=/foo/bar"
221 echo "got : $body"
222 return 1
223 fi
226 test_require_client_ca() {
227 setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
229 fetch /
230 check_reply "60 client certificate required" || return 1
232 ggflags="-C valid.crt -K valid.key"
233 fetch_hdr /
234 check_reply "20 text/gemini" || return 1
236 ggflags="-C invalid.cert.pem -K invalid.key.pem"
237 fetch_hdr /
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 }'
244 fetch /foo
245 check_reply "51 not found" || return 1
247 fetch_hdr /foo/
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 }'
256 fetch /foo
257 check_reply "31 /foo/" || return 1
259 fetch_hdr /foo/
260 check_reply "20 text/gemini"
263 test_fastcgi() {
264 # XXX: prefork 1 for testing
265 setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
267 fetch /
268 check_reply "20 text/gemini" "# Hello, world!"
271 test_macro_expansion() {
272 cat <<EOF > reg.conf
273 pwd = "$PWD"
274 $config_common
276 server "localhost" {
277 # the quoting of \$ is for sh
278 cert \$pwd "/cert.pem"
279 key \$pwd "/key.pem"
280 root \$pwd "/testdata"
282 EOF
284 if ! checkconf; then
285 echo "failed to parse the config"
286 return 1
287 fi
289 run
291 fetch /
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 '/'
297 test_174_bugfix() {
298 setup_simple_test '' 'cgi "*"'
300 # thanks cage :)
301 for i in 0 1 2 3 4 5 6 7 8 9; do
302 fetch /favicon.txt
303 check_reply "51 not found" || return 1
304 done