From d1577280ad36710e6ed6fc639e42883c59d5f23e Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Tue, 24 Oct 2023 12:27:19 -0700 Subject: [PATCH] fixes #9805 (#9816) --- certbot/CHANGELOG.md | 3 +++ certbot/certbot/_internal/renewal.py | 5 ++++- certbot/certbot/_internal/tests/renewal_test.py | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/certbot/CHANGELOG.md b/certbot/CHANGELOG.md index ef02517cf..7b35d7b11 100644 --- a/certbot/CHANGELOG.md +++ b/certbot/CHANGELOG.md @@ -15,6 +15,9 @@ Certbot adheres to [Semantic Versioning](https://semver.org/). ### Fixed * Fixed a bug where arguments with contained spaces weren't being handled correctly +* Fixed a bug that caused the ACME account to not be properly restored on + renewal causing problems in setups where the user had multiple accounts with + the same ACME server. More details about these changes can be found on our GitHub repo. diff --git a/certbot/certbot/_internal/renewal.py b/certbot/certbot/_internal/renewal.py index a33dd7ee5..62e31f865 100644 --- a/certbot/certbot/_internal/renewal.py +++ b/certbot/certbot/_internal/renewal.py @@ -194,6 +194,7 @@ def restore_required_config_elements(config: configuration.NamespaceConfig, """ + updated_values = {} required_items = itertools.chain( (("pref_challs", _restore_pref_challs),), zip(BOOL_CONFIG_ITEMS, itertools.repeat(_restore_bool)), @@ -202,7 +203,9 @@ def restore_required_config_elements(config: configuration.NamespaceConfig, for item_name, restore_func in required_items: if item_name in renewalparams and not config.set_by_user(item_name): value = restore_func(item_name, renewalparams[item_name]) - setattr(config, item_name, value) + updated_values[item_name] = value + for key, value in updated_values.items(): + setattr(config, key, value) def _remove_deprecated_config_elements(renewalparams: Mapping[str, Any]) -> Dict[str, Any]: diff --git a/certbot/certbot/_internal/tests/renewal_test.py b/certbot/certbot/_internal/tests/renewal_test.py index edc9eea35..239744692 100644 --- a/certbot/certbot/_internal/tests/renewal_test.py +++ b/certbot/certbot/_internal/tests/renewal_test.py @@ -253,6 +253,18 @@ class RestoreRequiredConfigElementsTest(test_util.ConfigTestCase): self._call(self.config, {'server': constants.V1_URI}) assert self.config.server == constants.CLI_DEFAULTS['server'] + def test_related_values(self): + # certbot.configuration.NamespaceConfig.set_by_user considers some values as related to each + # other and considers both set by the user if either is. This test ensures all renewal + # parameters are restored regardless of their restoration order or relation between values. + # See https://github.com/certbot/certbot/issues/9805 for more info. + renewalparams = { + 'server': 'https://example.org', + 'account': 'somehash', + } + self._call(self.config, renewalparams) + self.assertEqual(self.config.account, renewalparams['account']) + class DescribeResultsTest(unittest.TestCase): """Tests for certbot._internal.renewal._renew_describe_results."""