summaryrefslogtreecommitdiffstats
path: root/tests/unit.c
blob: 0d21ee3deb4c2ff641f9488e804f14c861aa01fa (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
/* unit.c - the pieces, tested directly.
 *
 * This links the matcher, not the command line: what a glob does, what a ref
 * normalises to, what a policy parses into and what it therefore decides.  The
 * behavioural suite (tests/run.sh) drives the program the way git does; this
 * file is for the cases that would need a whole push to reach otherwise.
 *
 * No test framework, because a test suite with a dependency is a test suite
 * that does not run at 3am.  Failures print "not ok" with the expression.
 */
#include "../src/authz.h"

#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

static int checks;
static int failures;
static char tmproot[128];

#define CHECK(cond) \
    do { \
        checks++; \
        if (!(cond)) { \
            failures++; \
            printf("not ok %d: %s  [%s:%d]\n", failures, #cond, __FILE__, __LINE__);\
        } \
    } while (0)

#define CHECK_STR(got, want) \
    do { \
        checks++; \
        if (strcmp((got), (want)) != 0) { \
            failures++; \
            printf("not ok %d: got \"%s\", want \"%s\"  [%s:%d]\n", failures, \
                   (got), (want), __FILE__, __LINE__); \
        } \
    } while (0)

#define CHECK_INT(got, want) \
    do { \
        checks++; \
        if ((got) != (want)) { \
            failures++; \
            printf("not ok %d: got %ld, want %ld  [%s:%d]\n", failures, \
                   (long)(got), (long)(want), __FILE__, __LINE__); \
        } \
    } while (0)

static void note(const char *fmt, ...)
{
    va_list ap;

    fputs("    # ", stdout);
    va_start(ap, fmt);
    vprintf(fmt, ap);
    va_end(ap);
    fputc('\n', stdout);
}

/* ------------------------------------------------------------- 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. */
static int load_text(policy_t *p, const char *text)
{
    static int seq;
    char path[512];
    FILE *f;
    int rc;

    snprintf(path, sizeof(path), "%s/unit-%d", tmproot, ++seq);
    f = fopen(path, "w");
    if (f == NULL) {
        printf("not ok %d: cannot write %s\n", ++failures, path);
        return -1;
    }
    fputs(text, f);
    fclose(f);

    policy_init(p, path);
    rc = policy_load(p);
    unlink(path);
    return rc;
}

static void expect_allow(const policy_t *p, const char *user, const char *repo,
                         level_t need, const char *ref)
{
    decision_t d;

    authz_check(p, user, repo, need, ref, &d);
    checks++;
    if (!d.allowed) {
        failures++;
        printf("not ok %d: expected %s %s %s %s to be allowed, got: %s\n", failures,
               user, repo, authz_level_name(need), ref != NULL ? ref : "(no ref)", d.why);
    }
}

static void expect_deny(const policy_t *p, const char *user, const char *repo,
                        level_t need, const char *ref, const char *needle)
{
    decision_t d;

    authz_check(p, user, repo, need, ref, &d);
    checks++;
    if (d.allowed) {
        failures++;
        printf("not ok %d: expected %s %s %s %s to be denied\n", failures, user, repo,
               authz_level_name(need), ref != NULL ? ref : "(no ref)");
    } else if (needle != NULL && strstr(d.why, needle) == NULL) {
        failures++;
        printf("not ok %d: denial said \"%s\", expected it to mention \"%s\"\n",
               failures, d.why, needle);
    }
}

/* ------------------------------------------------------------------ tests */

static void test_glob(void)
{
    CHECK(glob_match("*", ""));
    CHECK(glob_match("*", "anything/at/all"));
    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/tags/v1"));
    CHECK(glob_match("refs/heads/feature/*", "refs/heads/feature/login"));
    CHECK(!glob_match("refs/heads/feature/*", "refs/heads/featurey"));
    CHECK(glob_match("refs/tags/v?", "refs/tags/v1"));
    CHECK(!glob_match("refs/tags/v?", "refs/tags/v12"));
    CHECK(glob_match("refs/heads/[ab]*", "refs/heads/beta"));
    CHECK(glob_match("refs/heads/[ab]*", "refs/heads/alpha"));
    CHECK(!glob_match("refs/heads/[ab]*", "refs/heads/delta"));
    CHECK(glob_match("refs/heads/[!ab]*", "refs/heads/delta"));
    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("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/*/x", "refs/a/b/x"));
    CHECK(glob_match("**", "x"));                             /* redundant stars */
    CHECK(!glob_match("refs/heads/*", ""));
}

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"));
}

