From 307b2e5307002070ec33e3efabbc26775b3a8973 Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Fri, 16 Sep 2016 16:53:25 -0700 Subject: [PATCH] Reject domains with only one label --- certbot-nginx/certbot_nginx/tests/configurator_test.py | 4 ++-- certbot/tests/util_test.py | 3 +++ certbot/util.py | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/certbot-nginx/certbot_nginx/tests/configurator_test.py b/certbot-nginx/certbot_nginx/tests/configurator_test.py index 84f5e2e3b..d3bf52a2e 100644 --- a/certbot-nginx/certbot_nginx/tests/configurator_test.py +++ b/certbot-nginx/certbot_nginx/tests/configurator_test.py @@ -66,8 +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( - ["somename", "another.alias", "alias", "localhost", - "155.225.50.69.nephoscale.net", "www.example.org", "myhost"])) + ["155.225.50.69.nephoscale.net", + "www.example.org", "another.alias"])) def test_supported_enhancements(self): self.assertEqual(['redirect'], self.config.supported_enhancements()) diff --git a/certbot/tests/util_test.py b/certbot/tests/util_test.py index 47d764ed5..6f06c8306 100644 --- a/certbot/tests/util_test.py +++ b/certbot/tests/util_test.py @@ -351,6 +351,9 @@ class EnforceLeValidity(unittest.TestCase): self.assertRaises( errors.ConfigurationError, self._call, u"a-.example.com") + def test_one_label(self): + self.assertRaises(errors.ConfigurationError, self._call, u"com") + def test_valid_domain(self): self.assertEqual(self._call(u"example.com"), u"example.com") diff --git a/certbot/util.py b/certbot/util.py index 0b1431d98..5cb4b4cad 100644 --- a/certbot/util.py +++ b/certbot/util.py @@ -406,7 +406,12 @@ def enforce_le_validity(domain): raise errors.ConfigurationError( "{0} contains an invalid character. " "Valid characters are A-Z, a-z, 0-9, ., and -.".format(domain)) - for label in domain.split("."): + + labels = domain.split(".") + if len(labels) < 2: + raise errors.ConfigurationError( + "{0} needs at least two labels".format(domain)) + for label in labels: if label.startswith("-"): raise errors.ConfigurationError( 'label "{0}" in domain "{1}" cannot start with "-"'.format(