3 PowerDNS Versatile Database Driven Nameserver
4 Copyright (C) 2021 PowerDNS.COM BV
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
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.
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.
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
24 #define BOOST_TEST_DYN_LINK
25 #define BOOST_TEST_NO_MAIN
31 #include <boost/test/unit_test.hpp>
33 #include "auth-zonecache.hh"
36 BOOST_AUTO_TEST_SUITE(test_auth_zonecache_cc
)
38 BOOST_AUTO_TEST_CASE(test_replace
)
41 cache
.setRefreshInterval(3600);
43 vector
<std::tuple
<DNSName
, int>> zone_indices
{
44 {DNSName("example.org."), 1},
46 cache
.setReplacePending();
47 cache
.replace(zone_indices
);
50 bool found
= cache
.getEntry(DNSName("example.org."), zoneId
);
51 if (!found
|| zoneId
!= 1) {
52 BOOST_FAIL("zone added in replace() not found");
56 BOOST_AUTO_TEST_CASE(test_add_while_pending_replace
)
59 cache
.setRefreshInterval(3600);
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
);
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");
74 BOOST_AUTO_TEST_CASE(test_remove_while_pending_replace
)
77 cache
.setRefreshInterval(3600);
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
);
86 bool found
= cache
.getEntry(DNSName("example.org."), zoneId
);
88 BOOST_FAIL("zone removed while replace was pending is found");
92 // Add zone using .add(), but also in the .replace() data
93 BOOST_AUTO_TEST_CASE(test_add_while_pending_replace_duplicate
)
96 cache
.setRefreshInterval(3600);
98 vector
<std::tuple
<DNSName
, int>> zone_indices
{
99 {DNSName("powerdns.org."), 1},
100 {DNSName("example.org."), 2},
102 cache
.setReplacePending();
103 cache
.add(DNSName("example.org."), 3);
104 cache
.replace(zone_indices
);
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");
112 BOOST_FAIL(string("zoneId got overwritten using replace() data (zoneId=") + std::to_string(zoneId
) + ")");
116 BOOST_AUTO_TEST_SUITE_END();