1 176179b2 2021-10-04 op test_configless_mode() {
4 176179b2 2021-10-04 op $gmid -p $port -H localhost -d . testdata &
10 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
13 176179b2 2021-10-04 op test_static_files() {
14 176179b2 2021-10-04 op setup_simple_test
17 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
20 176179b2 2021-10-04 op check_reply "51 not found" || return 1
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
26 176179b2 2021-10-04 op test_directory_redirect() {
27 176179b2 2021-10-04 op setup_simple_test
30 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
33 176179b2 2021-10-04 op check_reply "51 not found" || return 1
36 176179b2 2021-10-04 op test_serve_big_files() {
37 176179b2 2021-10-04 op setup_simple_test
39 176179b2 2021-10-04 op hdr="$(head /bigfile)"
40 176179b2 2021-10-04 op get /bigfile > bigfile
41 6e0f14d5 2021-10-04 op ./sha bigfile bigfile.sha
42 176179b2 2021-10-04 op body="$(cat bigfile.sha)"
44 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "$(cat testdata/bigfile.sha)"
47 176179b2 2021-10-04 op test_dont_execute_scripts() {
48 176179b2 2021-10-04 op setup_simple_test
50 176179b2 2021-10-04 op fetch_hdr /hello
51 176179b2 2021-10-04 op check_reply "20 application/octet-stream" "" || return 1
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"' ''
58 176179b2 2021-10-04 op check_reply "20 text/x-funny"
61 176179b2 2021-10-04 op test_default_type() {
62 176179b2 2021-10-04 op setup_simple_test '' 'default type "application/x-foo"'
64 176179b2 2021-10-04 op fetch_hdr /hello
65 176179b2 2021-10-04 op check_reply "20 application/x-foo"
68 176179b2 2021-10-04 op test_custom_lang() {
69 176179b2 2021-10-04 op setup_simple_test '' 'lang it'
72 176179b2 2021-10-04 op check_reply "20 text/gemini;lang=it"
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
81 176179b2 2021-10-04 op test_cgi_scripts() {
82 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
85 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
88 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
91 176179b2 2021-10-04 op check_reply "42 CGI error" || return 1
93 176179b2 2021-10-04 op fetch /invalid
94 176179b2 2021-10-04 op check_reply "42 CGI error" || return 1
97 176179b2 2021-10-04 op test_cgi_big_replies() {
98 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
100 176179b2 2021-10-04 op hdr="$(head /serve-bigfile)"
101 176179b2 2021-10-04 op get /bigfile > bigfile
102 6e0f14d5 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)"
107 176179b2 2021-10-04 op test_cgi_split_query() {
108 176179b2 2021-10-04 op setup_simple_test '' 'cgi "*"'
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/^..//')"
114 176179b2 2021-10-04 op if [ "$exp" = "$qry" ]; then
115 176179b2 2021-10-04 op # the "1" case yields exp == qry
119 176179b2 2021-10-04 op url="/env$qry"
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"
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"
136 176179b2 2021-10-04 op test_custom_index() {
137 176179b2 2021-10-04 op setup_simple_test '' 'index "foo.gmi"'
140 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
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" }'
147 176179b2 2021-10-04 op check_reply "20 text/plain" "$(cat hello)"
150 176179b2 2021-10-04 op test_auto_index() {
151 176179b2 2021-10-04 op setup_simple_test '' 'location "/dir/*" { auto index on }'
154 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world" || return 1
156 176179b2 2021-10-04 op fetch_hdr /dir
157 176179b2 2021-10-04 op check_reply "30 /dir/" || return 1
159 176179b2 2021-10-04 op fetch_hdr /dir/
160 176179b2 2021-10-04 op check_reply "20 text/gemini"
162 176179b2 2021-10-04 op # we expect 5 lines from the auto index
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/'
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"
176 176179b2 2021-10-04 op test_block() {
177 176179b2 2021-10-04 op setup_simple_test '' 'location "*" { block }'
180 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
182 176179b2 2021-10-04 op fetch /nonexists
183 176179b2 2021-10-04 op check_reply "40 temporary failure" || return 1
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" {
190 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
192 176179b2 2021-10-04 op location "*" {
194 176179b2 2021-10-04 op block return 40 "%% %p %q %P %N test"
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
200 176179b2 2021-10-04 op fetch_hdr /bigfile
201 176179b2 2021-10-04 op check_reply "40 % / 10965 localhost test" || return 1
204 176179b2 2021-10-04 op test_entrypoint() {
205 176179b2 2021-10-04 op setup_simple_test '' 'entrypoint "/env"'
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
210 176179b2 2021-10-04 op # TODO: test something similar with plain cgi too
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"
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"
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"'
230 176179b2 2021-10-04 op check_reply "60 client certificate required" || return 1
232 176179b2 2021-10-04 op ggflags="-C valid.crt -K valid.key"
234 176179b2 2021-10-04 op check_reply "20 text/gemini" || return 1
236 176179b2 2021-10-04 op ggflags="-C invalid.cert.pem -K invalid.key.pem"
238 176179b2 2021-10-04 op check_reply "61 certificate not authorised" || return 1
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 }'
245 176179b2 2021-10-04 op check_reply "51 not found" || return 1
247 176179b2 2021-10-04 op fetch_hdr /foo/
248 176179b2 2021-10-04 op check_reply "20 text/gemini"
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 }'
257 176179b2 2021-10-04 op check_reply "31 /foo/" || return 1
259 176179b2 2021-10-04 op fetch_hdr /foo/
260 176179b2 2021-10-04 op check_reply "20 text/gemini"
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"'
268 176179b2 2021-10-04 op check_reply "20 text/gemini" "# Hello, world!"
271 176179b2 2021-10-04 op test_macro_expansion() {
272 176179b2 2021-10-04 op cat <<EOF > reg.conf
274 176179b2 2021-10-04 op $config_common
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"
284 176179b2 2021-10-04 op if ! checkconf; then
285 176179b2 2021-10-04 op echo "failed to parse the config"
292 176179b2 2021-10-04 op check_reply "20 text/gemini" "# hello world"
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 "*"'
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