Add a C99/POSIX CGI browser for bare Git-format repositories, using got for every read. Pages are HTML 4.01 Transitional with CSS1, table layout, no JavaScript, and a configurable CDE/Motif palette. The browser supports flat and owner-scoped repository layouts, tree, blob, raw, log, and commit views, and has tests plus generated-page validation. Assisted-by: OpenCode:DeepSeek-V4.1-Flash
133 lines
4.0 KiB
Bash
Executable File
133 lines
4.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# Tests for gotea-cgi. git is used only to create fixtures.
|
|
set -eu
|
|
|
|
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
cgi=$(dirname "$here")
|
|
bin="$cgi/gotea-cgi"
|
|
tmp=$(mktemp -d)
|
|
trap 'rm -rf "$tmp"' EXIT HUP INT TERM
|
|
|
|
fail() {
|
|
echo "FAIL: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
contains() {
|
|
printf '%s' "$1" | grep -Fq -- "$2"
|
|
}
|
|
|
|
expect_contains() {
|
|
contains "$1" "$2" || fail "$3 (missing: $2)"
|
|
}
|
|
|
|
expect_no() {
|
|
if contains "$1" "$2"; then
|
|
fail "$3 (found: $2)"
|
|
fi
|
|
}
|
|
|
|
run() {
|
|
env -i PATH=/usr/bin:/bin HOME="$tmp" \
|
|
GOTEA_REPO_ROOT="$tmp/repos" GOT_BIN="${GOT_BIN:-/usr/bin/got}" \
|
|
SCRIPT_NAME=/cgi-bin/gotea REQUEST_METHOD="${2:-GET}" \
|
|
PATH_INFO="$1" "$bin"
|
|
}
|
|
|
|
run_palette() {
|
|
env -i PATH=/usr/bin:/bin HOME="$tmp" \
|
|
GOTEA_REPO_ROOT="$tmp/repos" GOT_BIN="${GOT_BIN:-/usr/bin/got}" \
|
|
GOTEA_PALETTE="$2" SCRIPT_NAME=/cgi-bin/gotea \
|
|
REQUEST_METHOD=GET PATH_INFO="$1" "$bin"
|
|
}
|
|
|
|
make -C "$cgi" >/dev/null
|
|
|
|
mkdir -p "$tmp/repos/owner"
|
|
git init -q -b main "$tmp/src"
|
|
cd "$tmp/src"
|
|
printf 'hello gotea\n' > README.md
|
|
mkdir src
|
|
printf 'int main(void){return 0;}\n' > src/main.c
|
|
printf '\000\001\002' > src/logo.bin
|
|
git add .
|
|
GIT_AUTHOR_NAME='Test User' GIT_AUTHOR_EMAIL='test@example.com' \
|
|
GIT_COMMITTER_NAME='Test User' GIT_COMMITTER_EMAIL='test@example.com' \
|
|
git commit -qm 'initial import'
|
|
cd "$cgi"
|
|
hash=$(git -C "$tmp/src" rev-parse HEAD)
|
|
git clone -q --bare "$tmp/src" "$tmp/repos/owner/demo.git"
|
|
git clone -q --bare "$tmp/src" "$tmp/repos/flat.git"
|
|
git init -q --bare "$tmp/repos/owner/empty.git"
|
|
|
|
home=$(run /)
|
|
expect_contains "$home" 'DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"' "home: HTML 4.01 doctype"
|
|
expect_contains "$home" 'GOTEA' "home: brand"
|
|
expect_contains "$home" 'owner/demo' "home: nested repository"
|
|
expect_contains "$home" 'flat' "home: flat repository"
|
|
expect_contains "$home" 'empty repository' "home: empty repository"
|
|
expect_no "$home" '<script' "home: no script tag"
|
|
expect_no "$home" 'javascript:' "home: no javascript URL"
|
|
echo "PASS home"
|
|
|
|
tree=$(run /repo/owner/demo/tree)
|
|
expect_contains "$tree" 'README.md' "tree: README"
|
|
expect_contains "$tree" '[src]' "tree: directory link"
|
|
expect_contains "$tree" '/repo/owner/demo/blob/README.md' "tree: blob link"
|
|
echo "PASS tree"
|
|
|
|
sub=$(run /repo/owner/demo/tree/src)
|
|
expect_contains "$sub" 'main.c' "subtree: file"
|
|
expect_contains "$sub" 'logo.bin' "subtree: binary file"
|
|
echo "PASS subtree"
|
|
|
|
blob=$(run /repo/owner/demo/blob/README.md)
|
|
expect_contains "$blob" '<pre>hello gotea' "blob: content"
|
|
expect_contains "$blob" '/raw/README.md' "blob: raw link"
|
|
echo "PASS blob"
|
|
|
|
raw=$(run /repo/owner/demo/raw/README.md)
|
|
expect_contains "$raw" 'Content-Type: text/plain; charset=UTF-8' "raw: content type"
|
|
expect_contains "$raw" 'hello gotea' "raw: content"
|
|
echo "PASS raw"
|
|
|
|
binblob=$(run /repo/owner/demo/blob/src/logo.bin)
|
|
expect_contains "$binblob" 'Binary file' "binary: notice"
|
|
echo "PASS binary"
|
|
|
|
log=$(run /repo/owner/demo/log)
|
|
expect_contains "$log" 'commit ' "log: commit line"
|
|
expect_contains "$log" 'initial import' "log: message"
|
|
expect_contains "$log" "$hash" "log: full hash"
|
|
echo "PASS log"
|
|
|
|
commit=$(run "/repo/owner/demo/commit/$hash")
|
|
expect_contains "$commit" 'initial import' "commit: message"
|
|
expect_contains "$commit" 'diff ' "commit: patch"
|
|
echo "PASS commit"
|
|
|
|
notfound=$(run /repo/nope/tree)
|
|
expect_contains "$notfound" 'Status: 404' "missing repo: 404"
|
|
echo "PASS 404"
|
|
|
|
badpath=$(run /repo/../tree)
|
|
expect_contains "$badpath" 'Status: 400' "traversal: 400"
|
|
echo "PASS traversal"
|
|
|
|
head=$(run /repo/owner/demo/tree HEAD)
|
|
expect_contains "$head" 'Content-Type: text/html; charset=UTF-8' "HEAD: headers"
|
|
expect_no "$head" '<!DOCTYPE' "HEAD: no body"
|
|
echo "PASS HEAD"
|
|
|
|
printf 'base = #123456\n' > "$tmp/pal.palette"
|
|
pal=$(run_palette / "$tmp/pal.palette")
|
|
expect_contains "$pal" '#123456' "palette: custom base colour"
|
|
expect_contains "$pal" 'bgcolor="#123456"' "palette: body fallback"
|
|
echo "PASS palette"
|
|
|
|
flat=$(run /repo/flat/tree)
|
|
expect_contains "$flat" 'README.md' "flat: tree"
|
|
echo "PASS flat"
|
|
|
|
echo "all gotea-cgi tests passed"
|