From eaedd09199cdbaaa14130b2cd4d6c212069d8880 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sun, 27 Sep 2015 22:47:12 +0200 Subject: [PATCH] all travis binaries now build, testrunner passes too (and found some real bugs! yay unit tests!) --- pdns/calidns.cc | 2 +- pdns/dnstcpbench.cc | 2 +- pdns/notify.cc | 2 +- pdns/nsec3dig.cc | 12 ++++++------ pdns/packetcache.hh | 2 +- pdns/saxfr.cc | 16 ++++++++-------- pdns/sdig.cc | 2 +- pdns/test-bindparser_cc.cc | 2 +- pdns/test-distributor_hh.cc | 2 +- pdns/test-dnsname_cc.cc | 23 ++++++++++++++--------- pdns/test-dnsrecords_cc.cc | 18 +++++++++--------- pdns/test-packetcache_cc.cc | 20 ++++++++++---------- pdns/test-zoneparser_tng_cc.cc | 2 +- pdns/toysdig.cc | 2 +- pdns/tsig-tests.cc | 4 ++-- 15 files changed, 58 insertions(+), 53 deletions(-) diff --git a/pdns/calidns.cc b/pdns/calidns.cc index 25b10860c..47999d4e5 100644 --- a/pdns/calidns.cc +++ b/pdns/calidns.cc @@ -146,7 +146,7 @@ try vector packet; boost::trim(line); auto p = splitField(line, ' '); - DNSPacketWriter pw(packet, p.first, DNSRecordContent::TypeToNumber(p.second)); + DNSPacketWriter pw(packet, DNSName(p.first), DNSRecordContent::TypeToNumber(p.second)); packets.push_back(packet); } cout<<"Generated "< outpacket; - DNSPacketWriter pw(outpacket, argv[2], QType::SOA, 1, Opcode::Notify); + DNSPacketWriter pw(outpacket, DNSName(argv[2]), QType::SOA, 1, Opcode::Notify); pw.getHeader()->id = random(); diff --git a/pdns/nsec3dig.cc b/pdns/nsec3dig.cc index 2f141a0ce..ae0657619 100644 --- a/pdns/nsec3dig.cc +++ b/pdns/nsec3dig.cc @@ -77,7 +77,7 @@ try } vector packet; - string qname=argv[3]; + DNSName qname(argv[3]); DNSPacketWriter pw(packet, qname, DNSRecordContent::TypeToNumber(argv[4])); if(recurse) @@ -118,7 +118,7 @@ try delete[] creply; MOADNSParser mdp(reply); - cout<<"Reply to question for qname='"<first.d_type == QType::CNAME) { - namesseen.insert(stripDot(i->first.d_content->getZoneRepresentation())); + namesseen.insert(DNSName(i->first.d_content->getZoneRepresentation())); } cout<first.d_place-1<<"\t"<first.d_label.toString()<<"\tIN\t"<first.d_type); @@ -173,7 +173,7 @@ try cout<<"== nsec3 prove/deny report follows =="< proven; set denied; - namesseen.insert(stripDot(qname)); + namesseen.insert(qname); for(const auto &n: namesseen) { DNSName shorter(n); @@ -184,10 +184,10 @@ try for(const auto &n: namestocheck) { proveOrDeny(nsec3s, n, nsec3salt, nsec3iters, proven, denied); - proveOrDeny(nsec3s, "*."+n, nsec3salt, nsec3iters, proven, denied); + proveOrDeny(nsec3s, DNSName("*")+n, nsec3salt, nsec3iters, proven, denied); } - if(names.count(qname+".")) + if(names.count(qname)) { cout<<"== qname found in names, investigating NSEC3s in case it's a wildcard"< getCounts(); private: diff --git a/pdns/saxfr.cc b/pdns/saxfr.cc index c426098db..a5bd34796 100644 --- a/pdns/saxfr.cc +++ b/pdns/saxfr.cc @@ -53,7 +53,7 @@ try bool gss=false; bool tsig=false; TSIGHashEnum tsig_algo; - string tsig_key; + DNSName tsig_key; string tsig_secret; string tsigprevious; string remote_principal; @@ -84,12 +84,12 @@ try cerr<<"Invalid syntax for tsig"<id = dns_random(0xffff); @@ -295,7 +295,7 @@ try DNSName shorter(i->first.d_label); do { labels.insert(shorter); - if (pdns_iequals(shorter, argv[3])) + if (shorter == DNSName(argv[3])) break; }while(shorter.chopOff()); @@ -317,7 +317,7 @@ try DNSName label /* FIXME400 rename */=record.first; if (isNSEC3 && unhash) { - auto i = hashes.find(label.makeRelative(argv[3]).toStringNoDot()); + auto i = hashes.find(label.makeRelative(DNSName(argv[3])).toStringNoDot()); if (i != hashes.end()) label=i->second; } diff --git a/pdns/sdig.cc b/pdns/sdig.cc index f0ed8de47..41187feca 100644 --- a/pdns/sdig.cc +++ b/pdns/sdig.cc @@ -44,7 +44,7 @@ try vector packet; - DNSPacketWriter pw(packet, argv[3], DNSRecordContent::TypeToNumber(argv[4])); + DNSPacketWriter pw(packet, DNSName(argv[3]), DNSRecordContent::TypeToNumber(argv[4])); if(dnssec || getenv("SDIGBUFSIZE")) { diff --git a/pdns/test-bindparser_cc.cc b/pdns/test-bindparser_cc.cc index e0402824a..149ce0c91 100644 --- a/pdns/test-bindparser_cc.cc +++ b/pdns/test-bindparser_cc.cc @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(test_parser) { BOOST_CHECK_EQUAL(domains.size(), 11); #define checkzone(i, dname, fname, ztype, nmasters) { \ - BOOST_CHECK(domains[i].name == #dname); \ + BOOST_CHECK(domains[i].name == DNSName(#dname)); \ BOOST_CHECK_EQUAL(domains[i].filename, fname); \ BOOST_CHECK_EQUAL(domains[i].type, #ztype); \ BOOST_CHECK_EQUAL(domains[i].masters.size(), nmasters); \ diff --git a/pdns/test-distributor_hh.cc b/pdns/test-distributor_hh.cc index 0760be026..a1cd677bc 100644 --- a/pdns/test-distributor_hh.cc +++ b/pdns/test-distributor_hh.cc @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(test_distributor_dies) { for(int n=0; n < 100; ++n) { auto q = new Question(); q->d_dt.set(); - q->qdomain=std::to_string(n); + q->qdomain=DNSName(std::to_string(n)); d->question(q, report2); } diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index 54dd36902..5c78943e4 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -212,10 +212,10 @@ BOOST_AUTO_TEST_CASE(test_Append) { BOOST_AUTO_TEST_CASE(test_QuestionHash) { vector packet; reportBasicTypes(); - DNSPacketWriter dpw1(packet, "www.ds9a.nl.", QType::AAAA); + DNSPacketWriter dpw1(packet, DNSName("www.ds9a.nl."), QType::AAAA); auto hash1=hashQuestion((char*)&packet[0], packet.size(), 0); - DNSPacketWriter dpw2(packet, "wWw.Ds9A.nL.", QType::AAAA); + DNSPacketWriter dpw2(packet, DNSName("wWw.Ds9A.nL."), QType::AAAA); auto hash2=hashQuestion((char*)&packet[0], packet.size(), 0); BOOST_CHECK_EQUAL(hash1, hash2); @@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(test_QuestionHash) { for(unsigned int n=0; n < 100000; ++n) { packet.clear(); - DNSPacketWriter dpw1(packet, std::to_string(n)+"."+std::to_string(n*2)+".", QType::AAAA); + DNSPacketWriter dpw1(packet, DNSName(std::to_string(n)+"."+std::to_string(n*2)+"."), QType::AAAA); counts[hashQuestion((char*)&packet[0], packet.size(), 0) % counts.size()]++; } @@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(test_QuestionHash) { BOOST_AUTO_TEST_CASE(test_packetParse) { vector packet; reportBasicTypes(); - DNSPacketWriter dpw(packet, "www.ds9a.nl.", QType::AAAA); + DNSPacketWriter dpw(packet, DNSName("www.ds9a.nl."), QType::AAAA); uint16_t qtype, qclass; DNSName dn((char*)&packet[0], packet.size(), 12, false, &qtype, &qclass); @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(test_packetParse) { BOOST_CHECK(qtype == QType::AAAA); BOOST_CHECK_EQUAL(qclass, 1); - dpw.startRecord("ds9a.nl.", DNSRecordContent::TypeToNumber("NS")); + dpw.startRecord(DNSName("ds9a.nl."), DNSRecordContent::TypeToNumber("NS")); NSRecordContent nrc("ns1.powerdns.com"); nrc.toPacket(dpw); @@ -344,20 +344,25 @@ BOOST_AUTO_TEST_CASE(test_compare_canonical) { BOOST_CHECK(lower.canonCompare(higher)); - vector vec({"bert.com.", "alpha.nl.", "articles.xxx.", + vector vec; + for(const std::string& a : {"bert.com.", "alpha.nl.", "articles.xxx.", "Aleph1.powerdns.com.", "ZOMG.powerdns.com.", "aaa.XXX.", "yyy.XXX.", - "test.powerdns.com."}); + "test.powerdns.com."}) { + vec.push_back(DNSName(a)); + } sort(vec.begin(), vec.end(), CanonDNSNameCompare()); // for(const auto& v : vec) // cerr<<'"'< right({"bert.com.", "Aleph1.powerdns.com.", + vector right; + for(const auto& a: {"bert.com.", "Aleph1.powerdns.com.", "test.powerdns.com.", "ZOMG.powerdns.com.", "alpha.nl.", "aaa.XXX.", "articles.xxx.", - "yyy.XXX."}); + "yyy.XXX."}) + right.push_back(DNSName(a)); BOOST_CHECK(vec==right); } diff --git a/pdns/test-dnsrecords_cc.cc b/pdns/test-dnsrecords_cc.cc index db6dc4744..697dd2495 100644 --- a/pdns/test-dnsrecords_cc.cc +++ b/pdns/test-dnsrecords_cc.cc @@ -197,13 +197,13 @@ BOOST_AUTO_TEST_CASE(test_record_types) { default: REC_CHECK_EQUAL(rec->getZoneRepresentation(), val.get<2>()); } - recData = rec->serialize("rec.test"); + recData = rec->serialize(DNSName("rec.test")); } else { - std::shared_ptr rec3 = DNSRecordContent::unserialize("rec.test",q.getCode(),(val.get<3>())); + std::shared_ptr rec3 = DNSRecordContent::unserialize(DNSName("rec.test"),q.getCode(),(val.get<3>())); // TSIG special, only works the other way - recData = rec3->serialize("rec.test"); + recData = rec3->serialize(DNSName("rec.test")); } - std::shared_ptr rec2 = DNSRecordContent::unserialize("rec.test",q.getCode(),recData); + std::shared_ptr rec2 = DNSRecordContent::unserialize(DNSName("rec.test"),q.getCode(),recData); BOOST_CHECK_MESSAGE(rec2 != NULL, "unserialize(rec.test, " << q.getCode() << ", recData) returned NULL"); if (rec2 == NULL) continue; // now verify the zone representation (here it can be different!) @@ -260,14 +260,14 @@ BOOST_AUTO_TEST_CASE(test_record_types_bad_values) { BOOST_TEST_MESSAGE("Checking bad value for record type " << q.getName() << " test #" << n); vector packet; - DNSPacketWriter pw(packet, "unit.test", q.getCode()); + DNSPacketWriter pw(packet, DNSName("unit.test"), q.getCode()); if (val.get<2>()) { bool success=true; - BOOST_WARN_EXCEPTION( { boost::scoped_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord("unit.test", q.getCode()); drc->toPacket(pw); success=false; }, std::runtime_error, test_dnsrecords_cc_predicate ); + BOOST_WARN_EXCEPTION( { boost::scoped_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); success=false; }, std::runtime_error, test_dnsrecords_cc_predicate ); if (success==false) REC_FAIL_XSUCCESS2(q.getName() << " test #" << n << " has unexpectedly passed"); // a bad record was detected when it was supposed not to be detected } else { - BOOST_CHECK_EXCEPTION( { boost::scoped_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord("unit.test", q.getCode()); drc->toPacket(pw); }, std::runtime_error, test_dnsrecords_cc_predicate ); + BOOST_CHECK_EXCEPTION( { boost::scoped_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); }, std::runtime_error, test_dnsrecords_cc_predicate ); } }; } @@ -296,8 +296,8 @@ BOOST_AUTO_TEST_CASE(test_opt_record_out) { vector pak; vector > opts; - DNSPacketWriter pw(pak, "www.powerdns.com", QType::A); - pw.startRecord("www.powerdns.com", QType::A, 16, 1, DNSPacketWriter::ANSWER); + DNSPacketWriter pw(pak, DNSName("www.powerdns.com"), QType::A); + pw.startRecord(DNSName("www.powerdns.com"), QType::A, 16, 1, DNSPacketWriter::ANSWER); pw.xfrIP(htonl(0x7f000001)); opts.push_back(pair(3, "powerdns")); pw.addOpt(1280, 0, 0, opts); diff --git a/pdns/test-packetcache_cc.cc b/pdns/test-packetcache_cc.cc index 19052c1de..5ff82ef1c 100644 --- a/pdns/test-packetcache_cc.cc +++ b/pdns/test-packetcache_cc.cc @@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) { BOOST_CHECK_EQUAL(PC.size(), 0); - PC.insert("hello", QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); + PC.insert(DNSName("hello"), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); BOOST_CHECK_EQUAL(PC.size(), 1); PC.purge(); BOOST_CHECK_EQUAL(PC.size(), 0); @@ -39,14 +39,14 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) { int counter=0; try { for(counter = 0; counter < 100000; ++counter) { - PC.insert("hello "+boost::lexical_cast(counter), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); + PC.insert(DNSName("hello ")+DNSName(boost::lexical_cast(counter)), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); } BOOST_CHECK_EQUAL(PC.size(), counter); int delcounter=0; for(delcounter=0; delcounter < counter/100; ++delcounter) { - PC.purge("hello "+boost::lexical_cast(delcounter)); + PC.purge((DNSName("hello ")+DNSName(boost::lexical_cast(delcounter))).toString()); } BOOST_CHECK_EQUAL(PC.size(), counter-delcounter); @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) { string entry; int expected=counter-delcounter; for(; delcounter < counter; ++delcounter) { - if(PC.getEntry("hello "+boost::lexical_cast(delcounter), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) { + if(PC.getEntry(DNSName("hello ")+DNSName(boost::lexical_cast(delcounter)), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) { matches++; } } @@ -76,7 +76,7 @@ try { unsigned int offset=(unsigned int)(unsigned long)a; for(unsigned int counter=0; counter < 100000; ++counter) - g_PC->insert("hello "+boost::lexical_cast(counter+offset), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); + g_PC->insert(DNSName("hello ")+DNSName(boost::lexical_cast(counter+offset)), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); return 0; } catch(PDNSException& e) { @@ -92,7 +92,7 @@ try unsigned int offset=(unsigned int)(unsigned long)a; string entry; for(unsigned int counter=0; counter < 100000; ++counter) - if(!g_PC->getEntry("hello "+boost::lexical_cast(counter+offset), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) { + if(!g_PC->getEntry(DNSName("hello ")+DNSName(boost::lexical_cast(counter+offset)), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) { g_missing++; } return 0; @@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheClean) { PacketCache PC; for(unsigned int counter = 0; counter < 1000000; ++counter) { - PC.insert("hello "+boost::lexical_cast(counter), QType(QType::A), PacketCache::QUERYCACHE, "something", 1, 1); + PC.insert(DNSName("hello ")+DNSName(boost::lexical_cast(counter)), QType(QType::A), PacketCache::QUERYCACHE, "something", 1, 1); } sleep(1); @@ -189,13 +189,13 @@ BOOST_AUTO_TEST_CASE(test_PacketCachePacket) { vector pak; vector > opts; - DNSPacketWriter pw(pak, "www.powerdns.com", QType::A); + DNSPacketWriter pw(pak, DNSName("www.powerdns.com"), QType::A); DNSPacket q, r, r2; q.parse((char*)&pak[0], pak.size()); pak.clear(); - DNSPacketWriter pw2(pak, "www.powerdns.com", QType::A); - pw2.startRecord("www.powerdns.com", QType::A, 16, 1, DNSPacketWriter::ANSWER); + DNSPacketWriter pw2(pak, DNSName("www.powerdns.com"), QType::A); + pw2.startRecord(DNSName("www.powerdns.com"), QType::A, 16, 1, DNSPacketWriter::ANSWER); pw2.xfrIP(htonl(0x7f000001)); pw2.commit(); diff --git a/pdns/test-zoneparser_tng_cc.cc b/pdns/test-zoneparser_tng_cc.cc index c8ff12da8..e9955e615 100644 --- a/pdns/test-zoneparser_tng_cc.cc +++ b/pdns/test-zoneparser_tng_cc.cc @@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(test_tng_record_types) { if(!p) p = "."; pathbuf << p << "/../regression-tests/zones/unit.test"; - ZoneParserTNG zp(pathbuf.str(), "unit.test"); + ZoneParserTNG zp(pathbuf.str(), DNSName("unit.test")); DNSResourceRecord rr; ifstream ifs(pathbuf.str()); diff --git a/pdns/toysdig.cc b/pdns/toysdig.cc index da63fa2f8..5db9b7036 100644 --- a/pdns/toysdig.cc +++ b/pdns/toysdig.cc @@ -32,7 +32,7 @@ try else qname=boost::lexical_cast(n)+"."+argv[3]; - DNSPacketWriter pw(packet, qname, DNSRecordContent::TypeToNumber(argv[4])); + DNSPacketWriter pw(packet, DNSName(qname), DNSRecordContent::TypeToNumber(argv[4])); pw.getHeader()->rd=1; diff --git a/pdns/tsig-tests.cc b/pdns/tsig-tests.cc index 26d2818ca..8739bb915 100644 --- a/pdns/tsig-tests.cc +++ b/pdns/tsig-tests.cc @@ -39,7 +39,7 @@ try vector packet; - DNSPacketWriter pw(packet, argv[3], DNSRecordContent::TypeToNumber(argv[4])); + DNSPacketWriter pw(packet, DNSName(argv[3]), DNSRecordContent::TypeToNumber(argv[4])); pw.getHeader()->id=htons(0x4831); @@ -49,7 +49,7 @@ try DNSName keyname("pdns-b-aa"); TSIGRecordContent trc; - trc.d_algoName="hmac-md5.sig-alg.reg.int"; + trc.d_algoName=DNSName("hmac-md5.sig-alg.reg.int"); trc.d_time=time(0); trc.d_fudge=300; trc.d_origID=ntohs(pw.getHeader()->id); -- 2.40.0