summaryrefslogtreecommitdiffstats
path: root/test/check.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/check.c')
-rw-r--r--test/check.c67
1 files changed, 32 insertions, 35 deletions
diff --git a/test/check.c b/test/check.c
index 3df2ade..4db4b9e 100644
--- a/test/check.c
+++ b/test/check.c
@@ -1,10 +1,5 @@
-/* check.c - The decision, and the sentence that goes with it. A refusal has to name
- * the level held, the ref and the level required, because a person who is
- * refused should be able to fix it without opening the policy first.
- *
- * Part of the direct suite: this links the library, not the command
- * line. test/run.sh is the other half, and drives the program the way git does.
- */
+// The decision, and the sentence that goes with it: a refusal names the level
+// held, the ref, and the level required.
#include "test.h"
static void test_check(void)
@@ -22,65 +17,67 @@ static void test_check(void)
"erin secrets admin\n");
CHECK_INT(rc, 0);
- /* the ladder */
+ // the ladder
expect_allow(&p, "bob", "team", LV_WRITE, "refs/heads/feature/x");
expect_deny(&p, "bob", "team", LV_FORCE, "refs/heads/feature/x", "needs force");
expect_deny(&p, "bob", "team", LV_ADMIN, "refs/heads/feature/x", "needs admin");
expect_allow(&p, "carol", "team", LV_FORCE, "refs/heads/feature/x");
expect_allow(&p, "dave", "team", LV_ADMIN, "refs/heads/main");
- /* strongest match wins, additively */
+ // strongest match wins, additively
expect_allow(&p, "dave", "team", LV_WRITE, "refs/heads/feature/x");
expect_allow(&p, "alice", "anything", LV_ADMIN, "refs/heads/main");
- /* '@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. */
+ // '@all' reaches the named and nobody else. The '@all *' rule reaches every
+ // repository, so a named user is not confined to their own rule's repo.
+
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");
- /* 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. */
+ // main is not special: refused because no rule of theirs names it, 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 */
+ // 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 */
+ // frank reaches '@all' like anyone named, 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 */
+ // 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");
expect_allow(&p, "dave", "team", LV_ADMIN, "refs/pull/1/head");
expect_deny(&p, "bob", "team", LV_ADMIN, "refs/notes/x", "needs admin");
- /* the same branch, three spellings */
+ // the same branch, three spellings
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 */
+ // repository matching: .git is the same repository
expect_allow(&p, "bob", "team.git", LV_WRITE, "refs/heads/feature/x");
expect_allow(&p, "erin", "secrets.git", LV_ADMIN, "refs/heads/main");
- /* the question without a ref */
+ // the question without a ref
expect_allow(&p, "dave", "team", LV_FORCE, NULL);
expect_allow(&p, "alice", "team", LV_ADMIN, NULL);
expect_allow(&p, "bob", "team", LV_WRITE, NULL);
expect_deny(&p, "bob", "team", LV_FORCE, NULL, "no force");
- expect_allow(&p, "erin", "team", LV_WRITE, NULL); /* via '@all *' */
+ expect_allow(&p, "erin", "team", LV_WRITE, NULL); // via '@all *'
expect_deny(&p, "nobody", "team", LV_WRITE, NULL, "no write");
- /* what a denial names: the level held, and the level needed */
+ // what a denial names: the level held, and the level needed
{
decision_t d;
@@ -102,42 +99,42 @@ static void test_scope_edges(void)
policy_t p;
int rc;
- /* 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 */
+ // 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_allow(&p, "bob", "team", LV_WRITE, "refs/heads/main");
- /* write on everything still is not force */
+ // 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 */
+ // a bare name is a branch, and only a branch
rc = load_text(&p, "bob web write refs/heads/*\n");
CHECK_INT(rc, 0);
- expect_allow(&p, "bob", "web", LV_WRITE, "v1"); /* refs/heads/v1 */
+ expect_allow(&p, "bob", "web", LV_WRITE, "v1"); // refs/heads/v1
expect_deny(&p, "bob", "web", LV_WRITE, "refs/tags/v1", "needs write");
expect_deny(&p, "bob", "web", LV_WRITE, "tags/v1", "needs write");
policy_free(&p);
- /* a user may hold several rules for one repository; all of them count */
+ // a user may hold several rules for one repository; all of them count
rc = load_text(&p,
"bob team write refs/heads/dev\n"
"bob team force refs/heads/feature/*\n");
CHECK_INT(rc, 0);
expect_allow(&p, "bob", "team", LV_WRITE, "refs/heads/dev");
expect_allow(&p, "bob", "team", LV_FORCE, "refs/heads/feature/x");
- /* A refusal names the level held on the ref in question, not the strongest
- * level held somewhere in the repository: "you have force here" next to a
- * refusal is a sentence nobody can act on. */
+ // A refusal names the level held on the ref in question, not the strongest
+ // level held somewhere in the repository: "you have force here" next to a
+ // refusal is a sentence nobody can act on.
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",
"but not on refs/heads/other");
policy_free(&p);
- /* 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 */
+ // 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/dev");
@@ -146,7 +143,7 @@ static void test_scope_edges(void)
expect_deny(&p, "bob", "api", LV_WRITE, "refs/heads/dev", "no rule");
policy_free(&p);
- /* reachable-by-nobody detection, which validate reports */
+ // reachable-by-nobody detection, which validate reports
rc = load_text(&p, "bob team write\n");
CHECK_INT(rc, 0);
CHECK(authz_repo_reachable(&p, "team"));