1
0
mirror of https://github.com/certbot/certbot.git synced 2026-01-26 07:41:33 +03:00

Rewrite get_all_names

This commit is contained in:
Brad Warren
2017-08-24 14:59:25 -07:00
parent 90ffe2aac0
commit 967a1830e6
2 changed files with 20 additions and 20 deletions

View File

@@ -180,6 +180,15 @@ class Installer(plugins_common.Plugin):
mail_version = self.get_config_var("mail_version", default=True)
return tuple(int(i) for i in mail_version.split('.'))
def get_all_names(self):
"""Returns all names that may be authenticated.
:rtype: `set` of `str`
"""
return set(self.get_config_var(var)
for var in ('mydomain', 'myhostname', 'myorigin',))
def ensure_cf_var(self, var, ideal, also_acceptable):
"""
Ensure that existing postfix config @var is in the list of @acceptable
@@ -267,20 +276,6 @@ class Installer(plugins_common.Plugin):
with open(self.fn, "w") as f:
f.write(self.new_cf)
def get_all_names(self):
"""Returns all names that may be authenticated.
:rtype: `list` of `str`
"""
var_names = ('myhostname', 'mydomain', 'myorigin')
names_found = set()
for num, line in enumerate(self.cf):
num, found_var, found_value = parse_line((num, line))
if found_var in var_names:
names_found.add(found_value)
name_list = list(names_found)
name_list.sort()
return name_list
def deploy_cert(self, domain, _cert_path, key_path, _chain_path, fullchain_path):
"""Deploy certificate.
:param str domain: domain to deploy certificate file
@@ -398,7 +393,8 @@ class Installer(plugins_common.Plugin):
expected_prefix = name + " ="
if not output.startswith(expected_prefix):
raise errors.PluginError(
"Unexpected output from '{0}'".format(' '.join(cmd)))
"Unexpected output '{0}' from '{1}'".format(output,
' '.join(cmd)))
return output[len(expected_prefix):].strip()

View File

@@ -18,8 +18,8 @@ from certbot import errors
from certbot.tests import util as certbot_test_util
# Fake Postfix Configs
names_only_config = """myhostname = mail.fubard.org
mydomain = fubard.org
names_only_config = """mydomain = fubard.org
myhostname = mail.fubard.org
myorigin = fubard.org"""
@@ -74,11 +74,15 @@ class InstallerTest(certbot_test_util.TempDirTestCase):
installer.prepare()
self.assertEqual(installer.config_dir, expected)
def test_get_all_names(self):
sorted_names = ['fubard.org', 'mail.fubard.org']
@mock.patch("certbot_postfix.installer.util.check_output")
def test_get_all_names(self, mock_check_output):
self._write_config(names_only_config)
installer = self._create_prepared_installer()
self.assertEqual(sorted_names, installer.get_all_names())
mock_check_output.side_effect = names_only_config.splitlines()
result = installer.get_all_names()
self.assertTrue("fubard.org" in result)
self.assertTrue("mail.fubard.org" in result)
def _write_config(self, content):
config_dir = self.config.postfix_config_dir