diff options
Diffstat (limited to 'tests/run.sh')
| -rw-r--r-- | tests/run.sh | 89 |
1 files changed, 52 insertions, 37 deletions
diff --git a/tests/run.sh b/tests/run.sh index a1c687b..1d8aa7d 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -134,10 +134,9 @@ section "fixture" cat >"$TMP/authz.conf" <<'EOF' # who may move which refs -set protected-refs refs/heads/main refs/tags/* - alice * admin # the one account that can do anything -@all * write refs/heads/* # anyone the policy names: their own branches +@all * write refs/heads/feature/* # anyone the policy names: working branches +frank team write refs/heads/main refs/tags/* # releases, and nothing else bob team write refs/heads/feature/* carol team force refs/heads/feature/* dave team admin @@ -203,7 +202,7 @@ out=$(do_check dave team write refs/heads/anything); rc=$? expect "admin answers a write too" 0 "allow" "$rc" "$out" out=$(POLICY="$TMP/plain.conf" do_check erin other write refs/heads/dev); rc=$? expect "a stranger to the repository" 1 "no rule for other" "$rc" "$out" -out=$(do_check erin other write refs/heads/dev); rc=$? +out=$(do_check erin other write refs/heads/feature/x); rc=$? expect "unless '@all' reaches that repository too" 0 "allow" "$rc" "$out" section "check: names mean what they say" @@ -211,13 +210,13 @@ section "check: names mean what they say" out=$(do_check bob team.git write refs/heads/feature/x); rc=$? expect "team.git is team" 0 "allow" "$rc" "$out" out=$(do_check bob team write main); rc=$? -expect "a bare name is a branch, and a protected one" 1 "protected" "$rc" "$out" +expect "a bare name is a branch" 1 "refs/heads/main" "$rc" "$out" out=$(do_check bob team write heads/main); rc=$? -expect "heads/main is the same branch" 1 "protected" "$rc" "$out" +expect "heads/main is the same branch" 1 "refs/heads/main" "$rc" "$out" out=$(do_check bob team write refs/heads/main); rc=$? -expect "and so is refs/heads/main" 1 "protected" "$rc" "$out" +expect "and so is refs/heads/main" 1 "refs/heads/main" "$rc" "$out" out=$(do_check bob team write v1); rc=$? -expect "a bare v1 is a branch, never a tag" 0 "refs/heads/v1" "$rc" "$out" +expect "a bare v1 is a branch, never a tag" 1 "refs/heads/v1" "$rc" "$out" out=$(do_check bob team write tags/v1); rc=$? expect "and it takes tags/v1 to mean a tag" 1 "refs/tags/v1" "$rc" "$out" out=$(do_check dave team write refs/tags/v1); rc=$? @@ -225,18 +224,24 @@ expect "an admin can tag" 0 "allow" "$rc" "$out" out=$(do_check carol team write refs/heads/feature/deep/nested); rc=$? expect "* crosses a slash" 0 "allow" "$rc" "$out" -section "check: protected refs cost more" +section "check: a rule covers what it names, and nothing else" out=$(do_check bob team write refs/heads/main); rc=$? -expect "write on main costs force" 1 "raised from write" "$rc" "$out" -out=$(do_check carol team write refs/heads/main); rc=$? -expect "carol's force is on feature branches, not on main" 1 "carol has write on team refs/heads/main" "$rc" "$out" +expect "bob's rules never name main" 1 "but not on refs/heads/main" "$rc" "$out" out=$(do_check carol team force refs/heads/main); rc=$? -expect "force on a protected ref costs admin, wherever it is held" 1 "needs admin (raised" "$rc" "$out" +expect "and neither do carol's, at any level" 1 "but not on refs/heads/main" "$rc" "$out" +out=$(do_check frank team write refs/heads/main); rc=$? +expect "frank's rule does name it, so he may move it" 0 "allow" "$rc" "$out" +out=$(do_check frank team write refs/heads/feature/x); rc=$? +expect "and he reaches the '@all' rule like anyone else named" 0 "allow" "$rc" "$out" +out=$(do_check frank team force refs/heads/main); rc=$? +expect "naming a ref is not the same as holding every level on it" 1 "needs force" "$rc" "$out" out=$(do_check dave team force refs/heads/main); rc=$? -expect "admin pays nothing extra" 0 "allow" "$rc" "$out" +expect "an unscoped admin covers main too" 0 "allow" "$rc" "$out" out=$(do_check bob team write refs/tags/v1); rc=$? -expect "tags are protected too" 1 "protected" "$rc" "$out" +expect "tags have to be named as well" 1 "refs/tags/v1" "$rc" "$out" +out=$(do_check frank team write refs/tags/v1); rc=$? +expect "and frank named his" 0 "allow" "$rc" "$out" section "check: refs that are neither branch nor tag" @@ -249,7 +254,7 @@ expect "notes are for admins" 0 "allow" "$rc" "$out" section "check: '@all' is everyone the policy names" -out=$(do_check carol web write refs/heads/any); rc=$? +out=$(do_check carol web write refs/heads/feature/any); rc=$? expect "a named user reaches the @all rule" 0 "allow" "$rc" "$out" out=$(do_check nobody team write refs/heads/dev); rc=$? expect "a name the policy does not have gets nothing" 1 "no rule" "$rc" "$out" @@ -311,7 +316,8 @@ out=$(printf '%s %s %s\n' "$A" "$ZERO" refs/heads/feature/x | expect "deleting a branch she holds force on is allowed" 0 "-" "$rc" "$out" out=$(printf '%s %s %s\n' "$A" "$ZERO" refs/heads/dev | push carol team --head=refs/heads/other); rc=$? -expect "and only force on that ref will do, not force somewhere else" 1 "carol has write on team refs/heads/dev" "$rc" "$out" +expect "and only force on that ref will do, not force somewhere else" 1 \ + "carol holds force on team, but not on refs/heads/dev" "$rc" "$out" out=$(printf '%s %s %s\n' "$A" "$ZERO" refs/heads/dev | push dave team --head=refs/heads/dev); rc=$? @@ -365,14 +371,15 @@ out=$(printf '%s %s %s\n%s %s %s\n' \ "$ZERO" "$A" refs/heads/feature/one \ "$ZERO" "$B" refs/heads/main | push bob team); rc=$? -expect "one protected ref stops the whole push" 1 "refs/heads/main; it needs force" "$rc" "$out" +expect "one ref nobody may stop the whole push" 1 "refs/heads/main" "$rc" "$out" expect_not "and the refs before it are not reported either" 1 "feature/one" "$rc" "$out" out=$(printf '%s %s %s\n%s %s %s\n' \ "$ZERO" "$A" refs/heads/main \ "$ZERO" "$B" refs/heads/feature/one | push bob team); rc=$? -expect "the refusal says who, what and what it would take" 1 "bob has write" "$rc" "$out" +expect "the refusal says who, what and what it would take" 1 \ + "bob holds write on team, but not on refs/heads/main" "$rc" "$out" expect_not "and stops at the first refusal" 1 "feature/one" "$rc" "$out" section "authorize: input that is not a push" @@ -398,7 +405,8 @@ expect "the hook name selects authorize, and git's argument is ignored" 0 "-" "$ out=$(printf '%s %s %s\n' "$ZERO" "$A" refs/heads/release | POLICY="$TMP/plain.conf" hook bob "$TMP/root/team.git"); rc=$? -expect "and denies what authorize denies, on the repository it found" 1 "bob has write on team" "$rc" "$out" +expect "and denies what authorize denies, on the repository it found" 1 \ + "bob holds write on team, but not on refs/heads/release" "$rc" "$out" out=$(printf '%s %s %s\n' "$ZERO" "$A" refs/heads/feature/x | POLICY="$TMP/plain.conf" hook none "$TMP/root/team.git"); rc=$? @@ -580,12 +588,10 @@ expect "warnings alone still let the host serve" 0 "is in force" "$rc" "$out" # -------------------------------------------------------------- edit (grant) -section "grant, revoke, protect" +section "grant and revoke" cat >"$TMP/edit.conf" <<'EOF' # policy, kept in git and rolled out as a ConfigMap -set protected-refs refs/heads/main - alice * admin # break glass bob team write refs/heads/feature/* EOF @@ -602,7 +608,7 @@ else fi out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team admin 2>&1); rc=$? -expect "grant replaces the pair's rule" 0 "replaced line 5" "$rc" "$out" +expect "grant replaces the pair's rule" 0 "replaced line 3" "$rc" "$out" n=$(grep -c '^bob' "$TMP/edit.conf") [ "$n" = 1 ] && ok || bad "bob's rule is not collapsed into one line ($n lines)" out=$("$AUTHZ" --policy "$TMP/edit.conf" check bob team admin refs/heads/main 2>&1); rc=$? @@ -615,16 +621,16 @@ expect "and the access is gone" 1 "no rule" "$rc" "$out" out=$("$AUTHZ" --policy "$TMP/edit.conf" revoke bob team 2>&1); rc=$? expect "revoking nothing reports nothing" 1 "no rule for bob" "$rc" "$out" -out=$("$AUTHZ" --policy "$TMP/edit.conf" protect refs/heads/main refs/heads/stable 2>&1); rc=$? -expect "protect rewrites the setting" 0 "line 2" "$rc" "$out" -out=$("$AUTHZ" --policy "$TMP/edit.conf" check alice team force refs/heads/stable 2>&1); rc=$? -expect "the new protected ref is in force" 0 "allow" "$rc" "$out" -out=$("$AUTHZ" --policy "$TMP/edit.conf" protect --repo team refs/heads/release 2>&1); rc=$? -expect "protect can name one repository" 0 "protected-refs.team" "$rc" "$out" -if grep -q '^set protected-refs.team refs/heads/release$' "$TMP/edit.conf"; then +out=$("$AUTHZ" --policy "$TMP/edit.conf" grant frank team write refs/heads/main refs/tags/release/* 2>&1); rc=$? +expect "grant can name several refs" 0 "granted frank" "$rc" "$out" +out=$("$AUTHZ" --policy "$TMP/edit.conf" check frank team write refs/heads/main 2>&1); rc=$? +expect "and the list is in force" 0 "allow" "$rc" "$out" +out=$("$AUTHZ" --policy "$TMP/edit.conf" check frank team write refs/heads/dev 2>&1); rc=$? +expect "and covers nothing else of his own" 1 "but not on refs/heads/dev" "$rc" "$out" +if grep -q '^frank team write refs/heads/main refs/tags/release/\*$' "$TMP/edit.conf"; then ok else - bad "the per-repository setting is not the line it should be" + bad "the refs did not land on one line as written" fi out=$("$AUTHZ" --policy "$TMP/edit.conf" grant bob team nope 2>&1); rc=$? @@ -633,8 +639,17 @@ 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" -out=$("$AUTHZ" --policy "$TMP/edit.conf" protect 2>&1); rc=$? -expect "protect wants a pattern" 64 "wants" "$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" +out=$("$AUTHZ" --policy "$TMP/edit.conf" check alice team admin refs/heads/main 2>&1); rc=$? +expect "a policy that still carries protected-refs is refused, not ignored" 3 "no longer exists" "$rc" "$out" +out=$("$AUTHZ" --policy "$TMP/edit.conf" validate --no-host 2>&1); rc=$? +expect "and validate says every push is denied" 3 "not used" "$rc" "$out" +grep -v 'protected-refs' "$TMP/edit.conf" > "$TMP/edit.conf.clean" && + cp "$TMP/edit.conf.clean" "$TMP/edit.conf" +out=$("$AUTHZ" --policy "$TMP/edit.conf" validate --no-host 2>&1); rc=$? +expect "cleaned, it validates again" 0 "is in force" "$rc" "$out" cp "$TMP/edit.conf" "$TMP/edit.conf.orig" out=$("$AUTHZ" --policy "$TMP/broken.conf" grant bob team write 2>&1); rc=$? @@ -654,9 +669,9 @@ out=$("$AUTHZ" --policy "$TMP/edit.conf" grant erin secrets admin --stdout 2>&1 expect "--stdout reports on stderr" 0 "untouched" "$rc" "$out" cp "$TMP/edit.conf" "$TMP/edit.conf.bak" out=$("$AUTHZ" --policy "$TMP/edit.conf" revoke carol team --stdout 2>/dev/null); rc=$? -expect "--stdout prints the new file" 0 "set protected-refs" "$rc" "$out" +expect "--stdout prints the new file" 0 "alice * admin" "$rc" "$out" cmp -s "$TMP/edit.conf" "$TMP/edit.conf.bak" && ok || bad "--stdout modified the policy" -if contains "$out" "set protected-refs" && contains "$out" "break glass"; then +if contains "$out" "alice * admin" && contains "$out" "break glass"; then ok else bad "--stdout lost the comments or the settings" @@ -774,7 +789,7 @@ if [ -f authz.conf ]; then out=$("$AUTHZ" --policy authz.conf check bob team write refs/heads/feature/x 2>&1); rc=$? expect "bob works on features" 0 "allow" "$rc" "$out" out=$("$AUTHZ" --policy authz.conf check bob team write refs/heads/main 2>&1); rc=$? - expect "bob cannot touch main" 1 "protected" "$rc" "$out" + expect "bob cannot touch main" 1 "but not on refs/heads/main" "$rc" "$out" out=$("$AUTHZ" --policy authz.conf check nobody team write refs/heads/x 2>&1); rc=$? expect "a stranger cannot" 1 "no rule" "$rc" "$out" fi |
