]>
Commit | Line | Data |
---|---|---|
5a9bd2d8 CH |
1 | /* |
2 | PowerDNS Versatile Database Driven Nameserver | |
3 | Copyright (C) 2021 PowerDNS.COM BV | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License version 2 | |
7 | as published by the Free Software Foundation | |
8 | ||
9 | Additionally, the license of this program contains a special | |
10 | exception which allows to distribute the program in binary form when | |
11 | it is linked against OpenSSL. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
21 | */ | |
22 | ||
1c2d079d | 23 | #ifndef BOOST_TEST_DYN_LINK |
5a9bd2d8 | 24 | #define BOOST_TEST_DYN_LINK |
1c2d079d FM |
25 | #endif |
26 | ||
5a9bd2d8 CH |
27 | #define BOOST_TEST_NO_MAIN |
28 | ||
29 | #ifdef HAVE_CONFIG_H | |
30 | #include "config.h" | |
31 | #endif | |
32 | ||
33 | #include <boost/test/unit_test.hpp> | |
34 | ||
1f0fb39a | 35 | #include "auth-zonecache.hh" |
5a9bd2d8 CH |
36 | #include "misc.hh" |
37 | ||
1f0fb39a | 38 | BOOST_AUTO_TEST_SUITE(test_auth_zonecache_cc) |
5a9bd2d8 | 39 | |
68e2355f CH |
40 | BOOST_AUTO_TEST_CASE(test_replace) |
41 | { | |
1f0fb39a CH |
42 | AuthZoneCache cache; |
43 | cache.setRefreshInterval(3600); | |
5a9bd2d8 | 44 | |
905dae56 | 45 | vector<std::tuple<DNSName, int>> zone_indices{ |
5a9bd2d8 CH |
46 | {DNSName("example.org."), 1}, |
47 | }; | |
b72b74c5 | 48 | cache.setReplacePending(); |
1f0fb39a | 49 | cache.replace(zone_indices); |
5a9bd2d8 CH |
50 | |
51 | int zoneId = 0; | |
52 | bool found = cache.getEntry(DNSName("example.org."), zoneId); | |
9da243a3 | 53 | if (!found || zoneId != 1) { |
1f0fb39a | 54 | BOOST_FAIL("zone added in replace() not found"); |
5a9bd2d8 CH |
55 | } |
56 | } | |
57 | ||
68e2355f CH |
58 | BOOST_AUTO_TEST_CASE(test_add_while_pending_replace) |
59 | { | |
1f0fb39a CH |
60 | AuthZoneCache cache; |
61 | cache.setRefreshInterval(3600); | |
5a9bd2d8 | 62 | |
905dae56 | 63 | vector<std::tuple<DNSName, int>> zone_indices{ |
68e2355f | 64 | {DNSName("powerdns.org."), 1}}; |
5a9bd2d8 CH |
65 | cache.setReplacePending(); |
66 | cache.add(DNSName("example.org."), 2); | |
1f0fb39a | 67 | cache.replace(zone_indices); |
5a9bd2d8 CH |
68 | |
69 | int zoneId = 0; | |
70 | bool found = cache.getEntry(DNSName("example.org."), zoneId); | |
9da243a3 | 71 | if (!found || zoneId != 2) { |
1f0fb39a | 72 | BOOST_FAIL("zone added while replace was pending not found"); |
5a9bd2d8 CH |
73 | } |
74 | } | |
75 | ||
b72b74c5 KM |
76 | BOOST_AUTO_TEST_CASE(test_remove_while_pending_replace) |
77 | { | |
78 | AuthZoneCache cache; | |
79 | cache.setRefreshInterval(3600); | |
80 | ||
905dae56 | 81 | vector<std::tuple<DNSName, int>> zone_indices{ |
b72b74c5 KM |
82 | {DNSName("powerdns.org."), 1}}; |
83 | cache.setReplacePending(); | |
84 | cache.remove(DNSName("powerdns.org.")); | |
85 | cache.replace(zone_indices); | |
86 | ||
87 | int zoneId = 0; | |
88 | bool found = cache.getEntry(DNSName("example.org."), zoneId); | |
89 | if (found) { | |
90 | BOOST_FAIL("zone removed while replace was pending is found"); | |
91 | } | |
92 | } | |
93 | ||
1f0fb39a | 94 | // Add zone using .add(), but also in the .replace() data |
68e2355f CH |
95 | BOOST_AUTO_TEST_CASE(test_add_while_pending_replace_duplicate) |
96 | { | |
1f0fb39a CH |
97 | AuthZoneCache cache; |
98 | cache.setRefreshInterval(3600); | |
5a9bd2d8 | 99 | |
905dae56 | 100 | vector<std::tuple<DNSName, int>> zone_indices{ |
5a9bd2d8 CH |
101 | {DNSName("powerdns.org."), 1}, |
102 | {DNSName("example.org."), 2}, | |
103 | }; | |
104 | cache.setReplacePending(); | |
105 | cache.add(DNSName("example.org."), 3); | |
1f0fb39a | 106 | cache.replace(zone_indices); |
5a9bd2d8 CH |
107 | |
108 | int zoneId = 0; | |
109 | bool found = cache.getEntry(DNSName("example.org."), zoneId); | |
110 | if (!found || zoneId == 0) { | |
1f0fb39a | 111 | BOOST_FAIL("zone added while replace was pending not found"); |
5a9bd2d8 CH |
112 | } |
113 | if (zoneId != 3) { | |
114 | BOOST_FAIL(string("zoneId got overwritten using replace() data (zoneId=") + std::to_string(zoneId) + ")"); | |
115 | } | |
116 | } | |
117 | ||
118 | BOOST_AUTO_TEST_SUITE_END(); |