From a24f14d48f57957dc623593b70de2b9371a56a48 Mon Sep 17 00:00:00 2001 From: ohemorange Date: Wed, 12 Feb 2025 21:42:00 -0800 Subject: [PATCH] Be consistent with checking capitalization in rfc2136 plugin (#10188) Fixes https://github.com/certbot/certbot/issues/10177. We were using `.upper()` when validating the config but not when actually creating the object. Now we call it in both places. I updated a test to work as a regression test here. --- .../certbot_dns_rfc2136/_internal/dns_rfc2136.py | 5 +++-- .../_internal/tests/dns_rfc2136_test.py | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/certbot-dns-rfc2136/certbot_dns_rfc2136/_internal/dns_rfc2136.py b/certbot-dns-rfc2136/certbot_dns_rfc2136/_internal/dns_rfc2136.py index da59cae62..43dd27746 100644 --- a/certbot-dns-rfc2136/certbot_dns_rfc2136/_internal/dns_rfc2136.py +++ b/certbot-dns-rfc2136/certbot_dns_rfc2136/_internal/dns_rfc2136.py @@ -91,12 +91,13 @@ class Authenticator(dns_common.DNSAuthenticator): if not self.credentials: # pragma: no cover raise errors.Error("Plugin has not been prepared.") + algorithm: str = (self.credentials.conf('algorithm') or '').upper() + return _RFC2136Client(cast(str, self.credentials.conf('server')), int(cast(str, self.credentials.conf('port')) or self.PORT), cast(str, self.credentials.conf('name')), cast(str, self.credentials.conf('secret')), - self.ALGORITHMS.get(self.credentials.conf('algorithm') or '', - dns.tsig.HMAC_MD5), + self.ALGORITHMS.get(algorithm, dns.tsig.HMAC_MD5), (self.credentials.conf('sign_query') or '').upper() == "TRUE") diff --git a/certbot-dns-rfc2136/certbot_dns_rfc2136/_internal/tests/dns_rfc2136_test.py b/certbot-dns-rfc2136/certbot_dns_rfc2136/_internal/tests/dns_rfc2136_test.py index 90765c99b..d7dbe750e 100644 --- a/certbot-dns-rfc2136/certbot_dns_rfc2136/_internal/tests/dns_rfc2136_test.py +++ b/certbot-dns-rfc2136/certbot_dns_rfc2136/_internal/tests/dns_rfc2136_test.py @@ -79,12 +79,17 @@ class AuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthentic self.auth.perform([self.achall]) @test_util.patch_display_util() - def test_valid_algorithm_passes(self, unused_mock_get_utility): + @mock.patch('certbot_dns_rfc2136._internal.dns_rfc2136._RFC2136Client') + def test_valid_algorithm_passes(self, client, unused_mock_get_utility): + from certbot_dns_rfc2136._internal.dns_rfc2136 import Authenticator + config = VALID_CONFIG.copy() config["rfc2136_algorithm"] = "HMAC-sha512" dns_test_common.write(config, self.config.rfc2136_credentials) + self.auth = Authenticator(self.config, "rfc2136") self.auth.perform([self.achall]) + assert dns.tsig.HMAC_SHA512 in client.call_args.args def test_invalid_server_raises(self): config = VALID_CONFIG.copy()