From: Remi Gacogne Date: Mon, 1 May 2017 08:35:24 +0000 (+0200) Subject: rec: Add a unit test for the OOB flag on a auth zone cache hit X-Git-Tag: rec-4.1.0-alpha1~137^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f79a4e30df07d114a6b9a2132805da1475bdba86;p=thirdparty%2Fpdns.git rec: Add a unit test for the OOB flag on a auth zone cache hit --- diff --git a/pdns/recursordist/test-syncres_cc.cc b/pdns/recursordist/test-syncres_cc.cc index 812ccb32f3..435c5ee7eb 100644 --- a/pdns/recursordist/test-syncres_cc.cc +++ b/pdns/recursordist/test-syncres_cc.cc @@ -2356,6 +2356,61 @@ BOOST_AUTO_TEST_CASE(test_forward_zone_recurse_rd) { BOOST_CHECK_EQUAL(ret.size(), 1); } +BOOST_AUTO_TEST_CASE(test_auth_zone_delegation_oob) { + std::unique_ptr sr; + init(); + initSR(sr, true, false); + + primeHints(); + + size_t queriesCount = 0; + const DNSName target("test.xx."); + const ComboAddress targetAddr("127.0.0.1"); + const DNSName ns("localhost."); + const ComboAddress nsAddr("127.0.0.1"); + const DNSName authZone("test.xx"); + + SyncRes::AuthDomain ad; + DNSRecord dr; + dr.d_place = DNSResourceRecord::ANSWER; + dr.d_name = authZone; + dr.d_type = QType::NS; + dr.d_ttl = 1800; + dr.d_content = std::make_shared("localhost."); + ad.d_records.insert(dr); + + dr.d_place = DNSResourceRecord::ANSWER; + dr.d_name = authZone; + dr.d_type = QType::A; + dr.d_ttl = 1800; + dr.d_content = std::make_shared(nsAddr); + ad.d_records.insert(dr); + + (*t_sstorage->domainmap)[authZone] = ad; + + sr->setAsyncCallback([&queriesCount,nsAddr,target,targetAddr](const ComboAddress& ip, const DNSName& domain, int type, bool doTCP, bool sendRDQuery, int EDNS0Level, struct timeval* now, boost::optional& srcmask, boost::optional context, std::shared_ptr outgoingLogger, LWResult* res) { + queriesCount++; + return 0; + }); + + vector ret; + int res = sr->beginResolve(target, QType(QType::A), QClass::IN, ret); + BOOST_CHECK_EQUAL(res, 0); + BOOST_REQUIRE_EQUAL(ret.size(), 1); + BOOST_CHECK(ret[0].d_type == QType::A); + BOOST_CHECK_EQUAL(queriesCount, 0); + BOOST_CHECK(sr->wasOutOfBand()); + + /* a second time, to check that the OOB flag is set when the query cache is used */ + ret.clear(); + res = sr->beginResolve(target, QType(QType::A), QClass::IN, ret); + BOOST_CHECK_EQUAL(res, 0); + BOOST_REQUIRE_EQUAL(ret.size(), 1); + BOOST_CHECK(ret[0].d_type == QType::A); + BOOST_CHECK_EQUAL(queriesCount, 0); + BOOST_CHECK(sr->wasOutOfBand()); +} + /* // cerr<<"asyncresolve called to ask "<