filter names returned by get_all_names

This commit is contained in:
Brad Warren 2016-09-16 16:47:02 -07:00
parent f2e0afc96c
commit 275e3f748e
2 changed files with 21 additions and 5 deletions

View file

@ -308,7 +308,25 @@ class NginxConfigurator(common.Plugin):
except (socket.error, socket.herror, socket.timeout):
continue
return all_names
return self._get_filtered_names(all_names)
def _get_filtered_names(self, all_names):
"""Removes names that aren't considered valid by Let's Encrypt.
:param set all_names: all names found in the Nginx configuration
:returns: all found names that are considered valid by LE
:rtype: set
"""
filtered_names = set()
for name in all_names:
try:
filtered_names.add(util.enforce_le_validity(name))
except errors.ConfigurationError as error:
logger.debug('Not suggesting name "%s"', name)
logger.debug(error)
return filtered_names
def _get_snakeoil_paths(self):
# TODO: generate only once

View file

@ -66,10 +66,8 @@ class NginxConfiguratorTest(util.NginxTest):
mock_gethostbyaddr.return_value = ('155.225.50.69.nephoscale.net', [], [])
names = self.config.get_all_names()
self.assertEqual(names, set(
["*.www.foo.com", "somename", "another.alias",
"alias", "localhost", ".example.com", r"~^(www\.)?(example|bar)\.",
"155.225.50.69.nephoscale.net", "*.www.example.com",
"example.*", "www.example.org", "myhost"]))
["somename", "another.alias", "alias", "localhost",
"155.225.50.69.nephoscale.net", "www.example.org", "myhost"]))
def test_supported_enhancements(self):
self.assertEqual(['redirect'], self.config.supported_enhancements())