diff --git a/certbot-nginx/certbot_nginx/configurator.py b/certbot-nginx/certbot_nginx/configurator.py index 444e48903..a89e276c5 100644 --- a/certbot-nginx/certbot_nginx/configurator.py +++ b/certbot-nginx/certbot_nginx/configurator.py @@ -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 diff --git a/certbot-nginx/certbot_nginx/tests/configurator_test.py b/certbot-nginx/certbot_nginx/tests/configurator_test.py index 9e0c0dda5..84f5e2e3b 100644 --- a/certbot-nginx/certbot_nginx/tests/configurator_test.py +++ b/certbot-nginx/certbot_nginx/tests/configurator_test.py @@ -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())