static void test_parse(void)
{
    policy_t p;
    int rc;

    rc = load_text(&p,
        "# a comment\n"
        "\n"
        "   \n"
        "alice web admin                 # trailing comment\n"
        "bob   web write refs/heads/feature/* refs/heads/dev\n"
        "@all  team write main\n"
        "set protected-refs main refs/tags/*\n");
    CHECK_INT(rc, 0);
    CHECK_INT(p.errors, 0);
    CHECK_INT(p.nrules, 3);
    CHECK_STR(p.rules[0].user, "alice");
    CHECK_STR(p.rules[0].repo, "web");
    CHECK_INT(p.rules[0].level, LV_ADMIN);
    CHECK_INT(p.rules[0].nrefs, 0);
    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.protected_global, "refs/heads/main refs/tags/*");
    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. */
    {
        int keep = dup(2);
        int devnull = open("/dev/null", O_WRONLY);

        if (devnull >= 0) {
            dup2(devnull, 2);
            close(devnull);
        }

            rc = load_text(&p, "alice web everything\n");
        CHECK_INT(rc, -1);
        CHECK_INT(p.errors, 1);
        policy_free(&p);

        rc = load_text(&p, "alice web/extra write\n");
        CHECK_INT(rc, -1);
        policy_free(&p);

        rc = load_text(&p, "alice web write !refs/heads/main\n");
        CHECK_INT(rc, -1);
        policy_free(&p);

        rc = load_text(&p, "alice web\n");
        CHECK_INT(rc, -1);
        policy_free(&p);

        rc = load_text(&p, "set other-thing refs/heads/main\n");
        CHECK_INT(rc, -1);
        policy_free(&p);

        rc = load_text(&p, "set protected-refs\n");
        CHECK_INT(rc, -1);
        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 */
        policy_free(&p);

        fflush(stderr);
        dup2(keep, 2);
        close(keep);
    }

    /* The default protected list, and the two ways to replace it. */
    rc = load_text(&p, "alice * admin\n");
    CHECK_INT(rc, 0);
    CHECK_STR(authz_protected_for(&p, "web"), "refs/heads/main");
    policy_free(&p);

    rc = load_text(&p,
        "set protected-refs refs/heads/main refs/heads/stable\n"
        "set protected-refs.web refs/heads/release\n"
        "alice * admin\n");
    CHECK_INT(rc, 0);
    CHECK_STR(authz_protected_for(&p, "web"), "refs/heads/release");
    CHECK_STR(authz_protected_for(&p, "other"), "refs/heads/main refs/heads/stable");
    policy_free(&p);
}

static void test_known_users(void)
{
    policy_t p;
    int rc;

    rc = load_text(&p,
        "alice web admin\n"
        "bob   web write\n"
        "@all  web write refs/heads/*\n");
    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, ""));
    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 */
    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, "bob"));
    policy_free(&p);
}

static void test_need_for(void)
{
    policy_t p;
    char raised[64];
    int rc;

    rc = load_text(&p,
        "set protected-refs refs/heads/main refs/tags/*\n"
        "alice * admin\n");
    CHECK_INT(rc, 0);
    CHECK_INT(authz_need_for(&p, "web", "refs/heads/dev", LV_WRITE, raised,
                             sizeof(raised)), LV_WRITE);
    CHECK_STR(raised, "");
    CHECK_INT(authz_need_for(&p, "web", "refs/heads/main", LV_WRITE, raised,
                             sizeof(raised)), LV_FORCE);
    CHECK_STR(raised, "protected");
    CHECK_INT(authz_need_for(&p, "web", "refs/heads/main", LV_FORCE, raised,
                             sizeof(raised)), LV_ADMIN);
    CHECK_INT(authz_need_for(&p, "web", "refs/heads/main", LV_ADMIN, raised,
                             sizeof(raised)), LV_ADMIN);
    CHECK_STR(raised, "");                       /* admin is already the top */
    CHECK_INT(authz_need_for(&p, "web", "refs/tags/v1", LV_WRITE, raised,
                             sizeof(raised)), LV_FORCE);
    CHECK_INT(authz_need_for(&p, "web", "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(&p, "web", "refs/pull/1/head", LV_FORCE, raised,
                             sizeof(raised)), LV_ADMIN);
    CHECK_INT(authz_need_for(&p, "web", "refs/notes/x", LV_ADMIN, raised,
                             sizeof(raised)), LV_ADMIN);
    policy_free(&p);
}

