/* 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. */ #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. */ CHECK_INT(authz_need_for("refs/heads/dev", LV_WRITE, raised, sizeof(raised)), LV_WRITE); CHECK_STR(raised, ""); 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("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 */ } int main(void) { test_init(""); test_need_for(); return test_report("need"); }