2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2021 PowerDNS.COM BV
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
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.
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.
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
23 #ifndef BOOST_TEST_DYN_LINK
24 #define BOOST_TEST_DYN_LINK
27 #define BOOST_TEST_NO_MAIN
33 #include <boost/test/unit_test.hpp>
35 #include "auth-zonecache.hh"
38 BOOST_AUTO_TEST_SUITE(test_auth_zonecache_cc
)
40 BOOST_AUTO_TEST_CASE(test_replace
)
43 cache
.setRefreshInterval(3600);
45 vector
<std::tuple
<DNSName
, int>> zone_indices
{
46 {DNSName("example.org."), 1},
48 cache
.setReplacePending();
49 cache
.replace(zone_indices
);
52 bool found
= cache
.getEntry(DNSName("example.org."), zoneId
);
53 if (!found
|| zoneId
!= 1) {
54 BOOST_FAIL("zone added in replace() not found");
58 BOOST_AUTO_TEST_CASE(test_add_while_pending_replace
)
61 cache
.setRefreshInterval(3600);
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
);
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");
76 BOOST_AUTO_TEST_CASE(test_remove_while_pending_replace
)
79 cache
.setRefreshInterval(3600);
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
);
88 bool found
= cache
.getEntry(DNSName("example.org."), zoneId
);
90 BOOST_FAIL("zone removed while replace was pending is found");
94 // Add zone using .add(), but also in the .replace() data
95 BOOST_AUTO_TEST_CASE(test_add_while_pending_replace_duplicate
)
98 cache
.setRefreshInterval(3600);
100 vector
<std::tuple
<DNSName
, int>> zone_indices
{
101 {DNSName("powerdns.org."), 1},
102 {DNSName("example.org."), 2},
104 cache
.setReplacePending();
105 cache
.add(DNSName("example.org."), 3);
106 cache
.replace(zone_indices
);
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");
114 BOOST_FAIL(string("zoneId got overwritten using replace() data (zoneId=") + std::to_string(zoneId
) + ")");
118 BOOST_AUTO_TEST_SUITE_END();