From: Pieter Lexis Date: Wed, 7 Jan 2026 10:22:05 +0000 (+0100) Subject: chore(dnsparser): Add some more unit tests X-Git-Tag: rec-5.4.0-beta1~7^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5f75d0270944e640ce497daded8f0f9a8a6b978;p=thirdparty%2Fpdns.git chore(dnsparser): Add some more unit tests --- diff --git a/pdns/test-dnsparser_cc.cc b/pdns/test-dnsparser_cc.cc index 47113dc110..1e6ccbc746 100644 --- a/pdns/test-dnsparser_cc.cc +++ b/pdns/test-dnsparser_cc.cc @@ -618,6 +618,52 @@ BOOST_AUTO_TEST_CASE(test_clearDNSPacketUnsafeRecordTypes) { } +BOOST_AUTO_TEST_CASE(test_xfrSvcParamKeyVals) { + // Note, "happy path" parsing is mostly done in test-rcpgenerator_cc.cc + + vector fakePacket { + 0x00, 0x01, // Key 1 (ALPN) + 0x00, 0x03, // length 3 + 0x02, // ALPN length 2 + 'h', '2' + }; + + PacketReader pr(std::string_view(reinterpret_cast(fakePacket.data()), fakePacket.size()), 0); + + std::set svcParams; + + std::set expected; + std::vector alpns{"h2"}; + expected.insert(SvcParam(SvcParam::SvcParamKey::alpn, std::move(alpns))); + + BOOST_CHECK_NO_THROW(pr.xfrSvcParamKeyVals(svcParams)); + BOOST_CHECK(svcParams == expected); +} + +BOOST_AUTO_TEST_CASE(test_xfrSvcParamKeyVals_length_wrong) { + vector fakePacket { + 0x00, 0x01, // Key 1 (ALPN) + 0x00, 0x04, // length 4 (real length is 3) + 0x02, // ALPN length 2 + 'h', '2' + }; + + PacketReader pr(std::string_view(reinterpret_cast(fakePacket.data()), fakePacket.size()), 0); + + std::set svcParams; + + BOOST_CHECK_THROW(pr.xfrSvcParamKeyVals(svcParams), std::out_of_range); + + fakePacket = { + 0x00, 0x01, // Key 1 (ALPN) + 0x00, 0x02, // length 2 (real length is 3) + 0x02, // ALPN length 2 + 'h', '2' + }; + + BOOST_CHECK_THROW(pr.xfrSvcParamKeyVals(svcParams), std::out_of_range); +} + BOOST_AUTO_TEST_CASE(test_xfrSvcParamKeyVals_alpn_length_wrong) { vector fakePacket { 0x00, 0x01, // Key 1 (ALPN)