1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/* 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");
}
|