-
Notifications
You must be signed in to change notification settings - Fork 271
/
test-username-filter.c
68 lines (61 loc) · 2.14 KB
/
test-username-filter.c
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
/* Copyright (c) 2017 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "test-common.h"
#include "auth-common.h"
#include "auth-request.h"
struct auth_penalty *auth_penalty;
time_t process_start_time;
bool worker, worker_restart_request;
void auth_module_load(const char *names ATTR_UNUSED)
{
}
void auth_refresh_proctitle(void) {
}
static void test_username_filter(void)
{
const struct {
const char *filter;
const char *input;
bool accepted;
} cases[] = {
{ "", "", TRUE },
{ "*", "", TRUE },
{ "", "testuser1", TRUE },
{ "*", "testuser1", TRUE },
{ "!*", "testuser1", FALSE },
{ "!*", "", FALSE },
{ "*@*", "", FALSE },
{ "*@*", "@", TRUE },
{ "!*@*", "@", FALSE },
{ "!*@*", "", TRUE },
{ "*@*", "testuser1", FALSE },
{ "!*@*", "testuser1", TRUE },
{ "*@*", "testuser1@testdomain", TRUE },
{ "!*@*", "testuser1@testdomain", FALSE },
{ "*@testdomain *@testdomain2", "testuser1@testdomain", TRUE },
{ "*@testdomain *@testdomain2", "testuser1@testdomain2", TRUE },
{ "*@testdomain *@testdomain2", "testuser1@testdomain3", FALSE },
{ "!testuser@testdomain *@testdomain", "testuser@testdomain", FALSE },
{ "!testuser@testdomain *@testdomain", "testuser2@testdomain", TRUE },
{ "*@testdomain !testuser@testdomain !testuser2@testdomain", "testuser@testdomain", FALSE },
{ "*@testdomain !testuser@testdomain !testuser2@testdomain", "testuser3@testdomain", TRUE },
{ "!testuser@testdomain !testuser2@testdomain", "testuser", TRUE },
{ "!testuser@testdomain !testuser2@testdomain", "testuser@testdomain", FALSE },
{ "!testuser@testdomain *@testdomain !testuser2@testdomain", "testuser3@testdomain", TRUE },
{ "!testuser@testdomain *@testdomain !testuser2@testdomain", "testuser@testdomain", FALSE },
};
test_begin("test username_filter");
for(size_t i = 0; i < N_ELEMENTS(cases); i++) {
const char *const *filter = t_strsplit_spaces(cases[i].filter, " ,");
test_assert_idx(auth_request_username_accepted(filter, cases[i].input) == cases[i].accepted, i);
}
test_end();
}
int main(void)
{
static void (*test_functions[])(void) = {
test_username_filter,
NULL
};
return test_run(test_functions);
}