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
13 5c2e310e 2021-01-22 op server "localhost" {
14 5c2e310e 2021-01-22 op cert "cert.pem"
16 5c2e310e 2021-01-22 op root "testdata"
23 5c2e310e 2021-01-22 op ./../gmid -n -c reg.conf
26 5c2e310e 2021-01-22 op # usage: get <path>
27 5c2e310e 2021-01-22 op # return the body of the request on stdout
29 5c2e310e 2021-01-22 op (./gg.py "$1" 10965 | sed 1d) || true
32 5c2e310e 2021-01-22 op # usage: head <path>
33 5c2e310e 2021-01-22 op # return the meta response line on stdout
35 5c2e310e 2021-01-22 op (./gg.py "$1" 10965 | sed 1q) || true
39 5c2e310e 2021-01-22 op # filter out logs for GET requests
40 5c2e310e 2021-01-22 op (./../gmid -c reg.conf 2>&1 | grep -v GET) >&2 &
44 5c2e310e 2021-01-22 op # usage: check [exit-message]
45 5c2e310e 2021-01-22 op # check if gmid is still running
47 5c2e310e 2021-01-22 op if ! ps $pid >/dev/null; then
48 5c2e310e 2021-01-22 op echo ${1:-"gmid crashed?"}
55 5c2e310e 2021-01-22 op pkill gmid || true
59 5c2e310e 2021-01-22 op # usage: eq a b errmsg
60 5c2e310e 2021-01-22 op # if a and b aren't equal strings, exit with errmsg
62 5c2e310e 2021-01-22 op if ! [ "$1" = "$2" ]; then
63 5c2e310e 2021-01-22 op echo "$3: \"$1\" not equal \"$2\""
69 5c2e310e 2021-01-22 op rm -f bigfile bigfile.sha
75 5c2e310e 2021-01-22 op trap 'onexit' INT TERM EXIT
77 5c2e310e 2021-01-22 op endl=`printf "\r\n"`
84 5c2e310e 2021-01-22 op eq "$(head /)" "20 text/gemini" "Unexpected head for /"
85 5c2e310e 2021-01-22 op eq "$(get /)" "# hello world$ln" "Unexpected body for /"
88 5c2e310e 2021-01-22 op eq "$(head /foo)" "51 not found" "Unexpected head /foo"
89 5c2e310e 2021-01-22 op eq "$(get /foo)" "" "Unexpected body /foo"
90 5c2e310e 2021-01-22 op echo OK GET /foo
92 5c2e310e 2021-01-22 op # should redirect if asked for a directory but without the trailing /
93 5c2e310e 2021-01-22 op eq "$(head /dir)" "30 /dir/" "Unexpected redirect for /dir"
94 5c2e310e 2021-01-22 op eq "$(get /dir)" "" "Unexpected body for redirect"
95 5c2e310e 2021-01-22 op echo OK GET /dir
97 5c2e310e 2021-01-22 op # 51 for a directory without index.gmi
98 5c2e310e 2021-01-22 op eq "$(head /dir/)" "51 not found" "Unexpected head for /"
99 5c2e310e 2021-01-22 op eq "$(get /dir/)" "" "Unexpected body for error"
100 5c2e310e 2021-01-22 op echo OK GET /dir/
102 5c2e310e 2021-01-22 op eq "$(head /dir/foo.gmi)" "20 text/gemini" "Unexpected head for /dir/foo.gmi"
103 5c2e310e 2021-01-22 op eq "$(get /dir/foo.gmi)" "# hello world$ln" "Unexpected body for /dir/foo.gmi"
104 5c2e310e 2021-01-22 op echo OK GET /dir/foo.gmi
106 5c2e310e 2021-01-22 op # try a big file
107 5c2e310e 2021-01-22 op eq "$(head /bigfile)" "20 application/octet-stream" "Unexpected head for /bigfile"
108 5c2e310e 2021-01-22 op get /bigfile > bigfile
109 5c2e310e 2021-01-22 op ./sha bigfile bigfile.sha
110 5c2e310e 2021-01-22 op eq "$(cat bigfile.sha)" "$(cat testdata/bigfile.sha)" "Unexpected sha for /bigfile"
111 5c2e310e 2021-01-22 op echo OK GET /bigfile
113 5c2e310e 2021-01-22 op # shouldn't be executing cgi scripts
114 5c2e310e 2021-01-22 op eq "$(head /hello)" "20 application/octet-stream" "Unexpected head for /hello"
115 5c2e310e 2021-01-22 op echo OK GET /hello
117 5c2e310e 2021-01-22 op check "should be running"
120 5c2e310e 2021-01-22 op # try with custom mime
121 5c2e310e 2021-01-22 op config 'mime "text/x-funny-text" "gmi"' 'default type "application/x-trash"'
125 5c2e310e 2021-01-22 op eq "$(head /)" "20 text/x-funny-text" "Unexpected head for /"
126 5c2e310e 2021-01-22 op echo OK GET / with custom mime
128 5c2e310e 2021-01-22 op eq "$(head /hello)" "20 application/x-trash" "Unexpected head for /hello"
129 5c2e310e 2021-01-22 op echo OK GET /hello with custom mime
131 5c2e310e 2021-01-22 op check "should be running"
134 5c2e310e 2021-01-22 op # try with custom lang
135 5c2e310e 2021-01-22 op config '' 'lang "it"'
139 5c2e310e 2021-01-22 op eq "$(head /)" "20 text/gemini; lang=it" "Unexpected head for /"
140 5c2e310e 2021-01-22 op echo OK GET / with custom lang
142 5c2e310e 2021-01-22 op check "should be running"
145 5c2e310e 2021-01-22 op # finally try with CGI scripts
146 5c2e310e 2021-01-22 op config '' 'cgi ""'
150 5c2e310e 2021-01-22 op eq "$(head /hello)" "20 text/gemini" "Unexpected head for /hello"
151 5c2e310e 2021-01-22 op eq "$(get /hello)" "# hello world$ln" "Unexpected body for /hello"
152 5c2e310e 2021-01-22 op echo OK GET /hello with cgi
154 5c2e310e 2021-01-22 op eq "$(head /slow)" "20 text/gemini" "Unexpected head for /slow"
155 5c2e310e 2021-01-22 op eq "$(get /slow)" "# hello world$ln" "Unexpected body for /slow"
156 5c2e310e 2021-01-22 op echo OK GET /slow with cgi
158 5c2e310e 2021-01-22 op eq "$(head /err)" "" "Unexpected head for /err"
159 5c2e310e 2021-01-22 op eq "$(get /err)" "" "Unexpected body for /err"
160 5c2e310e 2021-01-22 op echo OK GET /err with cgi
162 3309ef97 2021-01-23 op eq "$(head /invalid | wc -c | xargs)" 2049 "Unexpected body for /invalid"
163 3309ef97 2021-01-23 op eq "$(get /invalid)" "" "Unexpected body for /invalid"
164 3309ef97 2021-01-23 op echo OK GET /invalid with cgi
166 5c2e310e 2021-01-22 op check "should be running"