Line data Source code
1 : /* Copyright (c) 2019-2021, The Tor Project, Inc. */
2 : /* See LICENSE for licensing information */
3 :
4 : #include "orconfig.h"
5 :
6 : #include "core/or/or.h"
7 : #include "feature/dirauth/process_descs.h"
8 :
9 : #include "test/test.h"
10 :
11 : static void
12 1 : test_process_descs_versions(void *arg)
13 : {
14 1 : (void)arg;
15 1 : struct {
16 : const char *version;
17 : bool should_reject;
18 1 : } cases[] = {
19 : // a very old version: reject.
20 : { "Tor 0.1.2.3-alpha", true },
21 : // a non-tor program: don't reject.
22 : { "Wombat 0.1.2.3-alpha", false },
23 : // some unsupported versions: reject.
24 : { "Tor 0.2.9.4-alpha", true },
25 : { "Tor 0.2.9.5-alpha", true },
26 : { "Tor 0.2.9.100", true },
27 : { "Tor 0.3.0.0-alpha-dev", true },
28 : { "Tor 0.3.0.2-alpha", true },
29 : { "Tor 0.3.0.5", true },
30 : { "Tor 0.3.1.4", true },
31 : { "Tor 0.3.2.4", true },
32 : { "Tor 0.3.3.4", true },
33 : { "Tor 0.3.4.1-alpha", true },
34 : { "Tor 0.3.4.100", true },
35 : { "Tor 0.3.5.1-alpha", true },
36 : { "Tor 0.3.5.6-rc", true},
37 : { "Tor 0.4.0.1-alpha", true },
38 : { "Tor 0.4.0.5", true },
39 : { "Tor 0.4.1.1-alpha", true },
40 : { "Tor 0.4.1.4-rc", true },
41 : { "Tor 0.4.1.5", true },
42 : // new enough to be supported
43 : { "Tor 0.3.5.7", false },
44 : { "Tor 0.3.5.8", false },
45 : { "Tor 0.4.2.1-alpha", false },
46 : { "Tor 0.4.2.4-rc", false },
47 : { "Tor 0.4.3.0-alpha-dev", false },
48 : // Very far in the future
49 : { "Tor 100.100.1.5", false },
50 : };
51 1 : size_t n_cases = ARRAY_LENGTH(cases);
52 :
53 27 : for (unsigned i = 0; i < n_cases; ++i) {
54 26 : const char *msg = NULL;
55 26 : bool rejected = dirserv_rejects_tor_version(cases[i].version, &msg);
56 26 : tt_int_op(rejected, OP_EQ, cases[i].should_reject);
57 26 : tt_int_op(msg == NULL, OP_EQ, rejected == false);
58 : }
59 :
60 1 : done:
61 1 : ;
62 1 : }
63 :
64 : #define T(name,flags) \
65 : { #name, test_process_descs_##name, (flags), NULL, NULL }
66 :
67 : struct testcase_t process_descs_tests[] = {
68 : T(versions,0),
69 : END_OF_TESTCASES
70 : };
|