/* 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. */ #include "test.h" static void test_normalisation(void) { char *s; s = authz_norm_ref("main"); CHECK_STR(s, "refs/heads/main"); free(s); s = authz_norm_ref("heads/main"); CHECK_STR(s, "refs/heads/main"); free(s); s = authz_norm_ref("refs/heads/main"); 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 */ free(s); s = authz_norm_ref("tags/v1.0"); CHECK_STR(s, "refs/tags/v1.0"); free(s); s = authz_norm_ref("notes/commits"); CHECK_STR(s, "refs/notes/commits"); free(s); s = authz_norm_ref("*"); CHECK_STR(s, "refs/*"); free(s); s = authz_norm_ref("all"); CHECK_STR(s, "refs/*"); free(s); s = authz_norm_ref("refs"); CHECK_STR(s, "refs/*"); free(s); s = authz_norm_repo("web.git"); CHECK_STR(s, "web"); free(s); s = authz_norm_repo("web"); CHECK_STR(s, "web"); free(s); s = authz_norm_repo("*"); CHECK_STR(s, "*"); free(s); s = authz_norm_repo(".git"); CHECK_STR(s, ".git"); /* a repository called ".git" is not a suffix */ free(s); CHECK_INT(authz_level_of("write"), LV_WRITE); CHECK_INT(authz_level_of("force"), LV_FORCE); CHECK_INT(authz_level_of("admin"), LV_ADMIN); CHECK_INT(authz_level_of("deny"), -1); CHECK_INT(authz_level_of("read"), -1); CHECK_STR(authz_level_name(LV_NONE), "none"); CHECK(authz_level_of("admin") > authz_level_of("force")); CHECK(authz_level_of("force") > authz_level_of("write")); CHECK(authz_user_pattern_ok("alice")); CHECK(authz_user_pattern_ok("a.b-c_1")); 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")); 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("")); CHECK(!authz_repo_pattern_ok("a$b")); } int main(void) { test_init(""); test_normalisation(); return test_report("norm"); }