wikid-cgi ist ein C99-CGI-Programm (HTML 4.01): Liste der Wikis, Seiten eines Wikis, eine Seite, Suche -- aus dem Datenverzeichnis von wikid ($WIKIDIR, sonst ~/.local/share/wikid). wikid-http, packaging/wikid-web.service, tests/test-http.sh; Makefile baut und installiert sie, README beschreibt sie.
108 lines
3.5 KiB
Bash
Executable File
108 lines
3.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# Prüft wikid-http als CGI gegen einen laufenden wikid.
|
|
# Kein Web-Server nötig: die CGI-Umgebung wird von Hand gesetzt.
|
|
set -eu
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
PORT=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1",0)); print(s.getsockname()[1]); s.close()')
|
|
DIR=$(mktemp -d)
|
|
LOG="$DIR/wikid.log"
|
|
PID=
|
|
|
|
cleanup() {
|
|
[ -n "$PID" ] && kill "$PID" 2>/dev/null || true
|
|
[ -n "$PID" ] && wait "$PID" 2>/dev/null || true
|
|
rm -rf "$DIR"
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
WIKIDIR="$DIR/data" ./wikid --http "127.0.0.1:$PORT" >"$LOG" 2>&1 &
|
|
PID=$!
|
|
|
|
for _ in $(seq 1 50); do
|
|
curl -s -o /dev/null "http://127.0.0.1:$PORT/mcp" -X POST \
|
|
-H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' \
|
|
&& break
|
|
sleep 0.1
|
|
done
|
|
|
|
export WIKID_URL="http://127.0.0.1:$PORT/mcp"
|
|
|
|
cgi() {
|
|
method=$1
|
|
uri=$2
|
|
if [ "$method" = POST ]; then
|
|
body=$3
|
|
printf '%s' "$body" | \
|
|
REQUEST_METHOD=POST REQUEST_URI="$uri" QUERY_STRING='' \
|
|
CONTENT_LENGTH=${#body} ./wikid-http
|
|
else
|
|
REQUEST_METHOD=GET REQUEST_URI="$uri" QUERY_STRING='' ./wikid-http
|
|
fi
|
|
}
|
|
|
|
fail() {
|
|
echo "FAIL: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
# 1. Leere Welt
|
|
cgi GET / >"$DIR/out"
|
|
grep -q 'no knowledge bases yet' "$DIR/out" || fail "empty index"
|
|
grep -q 'Content-Type: text/html' "$DIR/out" || fail "content type"
|
|
|
|
# 2. Wiki anlegen
|
|
cgi POST /wikid/create 'name=Field+Notes&description=Procedures' >"$DIR/out"
|
|
grep -q 'created knowledge base' "$DIR/out" || fail "create wiki"
|
|
|
|
# 3. Seite schreiben
|
|
cgi POST /wikid/field-notes/write \
|
|
'title=Water+chlorination&text=Two+drops+of+bleach+per+litre.&tags=water&source=manual' >"$DIR/out"
|
|
grep -q 'created field-notes/e00001' "$DIR/out" || fail "write page"
|
|
|
|
# 4. Wiki-Index zeigt die Basis als Link
|
|
cgi GET / >"$DIR/out"
|
|
grep -q 'href="/wikid/field-notes/"' "$DIR/out" || fail "wiki link"
|
|
grep -q 'Field Notes' "$DIR/out" || fail "wiki description"
|
|
|
|
# 5. Seitenliste zeigt die Seite
|
|
cgi GET /wikid/field-notes/ >"$DIR/out"
|
|
grep -q 'Water chlorination' "$DIR/out" || fail "page in list"
|
|
|
|
# 6. Seite per ID lesen
|
|
cgi GET /wikid/field-notes/e00001 >"$DIR/out"
|
|
grep -q 'Two drops of bleach per litre' "$DIR/out" || fail "read by id"
|
|
|
|
# 7. Seite per (URL-kodiertem) Titel lesen
|
|
cgi GET '/wikid/field-notes/Water%20chlorination' >"$DIR/out"
|
|
grep -q 'Water chlorination' "$DIR/out" || fail "read by title"
|
|
grep -q 'no page' "$DIR/out" && fail "title fallback did not happen"
|
|
|
|
# 8. Suche
|
|
cgi GET '/wikid/search?q=bleach' >"$DIR/out"
|
|
grep -q 'href="/wikid/field-notes/e00001"' "$DIR/out" || fail "search link"
|
|
grep -q 'hit(s)' "$DIR/out" || fail "search summary"
|
|
|
|
# 9. Löschen braucht POST und entfernt die Seite
|
|
cgi POST /wikid/field-notes/delete 'title=Water+chlorination' >"$DIR/out"
|
|
grep -q 'deleted field-notes/e00001' "$DIR/out" || fail "delete page"
|
|
cgi GET /wikid/field-notes/ >"$DIR/out"
|
|
grep -q 'Water chlorination' "$DIR/out" && fail "deleted page still listed"
|
|
true
|
|
|
|
# 10. Unbekannte Route ist eine 404-Seite, kein Absturz
|
|
cgi GET /nope >"$DIR/out"
|
|
grep -q 'Not found' "$DIR/out" || fail "404 page"
|
|
|
|
# 11. Unter /cgi-bin/wikid-http eingehängt (busybox httpd)
|
|
REQUEST_METHOD=GET SCRIPT_NAME=/cgi-bin/wikid-http PATH_INFO=/ \
|
|
REQUEST_URI=/cgi-bin/wikid-http/ ./wikid-http >"$DIR/out"
|
|
grep -q 'href="/cgi-bin/wikid-http/wikid/search"' "$DIR/out" || fail "prefix links"
|
|
REQUEST_METHOD=GET SCRIPT_NAME=/cgi-bin/wikid-http PATH_INFO=/wikid/search \
|
|
REQUEST_URI=/cgi-bin/wikid-http/wikid/search QUERY_STRING='' \
|
|
./wikid-http >"$DIR/out"
|
|
grep -q '<h1>Search</h1>' "$DIR/out" || fail "prefix routing"
|
|
|
|
echo "wikid-http: ok"
|