summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/run.sh89
-rw-r--r--tests/unit.c134
2 files changed, 119 insertions, 104 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
diff --git a/tests/unit.c b/tests/unit.c
index 0d21ee3..cf55282 100644
--- a/tests/unit.c
+++ b/tests/unit.c
@@ -237,8 +237,7 @@ static void test_parse(void)
" \n"
"alice web admin # trailing comment\n"
"bob web write refs/heads/feature/* refs/heads/dev\n"
- "@all team write main\n"
- "set protected-refs main refs/tags/*\n");
+ "@all team write main\n");
CHECK_INT(rc, 0);
CHECK_INT(p.errors, 0);
CHECK_INT(p.nrules, 3);
@@ -250,7 +249,6 @@ static void test_parse(void)
CHECK_STR(p.rules[1].refs[0], "refs/heads/feature/*");
CHECK_INT(p.rules[1].nrefs, 2);
CHECK_STR(p.rules[2].refs[0], "refs/heads/main"); /* normalised at parse time */
- CHECK_STR(p.protected_global, "refs/heads/main refs/tags/*");
policy_free(&p);
/* Errors: each of these must stop the file being used at all. The complaints
@@ -288,7 +286,14 @@ static void test_parse(void)
CHECK_INT(rc, -1);
policy_free(&p);
- rc = load_text(&p, "set protected-refs\n");
+ /* Removed settings are refused by name, not ignored: a policy that
+ * still carries one would otherwise mean "everyone with write can fast
+ * -forward main" while looking like it said the opposite. */
+ rc = load_text(&p, "set protected-refs refs/heads/main\n");
+ CHECK_INT(rc, -1);
+ policy_free(&p);
+
+ rc = load_text(&p, "set protected-refs.web refs/heads/main\n");
CHECK_INT(rc, -1);
policy_free(&p);
@@ -301,19 +306,10 @@ static void test_parse(void)
close(keep);
}
- /* The default protected list, and the two ways to replace it. */
+ /* There is no settings list any more: a rule says what it says. */
rc = load_text(&p, "alice * admin\n");
CHECK_INT(rc, 0);
- CHECK_STR(authz_protected_for(&p, "web"), "refs/heads/main");
- policy_free(&p);
-
- rc = load_text(&p,
- "set protected-refs refs/heads/main refs/heads/stable\n"
- "set protected-refs.web refs/heads/release\n"
- "alice * admin\n");
- CHECK_INT(rc, 0);
- CHECK_STR(authz_protected_for(&p, "web"), "refs/heads/release");
- CHECK_STR(authz_protected_for(&p, "other"), "refs/heads/main refs/heads/stable");
+ CHECK_INT(p.nrules, 1);
policy_free(&p);
}
@@ -347,35 +343,32 @@ static void test_known_users(void)
static void test_need_for(void)
{
- policy_t p;
char raised[64];
- int rc;
- rc = load_text(&p,
- "set protected-refs refs/heads/main refs/tags/*\n"
- "alice * admin\n");
- CHECK_INT(rc, 0);
- CHECK_INT(authz_need_for(&p, "web", "refs/heads/dev", LV_WRITE, raised,
- sizeof(raised)), LV_WRITE);
+ /* A branch or a tag costs exactly what the rule said: there is no list
+ * elsewhere in the file that can raise the price of one. */
+ CHECK_INT(authz_need_for("refs/heads/dev", LV_WRITE, raised, sizeof(raised)),
+ LV_WRITE);
CHECK_STR(raised, "");
- CHECK_INT(authz_need_for(&p, "web", "refs/heads/main", LV_WRITE, raised,
- sizeof(raised)), LV_FORCE);
- CHECK_STR(raised, "protected");
- CHECK_INT(authz_need_for(&p, "web", "refs/heads/main", LV_FORCE, raised,
- sizeof(raised)), LV_ADMIN);
- CHECK_INT(authz_need_for(&p, "web", "refs/heads/main", LV_ADMIN, raised,
- sizeof(raised)), LV_ADMIN);
- CHECK_STR(raised, ""); /* admin is already the top */
- CHECK_INT(authz_need_for(&p, "web", "refs/tags/v1", LV_WRITE, raised,
- sizeof(raised)), LV_FORCE);
- CHECK_INT(authz_need_for(&p, "web", "refs/pull/1/head", LV_WRITE, raised,
- sizeof(raised)), LV_ADMIN);
+ CHECK_INT(authz_need_for("refs/heads/main", LV_WRITE, raised, sizeof(raised)),
+ LV_WRITE);
+ CHECK_INT(authz_need_for("refs/tags/v1", LV_WRITE, raised, sizeof(raised)),
+ LV_WRITE);
+ CHECK_INT(authz_need_for("refs/heads/feature/x", LV_FORCE, raised, sizeof(raised)),
+ LV_FORCE);
+
+ /* Anything outside refs/heads and refs/tags is for maintainers, whatever a
+ * rule appears to grant about it. */
+ CHECK_INT(authz_need_for("refs/pull/1/head", LV_WRITE, raised, sizeof(raised)),
+ LV_ADMIN);
CHECK_STR(raised, "neither a branch nor a tag");
- CHECK_INT(authz_need_for(&p, "web", "refs/pull/1/head", LV_FORCE, raised,
- sizeof(raised)), LV_ADMIN);
- CHECK_INT(authz_need_for(&p, "web", "refs/notes/x", LV_ADMIN, raised,
- sizeof(raised)), LV_ADMIN);
- policy_free(&p);
+ CHECK_INT(authz_need_for("refs/pull/1/head", LV_FORCE, raised, sizeof(raised)),
+ LV_ADMIN);
+ CHECK_INT(authz_need_for("refs/notes/x", LV_WRITE, raised, sizeof(raised)),
+ LV_ADMIN);
+ CHECK_INT(authz_need_for("refs/notes/x", LV_ADMIN, raised, sizeof(raised)),
+ LV_ADMIN);
+ CHECK_STR(raised, ""); /* admin is already the top */
}
static void test_check(void)
@@ -384,9 +377,9 @@ static void test_check(void)
int rc;
rc = load_text(&p,
- "set protected-refs refs/heads/main refs/tags/*\n"
"alice * admin\n"
- "@all * write refs/heads/*\n"
+ "@all * write refs/heads/feature/*\n"
+ "frank team write refs/heads/main refs/tags/*\n"
"bob team write refs/heads/feature/*\n"
"carol team force refs/heads/feature/*\n"
"dave team admin\n"
@@ -407,19 +400,27 @@ static void test_check(void)
/* '@all' reaches the named, and nobody else. Note that the '@all *' rule
* below reaches every repository, so a named user is not confined to the
* repository their own rule names - that is what the rule says. */
- expect_allow(&p, "carol", "web", LV_WRITE, "refs/heads/any");
- expect_allow(&p, "erin", "web", LV_WRITE, "refs/heads/any");
+ expect_allow(&p, "carol", "web", LV_WRITE, "refs/heads/feature/any");
+ expect_allow(&p, "erin", "web", LV_WRITE, "refs/heads/feature/any");
expect_deny(&p, "nobody", "web", LV_WRITE, "refs/heads/any", "no rule");
expect_deny(&p, "", "web", LV_WRITE, "refs/heads/any", "no identity");
expect_deny(&p, NULL, "web", LV_WRITE, "refs/heads/any", "no identity");
- /* protected refs raise the cost, and say so */
- expect_deny(&p, "bob", "team", LV_WRITE, "refs/heads/main", "raised from write");
- expect_deny(&p, "carol", "team", LV_FORCE, "refs/heads/main", "raised from force");
- /* the raise applies to the level the action asked for, not to the best
- * level the user happens to hold somewhere else */
- expect_deny(&p, "carol", "team", LV_WRITE, "refs/heads/main", "needs force");
+ /* main is not special: it is refused here because no rule of bob's or
+ * carol's names it, and allowed for dave because his names everything. */
+ expect_deny(&p, "bob", "team", LV_WRITE, "refs/heads/main",
+ "but not on refs/heads/main");
+ expect_deny(&p, "carol", "team", LV_FORCE, "refs/heads/main",
+ "but not on refs/heads/main");
expect_allow(&p, "dave", "team", LV_WRITE, "refs/heads/main");
+ /* and the person whose rule does name main, and nothing else, gets main */
+ expect_allow(&p, "frank", "team", LV_WRITE, "refs/heads/main");
+ /* frank reaches the '@all' rule like anyone else the policy names, so what
+ * he lacks is a branch nobody's rule names, and a rewrite of his own */
+ expect_allow(&p, "frank", "team", LV_WRITE, "refs/heads/feature/x");
+ expect_deny(&p, "frank", "team", LV_WRITE, "refs/heads/dev",
+ "but not on refs/heads/dev");
+ expect_deny(&p, "frank", "team", LV_FORCE, "refs/heads/main", "needs force");
/* refs that are not branches or tags: only an admin, at any request level */
expect_allow(&p, "dave", "team", LV_WRITE, "refs/pull/1/head");
@@ -427,9 +428,9 @@ static void test_check(void)
expect_deny(&p, "bob", "team", LV_ADMIN, "refs/notes/x", "needs admin");
/* the same branch, three spellings */
- expect_deny(&p, "bob", "team", LV_WRITE, "main", "protected");
- expect_deny(&p, "bob", "team", LV_WRITE, "heads/main", "protected");
- expect_deny(&p, "bob", "team", LV_WRITE, "refs/heads/main", "protected");
+ expect_deny(&p, "bob", "team", LV_WRITE, "main", "but not on refs/heads/main");
+ expect_deny(&p, "bob", "team", LV_WRITE, "heads/main",
+ "but not on refs/heads/main");
/* repository matching: .git is the same repository */
expect_allow(&p, "bob", "team.git", LV_WRITE, "refs/heads/feature/x");
@@ -465,14 +466,14 @@ static void test_scope_edges(void)
policy_t p;
int rc;
- /* a rule with no refs is the whole repository, protected refs included */
+ /* a rule with no refs is the whole repository: every branch, main included,
+ * which is exactly why naming the refs is the honest way to write one */
rc = load_text(&p, "bob team write\n");
CHECK_INT(rc, 0);
expect_allow(&p, "bob", "team", LV_WRITE, "refs/heads/anything");
- expect_deny(&p, "bob", "team", LV_WRITE, "refs/heads/main", "protected");
- /* write on everything still is not force: the raise asks for the next step
- * up, and bob never got it */
- expect_deny(&p, "bob", "team", LV_FORCE, "refs/heads/main", "needs admin");
+ expect_allow(&p, "bob", "team", LV_WRITE, "refs/heads/main");
+ /* write on everything still is not force */
+ expect_deny(&p, "bob", "team", LV_FORCE, "refs/heads/main", "needs force");
policy_free(&p);
/* a bare name is a branch, and only a branch */
@@ -496,18 +497,17 @@ static void test_scope_edges(void)
expect_deny(&p, "bob", "team", LV_FORCE, "refs/heads/dev",
"bob has write on team refs/heads/dev; it needs force");
expect_deny(&p, "bob", "team", LV_WRITE, "refs/heads/other",
- "nothing at all on refs/heads/other");
+ "but not on refs/heads/other");
policy_free(&p);
- /* per-repository protection replaces the global list, it does not add to it */
- rc = load_text(&p,
- "set protected-refs refs/heads/main\n"
- "set protected-refs.web refs/heads/release\n"
- "bob web write refs/heads/*\n");
+ /* naming refs in a rule is the whole of the mechanism: what is not named is
+ * not granted, and the refusal says so rather than blaming a list */
+ rc = load_text(&p, "bob web write refs/heads/feature/* refs/heads/dev\n");
CHECK_INT(rc, 0);
- expect_allow(&p, "bob", "web", LV_WRITE, "refs/heads/main");
- expect_deny(&p, "bob", "web", LV_WRITE, "refs/heads/release", "protected");
- expect_deny(&p, "bob", "api", LV_WRITE, "refs/heads/release", "no rule");
+ expect_allow(&p, "bob", "web", LV_WRITE, "refs/heads/dev");
+ expect_allow(&p, "bob", "web", LV_WRITE, "refs/heads/feature/x");
+ expect_deny(&p, "bob", "web", LV_WRITE, "refs/heads/main", "but not on");
+ expect_deny(&p, "bob", "api", LV_WRITE, "refs/heads/dev", "no rule");
policy_free(&p);
/* reachable-by-nobody detection, which validate reports */