diff options
Diffstat (limited to 'test/run.sh')
| -rwxr-xr-x | test/run.sh | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test/run.sh b/test/run.sh index bc1a9e4..a608468 100755 --- a/test/run.sh +++ b/test/run.sh @@ -388,6 +388,34 @@ expect "no refs at all is nothing to deny" 0 "-" "$rc" "$out" out=$(printf '\n\n' | push bob team); rc=$? expect "blank lines are skipped" 0 "-" "$rc" "$out" +# ------------------------------------------------------------ option forms + +# The usage text writes these as two words ("--user U", "--ff auto|yes|no"), and +# validate accepts both spellings, so authorize has to accept them too: a person +# following the help must not be told the option is unknown. + +section "authorize: the options as the usage spells them" + +out=$(printf '%s %s %s\n' "$ZERO" "$A" refs/heads/feature/x | + "$AUTHZ" --policy "$P" authorize --user bob --repo team --no-git 2>&1); rc=$? +expect "--user and --repo as two words" 0 "-" "$rc" "$out" + +out=$(printf '%s %s %s\n' "$A" "$B" refs/heads/feature/x | + "$AUTHZ" --policy "$P" authorize --user bob --repo team --ff no 2>&1); rc=$? +expect "--ff no as two words costs force" 1 "needs force" "$rc" "$out" + +out=$(printf '%s %s %s\n' "$B" "$ZERO" refs/heads/main | + "$AUTHZ" --policy "$P" authorize --user bob --repo team --head none 2>&1); rc=$? +expect "--head none as two words" 1 "-" "$rc" "$out" + +out=$(printf '%s %s %s\n' "$ZERO" "$A" refs/heads/feature/x | + "$AUTHZ" --policy "$P" authorize --user=bob --repo=team --no-git 2>&1); rc=$? +expect "and the = form still works" 0 "-" "$rc" "$out" + +out=$(printf '%s %s %s\n' "$ZERO" "$A" refs/heads/feature/x | + "$AUTHZ" --policy "$P" authorize --user 2>&1); rc=$? +expect "an option with no value says so" 64 "wants a value" "$rc" "$out" + # --------------------------------------------------------- the hook by name section "authorize: reached as pre-receive" @@ -644,6 +672,33 @@ else fi expect "warnings alone still let the host serve" 0 "is in force" "$rc" "$out" +# sshd reads a directive once and keeps the first answer it got, and "none" is +# how a Match block turns a ForceCommand back off - both of those are the same +# wide-open state as having no ForceCommand at all, so validate has to see them +# that way too. + +mkhost +printf 'PermitUserEnvironment yes\nForceCommand none\n' >"$H/sshd_config" +out=$(host_validate); rc=$? +expect "ForceCommand none is as open as no ForceCommand" 1 "interactive shell" "$rc" "$out" + +mkhost +printf 'PermitUserEnvironment no\nPermitUserEnvironment yes\n' >"$H/sshd_config" +out=$(host_validate); rc=$? +expect "sshd keeps the first PermitUserEnvironment, not the last" 1 "anonymous" "$rc" "$out" + +mkhost +printf 'PermitUserEnvironment yes\nForceCommand /usr/bin/git-shell\nForceCommand none\n' >"$H/sshd_config" +out=$(host_validate); rc=$? +expect "and the first ForceCommand is the one that counts" 0 "ForceCommand /usr/bin/git-shell" "$rc" "$out" + +# git spells section names case-insensitively, so [CORE] sets core.hooksPath just +# as [core] does; refusing to see it reports a broken host that is not broken. +mkhost +printf '[CORE]\n\thooksPath = %s/hooks\n' "$H" >"$H/gitconfig" +out=$(host_validate); rc=$? +expect "a gitconfig section name is case-insensitive, like git's own" 0 "core.hooksPath" "$rc" "$out" + # -------------------------------------------------------------- edit (grant) section "grant and revoke" @@ -697,6 +752,31 @@ out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob group/team write 2>&1); rc=$? expect "grant rejects a repository name with a slash in it" 64 "invalid repo pattern" "$rc" "$out" out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team write '!refs/heads/main' 2>&1); rc=$? expect "grant has no deny" 64 "no deny" "$rc" "$out" + +# A ref argument has to be one field. The line it lands on is split on whitespace +# again when the file is read, and '#' starts a comment, so writing an argument +# verbatim would either grant more than was asked for or leave a file that no +# longer parses - and a policy that does not parse denies every push there is. +cp "$TMP/edit.conf" "$TMP/edit.conf.before" +out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team write 'refs/heads/a b' 2>&1); rc=$? +expect "a ref argument with a space in it is refused" 64 "not a ref pattern" "$rc" "$out" +out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team write 'refs/heads/a#b' 2>&1); rc=$? +expect "a ref argument with a comment marker is refused" 64 "not a ref pattern" "$rc" "$out" +out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team write "$(printf 'refs/heads/a\nb')" 2>&1); rc=$? +expect "a ref argument with a newline in it is refused" 64 "not a ref pattern" "$rc" "$out" +cmp -s "$TMP/edit.conf" "$TMP/edit.conf.before" || + bad "a refused grant still changed the file" + +# The pair's rule being the last line of the file is still a replacement: nothing +# was appended, and the message says which line was taken over. +cat >"$TMP/lastline.conf" <<'EOF' +alice * admin +bob team write refs/heads/feature/* +EOF +out=$("$AUTHZ" --policy "$TMP/lastline.conf" grant bob team admin 2>&1); rc=$? +expect "replacing the last line says replaced, not appended" 0 "replaced line 2" "$rc" "$out" +out=$("$AUTHZ" --policy "$TMP/lastline.conf" grant zed team admin 2>&1); rc=$? +expect "and a rule with no pair yet is still an append" 0 "appended as line 3" "$rc" "$out" out=$("$AUTHZ" --policy "$TMP/edit.conf" protect refs/heads/main 2>&1); rc=$? expect "protect is gone, and says it is unknown" 64 "unknown command" "$rc" "$out" printf 'set protected-refs refs/heads/main\n' >>"$TMP/edit.conf" |
