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