Blame


1 5741561d 2021-12-09 op test_punycode() {
2 a721c233 2021-12-09 op dont_check_server_alive=yes
3 5741561d 2021-12-09 op ./puny-test
4 5741561d 2021-12-09 op }
5 5741561d 2021-12-09 op
6 5741561d 2021-12-09 op test_iri() {
7 a721c233 2021-12-09 op dont_check_server_alive=yes
8 5741561d 2021-12-09 op ./iri_test
9 5741561d 2021-12-09 op }
10 5741561d 2021-12-09 op
11 a5fb2593 2022-09-08 op test_ge() {
12 a721c233 2021-12-09 op dont_check_server_alive=yes
13 176179b2 2021-10-04 op
14 a5fb2593 2022-09-08 op $ge -p $port -d . testdata &
15 176179b2 2021-10-04 op pid=$!
16 176179b2 2021-10-04 op sleep 1
17 176179b2 2021-10-04 op
18 176179b2 2021-10-04 op fetch /
19 176179b2 2021-10-04 op kill $pid
20 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
21 176179b2 2021-10-04 op }
22 176179b2 2021-10-04 op
23 176179b2 2021-10-04 op test_static_files() {
24 176179b2 2021-10-04 op setup_simple_test
25 176179b2 2021-10-04 op
26 176179b2 2021-10-04 op fetch /
27 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
28 176179b2 2021-10-04 op
29 176179b2 2021-10-04 op fetch /foo
30 176179b2 2021-10-04 op check_reply "51 not found" || return 1
31 176179b2 2021-10-04 op
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
34 176179b2 2021-10-04 op }
35 176179b2 2021-10-04 op
36 176179b2 2021-10-04 op test_directory_redirect() {
37 176179b2 2021-10-04 op setup_simple_test
38 176179b2 2021-10-04 op
39 176179b2 2021-10-04 op fetch /dir
40 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
41 176179b2 2021-10-04 op
42 176179b2 2021-10-04 op fetch /dir/
43 176179b2 2021-10-04 op check_reply "51 not found" || return 1
44 176179b2 2021-10-04 op }
45 176179b2 2021-10-04 op
46 176179b2 2021-10-04 op test_serve_big_files() {
47 176179b2 2021-10-04 op setup_simple_test
48 176179b2 2021-10-04 op
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)"
53 176179b2 2021-10-04 op
54 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
55 176179b2 2021-10-04 op }
56 176179b2 2021-10-04 op
57 176179b2 2021-10-04 op test_dont_execute_scripts() {
58 176179b2 2021-10-04 op setup_simple_test
59 176179b2 2021-10-04 op
60 176179b2 2021-10-04 op fetch_hdr /hello
61 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "" || return 1
62 176179b2 2021-10-04 op }
63 176179b2 2021-10-04 op
64 176179b2 2021-10-04 op test_custom_mime() {
65 9448a01f 2022-04-07 op setup_simple_test '
66 9448a01f 2022-04-07 op types {
67 9448a01f 2022-04-07 op text/x-funny gmi
68 9448a01f 2022-04-07 op }
69 9448a01f 2022-04-07 op ' ''
70 176179b2 2021-10-04 op
71 176179b2 2021-10-04 op fetch_hdr /
72 176179b2 2021-10-04 op check_reply "20 text/x-funny"
73 176179b2 2021-10-04 op }
74 176179b2 2021-10-04 op
75 176179b2 2021-10-04 op test_default_type() {
76 176179b2 2021-10-04 op setup_simple_test '' 'default type "application/x-foo"'
77 176179b2 2021-10-04 op
78 176179b2 2021-10-04 op fetch_hdr /hello
79 176179b2 2021-10-04 op check_reply "20 application/x-foo"
80 176179b2 2021-10-04 op }
81 176179b2 2021-10-04 op
82 176179b2 2021-10-04 op test_custom_lang() {
83 176179b2 2021-10-04 op setup_simple_test '' 'lang it'
84 176179b2 2021-10-04 op
85 176179b2 2021-10-04 op fetch_hdr /
86 176179b2 2021-10-04 op check_reply "20 text/gemini;lang=it"
87 176179b2 2021-10-04 op }
88 176179b2 2021-10-04 op
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
93 176179b2 2021-10-04 op }
94 176179b2 2021-10-04 op
95 176179b2 2021-10-04 op test_custom_index() {
96 176179b2 2021-10-04 op setup_simple_test '' 'index "foo.gmi"'
97 176179b2 2021-10-04 op
98 176179b2 2021-10-04 op fetch /dir/
99 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
100 176179b2 2021-10-04 op }
101 176179b2 2021-10-04 op
102 176179b2 2021-10-04 op test_custom_index_default_type_per_location() {
103 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { default type "text/plain" index "hello" }'
104 176179b2 2021-10-04 op
105 176179b2 2021-10-04 op fetch /dir/
106 176179b2 2021-10-04 op check_reply "20 text/plain" "$(cat hello)"
107 176179b2 2021-10-04 op }
108 176179b2 2021-10-04 op
109 176179b2 2021-10-04 op test_auto_index() {
110 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { auto index on }'
111 176179b2 2021-10-04 op
112 176179b2 2021-10-04 op fetch /
113 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
114 176179b2 2021-10-04 op
115 176179b2 2021-10-04 op fetch_hdr /dir
116 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
117 176179b2 2021-10-04 op
118 176179b2 2021-10-04 op fetch_hdr /dir/
119 475205fa 2022-07-04 op check_reply "20 text/gemini" || return 1
120 176179b2 2021-10-04 op
121 475205fa 2022-07-04 op get /dir/ > listing || return 1
122 475205fa 2022-07-04 op cat <<EOF > listing.expected
123 475205fa 2022-07-04 op # Index of /dir/
124 176179b2 2021-10-04 op
125 d45d5306 2022-07-04 op => ./../
126 475205fa 2022-07-04 op => ./current%20date
127 475205fa 2022-07-04 op => ./foo.gmi
128 475205fa 2022-07-04 op => ./hello
129 475205fa 2022-07-04 op EOF
130 176179b2 2021-10-04 op
131 475205fa 2022-07-04 op cmp -s listing.expected listing
132 475205fa 2022-07-04 op ret=$?
133 475205fa 2022-07-04 op if [ $ret -ne 0 ]; then
134 475205fa 2022-07-04 op echo 'unexpected dir content:'
135 475205fa 2022-07-04 op diff -u listing.expected listing
136 176179b2 2021-10-04 op fi
137 475205fa 2022-07-04 op rm listing listing.expected
138 475205fa 2022-07-04 op
139 475205fa 2022-07-04 op return $ret
140 176179b2 2021-10-04 op }
141 176179b2 2021-10-04 op
142 176179b2 2021-10-04 op test_block() {
143 176179b2 2021-10-04 op setup_simple_test '' 'location "*" { block }'
144 176179b2 2021-10-04 op
145 176179b2 2021-10-04 op fetch /
146 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
147 176179b2 2021-10-04 op
148 176179b2 2021-10-04 op fetch /nonexists
149 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
150 176179b2 2021-10-04 op }
151 176179b2 2021-10-04 op
152 176179b2 2021-10-04 op test_block_return_fmt() {
153 176179b2 2021-10-04 op setup_simple_test '' '
154 176179b2 2021-10-04 op location "/dir" {
155 176179b2 2021-10-04 op strip 1
156 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
157 176179b2 2021-10-04 op }
158 176179b2 2021-10-04 op location "*" {
159 176179b2 2021-10-04 op strip 99
160 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
161 176179b2 2021-10-04 op }'
162 176179b2 2021-10-04 op
163 176179b2 2021-10-04 op fetch_hdr /dir/foo.gmi
164 176179b2 2021-10-04 op check_reply "40 % /foo.gmi 10965 localhost test" || return 1
165 176179b2 2021-10-04 op
166 176179b2 2021-10-04 op fetch_hdr /bigfile
167 176179b2 2021-10-04 op check_reply "40 % / 10965 localhost test" || return 1
168 176179b2 2021-10-04 op }
169 176179b2 2021-10-04 op
170 176179b2 2021-10-04 op test_require_client_ca() {
171 176179b2 2021-10-04 op setup_simple_test '' 'require client ca "'$PWD'/testca.pem"'
172 176179b2 2021-10-04 op
173 176179b2 2021-10-04 op fetch /
174 176179b2 2021-10-04 op check_reply "60 client certificate required" || return 1
175 176179b2 2021-10-04 op
176 176179b2 2021-10-04 op ggflags="-C valid.crt -K valid.key"
177 176179b2 2021-10-04 op fetch_hdr /
178 176179b2 2021-10-04 op check_reply "20 text/gemini" || return 1
179 176179b2 2021-10-04 op
180 176179b2 2021-10-04 op ggflags="-C invalid.cert.pem -K invalid.key.pem"
181 176179b2 2021-10-04 op fetch_hdr /
182 176179b2 2021-10-04 op check_reply "61 certificate not authorised" || return 1
183 176179b2 2021-10-04 op }
184 176179b2 2021-10-04 op
185 176179b2 2021-10-04 op test_root_inside_location() {
186 176179b2 2021-10-04 op setup_simple_test '' 'location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
187 176179b2 2021-10-04 op
188 176179b2 2021-10-04 op fetch /foo
189 176179b2 2021-10-04 op check_reply "51 not found" || return 1
190 176179b2 2021-10-04 op
191 176179b2 2021-10-04 op fetch_hdr /foo/
192 176179b2 2021-10-04 op check_reply "20 text/gemini"
193 176179b2 2021-10-04 op }
194 176179b2 2021-10-04 op
195 176179b2 2021-10-04 op test_root_inside_location_with_redirect() {
196 176179b2 2021-10-04 op setup_simple_test '' '
197 176179b2 2021-10-04 op location "/foo" { block return 31 "%p/" }
198 176179b2 2021-10-04 op location "/foo/*" { root "'$PWD'/testdata" strip 1 }'
199 176179b2 2021-10-04 op
200 176179b2 2021-10-04 op fetch /foo
201 176179b2 2021-10-04 op check_reply "31 /foo/" || return 1
202 176179b2 2021-10-04 op
203 176179b2 2021-10-04 op fetch_hdr /foo/
204 176179b2 2021-10-04 op check_reply "20 text/gemini"
205 176179b2 2021-10-04 op }
206 176179b2 2021-10-04 op
207 176179b2 2021-10-04 op test_fastcgi() {
208 176179b2 2021-10-04 op # XXX: prefork 1 for testing
209 176179b2 2021-10-04 op setup_simple_test 'prefork 1' 'fastcgi spawn "'$PWD'/fcgi-test"'
210 176179b2 2021-10-04 op
211 176179b2 2021-10-04 op fetch /
212 176179b2 2021-10-04 op check_reply "20 text/gemini" "# Hello, world!"
213 176179b2 2021-10-04 op }
214 176179b2 2021-10-04 op
215 176179b2 2021-10-04 op test_macro_expansion() {
216 176179b2 2021-10-04 op cat <<EOF > reg.conf
217 176179b2 2021-10-04 op pwd = "$PWD"
218 176179b2 2021-10-04 op $config_common
219 176179b2 2021-10-04 op
220 176179b2 2021-10-04 op server "localhost" {
221 176179b2 2021-10-04 op # the quoting of \$ is for sh
222 176179b2 2021-10-04 op cert \$pwd "/cert.pem"
223 176179b2 2021-10-04 op key \$pwd "/key.pem"
224 176179b2 2021-10-04 op root \$pwd "/testdata"
225 176179b2 2021-10-04 op }
226 176179b2 2021-10-04 op EOF
227 176179b2 2021-10-04 op
228 176179b2 2021-10-04 op if ! checkconf; then
229 176179b2 2021-10-04 op echo "failed to parse the config"
230 176179b2 2021-10-04 op return 1
231 176179b2 2021-10-04 op fi
232 176179b2 2021-10-04 op
233 176179b2 2021-10-04 op run
234 176179b2 2021-10-04 op
235 176179b2 2021-10-04 op fetch /
236 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
237 176179b2 2021-10-04 op }
238 176179b2 2021-10-04 op
239 4b5b1e82 2021-12-29 op test_proxy_relay_to() {
240 4b5b1e82 2021-12-29 op gen_config '' ''
241 92a9f41d 2022-01-03 op set_proxy ''
242 92a9f41d 2022-01-03 op
243 c064f3de 2021-01-01 op run
244 c064f3de 2021-01-01 op
245 c064f3de 2021-01-01 op ggflags="-P localhost:$port -H localhost.local"
246 c064f3de 2021-01-01 op
247 c064f3de 2021-01-01 op fetch /
248 c064f3de 2021-01-01 op check_reply "20 text/gemini" "# hello world"
249 c064f3de 2021-01-01 op }
250 c064f3de 2021-01-01 op
251 c064f3de 2021-01-01 op test_proxy_with_certs() {
252 92a9f41d 2022-01-03 op ggflags="-P localhost:$port -H localhost.local"
253 92a9f41d 2022-01-03 op
254 92a9f41d 2022-01-03 op # first test using the valid keys
255 92a9f41d 2022-01-03 op
256 c064f3de 2021-01-01 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
257 92a9f41d 2022-01-03 op set_proxy "
258 92a9f41d 2022-01-03 op cert \"$PWD/valid.crt\"
259 92a9f41d 2022-01-03 op key \"$PWD/valid.key\"
260 92a9f41d 2022-01-03 op "
261 4b5b1e82 2021-12-29 op run
262 4b5b1e82 2021-12-29 op
263 92a9f41d 2022-01-03 op fetch /
264 92a9f41d 2022-01-03 op check_reply "20 text/gemini" "# hello world" || return 1
265 4b5b1e82 2021-12-29 op
266 92a9f41d 2022-01-03 op # then using some invalid keys
267 92a9f41d 2022-01-03 op
268 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
269 92a9f41d 2022-01-03 op set_proxy "
270 92a9f41d 2022-01-03 op cert \"$PWD/invalid.cert.pem\"
271 92a9f41d 2022-01-03 op key \"$PWD/invalid.key.pem\"
272 92a9f41d 2022-01-03 op "
273 92a9f41d 2022-01-03 op run
274 92a9f41d 2022-01-03 op
275 4b5b1e82 2021-12-29 op fetch /
276 92a9f41d 2022-01-03 op check_reply "61 certificate not authorised" || return 1
277 92a9f41d 2022-01-03 op
278 92a9f41d 2022-01-03 op # and finally without keys
279 92a9f41d 2022-01-03 op
280 92a9f41d 2022-01-03 op gen_config '' 'require client ca "'$PWD'/testca.pem"'
281 92a9f41d 2022-01-03 op set_proxy ''
282 92a9f41d 2022-01-03 op run
283 92a9f41d 2022-01-03 op
284 92a9f41d 2022-01-03 op fetch /
285 92a9f41d 2022-01-03 op check_reply "60 client certificate required" || return 1
286 901905e0 2022-01-05 op }
287 901905e0 2022-01-05 op
288 901905e0 2022-01-05 op test_unknown_host() {
289 901905e0 2022-01-05 op setup_simple_test '' ''
290 901905e0 2022-01-05 op
291 901905e0 2022-01-05 op ggflags="-N -H foobar"
292 901905e0 2022-01-05 op fetch /
293 901905e0 2022-01-05 op check_reply '59 Wrong/malformed host or missing SNI'
294 4b5b1e82 2021-12-29 op }
295 fb121226 2022-02-26 op
296 fb121226 2022-02-26 op test_include_mime() {
297 fb121226 2022-02-26 op setup_simple_test "types { include '$PWD/example.mime.types' }" ""
298 fb121226 2022-02-26 op
299 fb121226 2022-02-26 op fetch_hdr /
300 91971201 2022-03-26 op check_reply '20 text/gemini' || return 1
301 fb121226 2022-02-26 op
302 fb121226 2022-02-26 op fetch_hdr /test.m3u8
303 91971201 2022-03-26 op check_reply '20 application/vnd.apple.mpegurl' || return 1
304 fb121226 2022-02-26 op
305 fb121226 2022-02-26 op fetch_hdr /foo.1
306 91971201 2022-03-26 op check_reply '20 text/x-mandoc' || return 1
307 fb121226 2022-02-26 op }