]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: No trailing ':' after the protobuf tag key when the value is empty
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 14 Feb 2023 11:00:10 +0000 (12:00 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 14 Feb 2023 11:00:10 +0000 (12:00 +0100)
pdns/dnsdist-protobuf.cc
pdns/dnsdistdist/docs/rules-actions.rst
regression-tests.dnsdist/test_Protobuf.py

index 8bfd704f97aa42b66bfbe5dc2741c832b237c0fe..c1250ba1547eb3eb57bd478617c3f484f516c915 100644 (file)
@@ -333,7 +333,13 @@ const ProtoBufMetaKey::TypeContainer ProtoBufMetaKey::s_types = {
       return result;
     }
     for (const auto& [key, value] : *dq.ids.qTag) {
-      result.push_back(key + ":" + value);
+      if (value.empty()) {
+        /* avoids a spurious ':' when the value is empty */
+        result.push_back(key);
+      }
+      else {
+        result.push_back(key + ":" + value);
+      }
     }
     return result;
   } },
index 068c5ee1f40e68cfc8f02661d7743c0eaa60a756..8db6d1cb36cdd12ebb7acd554bd6e8e977403358 100644 (file)
@@ -1340,7 +1340,7 @@ The following actions exist.
   * ``b64-content``: the base64-encoded DNS payload of the current query
   * ``sni``: the Server Name Indication value for queries received over DoT or DoH. Empty otherwise.
   * ``tag:<TAG>``: the content of the corresponding ``<TAG>`` if any
-  * ``tags``: the list of all tags, and their values, as a "<key1>:<value1>", ..., "<keyN>:<valueN>" strings
+  * ``tags``: the list of all tags, and their values, as a "<key1>:<value1>", ..., "<keyN>:<valueN>" strings. Note that a tag with an empty value will be exported as "<key>", not "<key>:".
 
   Subsequent rules are processed after this action.
 
index b409f8d97e17db60889c1acf562b9e7f1088e83a..125788915b3651cc0574c939797b89da40e809b4 100644 (file)
@@ -418,6 +418,7 @@ class TestProtobufMetaTags(DNSDistProtobufTest):
     rl = newRemoteLogger('127.0.0.1:%d')
 
     addAction(AllRule(), SetTagAction('my-tag-key', 'my-tag-value'))
+    addAction(AllRule(), SetTagAction('my-empty-key', ''))
     addAction(AllRule(), RemoteLogAction(rl, nil, {serverID='dnsdist-server-1'}, {b64='b64-content', ['my-tag-export-name']='tag:my-tag-key'}))
     addResponseAction(AllRule(), SetTagResponseAction('my-tag-key2', 'my-tag-value2'))
     addResponseAction(AllRule(), RemoteLogResponseAction(rl, nil, false, {serverID='dnsdist-server-1'}, {['my-tag-export-name']='tags'}))
@@ -468,9 +469,11 @@ class TestProtobufMetaTags(DNSDistProtobufTest):
         self.checkProtobufResponse(msg, dnsmessage_pb2.PBDNSMessage.UDP, response)
         self.assertEqual(len(msg.meta), 1)
         self.assertEqual(msg.meta[0].key, 'my-tag-export-name')
-        self.assertEqual(len(msg.meta[0].value.stringVal), 2)
+        self.assertEqual(len(msg.meta[0].value.stringVal), 3)
         self.assertIn('my-tag-key:my-tag-value', msg.meta[0].value.stringVal)
         self.assertIn('my-tag-key2:my-tag-value2', msg.meta[0].value.stringVal)
+        # no ':' when the value is empty
+        self.assertIn('my-empty-key', msg.meta[0].value.stringVal)
 
 class TestProtobufMetaDOH(DNSDistProtobufTest):