Merge pull request #3061 from cowlicks/gh-3057

Fix FQDN checks, closes #3057 and #3056 [needs minor revision]
This commit is contained in:
bmw
2016-06-17 19:17:09 -07:00
committed by GitHub
3 changed files with 22 additions and 20 deletions
+2 -2
View File
@@ -342,11 +342,11 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods
# FQDN # FQDN
self.assertRaises(errors.ConfigurationError, self.assertRaises(errors.ConfigurationError,
self._call, self._call,
['-d', 'comma,gotwrong.tld']) ['-d', 'a' * 64])
# FQDN 2 # FQDN 2
self.assertRaises(errors.ConfigurationError, self.assertRaises(errors.ConfigurationError,
self._call, self._call,
['-d', 'illegal.character=.tld']) ['-d', (('a' * 50) + '.') * 10])
# Wildcard # Wildcard
self.assertRaises(errors.ConfigurationError, self.assertRaises(errors.ConfigurationError,
self._call, self._call,
+9 -10
View File
@@ -248,9 +248,9 @@ class ChooseNamesTest(unittest.TestCase):
def test_get_valid_domains(self): def test_get_valid_domains(self):
from certbot.display.ops import get_valid_domains from certbot.display.ops import get_valid_domains
all_valid = ["example.com", "second.example.com", all_valid = ["example.com", "second.example.com",
"also.example.com"] "also.example.com", "under_score.example.com",
all_invalid = ["xn--ls8h.tld", "*.wildcard.com", "notFQDN", "justtld"]
"uniçodé.com"] all_invalid = ["xn--ls8h.tld", "*.wildcard.com", "uniçodé.com"]
two_valid = ["example.com", "xn--ls8h.tld", "also.example.com"] two_valid = ["example.com", "xn--ls8h.tld", "also.example.com"]
self.assertEqual(get_valid_domains(all_valid), all_valid) self.assertEqual(get_valid_domains(all_valid), all_valid)
self.assertEqual(get_valid_domains(all_invalid), []) self.assertEqual(get_valid_domains(all_invalid), [])
@@ -276,19 +276,18 @@ class ChooseNamesTest(unittest.TestCase):
mock_util().input.return_value = (display_util.OK, mock_util().input.return_value = (display_util.OK,
"xn--ls8h.tld") "xn--ls8h.tld")
self.assertEqual(_choose_names_manually(), []) self.assertEqual(_choose_names_manually(), [])
# non-FQDN and no retry # Valid domains
mock_util().input.return_value = (display_util.OK,
"notFQDN")
self.assertEqual(_choose_names_manually(), [])
# Two valid domains
mock_util().input.return_value = (display_util.OK, mock_util().input.return_value = (display_util.OK,
("example.com," ("example.com,"
"under_score.example.com,"
"justtld,"
"valid.example.com")) "valid.example.com"))
self.assertEqual(_choose_names_manually(), self.assertEqual(_choose_names_manually(),
["example.com", "valid.example.com"]) ["example.com", "under_score.example.com",
"justtld", "valid.example.com"])
# Three iterations # Three iterations
mock_util().input.return_value = (display_util.OK, mock_util().input.return_value = (display_util.OK,
"notFQDN") "uniçodé.com")
yn = mock.MagicMock() yn = mock.MagicMock()
yn.side_effect = [True, True, False] yn.side_effect = [True, True, False]
mock_util().yesno = yn mock_util().yesno = yn
+11 -8
View File
@@ -423,14 +423,17 @@ def enforce_domain_sanity(domain):
# It wasn't an IP address, so that's good # It wasn't an IP address, so that's good
pass pass
# FQDN checks from # FQDN checks according to RFC 2181: domain name should be less than 255
# http://www.mkyong.com/regular-expressions/domain-name-regular-expression-example/ # octets (inclusive). And each label is 1 - 63 octets (inclusive).
# Characters used, domain parts < 63 chars, tld > 1 < 64 chars # https://tools.ietf.org/html/rfc2181#section-11
# first and last char is not "-" msg = "Requested domain {0} is not a FQDN because ".format(domain)
fqdn = re.compile("^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,63}$") labels = domain.split('.')
if not fqdn.match(domain): for l in labels:
raise errors.ConfigurationError("Requested domain {0} is not a FQDN" if not 0 < len(l) < 64:
.format(domain)) raise errors.ConfigurationError(msg + "label {0} is too long.".format(l))
if len(domain) > 255:
raise errors.ConfigurationError(msg + "it is too long.")
return domain return domain