Mercurial > dovecot > core-2.2
annotate src/anvil/test-penalty.c @ 22955:812e5c961328
fts: Indexing virtual mailbox didn't always index the last mails
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 03 May 2018 18:33:00 +0300 |
parents | cb108f786fb4 |
children |
rev | line source |
---|---|
22713
cb108f786fb4
Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21390
diff
changeset
|
1 /* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */ |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "ioloop.h" |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "penalty.h" |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "test-common.h" |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 static void test_penalty_checksum(void) |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 struct penalty *penalty; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 struct ioloop *ioloop; |
10823 | 12 time_t t; |
13 unsigned int i, j; | |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 test_begin("penalty"); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 ioloop = io_loop_create(); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 penalty = penalty_init(); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 test_assert(penalty_get(penalty, "foo", &t) == 0); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 for (i = 1; i <= 10; i++) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 ioloop_time = 12345678 + i; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 penalty_inc(penalty, "foo", i, 5+i); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 for (j = I_MIN(1, i-1); j <= i; j++) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 test_assert(penalty_get(penalty, "foo", &t) == 5+i); |
10823 | 27 test_assert(t == (time_t)(12345678 + i)); |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 test_assert(penalty_has_checksum(penalty, "foo", i)); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 test_assert(penalty_get(penalty, "foo", &t) == 5+i); |
10823 | 31 test_assert(t == (time_t)(12345678 + i)); |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 test_assert(!penalty_has_checksum(penalty, "foo", j)); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 test_assert(penalty_get(penalty, "foo2", &t) == 0); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 /* overflows checksum array */ |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 ioloop_time = 12345678 + i; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 penalty_inc(penalty, "foo", i, 5 + i); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 penalty_inc(penalty, "foo", i, 5 + i); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 penalty_inc(penalty, "foo", 0, 5 + i); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 test_assert(penalty_get(penalty, "foo", &t) == 5+i); |
10823 | 43 test_assert(t == (time_t)(12345678 + i)); |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 test_assert(!penalty_has_checksum(penalty, "foo", 1)); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 for (j = 2; j <= i; j++) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 test_assert(penalty_get(penalty, "foo", &t) == 5+i); |
10823 | 48 test_assert(t == (time_t)(12345678 + i)); |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 test_assert(penalty_has_checksum(penalty, "foo", i)); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 penalty_deinit(&penalty); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 io_loop_destroy(&ioloop); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 test_end(); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 int main(void) |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 static void (*test_functions[])(void) = { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 test_penalty_checksum, |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 NULL |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 }; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 return test_run(test_functions); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 } |