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