]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/test-auth-zonecache_cc.cc
rec: mention rust compiler in compiling docs
[thirdparty/pdns.git] / pdns / test-auth-zonecache_cc.cc
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
23 #ifndef BOOST_TEST_DYN_LINK
24 #define BOOST_TEST_DYN_LINK
25 #endif
26
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
35 #include "auth-zonecache.hh"
36 #include "misc.hh"
37
38 BOOST_AUTO_TEST_SUITE(test_auth_zonecache_cc)
39
40 BOOST_AUTO_TEST_CASE(test_replace)
41 {
42 AuthZoneCache cache;
43 cache.setRefreshInterval(3600);
44
45 vector<std::tuple<DNSName, int>> zone_indices{
46 {DNSName("example.org."), 1},
47 };
48 cache.setReplacePending();
49 cache.replace(zone_indices);
50
51 int zoneId = 0;
52 bool found = cache.getEntry(DNSName("example.org."), zoneId);
53 if (!found || zoneId != 1) {
54 BOOST_FAIL("zone added in replace() not found");
55 }
56 }
57
58 BOOST_AUTO_TEST_CASE(test_add_while_pending_replace)
59 {
60 AuthZoneCache cache;
61 cache.setRefreshInterval(3600);
62
63 vector<std::tuple<DNSName, int>> zone_indices{
64 {DNSName("powerdns.org."), 1}};
65 cache.setReplacePending();
66 cache.add(DNSName("example.org."), 2);
67 cache.replace(zone_indices);
68
69 int zoneId = 0;
70 bool found = cache.getEntry(DNSName("example.org."), zoneId);
71 if (!found || zoneId != 2) {
72 BOOST_FAIL("zone added while replace was pending not found");
73 }
74 }
75
76 BOOST_AUTO_TEST_CASE(test_remove_while_pending_replace)
77 {
78 AuthZoneCache cache;
79 cache.setRefreshInterval(3600);
80
81 vector<std::tuple<DNSName, int>> zone_indices{
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
94 // Add zone using .add(), but also in the .replace() data
95 BOOST_AUTO_TEST_CASE(test_add_while_pending_replace_duplicate)
96 {
97 AuthZoneCache cache;
98 cache.setRefreshInterval(3600);
99
100 vector<std::tuple<DNSName, int>> zone_indices{
101 {DNSName("powerdns.org."), 1},
102 {DNSName("example.org."), 2},
103 };
104 cache.setReplacePending();
105 cache.add(DNSName("example.org."), 3);
106 cache.replace(zone_indices);
107
108 int zoneId = 0;
109 bool found = cache.getEntry(DNSName("example.org."), zoneId);
110 if (!found || zoneId == 0) {
111 BOOST_FAIL("zone added while replace was pending not found");
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();