From 429ce1dac685532e7a4d3e83063c21b16655281f Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Thu, 28 Sep 2017 13:04:28 +0200 Subject: [PATCH] Add test for lowercase-outgoing --- pdns/recursordist/test-syncres_cc.cc | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/pdns/recursordist/test-syncres_cc.cc b/pdns/recursordist/test-syncres_cc.cc index bce93a4eb..0bbf0d2b1 100644 --- a/pdns/recursordist/test-syncres_cc.cc +++ b/pdns/recursordist/test-syncres_cc.cc @@ -7434,6 +7434,68 @@ BOOST_AUTO_TEST_CASE(test_dnssec_rrsig_cache_validity) { BOOST_CHECK_EQUAL(queriesCount, 4); } +BOOST_AUTO_TEST_CASE(test_lowercase_outgoing) { + g_lowercaseOutgoing = true; + std::unique_ptr sr; + initSR(sr); + + primeHints(); + + vector sentOutQnames; + + const DNSName target("WWW.POWERDNS.COM"); + const DNSName cname("WWW.PowerDNS.org"); + + sr->setAsyncCallback([target, cname, &sentOutQnames](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) { + + sentOutQnames.push_back(domain); + + if (isRootServer(ip)) { + if (domain == target) { + setLWResult(res, 0, false, false, true); + addRecordToLW(res, "powerdns.com.", QType::NS, "pdns-public-ns1.powerdns.com.", DNSResourceRecord::AUTHORITY, 172800); + addRecordToLW(res, "pdns-public-ns1.powerdns.com.", QType::A, "192.0.2.1", DNSResourceRecord::ADDITIONAL, 3600); + return 1; + } + if (domain == cname) { + setLWResult(res, 0, false, false, true); + addRecordToLW(res, "powerdns.org.", QType::NS, "pdns-public-ns1.powerdns.org.", DNSResourceRecord::AUTHORITY, 172800); + addRecordToLW(res, "pdns-public-ns1.powerdns.org.", QType::A, "192.0.2.2", DNSResourceRecord::ADDITIONAL, 3600); + return 1; + } + } else if (ip == ComboAddress("192.0.2.1:53")) { + if (domain == target) { + setLWResult(res, 0, true, false, false); + addRecordToLW(res, domain, QType::CNAME, cname.toString()); + return 1; + } + } else if (ip == ComboAddress("192.0.2.2:53")) { + if (domain == cname) { + setLWResult(res, 0, true, false, false); + addRecordToLW(res, domain, QType::A, "127.0.0.1"); + return 1; + } + } + return 0; + }); + + vector ret; + int res = sr->beginResolve(target, QType(QType::A), QClass::IN, ret); + + BOOST_CHECK_EQUAL(res, RCode::NoError); + + BOOST_REQUIRE_EQUAL(ret.size(), 2); + BOOST_CHECK_EQUAL(ret[0].d_content->getZoneRepresentation(), cname.toString()); + + BOOST_REQUIRE_EQUAL(sentOutQnames.size(), 4); + BOOST_CHECK_EQUAL(sentOutQnames[0].toString(), target.makeLowerCase().toString()); + BOOST_CHECK_EQUAL(sentOutQnames[1].toString(), target.makeLowerCase().toString()); + BOOST_CHECK_EQUAL(sentOutQnames[2].toString(), cname.makeLowerCase().toString()); + BOOST_CHECK_EQUAL(sentOutQnames[3].toString(), cname.makeLowerCase().toString()); + + g_lowercaseOutgoing = false; +} + /* // cerr<<"asyncresolve called to ask "<