diff options
Diffstat (limited to 'test/run.sh')
| -rwxr-xr-x | test/run.sh | 71 |
1 files changed, 29 insertions, 42 deletions
diff --git a/test/run.sh b/test/run.sh index 39f26b7..bc1a9e4 100755 --- a/test/run.sh +++ b/test/run.sh @@ -1,16 +1,11 @@ #!/bin/sh -# run.sh - drive git-authz the way git does, without git. +# Drive git-authz the way git does, without git: identity in the environment, +# "old new ref" on stdin, the repository as cwd. The two facts only git knows are +# supplied with --ff and --head, so no repository or commits are needed. # -# Everything a receive hook knows, this feeds it: an identity in the -# environment, "old new ref" lines on stdin, the repository as the working -# directory. What only the object store knows - whether old is an ancestor of -# new, and which branch HEAD points at - is supplied explicitly (--ff, --head), -# so the suite is deterministic and needs no repository, no commits, and no -# git. hook.c asks git those questions in production; the answers it gets are -# what the tests below pin the consequences of. -# -# POSIX sh: this runs under dash, busybox ash and bash alike, because the -# container it has to survive is Alpine. +# POSIX sh: runs under dash, busybox ash and bash, because the container it has to +# survive is Alpine. + AUTHZ=${AUTHZ:-./git-authz} if [ ! -x "$AUTHZ" ]; then @@ -91,9 +86,9 @@ do_check() { "$AUTHZ" --policy "$POLICY" check "$@" 2>&1 } -# Which policy the two drivers below read. Overridden per test with -# "out=$(POLICY=something push ...)", which is a subshell and therefore does not -# leak into the next test. +# Overridden per test with "out=$(POLICY=something push ...)", a subshell, so it +# does not leak into the next test. + POLICY=$P # push <user|none> <repo> [extra authorize args] (ref lines on stdin) @@ -110,12 +105,10 @@ push() { fi } -# hook <user|none> <repodir> (invoked through the hook name, as git does, with -# the repository as the working directory and git's own argument in hand) -# Reached the way core.hooksPath reaches it: by name, with the repository as the -# working directory, git's own argument in hand (which is not ours, and must not -# be read as one), and no --policy anywhere - the hook gets its policy from -# GIT_HOST_AUTHZ or the default path, exactly as a deployed one does. +# hook <user|none> <repodir> +# The way core.hooksPath reaches it: by name, repo as cwd, git's own argument in +# hand (not ours, and must not be read as one), no --policy anywhere. + hook() { user=$1 dir=$2 @@ -154,8 +147,8 @@ if [ ! -L "$TMP/bin/pre-receive" ]; then skip_it "hook reached by its own name" "cannot make a symlink here" fi -# A policy with no '@all' line, for the tests that need a repository and a -# stranger rather than a policy that reaches everywhere. +# No '@all' line: for tests that need a stranger and a specific repository. + cat >"$TMP/plain.conf" <<'EOF' alice * admin bob team write refs/heads/feature/* @@ -429,14 +422,10 @@ expect "and the last path component works when it is not the root" 0 "team" "$rc # ------------------------------------------- the two facts that belong to git # -# Everything else the hook knows it works out of the line git gave it. Two -# facts do not come that way: whether HEAD is a branch, and whether old is an -# ancestor of new. Those are asked of git, and asking them is a code path the -# rest of this suite cannot reach, because there is no git in it. -# -# So: a stand-in named git, and the real one kept out of PATH. A fake that -# answers whatever it is told is worth more here than the real thing, which -# would answer a question about the host instead of the question the hook asked. +# The two questions the rest of this suite cannot reach, because there is no git +# in it. A stand-in named git answers to order, with the real one kept out of +# PATH: the host's git would answer a different question than the one asked. + mkdir -p "$TMP/fakegit" cat >"$TMP/fakegit/git" <<'EOF' @@ -486,8 +475,8 @@ out=$(printf '%s %s %s\n' "$A" "$B" refs/heads/feature/x | hookgit bob "$TMP/root/team.git" PATH="$TMP/fakegit" FAKE_HEAD=refs/heads/main FAKE_FF=1); rc=$? expect "and one it does not, force" 1 "needs force" "$rc" "$out" -# No git at all: the hook cannot ask, so it must not guess in the caller's -# favour. A deletion it cannot place is charged the most, not the least. +# No git to ask: the hook must not guess in the caller's favour. + out=$(printf '%s %s %s\n' "$A" "$ZERO" refs/heads/feature/x | hookgit carol "$TMP/root/team.git" PATH="$TMP/empty"); rc=$? expect "with no git to ask, a deletion is the expensive kind" 1 "needs admin" "$rc" "$out" @@ -746,10 +735,9 @@ else bad "--stdout lost the comments or the settings" fi -# A file whose *directory* is read-only cannot be replaced, which is what a -# read-only ConfigMap mount means in practice. A 0444 file in a writable -# directory is a different thing and worth pinning too: the grant succeeds and -# the mode survives, because it is the directory that decides. +# It is the directory that decides: a read-only mount is a read-only directory, +# while a 0444 file in a writable directory is still replaceable. + cp "$TMP/edit.conf" "$TMP/ro.conf" chmod 444 "$TMP/ro.conf" out=$("$AUTHZ" --policy "$TMP/ro.conf" grant bob team admin 2>&1); rc=$? @@ -808,9 +796,9 @@ else out=$(make install DESTDIR="$S" 2>&1); rc=$? expect "make install into a DESTDIR" 0 "pre-receive" "$rc" "$out" - # The hook has to be a relative link: staged, unpacked, or shipped in an - # image, it must point at the binary that came with it rather than at - # whatever occupies that absolute path on the machine reading it. + # A relative link: an absolute one points at whatever occupies that path on + # whatever machine reads it. + link=$(ls -l "$S/usr/local/share/git-host/hooks/pre-receive") case $link in *'= /'*) bad "the installed hook is an absolute symlink: $link" ;; @@ -818,9 +806,8 @@ else *) bad "the installed hook is not a relative symlink: $link" ;; esac - # End to end through the installed name, with the installed policy, in a - # repository under an installed root: nothing but the paths from the - # installer here. + # Nothing here but the paths the installer chose. + mkdir -p "$S/var/lib/git/team.git" out=$(printf '%s %s %s\n' "$ZERO" "$A" refs/heads/feature/x | ( cd "$S/var/lib/git/team.git" && env GIT_HOST_USER=bob \ |
