From 04ba56eda80a35c3cfa98b82e2175a1a62292a2d Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 17 Feb 2023 14:30:50 +0100 Subject: [PATCH] dnsdist: Ensure we have at least one protobuf MetaValue --- pdns/dnsdist-protobuf.cc | 8 +++++++- regression-tests.dnsdist/test_Protobuf.py | 16 ++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pdns/dnsdist-protobuf.cc b/pdns/dnsdist-protobuf.cc index c1250ba154..3eb5b82d92 100644 --- a/pdns/dnsdist-protobuf.cc +++ b/pdns/dnsdist-protobuf.cc @@ -197,7 +197,13 @@ void DNSDistProtoBufMessage::serialize(std::string& data) const m.commitResponse(); for (const auto& [key, values] : d_metaTags) { - m.setMeta(key, values, {}); + if (!values.empty()) { + m.setMeta(key, values, {}); + } + else { + /* the MetaValue field is _required_ to exist, even if we have no value */ + m.setMeta(key, {std::string()}, {}); + } } } diff --git a/regression-tests.dnsdist/test_Protobuf.py b/regression-tests.dnsdist/test_Protobuf.py index fead59012a..eee259b048 100644 --- a/regression-tests.dnsdist/test_Protobuf.py +++ b/regression-tests.dnsdist/test_Protobuf.py @@ -551,12 +551,8 @@ class TestProtobufMetaDOH(DNSDistProtobufTest): self.assertEqual(len(msg.meta), 5) tags = {} for entry in msg.meta: - if method == "sendDOHQueryWrapper": - self.assertEqual(len(entry.value.stringVal), 1) - tags[entry.key] = entry.value.stringVal[0] - else: - self.assertEqual(len(entry.value.stringVal), 0) - tags[entry.key] = None + self.assertEqual(len(entry.value.stringVal), 1) + tags[entry.key] = entry.value.stringVal[0] self.assertIn('agent', tags) if method == "sendDOHQueryWrapper": @@ -576,12 +572,8 @@ class TestProtobufMetaDOH(DNSDistProtobufTest): self.assertEqual(len(msg.meta), 5) tags = {} for entry in msg.meta: - if method == "sendDOHQueryWrapper": - self.assertEqual(len(entry.value.stringVal), 1) - tags[entry.key] = entry.value.stringVal[0] - else: - self.assertEqual(len(entry.value.stringVal), 0) - tags[entry.key] = None + self.assertEqual(len(entry.value.stringVal), 1) + tags[entry.key] = entry.value.stringVal[0] self.assertIn('agent', tags) if method == "sendDOHQueryWrapper": -- 2.47.2