From: Remi Gacogne Date: Tue, 17 Sep 2024 08:52:06 +0000 (+0200) Subject: dnsdist: Add unit tests for the proxy protocol TLV FFI accessor X-Git-Tag: rec-5.2.0-alpha1~55^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00bb88d7a0df28e740ccbebc202ef6fe4a982243;p=thirdparty%2Fpdns.git dnsdist: Add unit tests for the proxy protocol TLV FFI accessor --- diff --git a/pdns/dnsdistdist/test-dnsdist-lua-ffi.cc b/pdns/dnsdistdist/test-dnsdist-lua-ffi.cc index 33e8140ee2..3de6749da9 100644 --- a/pdns/dnsdistdist/test-dnsdist-lua-ffi.cc +++ b/pdns/dnsdistdist/test-dnsdist-lua-ffi.cc @@ -621,6 +621,59 @@ BOOST_AUTO_TEST_CASE(test_ProxyProtocolQuery) } } +BOOST_AUTO_TEST_CASE(test_ProxyProtocolIncoming) +{ + InternalQueryState ids; + ids.origRemote = ComboAddress("192.0.2.1:4242"); + ids.origDest = ComboAddress("192.0.2.255:53"); + ids.qtype = QType::A; + ids.qclass = QClass::IN; + ids.protocol = dnsdist::Protocol::DoUDP; + ids.qname = DNSName("www.powerdns.com."); + ids.queryRealTime.start(); + PacketBuffer query; + GenericDNSPacketWriter pwQ(query, ids.qname, QType::A, QClass::IN, 0); + pwQ.getHeader()->rd = 1; + pwQ.getHeader()->id = htons(42); + + DNSQuestion dnsQuestion(ids, query); + dnsdist_ffi_dnsquestion_t lightDQ(&dnsQuestion); + + { + /* invalid dq */ + const dnsdist_ffi_proxy_protocol_value_t* out = nullptr; + BOOST_CHECK_EQUAL(dnsdist_ffi_dnsquestion_get_proxy_protocol_values(nullptr, &out), 0U); + } + { + /* invalid pointer */ + BOOST_CHECK_EQUAL(dnsdist_ffi_dnsquestion_get_proxy_protocol_values(&lightDQ, nullptr), 0U); + } + { + /* no proxy protocol values */ + const dnsdist_ffi_proxy_protocol_value_t* out = nullptr; + BOOST_CHECK_EQUAL(dnsdist_ffi_dnsquestion_get_proxy_protocol_values(&lightDQ, &out), 0U); + } + + { + /* add some proxy protocol TLV values */ + dnsQuestion.proxyProtocolValues = std::make_unique>(); + dnsQuestion.proxyProtocolValues->emplace_back(ProxyProtocolValue{"foo", 42}); + dnsQuestion.proxyProtocolValues->emplace_back(ProxyProtocolValue{"bar", 255}); + dnsQuestion.proxyProtocolValues->emplace_back(ProxyProtocolValue{"", 0}); + const dnsdist_ffi_proxy_protocol_value_t* out = nullptr; + auto count = dnsdist_ffi_dnsquestion_get_proxy_protocol_values(&lightDQ, &out); + BOOST_REQUIRE_EQUAL(count, 3U); + // NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic): sorry, this is a C API + BOOST_CHECK_EQUAL(out[0].type, 42U); + BOOST_CHECK_EQUAL(out[0].value, "foo"); + BOOST_CHECK_EQUAL(out[1].type, 255U); + BOOST_CHECK_EQUAL(out[1].value, "bar"); + BOOST_CHECK_EQUAL(out[2].type, 0U); + BOOST_CHECK_EQUAL(out[2].value, ""); + // NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic): sorry, this is a C API + } +} + BOOST_AUTO_TEST_CASE(test_PacketOverlay) { const DNSName target("powerdns.com.");