static void test_check(void)
{
    policy_t p;
    int rc;

    rc = load_text(&p,
        "set protected-refs refs/heads/main refs/tags/*\n"
        "alice * admin\n"
        "@all * write refs/heads/*\n"
        "bob   team write refs/heads/feature/*\n"
        "carol team force refs/heads/feature/*\n"
        "dave  team admin\n"
        "erin  secrets admin\n");
    CHECK_INT(rc, 0);

    /* 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 */
    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. */
    expect_allow(&p, "carol", "web", LV_WRITE, "refs/heads/any");
    expect_allow(&p, "erin", "web", LV_WRITE, "refs/heads/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");

    /* protected refs raise the cost, and say so */
    expect_deny(&p, "bob", "team", LV_WRITE, "refs/heads/main", "raised from write");
    expect_deny(&p, "carol", "team", LV_FORCE, "refs/heads/main", "raised from force");
    /* the raise applies to the level the action asked for, not to the best
     * level the user happens to hold somewhere else */
    expect_deny(&p, "carol", "team", LV_WRITE, "refs/heads/main", "needs force");
    expect_allow(&p, "dave", "team", LV_WRITE, "refs/heads/main");

    /* 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 */
    expect_deny(&p, "bob", "team", LV_WRITE, "main", "protected");
    expect_deny(&p, "bob", "team", LV_WRITE, "heads/main", "protected");
    expect_deny(&p, "bob", "team", LV_WRITE, "refs/heads/main", "protected");

    /* 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 */
    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_deny(&p, "nobody", "team", LV_WRITE, NULL, "no write");

    /* what a denial names: the level held, and the level needed */
    {
        decision_t d;

        authz_check(&p, "bob", "team", LV_ADMIN, "refs/heads/feature/x", &d);
        CHECK(!d.allowed);
        CHECK_INT(d.need, LV_ADMIN);
        CHECK(strstr(d.why, "bob has write") != NULL);
        CHECK(strstr(d.why, "needs admin") != NULL);

        authz_check(&p, "nobody", "team", LV_WRITE, "refs/heads/dev", &d);
        CHECK(!d.allowed);
        CHECK(strstr(d.why, "nobody has no rule for team") != NULL);
    }
    policy_free(&p);
}

static void test_scope_edges(void)
{
    policy_t p;
    int rc;

    /* a rule with no refs is the whole repository, protected refs included */
    rc = load_text(&p, "bob team write\n");
    CHECK_INT(rc, 0);
    expect_allow(&p, "bob", "team", LV_WRITE, "refs/heads/anything");
    expect_deny(&p, "bob", "team", LV_WRITE, "refs/heads/main", "protected");
    /* write on everything still is not force: the raise asks for the next step
     * up, and bob never got it */
    expect_deny(&p, "bob", "team", LV_FORCE, "refs/heads/main", "needs admin");
    policy_free(&p);

    /* 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_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 */
    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. */
    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",
                "nothing at all on refs/heads/other");
    policy_free(&p);

    /* per-repository protection replaces the global list, it does not add to it */
    rc = load_text(&p,
        "set protected-refs refs/heads/main\n"
        "set protected-refs.web refs/heads/release\n"
        "bob web write refs/heads/*\n");
    CHECK_INT(rc, 0);
    expect_allow(&p, "bob", "web", LV_WRITE, "refs/heads/main");
    expect_deny(&p, "bob", "web", LV_WRITE, "refs/heads/release", "protected");
    expect_deny(&p, "bob", "api", LV_WRITE, "refs/heads/release", "no rule");
    policy_free(&p);

    /* 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"));
    CHECK(authz_repo_reachable(&p, "team.git"));
    CHECK(!authz_repo_reachable(&p, "other"));
    policy_free(&p);

    rc = load_text(&p, "bob * write\n");
    CHECK_INT(rc, 0);
    CHECK(authz_repo_reachable(&p, "anything"));
    policy_free(&p);
}

int main(void)
{
    const char *dir = getenv("UNIT_TMPDIR");

    snprintf(tmproot, sizeof(tmproot), "%s", dir != NULL ? dir : "tests/tmp");

    test_glob();
    test_normalisation();
    test_parse();
    test_known_users();
    test_need_for();
    test_check();
    test_scope_edges();

    printf("unit: %d checks, %d failure(s)\n", checks, failures);
    if (failures != 0)
        note("these are the semantics; the behavioural suite assumes them");
    return failures != 0;
}