5 5c2e310e 2021-01-22 op # usage: config <global config> <stuff for localhost>
6 5c2e310e 2021-01-22 op # generates a configuration file reg.conf
8 5c2e310e 2021-01-22 op cat <<EOF > reg.conf
12 5c2e310e 2021-01-22 op server "localhost" {
13 6ff23c67 2021-02-01 op cert "$PWD/cert.pem"
14 6ff23c67 2021-02-01 op key "$PWD/key.pem"
15 6ff23c67 2021-02-01 op root "$PWD/testdata"
22 5c2e310e 2021-01-22 op ./../gmid -n -c reg.conf
25 5c2e310e 2021-01-22 op # usage: get <path>
26 5c2e310e 2021-01-22 op # return the body of the request on stdout
28 31a4993a 2021-01-23 op ./../gg -b "gemini://localhost:10965/$1"
31 5c2e310e 2021-01-22 op # usage: head <path>
32 5c2e310e 2021-01-22 op # return the meta response line on stdout
34 31a4993a 2021-01-23 op ./../gg -h "gemini://localhost:10965/$1"
37 31a4993a 2021-01-23 op # usage: raw <path>
38 31a4993a 2021-01-23 op # return both header and body
40 31a4993a 2021-01-23 op ./../gg "gemini://localhost:10965/$1"
44 5c2e310e 2021-01-22 op # filter out logs for GET requests
45 46af8c6c 2021-01-27 op (./../gmid -f -c reg.conf 2>&1 | grep -v GET) >&2 &
47 31a4993a 2021-01-23 op # give gmid time to bind the port, otherwise we end up
48 31a4993a 2021-01-23 op # executing gg when gmid isn't ready yet.
52 5c2e310e 2021-01-22 op # usage: check [exit-message]
53 5c2e310e 2021-01-22 op # check if gmid is still running
55 5c2e310e 2021-01-22 op if ! ps $pid >/dev/null; then
56 5c2e310e 2021-01-22 op echo ${1:-"gmid crashed?"}
62 afc025ff 2021-02-06 op pkill -SIGHUP gmid
68 5c2e310e 2021-01-22 op pkill gmid || true
72 5c2e310e 2021-01-22 op # usage: eq a b errmsg
73 5c2e310e 2021-01-22 op # if a and b aren't equal strings, exit with errmsg
75 5c2e310e 2021-01-22 op if ! [ "$1" = "$2" ]; then
76 5c2e310e 2021-01-22 op echo "$3: \"$1\" not equal \"$2\""
82 5c2e310e 2021-01-22 op rm -f bigfile bigfile.sha
88 5c2e310e 2021-01-22 op trap 'onexit' INT TERM EXIT
90 5c2e310e 2021-01-22 op endl=`printf "\r\n"`
97 5c2e310e 2021-01-22 op eq "$(head /)" "20 text/gemini" "Unexpected head for /"
98 5c2e310e 2021-01-22 op eq "$(get /)" "# hello world$ln" "Unexpected body for /"
101 5c2e310e 2021-01-22 op eq "$(head /foo)" "51 not found" "Unexpected head /foo"
102 5c2e310e 2021-01-22 op eq "$(get /foo)" "" "Unexpected body /foo"
103 5c2e310e 2021-01-22 op echo OK GET /foo
105 5c2e310e 2021-01-22 op # should redirect if asked for a directory but without the trailing /
106 5c2e310e 2021-01-22 op eq "$(head /dir)" "30 /dir/" "Unexpected redirect for /dir"
107 5c2e310e 2021-01-22 op eq "$(get /dir)" "" "Unexpected body for redirect"
108 5c2e310e 2021-01-22 op echo OK GET /dir
110 5c2e310e 2021-01-22 op # 51 for a directory without index.gmi
111 5c2e310e 2021-01-22 op eq "$(head /dir/)" "51 not found" "Unexpected head for /"
112 5c2e310e 2021-01-22 op eq "$(get /dir/)" "" "Unexpected body for error"
113 5c2e310e 2021-01-22 op echo OK GET /dir/
115 5c2e310e 2021-01-22 op eq "$(head /dir/foo.gmi)" "20 text/gemini" "Unexpected head for /dir/foo.gmi"
116 5c2e310e 2021-01-22 op eq "$(get /dir/foo.gmi)" "# hello world$ln" "Unexpected body for /dir/foo.gmi"
117 5c2e310e 2021-01-22 op echo OK GET /dir/foo.gmi
119 5c2e310e 2021-01-22 op # try a big file
120 5c2e310e 2021-01-22 op eq "$(head /bigfile)" "20 application/octet-stream" "Unexpected head for /bigfile"
121 5c2e310e 2021-01-22 op get /bigfile > bigfile
122 5c2e310e 2021-01-22 op ./sha bigfile bigfile.sha
123 5c2e310e 2021-01-22 op eq "$(cat bigfile.sha)" "$(cat testdata/bigfile.sha)" "Unexpected sha for /bigfile"
124 5c2e310e 2021-01-22 op echo OK GET /bigfile
126 5c2e310e 2021-01-22 op # shouldn't be executing cgi scripts
127 5c2e310e 2021-01-22 op eq "$(head /hello)" "20 application/octet-stream" "Unexpected head for /hello"
128 5c2e310e 2021-01-22 op echo OK GET /hello
130 5c2e310e 2021-01-22 op check "should be running"
132 5c2e310e 2021-01-22 op # try with custom mime
133 5c2e310e 2021-01-22 op config 'mime "text/x-funny-text" "gmi"' 'default type "application/x-trash"'
137 5c2e310e 2021-01-22 op eq "$(head /)" "20 text/x-funny-text" "Unexpected head for /"
138 5c2e310e 2021-01-22 op echo OK GET / with custom mime
140 5c2e310e 2021-01-22 op eq "$(head /hello)" "20 application/x-trash" "Unexpected head for /hello"
141 5c2e310e 2021-01-22 op echo OK GET /hello with custom mime
143 5c2e310e 2021-01-22 op check "should be running"
145 5c2e310e 2021-01-22 op # try with custom lang
146 5c2e310e 2021-01-22 op config '' 'lang "it"'
150 5c2e310e 2021-01-22 op eq "$(head /)" "20 text/gemini; lang=it" "Unexpected head for /"
151 5c2e310e 2021-01-22 op echo OK GET / with custom lang
153 5c2e310e 2021-01-22 op check "should be running"
155 5c2e310e 2021-01-22 op # finally try with CGI scripts
156 87f2b68b 2021-02-02 op config '' 'cgi "*"'
160 5c2e310e 2021-01-22 op eq "$(head /hello)" "20 text/gemini" "Unexpected head for /hello"
161 5c2e310e 2021-01-22 op eq "$(get /hello)" "# hello world$ln" "Unexpected body for /hello"
162 5c2e310e 2021-01-22 op echo OK GET /hello with cgi
164 5c2e310e 2021-01-22 op eq "$(head /slow)" "20 text/gemini" "Unexpected head for /slow"
165 5c2e310e 2021-01-22 op eq "$(get /slow)" "# hello world$ln" "Unexpected body for /slow"
166 5c2e310e 2021-01-22 op echo OK GET /slow with cgi
168 35744950 2021-02-01 op eq "$(head /err)" "42 CGI error" "Unexpected head for /err"
169 5c2e310e 2021-01-22 op eq "$(get /err)" "" "Unexpected body for /err"
170 5c2e310e 2021-01-22 op echo OK GET /err with cgi
172 6cdecad8 2021-01-23 op eq "$(raw /invalid | wc -c | xargs)" 2048 "Unexpected body for /invalid"
173 3309ef97 2021-01-23 op echo OK GET /invalid with cgi
175 7b31a638 2021-01-24 op # try a big file
176 7b31a638 2021-01-24 op eq "$(head /serve-bigfile)" "20 application/octet-stream" "Unexpected head for /serve-bigfile"
177 7b31a638 2021-01-24 op get /bigfile > bigfile
178 7b31a638 2021-01-24 op ./sha bigfile bigfile.sha
179 7b31a638 2021-01-24 op eq "$(cat bigfile.sha)" "$(cat testdata/bigfile.sha)" "Unexpected sha for /serve-bigfile"
180 7b31a638 2021-01-24 op echo OK GET /serve-bigfile with cgi
182 5c2e310e 2021-01-22 op check "should be running"
184 e7a2a99b 2021-01-24 op config '' 'index "foo.gmi"'
188 e7a2a99b 2021-01-24 op eq "$(head /dir/)" "20 text/gemini" "Unexpected head for /"
189 e7a2a99b 2021-01-24 op eq "$(get /dir/)" "# hello world$ln" "Unexpected body for error"
190 e7a2a99b 2021-01-24 op echo OK GET /dir/ with custom index
192 e7a2a99b 2021-01-24 op check "should be running"
194 c8b74339 2021-01-24 op config '' 'location "/dir/" { default type "text/plain" index "hello" }'
198 c8b74339 2021-01-24 op eq "$(head /dir/hello)" "20 text/plain" "Unexpected head for /"
199 c8b74339 2021-01-24 op echo OK GET /dir/hello with location and default type
201 252908e6 2021-01-24 op eq "$(head /dir/)" "20 text/plain" "Unexpected head for /dir/"
202 c8b74339 2021-01-24 op eq "$(get /dir/|tail -1)" 'echo "# hello world"' "Unexpected body for /dir/"
203 c8b74339 2021-01-24 op echo OK GET /dir/ with location and custom index
205 c8b74339 2021-01-24 op check "should be running"
207 252908e6 2021-01-24 op config '' 'location "/dir/" { auto index on }'
211 252908e6 2021-01-24 op eq "$(head /)" "20 text/gemini" "Unexpected head for /"
212 252908e6 2021-01-24 op eq "$(get /)" "# hello world$ln" "Unexpected body for /"
213 252908e6 2021-01-24 op echo OK GET / with auto index
215 252908e6 2021-01-24 op eq "$(head /dir)" "30 /dir/" "Unexpected head for /dir"
216 252908e6 2021-01-24 op eq "$(head /dir/)" "20 text/gemini" "Unexpected head for /dir/"
217 5f715ce4 2021-02-02 op eq "$(get /dir/|wc -l|xargs)" "5" "Unexpected body for /dir/"
218 252908e6 2021-01-24 op echo OK GET /dir/ with auto index on
220 252908e6 2021-01-24 op check "should be running"
222 6abda252 2021-02-06 op # test block return and strip
224 6abda252 2021-02-06 op config '' 'location "*" { block }'
228 6abda252 2021-02-06 op eq "$(head /)" "40 temporary failure" "Unexpected head for /"
229 6abda252 2021-02-06 op eq "$(get /)" "" "Unexpected body for /"
230 6abda252 2021-02-06 op echo OK GET / with block
232 6abda252 2021-02-06 op eq "$(head /nonexists)" "40 temporary failure" "Unexpected head for /nonexists"
233 6abda252 2021-02-06 op eq "$(get /nonexists)" "" "Unexpected body for /nonexists"
234 6abda252 2021-02-06 op echo OK GET /nonexists with block
236 6abda252 2021-02-06 op check "should be running"
239 6abda252 2021-02-06 op location "/dir" {
241 6abda252 2021-02-06 op block return 40 "%% %p %q %P %N test"
243 6abda252 2021-02-06 op location "*" {
245 6abda252 2021-02-06 op block return 40 "%% %p %q %P %N test"
250 6abda252 2021-02-06 op eq "$(head /dir/foo.gmi)" "40 % /foo.gmi 10965 localhost test"
251 6abda252 2021-02-06 op echo OK GET /dir/foo.gmi with strip and block
253 6abda252 2021-02-06 op eq "$(head /bigfile)" "40 % 10965 localhost test"
254 6abda252 2021-02-06 op echo OK GET /bigfile with strip and block
256 6abda252 2021-02-06 op check "should be running"
258 e3ddf390 2021-02-06 op # test the entrypoint
260 e3ddf390 2021-02-06 op config '' 'entrypoint "/env"'
264 e3ddf390 2021-02-06 op eq "$(head /foo/bar)" "20 text/plain; lang=en" "Unknown head for /foo/bar"
265 e3ddf390 2021-02-06 op eq "$(get /foo/bar|grep PATH_INFO)" "PATH_INFO=/foo/bar" "Unexpected PATH_INFO"
266 e3ddf390 2021-02-06 op echo OK GET /foo/bar with entrypoint