]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Fix repr() of GSS-TSIG key [Issue #657]
authorBob Halley <halley@dnspython.org>
Sat, 17 Apr 2021 13:57:31 +0000 (06:57 -0700)
committerBob Halley <halley@dnspython.org>
Sat, 17 Apr 2021 13:57:31 +0000 (06:57 -0700)
dns/tsig.py
tests/test_tsig.py

index 5c773fffa21430c1c5b49666ccf3b6f6693b67be..50b2d47ea943ce86fb0c08699433db094d42a0c7 100644 (file)
@@ -338,6 +338,9 @@ class Key:
                 self.algorithm == other.algorithm)
 
     def __repr__(self):
-        return f"<DNS key name='{self.name}', " + \
-               f"algorithm='{self.algorithm}', " + \
-               f"secret='{base64.b64encode(self.secret).decode()}'>"
+        r = f"<DNS key name='{self.name}', " + \
+            f"algorithm='{self.algorithm}'"
+        if self.algorithm != GSS_TSIG:
+            r += f", secret='{base64.b64encode(self.secret).decode()}'"
+        r += ">"
+        return r
index a016cf81d646fc8aef3ebf121c2f6c020d4f0528..4c793d535613d0248dc5ab2eb4724673f78dc2b3 100644 (file)
@@ -273,3 +273,17 @@ class TSIGTestCase(unittest.TestCase):
 
     def test_text_hmac_sha512_256(self):
         self._test_text_format(dns.tsig.HMAC_SHA512_256)
+
+    def test_non_gss_key_repr(self):
+        key = dns.tsig.Key('foo', b'0123456789abcdef' * 2,
+                           algorithm=dns.tsig.HMAC_SHA256)
+        self.assertEqual(repr(key),
+                         "<DNS key name='foo.', algorithm='hmac-sha256.', " +
+                         "secret=" +
+                         "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY='>")
+
+    def test_gss_key_repr(self):
+        key = dns.tsig.Key('foo', None,
+                           algorithm=dns.tsig.GSS_TSIG)
+        self.assertEqual(repr(key),
+                         "<DNS key name='foo.', algorithm='gss-tsig.'>")