From 312ddd4936f09ae27a180ca495cacf2c06faf33e Mon Sep 17 00:00:00 2001 From: dev Date: Sat, 14 Nov 2026 01:05:08 +0000 Subject: Comments: cut to what the code cannot say The comments had grown into essays. A file header explaining why the file exists, then a paragraph above each function restating what the next eight lines do, then a paragraph above that one explaining why that matters. The reader gets no further than the first paragraph, and the second is the one that goes stale: it describes code that has since changed, and nothing fails when it does. Cut by about half. What is left is the three things a comment can do that code cannot: say why the constraint exists (no regex because a hook must not depend on what might be missing at 3am), say what is not obvious from the shape (a bare ref name is a branch, never a tag; the seventh field of /etc/passwd is the shell), and say where it hurts (the NULL in an execvp array, the mode and owner that have to survive an atomic rewrite, the child that must not keep the hook's stdin). Block comments became // lines, which is also what the other C trees here use, and the file headers went to two or three lines. Section banners stayed: they are navigation, not prose. Behaviour is unchanged and the suites prove it: 171 direct checks, 162 behavioural, clean under -Werror and under ASan/UBSan. --- test/check.c | 67 +++++++++++++++++++++++++++----------------------------- test/glob.c | 19 ++++++---------- test/need.c | 19 ++++++---------- test/norm.c | 17 +++++---------- test/parse.c | 37 ++++++++++++++----------------- test/run.sh | 71 +++++++++++++++++++++++++----------------------------------- test/test.h | 21 +++++++----------- 7 files changed, 105 insertions(+), 146 deletions(-) (limited to 'test') 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")); diff --git a/test/glob.c b/test/glob.c index ee1bece..cbb97c8 100644 --- a/test/glob.c +++ b/test/glob.c @@ -1,9 +1,4 @@ -/* glob.c - What a glob matches. Written out rather than reached for with fnmatch(3) - * or regex(3), so this is the file that says what "*" and "[!a-z]" mean here. - * - * 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. - */ +// What a glob matches, since nothing here uses fnmatch or regex. #include "test.h" static void test_glob(void) @@ -13,7 +8,7 @@ static void test_glob(void) CHECK(!glob_match("", "x")); CHECK(glob_match("", "")); CHECK(glob_match("refs/heads/*", "refs/heads/main")); - CHECK(glob_match("refs/heads/*", "refs/heads/a/b/c")); /* '*' crosses '/' */ + CHECK(glob_match("refs/heads/*", "refs/heads/a/b/c")); // '*' crosses '/' CHECK(!glob_match("refs/heads/*", "refs/tags/v1")); CHECK(glob_match("refs/heads/feature/*", "refs/heads/feature/login")); CHECK(!glob_match("refs/heads/feature/*", "refs/heads/featurey")); @@ -26,17 +21,17 @@ static void test_glob(void) CHECK(!glob_match("refs/heads/[!ab]*", "refs/heads/alpha")); CHECK(glob_match("refs/heads/[a-c]1", "refs/heads/b1")); CHECK(!glob_match("refs/heads/[a-c]1", "refs/heads/d1")); - CHECK(glob_match("refs/heads/]", "refs/heads/]")); /* ']' first is a member */ - CHECK(glob_match("refs/heads/a[-]z", "refs/heads/a-z")); /* trailing '-' literal */ - CHECK(glob_match("refs/heads/[", "refs/heads/[")); /* unclosed is literal */ + CHECK(glob_match("refs/heads/]", "refs/heads/]")); // ']' first is a member + CHECK(glob_match("refs/heads/a[-]z", "refs/heads/a-z")); // trailing '-' literal + CHECK(glob_match("refs/heads/[", "refs/heads/[")); // unclosed is literal CHECK(glob_match("a*b*c", "aXXbYYc")); CHECK(!glob_match("a*b*c", "aXXbYY")); CHECK(glob_match("*.git", "team.git")); CHECK(glob_match("team*", "team")); CHECK(glob_match("refs/heads/ma?n", "refs/heads/main")); - CHECK(!glob_match("refs/heads/main", "refs/heads/MAIN")); /* case matters */ + CHECK(!glob_match("refs/heads/main", "refs/heads/MAIN")); // case matters CHECK(glob_match("refs/*/x", "refs/a/b/x")); - CHECK(glob_match("**", "x")); /* redundant stars */ + CHECK(glob_match("**", "x")); // redundant stars CHECK(!glob_match("refs/heads/*", "")); } diff --git a/test/need.c b/test/need.c index f831111..013674e 100644 --- a/test/need.c +++ b/test/need.c @@ -1,18 +1,13 @@ -/* need.c - What a ref costs beyond what the rule said - which is only ever the case - * for refs outside refs/heads and refs/tags. There is no second list in the - * policy that can raise the price of a ref behind the operator's back. - * - * 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. - */ +// What a ref costs beyond what the rule said - only ever refs outside +// refs/heads and refs/tags. #include "test.h" static void test_need_for(void) { char raised[64]; - /* 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. */ + // 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, ""); @@ -23,8 +18,8 @@ static void test_need_for(void) 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. */ + // 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"); @@ -34,7 +29,7 @@ static void test_need_for(void) 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 */ + CHECK_STR(raised, ""); // admin is already the top } int main(void) diff --git a/test/norm.c b/test/norm.c index acfb6ec..4b8a35a 100644 --- a/test/norm.c +++ b/test/norm.c @@ -1,10 +1,5 @@ -/* norm.c - Refs and repositories have one spelling each internally. This is the file - * that pins "main", "heads/main" and "refs/heads/main" being one branch, and - * a bare name never meaning a tag. - * - * 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. - */ +// One spelling per ref: "main", "heads/main" and "refs/heads/main" are one +// branch, and a bare name is never a tag. #include "test.h" static void test_normalisation(void) @@ -21,7 +16,7 @@ static void test_normalisation(void) CHECK_STR(s, "refs/heads/main"); free(s); s = authz_norm_ref("v1.0"); - CHECK_STR(s, "refs/heads/v1.0"); /* a bare name is never a tag */ + CHECK_STR(s, "refs/heads/v1.0"); // a bare name is never a tag free(s); s = authz_norm_ref("tags/v1.0"); CHECK_STR(s, "refs/tags/v1.0"); @@ -49,7 +44,7 @@ static void test_normalisation(void) CHECK_STR(s, "*"); free(s); s = authz_norm_repo(".git"); - CHECK_STR(s, ".git"); /* a repository called ".git" is not a suffix */ + CHECK_STR(s, ".git"); // a repository called ".git" is not a suffix free(s); CHECK_INT(authz_level_of("write"), LV_WRITE); @@ -66,13 +61,13 @@ static void test_normalisation(void) CHECK(authz_user_pattern_ok("@all")); CHECK(authz_user_pattern_ok("a[bc]d")); CHECK(!authz_user_pattern_ok("")); - CHECK(!authz_user_pattern_ok("a/b")); /* a path is not a user name */ + CHECK(!authz_user_pattern_ok("a/b")); // a path is not a user name CHECK(!authz_user_pattern_ok("a$b")); CHECK(!authz_user_pattern_ok("-x")); CHECK(authz_repo_pattern_ok("team")); CHECK(authz_repo_pattern_ok("*")); CHECK(authz_repo_pattern_ok("team-*")); - CHECK(!authz_repo_pattern_ok("group/team")); /* flat names only */ + CHECK(!authz_repo_pattern_ok("group/team")); // flat names only CHECK(!authz_repo_pattern_ok("")); CHECK(!authz_repo_pattern_ok("a$b")); } diff --git a/test/parse.c b/test/parse.c index fb137c5..5c8cb5f 100644 --- a/test/parse.c +++ b/test/parse.c @@ -1,10 +1,5 @@ -/* parse.c - Reading the file: what parses, what is refused, and who "@all" turns out to - * be. One bad line poisons the whole file, so the error cases matter as much - * as the good ones. - * - * 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. - */ +// What parses, what is refused, and who "@all" turns out to be. One bad line +// poisons the whole file. #include "test.h" static void test_parse(void) @@ -29,14 +24,14 @@ static void test_parse(void) CHECK_INT(p.rules[0].line, 4); 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.rules[2].refs[0], "refs/heads/main"); // normalised at parse time policy_free(&p); - /* Errors: each of these must stop the file being used at all. The complaints - * are asserted as counts, and the parser writes them to stderr as it goes, so - * stderr is set aside here - a wall of expected errors would hide the failures. - * The descriptor is redirected rather than freopen'd, because freopen would - * quietly make stderr block-buffered and hand the whole wall back at exit. */ + // Errors: each of these must stop the file being used at all. The complaints + // are asserted as counts, and the parser writes them to stderr as it goes, so + // stderr is set aside here - a wall of expected errors would hide the failures. + // The descriptor is redirected rather than freopen'd, because freopen would + // quietly make stderr block-buffered and hand the whole wall back at exit. { int keep = dup(2); int devnull = open("/dev/null", O_WRONLY); @@ -67,9 +62,9 @@ static void test_parse(void) CHECK_INT(rc, -1); policy_free(&p); - /* 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. */ + // 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); @@ -79,7 +74,7 @@ static void test_parse(void) policy_free(&p); rc = load_text(&p, "alice web write refs/heads/main\nbob web nope refs/heads/dev\n"); - CHECK_INT(rc, -1); /* one bad line poisons the file: nothing is used */ + CHECK_INT(rc, -1); // one bad line poisons the file: nothing is used policy_free(&p); fflush(stderr); @@ -87,7 +82,7 @@ static void test_parse(void) close(keep); } - /* There is no settings list any more: a rule says what it says. */ + // 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_INT(p.nrules, 1); @@ -106,18 +101,18 @@ static void test_known_users(void) CHECK_INT(rc, 0); CHECK(authz_user_known(&p, "alice")); CHECK(authz_user_known(&p, "bob")); - CHECK(!authz_user_known(&p, "carol")); /* '@all' never invents a name */ + CHECK(!authz_user_known(&p, "carol")); // '@all' never invents a name CHECK(!authz_user_known(&p, "")); policy_free(&p); rc = load_text(&p, "@all web write\n"); CHECK_INT(rc, 0); - CHECK(!authz_user_known(&p, "alice")); /* nobody is known yet */ + CHECK(!authz_user_known(&p, "alice")); // nobody is known yet policy_free(&p); rc = load_text(&p, "ali* web write\n"); CHECK_INT(rc, 0); - CHECK(authz_user_known(&p, "alice")); /* a pattern is still a name */ + CHECK(authz_user_known(&p, "alice")); // a pattern is still a name CHECK(!authz_user_known(&p, "bob")); policy_free(&p); } 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 [extra authorize args] (ref lines on stdin) @@ -110,12 +105,10 @@ push() { fi } -# hook (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 +# 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 \ diff --git a/test/test.h b/test/test.h index c4f63d0..e60e5af 100644 --- a/test/test.h +++ b/test/test.h @@ -1,10 +1,5 @@ -/* test.h - the little harness the test programs share. - * - * No test framework, because a test suite with a dependency is a test suite - * that does not run at 3am. Each program in test/ is its own: it links the - * library, runs its own cases and reports its own count, so one failing file - * says which area broke rather than taking the whole run down with it. - */ +// No test framework: a suite with a dependency is a suite that does not run at +// 3am. Each program in test/ links the library and reports its own count. #ifndef TEST_H #define TEST_H @@ -61,8 +56,8 @@ static inline void note(const char *fmt, ...) fputc('\n', stdout); } -/* Where the fixtures are written. UNIT_TMPDIR is there for a build that runs - * the tests somewhere the source tree is not writable. */ +// Where the fixtures are written. UNIT_TMPDIR is there for a build that runs * +// the tests somewhere the source tree is not writable. static inline void test_init(const char *argv0) { const char *dir = getenv("UNIT_TMPDIR"); @@ -79,11 +74,11 @@ static inline int test_report(const char *what) return failures != 0; } -/* ------------------------------------------------------------- fixtures */ +// ------------------------------------------------------------- fixtures -/* A policy from a string. The file is unlinked straight after loading: the - * decisions are made in memory, and a test that left policies behind would - * leave them to be trusted. */ +// A policy from a string. The file is unlinked straight after loading: the +// decisions are made in memory, and a test that left policies behind would leave +// them to be trusted. static inline int load_text(policy_t *p, const char *text) { static int seq; -- cgit v1.2.3