Blame


1 176179b2 2021-10-04 op test_configless_mode() {
2 176179b2 2021-10-04 op dont_check=yes
3 176179b2 2021-10-04 op
4 176179b2 2021-10-04 op $gmid -p $port -H localhost -d . testdata &
5 176179b2 2021-10-04 op pid=$!
6 176179b2 2021-10-04 op sleep 1
7 176179b2 2021-10-04 op
8 176179b2 2021-10-04 op fetch /
9 176179b2 2021-10-04 op kill $pid
10 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
11 176179b2 2021-10-04 op }
12 176179b2 2021-10-04 op
13 176179b2 2021-10-04 op test_static_files() {
14 176179b2 2021-10-04 op setup_simple_test
15 176179b2 2021-10-04 op
16 176179b2 2021-10-04 op fetch /
17 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
18 176179b2 2021-10-04 op
19 176179b2 2021-10-04 op fetch /foo
20 176179b2 2021-10-04 op check_reply "51 not found" || return 1
21 176179b2 2021-10-04 op
22 176179b2 2021-10-04 op fetch /dir/foo.gmi
23 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
24 176179b2 2021-10-04 op }
25 176179b2 2021-10-04 op
26 176179b2 2021-10-04 op test_directory_redirect() {
27 176179b2 2021-10-04 op setup_simple_test
28 176179b2 2021-10-04 op
29 176179b2 2021-10-04 op fetch /dir
30 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
31 176179b2 2021-10-04 op
32 176179b2 2021-10-04 op fetch /dir/
33 176179b2 2021-10-04 op check_reply "51 not found" || return 1
34 176179b2 2021-10-04 op }
35 176179b2 2021-10-04 op
36 176179b2 2021-10-04 op test_serve_big_files() {
37 176179b2 2021-10-04 op setup_simple_test
38 176179b2 2021-10-04 op
39 176179b2 2021-10-04 op hdr="$(head /bigfile)"
40 176179b2 2021-10-04 op get /bigfile > bigfile
41 176179b2 2021-10-04 op sha bigfile bigfile.sha
42 176179b2 2021-10-04 op body="$(cat bigfile.sha)"
43 176179b2 2021-10-04 op
44 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
45 176179b2 2021-10-04 op }
46 176179b2 2021-10-04 op
47 176179b2 2021-10-04 op test_dont_execute_scripts() {
48 176179b2 2021-10-04 op setup_simple_test
49 176179b2 2021-10-04 op
50 176179b2 2021-10-04 op fetch_hdr /hello
51 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "" || return 1
52 176179b2 2021-10-04 op }
53 176179b2 2021-10-04 op
54 176179b2 2021-10-04 op test_custom_mime() {
55 176179b2 2021-10-04 op setup_simple_test 'map "text/x-funny" to-ext "gmi"' ''
56 176179b2 2021-10-04 op
57 176179b2 2021-10-04 op fetch_hdr /
58 176179b2 2021-10-04 op check_reply "20 text/x-funny"
59 176179b2 2021-10-04 op }
60 176179b2 2021-10-04 op
61 176179b2 2021-10-04 op test_default_type() {
62 176179b2 2021-10-04 op setup_simple_test '' 'default type "application/x-foo"'
63 176179b2 2021-10-04 op
64 176179b2 2021-10-04 op fetch_hdr /hello
65 176179b2 2021-10-04 op check_reply "20 application/x-foo"
66 176179b2 2021-10-04 op }
67 176179b2 2021-10-04 op
68 176179b2 2021-10-04 op test_custom_lang() {
69 176179b2 2021-10-04 op setup_simple_test '' 'lang it'
70 176179b2 2021-10-04 op
71 176179b2 2021-10-04 op fetch_hdr /
72 176179b2 2021-10-04 op check_reply "20 text/gemini;lang=it"
73 176179b2 2021-10-04 op }
74 176179b2 2021-10-04 op
75 176179b2 2021-10-04 op test_parse_custom_lang_per_location() {
76 176179b2 2021-10-04 op setup_simple_test '' \
77 176179b2 2021-10-04 op 'lang it location "/en/*" {lang en} location "/de/*" {lang de}'
78 176179b2 2021-10-04 op # can parse multiple locations
79 176179b2 2021-10-04 op }
80 176179b2 2021-10-04 op
81 176179b2 2021-10-04 op test_cgi_scripts() {
82 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
83 176179b2 2021-10-04 op
84 176179b2 2021-10-04 op fetch /hello
85 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
86 176179b2 2021-10-04 op
87 176179b2 2021-10-04 op fetch /slow
88 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
89 176179b2 2021-10-04 op
90 176179b2 2021-10-04 op fetch /err
91 176179b2 2021-10-04 op check_reply "42 CGI error" || return 1
92 176179b2 2021-10-04 op
93 176179b2 2021-10-04 op fetch /invalid
94 176179b2 2021-10-04 op check_reply "42 CGI error" || return 1
95 176179b2 2021-10-04 op }
96 176179b2 2021-10-04 op
97 176179b2 2021-10-04 op test_cgi_big_replies() {
98 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
99 176179b2 2021-10-04 op
100 176179b2 2021-10-04 op hdr="$(head /serve-bigfile)"
101 176179b2 2021-10-04 op get /bigfile > bigfile
102 176179b2 2021-10-04 op sha bigfile bigfile.sha
103 176179b2 2021-10-04 op body="$(cat bigfile.sha)"
104 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
105 176179b2 2021-10-04 op }
106 176179b2 2021-10-04 op
107 176179b2 2021-10-04 op test_cgi_split_query() {
108 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
109 176179b2 2021-10-04 op
110 176179b2 2021-10-04 op for s in "1" "2 ?foo" "3 ?foo+bar" "1 ?foo+bar=5" "3 ?foo+bar%3d5"; do
111 176179b2 2021-10-04 op exp="$(echo $s | sed 's/ .*//')"
112 176179b2 2021-10-04 op qry="$(echo $s | sed 's/^..//')"
113 176179b2 2021-10-04 op
114 176179b2 2021-10-04 op if [ "$exp" = "$qry" ]; then
115 176179b2 2021-10-04 op # the "1" case yields exp == qry
116 176179b2 2021-10-04 op qry=''
117 176179b2 2021-10-04 op fi
118 176179b2 2021-10-04 op
119 176179b2 2021-10-04 op url="/env$qry"
120 176179b2 2021-10-04 op
121 176179b2 2021-10-04 op n="$(get "$url" | awk /^-/ | count)"
122 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
123 176179b2 2021-10-04 op echo "failed to get /$url"
124 176179b2 2021-10-04 op return 1
125 176179b2 2021-10-04 op fi
126 176179b2 2021-10-04 op
127 176179b2 2021-10-04 op if [ "$n" -ne $exp ]; then
128 176179b2 2021-10-04 op echo "Unexpected number of args"
129 176179b2 2021-10-04 op echo "want : $exp"
130 176179b2 2021-10-04 op echo "got : $n"
131 176179b2 2021-10-04 op return 1
132 176179b2 2021-10-04 op fi
133 176179b2 2021-10-04 op done
134 176179b2 2021-10-04 op }
135 176179b2 2021-10-04 op
136 176179b2 2021-10-04 op test_custom_index() {
137 176179b2 2021-10-04 op setup_simple_test '' 'index "foo.gmi"'
138 176179b2 2021-10-04 op
139 176179b2 2021-10-04 op fetch /dir/
140 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
141 176179b2 2021-10-04 op }
142 176179b2 2021-10-04 op
143 176179b2 2021-10-04 op test_custom_index_default_type_per_location() {
144 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
145 176179b2 2021-10-04 op
146 176179b2 2021-10-04 op fetch /dir/
147 176179b2 2021-10-04 op check_reply "20 text/plain" "$(cat hello)"
148 176179b2 2021-10-04 op }
149 176179b2 2021-10-04 op
150 176179b2 2021-10-04 op test_auto_index() {
151 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { auto index on }'
152 176179b2 2021-10-04 op
153 176179b2 2021-10-04 op fetch /
154 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
155 176179b2 2021-10-04 op
156 176179b2 2021-10-04 op fetch_hdr /dir
157 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
158 176179b2 2021-10-04 op
159 176179b2 2021-10-04 op fetch_hdr /dir/
160 176179b2 2021-10-04 op check_reply "20 text/gemini"
161 176179b2 2021-10-04 op
162 176179b2 2021-10-04 op # we expect 5 lines from the auto index
163 176179b2 2021-10-04 op
164 176179b2 2021-10-04 op body="$(get /dir/ | count)"
165 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
166 176179b2 2021-10-04 op echo 'failed to get /dir/'
167 176179b2 2021-10-04 op return 1
168 176179b2 2021-10-04 op fi
169 176179b2 2021-10-04 op
170 176179b2 2021-10-04 op if [ "$body" -ne 5 ]; then
171 176179b2 2021-10-04 op echo "expected five lines from the auto index, got $body"
172 176179b2 2021-10-04 op return 1
173 176179b2 2021-10-04 op fi
174 176179b2 2021-10-04 op }
175 176179b2 2021-10-04 op
176 176179b2 2021-10-04 op test_block() {
177 176179b2 2021-10-04 op setup_simple_test '' 'location "*" { block }'
178 176179b2 2021-10-04 op
179 176179b2 2021-10-04 op fetch /
180 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
181 176179b2 2021-10-04 op
182 176179b2 2021-10-04 op fetch /nonexists
183 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
184 176179b2 2021-10-04 op }
185 176179b2 2021-10-04 op
186 176179b2 2021-10-04 op test_block_return_fmt() {
187 176179b2 2021-10-04 op setup_simple_test '' '
188 176179b2 2021-10-04 op location "/dir" {
189 176179b2 2021-10-04 op strip 1
190 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
191 176179b2 2021-10-04 op }
192 176179b2 2021-10-04 op location "*" {
193 176179b2 2021-10-04 op strip 99
194 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
195 176179b2 2021-10-04 op }'
196 176179b2 2021-10-04 op
197 176179b2 2021-10-04 op fetch_hdr /dir/foo.gmi
198 176179b2 2021-10-04 op check_reply "40 % /foo.gmi 10965 localhost test" || return 1
199 176179b2 2021-10-04 op
200 176179b2 2021-10-04 op fetch_hdr /bigfile
201 176179b2 2021-10-04 op check_reply "40 % / 10965 localhost test" || return 1
202 176179b2 2021-10-04 op }
203 176179b2 2021-10-04 op
204 176179b2 2021-10-04 op test_entrypoint() {
205 176179b2 2021-10-04 op setup_simple_test '' 'entrypoint "/env"'
206 176179b2 2021-10-04 op
207 176179b2 2021-10-04 op fetch_hdr /foo/bar
208 176179b2 2021-10-04 op check_reply "20 text/plain; lang=en" || return 1
209 176179b2 2021-10-04 op
210 176179b2 2021-10-04 op # TODO: test something similar with plain cgi too
211 176179b2 2021-10-04 op
212 176179b2 2021-10-04 op body="$(get /foo/bar|grep PATH_INFO)"
213 176179b2 2021-10-04 op if [ $? -ne 0 ]; then
214 176179b2 2021-10-04 op echo "failed to get /foo/bar"
215 176179b2 2021-10-04 op return 1
216 176179b2 2021-10-04 op fi
217 176179b2 2021-10-04 op
218 176179b2 2021-10-04 op if [ "$body" != "PATH_INFO=/foo/bar" ]; then
219 176179b2 2021-10-04 op echo "Invalid PATH_INFO generated"
220 176179b2 2021-10-04 op echo "want : PATH_INFO=/foo/bar"
221 176179b2 2021-10-04 op echo "got : $body"
222 176179b2 2021-10-04 op return 1
223 176179b2 2021-10-04 op fi
224 176179b2 2021-10-04 op }
225 176179b2 2021-10-04 op
226 176179b2 2021-10-04 op test_require_client_ca() {
227 176179b2 2021-10-04 op setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
228 176179b2 2021-10-04 op
229 176179b2 2021-10-04 op fetch /
230 176179b2 2021-10-04 op check_reply "60 client certificate required" || return 1
231 176179b2 2021-10-04 op
232 176179b2 2021-10-04 op ggflags="-C valid.crt -K valid.key"
233 176179b2 2021-10-04 op fetch_hdr /
234 176179b2 2021-10-04 op check_reply "20 text/gemini" || return 1
235 176179b2 2021-10-04 op
236 176179b2 2021-10-04 op ggflags="-C invalid.cert.pem -K invalid.key.pem"
237 176179b2 2021-10-04 op fetch_hdr /
238 176179b2 2021-10-04 op check_reply "61 certificate not authorised" || return 1
239 176179b2 2021-10-04 op }
240 176179b2 2021-10-04 op
241 176179b2 2021-10-04 op test_root_inside_location() {
242 176179b2 2021-10-04 op setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
243 176179b2 2021-10-04 op
244 176179b2 2021-10-04 op fetch /foo
245 176179b2 2021-10-04 op check_reply "51 not found" || return 1
246 176179b2 2021-10-04 op
247 176179b2 2021-10-04 op fetch_hdr /foo/
248 176179b2 2021-10-04 op check_reply "20 text/gemini"
249 176179b2 2021-10-04 op }
250 176179b2 2021-10-04 op
251 176179b2 2021-10-04 op test_root_inside_location_with_redirect() {
252 176179b2 2021-10-04 op setup_simple_test '' '
253 176179b2 2021-10-04 op location "/foo" { block return 31 "%p/" }
254 176179b2 2021-10-04 op location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
255 176179b2 2021-10-04 op
256 176179b2 2021-10-04 op fetch /foo
257 176179b2 2021-10-04 op check_reply "31 /foo/" || return 1
258 176179b2 2021-10-04 op
259 176179b2 2021-10-04 op fetch_hdr /foo/
260 176179b2 2021-10-04 op check_reply "20 text/gemini"
261 176179b2 2021-10-04 op }
262 176179b2 2021-10-04 op
263 176179b2 2021-10-04 op test_fastcgi() {
264 176179b2 2021-10-04 op # XXX: prefork 1 for testing
265 176179b2 2021-10-04 op setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
266 176179b2 2021-10-04 op
267 176179b2 2021-10-04 op fetch /
268 176179b2 2021-10-04 op check_reply "20 text/gemini" "# Hello, world!"
269 176179b2 2021-10-04 op }
270 176179b2 2021-10-04 op
271 176179b2 2021-10-04 op test_macro_expansion() {
272 176179b2 2021-10-04 op cat <<EOF > reg.conf
273 176179b2 2021-10-04 op pwd = "$PWD"
274 176179b2 2021-10-04 op $config_common
275 176179b2 2021-10-04 op
276 176179b2 2021-10-04 op server "localhost" {
277 176179b2 2021-10-04 op # the quoting of \$ is for sh
278 176179b2 2021-10-04 op cert \$pwd "/cert.pem"
279 176179b2 2021-10-04 op key \$pwd "/key.pem"
280 176179b2 2021-10-04 op root \$pwd "/testdata"
281 176179b2 2021-10-04 op }
282 176179b2 2021-10-04 op EOF
283 176179b2 2021-10-04 op
284 176179b2 2021-10-04 op if ! checkconf; then
285 176179b2 2021-10-04 op echo "failed to parse the config"
286 176179b2 2021-10-04 op return 1
287 176179b2 2021-10-04 op fi
288 176179b2 2021-10-04 op
289 176179b2 2021-10-04 op run
290 176179b2 2021-10-04 op
291 176179b2 2021-10-04 op fetch /
292 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
293 176179b2 2021-10-04 op }
294 176179b2 2021-10-04 op
295 176179b2 2021-10-04 op # 1.7.4 bugfix: check_for_cgi goes out-of-bound processing a string
296 176179b2 2021-10-04 op # that doesn't contain a '/'
297 176179b2 2021-10-04 op test_174_bugfix() {
298 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
299 176179b2 2021-10-04 op
300 176179b2 2021-10-04 op # thanks cage :)
301 176179b2 2021-10-04 op for i in 0 1 2 3 4 5 6 7 8 9; do
302 176179b2 2021-10-04 op fetch /favicon.txt
303 176179b2 2021-10-04 op check_reply "51 not found" || return 1
304 176179b2 2021-10-04 op done
305 176179b2 2021-10-04 op }