2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #define BOOST_TEST_DYN_LINK
23 #define BOOST_TEST_NO_MAIN
28 #include <boost/test/unit_test.hpp>
29 #include <boost/assign/list_of.hpp>
31 #include <boost/tuple/tuple.hpp>
32 #include "pdns/namespaces.hh"
33 #include "pdns/dns.hh"
34 #include "pdns/dnsbackend.hh"
35 #include "pdns/dnspacket.hh"
36 #include "pdns/ueberbackend.hh"
37 #include "pdns/pdnsexception.hh"
38 #include "pdns/logger.hh"
39 #include "pdns/arguments.hh"
40 #include "pdns/json.hh"
41 #include "pdns/statbag.hh"
42 #include "pdns/packetcache.hh"
44 #include "test-remotebackend-keys.hh"
46 extern DNSBackend
*be
;
48 BOOST_AUTO_TEST_SUITE(test_remotebackend_so
)
50 BOOST_AUTO_TEST_CASE(test_method_lookup
) {
51 BOOST_TEST_MESSAGE("Testing lookup method");
53 be
->lookup(QType(QType::SOA
), DNSName("unit.test."));
55 BOOST_CHECK(be
->get(rr
)); // and this should be TRUE.
56 // then we check rr contains what we expect
57 BOOST_CHECK_EQUAL(rr
.qname
.toString(), "unit.test.");
58 BOOST_CHECK_MESSAGE(rr
.qtype
== QType::SOA
, "returned qtype was not SOA");
59 BOOST_CHECK_EQUAL(rr
.content
, "ns.unit.test. hostmaster.unit.test. 1 2 3 4 5 6");
60 BOOST_CHECK_EQUAL(rr
.ttl
, 300);
63 BOOST_AUTO_TEST_CASE(test_method_lookup_empty
) {
64 BOOST_TEST_MESSAGE("Testing lookup method with empty result");
66 be
->lookup(QType(QType::SOA
), DNSName("empty.unit.test."));
68 BOOST_CHECK(!be
->get(rr
)); // and this should be FALSE
71 BOOST_AUTO_TEST_CASE(test_method_list
) {
75 BOOST_TEST_MESSAGE("Testing list method");
76 be
->list(DNSName("unit.test."), -1);
77 while(be
->get(rr
)) record_count
++;
79 BOOST_CHECK_EQUAL(record_count
, 5); // number of records our test domain has
82 BOOST_AUTO_TEST_CASE(test_method_doesDNSSEC
) {
83 BOOST_TEST_MESSAGE("Testing doesDNSSEC method");
84 BOOST_CHECK(be
->doesDNSSEC()); // should be true
87 BOOST_AUTO_TEST_CASE(test_method_setDomainMetadata
) {
88 std::vector
<std::string
> meta
;
89 meta
.push_back("VALUE");
90 BOOST_TEST_MESSAGE("Testing setDomainMetadata method");
91 BOOST_CHECK(be
->setDomainMetadata(DNSName("unit.test."),"TEST", meta
));
94 BOOST_AUTO_TEST_CASE(test_method_getDomainMetadata
) {
95 std::vector
<std::string
> meta
;
96 BOOST_TEST_MESSAGE("Testing getDomainMetadata method");
97 be
->getDomainMetadata(DNSName("unit.test."),"TEST", meta
);
98 BOOST_CHECK_EQUAL(meta
.size(), 1);
99 // in case we got more than one value, which would be unexpected
102 BOOST_CHECK_EQUAL(meta
[0], "VALUE");
105 BOOST_AUTO_TEST_CASE(test_method_getAllDomainMetadata
) {
106 std::map
<std::string
, std::vector
<std::string
> > meta
;
107 BOOST_TEST_MESSAGE("Testing getAllDomainMetadata method");
108 be
->getAllDomainMetadata(DNSName("unit.test."), meta
);
109 BOOST_CHECK_EQUAL(meta
.size(), 1);
110 // in case we got more than one value, which would be unexpected
113 BOOST_CHECK_EQUAL(meta
["TEST"][0], "VALUE");
116 BOOST_AUTO_TEST_CASE(test_method_addDomainKey
) {
117 BOOST_TEST_MESSAGE("Testing addDomainKey method");
118 BOOST_CHECK_EQUAL(be
->addDomainKey(DNSName("unit.test."),k1
), 1);
119 BOOST_CHECK_EQUAL(be
->addDomainKey(DNSName("unit.test."),k2
), 2);
122 BOOST_AUTO_TEST_CASE(test_method_getDomainKeys
) {
123 std::vector
<DNSBackend::KeyData
> keys
;
124 BOOST_TEST_MESSAGE("Testing getDomainKeys method");
125 // we expect to get two keys
126 be
->getDomainKeys(DNSName("unit.test."),0,keys
);
127 BOOST_CHECK_EQUAL(keys
.size(), 2);
128 // in case we got more than 2 keys, which would be unexpected
130 if (keys
.size() > 1) {
131 // check that we have two keys
132 for(DNSBackend::KeyData
&kd
: keys
) {
133 BOOST_CHECK(kd
.id
> 0);
134 BOOST_CHECK(kd
.flags
== 256 || kd
.flags
== 257);
135 BOOST_CHECK(kd
.active
== true);
136 BOOST_CHECK(kd
.content
.size() > 500);
141 BOOST_AUTO_TEST_CASE(test_method_deactivateDomainKey
) {
142 BOOST_TEST_MESSAGE("Testing deactivateDomainKey method");
143 BOOST_CHECK(be
->deactivateDomainKey(DNSName("unit.test."),1));
146 BOOST_AUTO_TEST_CASE(test_method_activateDomainKey
) {
147 BOOST_TEST_MESSAGE("Testing activateDomainKey method");
148 BOOST_CHECK(be
->activateDomainKey(DNSName("unit.test."),1));
151 BOOST_AUTO_TEST_CASE(test_method_removeDomainKey
) {
152 BOOST_CHECK(be
->removeDomainKey(DNSName("unit.test."),2));
153 BOOST_CHECK(be
->removeDomainKey(DNSName("unit.test."),1));
156 BOOST_AUTO_TEST_CASE(test_method_getBeforeAndAfterNamesAbsolute
) {
158 std::string before
,after
;
159 BOOST_TEST_MESSAGE("Testing getBeforeAndAfterNamesAbsolute method");
161 be
->getBeforeAndAfterNamesAbsolute(-1, "middle.unit.test.", unhashed
, before
, after
);
162 BOOST_CHECK_EQUAL(unhashed
.toString(), "middle.");
163 BOOST_CHECK_EQUAL(before
, "begin.");
164 BOOST_CHECK_EQUAL(after
, "stop.");
167 BOOST_AUTO_TEST_CASE(test_method_setTSIGKey
) {
168 std::string algorithm
, content
;
169 BOOST_TEST_MESSAGE("Testing setTSIGKey method");
170 BOOST_CHECK_MESSAGE(be
->setTSIGKey(DNSName("unit.test."),DNSName("hmac-md5."),"kp4/24gyYsEzbuTVJRUMoqGFmN3LYgVDzJ/3oRSP7ys="), "did not return true");
173 BOOST_AUTO_TEST_CASE(test_method_getTSIGKey
) {
176 BOOST_TEST_MESSAGE("Testing getTSIGKey method");
177 be
->getTSIGKey(DNSName("unit.test."),&algorithm
,&content
);
178 BOOST_CHECK_EQUAL(algorithm
.toString(), "hmac-md5.");
179 BOOST_CHECK_EQUAL(content
, "kp4/24gyYsEzbuTVJRUMoqGFmN3LYgVDzJ/3oRSP7ys=");
182 BOOST_AUTO_TEST_CASE(test_method_deleteTSIGKey
) {
183 std::string algorithm
, content
;
184 BOOST_TEST_MESSAGE("Testing deleteTSIGKey method");
185 BOOST_CHECK_MESSAGE(be
->deleteTSIGKey(DNSName("unit.test.")), "did not return true");
188 BOOST_AUTO_TEST_CASE(test_method_getTSIGKeys
) {
189 std::vector
<struct TSIGKey
> keys
;
190 BOOST_TEST_MESSAGE("Testing getTSIGKeys method");
191 be
->getTSIGKeys(keys
);
192 BOOST_CHECK(keys
.size() > 0);
193 if (keys
.size() > 0) {
194 BOOST_CHECK_EQUAL(keys
[0].name
.toString(), "test.");
195 BOOST_CHECK_EQUAL(keys
[0].algorithm
.toString(), "NULL.");
196 BOOST_CHECK_EQUAL(keys
[0].key
, "NULL");
200 BOOST_AUTO_TEST_CASE(test_method_setNotified
) {
201 BOOST_TEST_MESSAGE("Testing setNotified method");
202 be
->setNotified(1, 2);
203 BOOST_CHECK(true); // we check this on next step
206 BOOST_AUTO_TEST_CASE(test_method_getDomainInfo
) {
208 BOOST_TEST_MESSAGE("Testing getDomainInfo method");
209 be
->getDomainInfo(DNSName("unit.test."), di
);
210 BOOST_CHECK_EQUAL(di
.zone
.toString(), "unit.test.");
211 BOOST_CHECK_EQUAL(di
.serial
, 2);
212 BOOST_CHECK_EQUAL(di
.notified_serial
, 2);
213 BOOST_CHECK_EQUAL(di
.kind
, DomainInfo::Native
);
214 BOOST_CHECK_EQUAL(di
.backend
, be
);
217 BOOST_AUTO_TEST_CASE(test_method_getAllDomains
) {
219 BOOST_TEST_MESSAGE("Testing getAllDomains method");
220 vector
<DomainInfo
> result
;
222 be
->getAllDomains(&result
, true);
225 BOOST_CHECK_EQUAL(di
.zone
.toString(), "unit.test.");
226 BOOST_CHECK_EQUAL(di
.serial
, 2);
227 BOOST_CHECK_EQUAL(di
.notified_serial
, 2);
228 BOOST_CHECK_EQUAL(di
.kind
, DomainInfo::Native
);
229 BOOST_CHECK_EQUAL(di
.backend
, be
);
232 BOOST_AUTO_TEST_CASE(test_method_isMaster
) {
233 BOOST_TEST_MESSAGE("Testing isMaster method");
234 BOOST_CHECK(be
->isMaster(DNSName("ns1.unit.test."), "10.0.0.1"));
235 BOOST_CHECK(!be
->isMaster(DNSName("ns2.unit.test."), "10.0.0.2"));
238 BOOST_AUTO_TEST_CASE(test_method_superMasterBackend
) {
239 DNSResourceRecord rr
;
240 std::vector
<DNSResourceRecord
> nsset
;
242 BOOST_TEST_MESSAGE("Testing superMasterBackend method");
244 rr
.qname
= DNSName("example.com.");
245 rr
.qtype
= QType::NS
;
246 rr
.qclass
= QClass::IN
;
248 rr
.content
= "ns1.example.com.";
250 rr
.qname
= DNSName("example.com.");
251 rr
.qtype
= QType::NS
;
252 rr
.qclass
= QClass::IN
;
254 rr
.content
= "ns2.example.com.";
257 BOOST_CHECK(be
->superMasterBackend("10.0.0.1", DNSName("example.com."), nsset
, NULL
, NULL
, &dbd
));
259 // let's see what we got
260 BOOST_CHECK_EQUAL(dbd
, be
);
263 BOOST_AUTO_TEST_CASE(test_method_createSlaveDomain
) {
264 BOOST_TEST_MESSAGE("Testing createSlaveDomain method");
265 BOOST_CHECK(be
->createSlaveDomain("10.0.0.1", DNSName("pirate.unit.test."), "", ""));
268 BOOST_AUTO_TEST_CASE(test_method_feedRecord
) {
269 DNSResourceRecord rr
;
270 BOOST_TEST_MESSAGE("Testing feedRecord method");
271 be
->startTransaction(DNSName("example.com."),2);
272 rr
.qname
= DNSName("example.com.");
273 rr
.qtype
= QType::SOA
;
274 rr
.qclass
= QClass::IN
;
276 rr
.content
= "ns1.example.com. hostmaster.example.com. 2013013441 7200 3600 1209600 300";
277 BOOST_CHECK(be
->feedRecord(rr
, NULL
));
278 rr
.qname
= DNSName("replace.example.com.");
280 rr
.qclass
= QClass::IN
;
282 rr
.content
= "127.0.0.1";
283 BOOST_CHECK(be
->feedRecord(rr
, NULL
));
284 be
->commitTransaction();
287 BOOST_AUTO_TEST_CASE(test_method_replaceRRSet
) {
288 be
->startTransaction(DNSName("example.com."),2);
289 DNSResourceRecord rr
;
290 std::vector
<DNSResourceRecord
> rrset
;
291 BOOST_TEST_MESSAGE("Testing replaceRRSet method");
292 rr
.qname
= DNSName("replace.example.com.");
294 rr
.qclass
= QClass::IN
;
296 rr
.content
= "1.1.1.1";
298 BOOST_CHECK(be
->replaceRRSet(2, DNSName("replace.example.com."), QType(QType::A
), rrset
));
299 be
->commitTransaction();
302 BOOST_AUTO_TEST_CASE(test_method_feedEnts
) {
303 BOOST_TEST_MESSAGE("Testing feedEnts method");
304 be
->startTransaction(DNSName("example.com."),2);
305 map
<DNSName
, bool> nonterm
= boost::assign::map_list_of(DNSName("_udp"), true)(DNSName("_sip._udp"), true);
306 BOOST_CHECK(be
->feedEnts(2, nonterm
));
307 be
->commitTransaction();
310 BOOST_AUTO_TEST_CASE(test_method_feedEnts3
) {
311 BOOST_TEST_MESSAGE("Testing feedEnts3 method");
312 be
->startTransaction(DNSName("example.com"),2);
313 NSEC3PARAMRecordContent ns3prc
;
314 ns3prc
.d_iterations
=1;
315 ns3prc
.d_salt
="\u00aa\u00bb\u00cc\u00dd";
316 map
<DNSName
, bool> nonterm
= boost::assign::map_list_of(DNSName("_udp"), true)(DNSName("_sip._udp"), true);
317 BOOST_CHECK(be
->feedEnts3(2, DNSName("example.com."), nonterm
, ns3prc
, 0));
318 be
->commitTransaction();
321 BOOST_AUTO_TEST_CASE(test_method_abortTransaction
) {
322 BOOST_TEST_MESSAGE("Testing abortTransaction method");
323 be
->startTransaction(DNSName("example.com."),2);
324 BOOST_CHECK(be
->abortTransaction());
327 BOOST_AUTO_TEST_CASE(test_method_calculateSOASerial
) {
331 be
->getSOA(DNSName("unit.test."),sd
);
332 BOOST_CHECK(be
->calculateSOASerial(DNSName("unit.test."),sd
,serial
));
334 BOOST_CHECK_EQUAL(serial
, 2013060300);
337 BOOST_AUTO_TEST_CASE(test_method_directBackendCmd
) {
338 BOOST_TEST_MESSAGE("Testing directBackendCmd method");
339 BOOST_CHECK_EQUAL(be
->directBackendCmd("PING 1234"), "PING 1234");
342 BOOST_AUTO_TEST_SUITE_END();