annotate src/anvil/test-penalty.c @ 22715:20415dd0b85a

dsync: Add per-mailbox sync lock that is always used. Both importing and exporting gets the lock before they even sync the mailbox. The lock is kept until the import/export finishes. This guarantees that no matter how dsync is run, two dsyncs can't be working on the same mailbox at the same time. This lock is in addition to the optional per-user lock enabled by the -l parameter. If the -l parameter is used, the same lock timeout is used for the per-mailbox lock. Otherwise 30s timeout is used. This should help to avoid email duplication when replication is enabled for public namespaces, and maybe in some other rare situations as well.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 28 Dec 2017 14:10:23 +0200
parents cb108f786fb4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
fb0666d3b067 Compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents: 10822
diff changeset
12 time_t t;
fb0666d3b067 Compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents: 10822
diff changeset
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
fb0666d3b067 Compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents: 10822
diff changeset
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
fb0666d3b067 Compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents: 10822
diff changeset
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
fb0666d3b067 Compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents: 10822
diff changeset
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
fb0666d3b067 Compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents: 10822
diff changeset
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 }