Merge pull request #2190 from filipochnik/coverage

Improve test coverage in letsencrypt module
This commit is contained in:
Peter Eckersley
2016-01-15 15:09:09 -08:00
5 changed files with 32 additions and 6 deletions
+2 -2
View File
@@ -98,8 +98,8 @@ to serve all files under specified web root ({0})."""
def _path_for_achall(self, achall): def _path_for_achall(self, achall):
try: try:
path = self.full_roots[achall.domain] path = self.full_roots[achall.domain]
except IndexError: except KeyError:
raise errors.PluginError("Missing --webroot-path for domain: {1}" raise errors.PluginError("Missing --webroot-path for domain: {0}"
.format(achall.domain)) .format(achall.domain))
if not os.path.exists(path): if not os.path.exists(path):
raise errors.PluginError("Mysteriously missing path {0} for domain: {1}" raise errors.PluginError("Mysteriously missing path {0} for domain: {1}"
+12
View File
@@ -111,6 +111,18 @@ class AuthenticatorTest(unittest.TestCase):
self.assertEqual(os.stat(self.validation_path).st_gid, parent_gid) self.assertEqual(os.stat(self.validation_path).st_gid, parent_gid)
self.assertEqual(os.stat(self.validation_path).st_uid, parent_uid) self.assertEqual(os.stat(self.validation_path).st_uid, parent_uid)
def test_perform_missing_path(self):
self.auth.prepare()
missing_achall = achallenges.KeyAuthorizationAnnotatedChallenge(
challb=acme_util.HTTP01_P, domain="thing2.com", account_key=KEY)
self.assertRaises(
errors.PluginError, self.auth.perform, [missing_achall])
self.auth.full_roots[self.achall.domain] = 'null'
self.assertRaises(
errors.PluginError, self.auth.perform, [self.achall])
def test_perform_cleanup(self): def test_perform_cleanup(self):
self.auth.prepare() self.auth.prepare()
responses = self.auth.perform([self.achall]) responses = self.auth.perform([self.achall])
+5 -4
View File
@@ -407,10 +407,11 @@ class ChooseNamesTest(unittest.TestCase):
"uniçodé.com") "uniçodé.com")
self.assertEqual(_choose_names_manually(), []) self.assertEqual(_choose_names_manually(), [])
# IDN exception with previous mocks # IDN exception with previous mocks
with mock.patch("letsencrypt.display.util") as mock_sl: with mock.patch(
uerror = UnicodeEncodeError('mock', u'', "letsencrypt.display.ops.display_util.separate_list_input"
0, 1, 'mock') ) as mock_sli:
mock_sl.separate_list_input.side_effect = uerror unicode_error = UnicodeEncodeError('mock', u'', 0, 1, 'mock')
mock_sli.side_effect = unicode_error
self.assertEqual(_choose_names_manually(), []) self.assertEqual(_choose_names_manually(), [])
# Punycode and no retry # Punycode and no retry
mock_util().input.return_value = (display_util.OK, mock_util().input.return_value = (display_util.OK,
+4
View File
@@ -381,6 +381,10 @@ class RenewableCertTests(BaseRenewableCertTest):
self.assertEqual(self.test_rc.names(12), self.assertEqual(self.test_rc.names(12),
["example.com", "www.example.com"]) ["example.com", "www.example.com"])
# Trying missing cert
os.unlink(self.test_rc.cert)
self.assertRaises(errors.CertStorageError, self.test_rc.names)
@mock.patch("letsencrypt.storage.datetime") @mock.patch("letsencrypt.storage.datetime")
def test_time_interval_judgments(self, mock_datetime): def test_time_interval_judgments(self, mock_datetime):
"""Test should_autodeploy() and should_autorenew() on the basis """Test should_autodeploy() and should_autorenew() on the basis
+9
View File
@@ -385,6 +385,15 @@ class TestFullCheckpointsReverter(unittest.TestCase):
self.assertRaises( self.assertRaises(
errors.ReverterError, self.reverter.view_config_changes) errors.ReverterError, self.reverter.view_config_changes)
def test_view_config_changes_for_logging(self):
self._setup_three_checkpoints()
config_changes = self.reverter.view_config_changes(for_logging=True)
self.assertTrue("First Checkpoint" in config_changes)
self.assertTrue("Second Checkpoint" in config_changes)
self.assertTrue("Third Checkpoint" in config_changes)
def _setup_three_checkpoints(self): def _setup_three_checkpoints(self):
"""Generate some finalized checkpoints.""" """Generate some finalized checkpoints."""
# Checkpoint1 - config1 # Checkpoint1 - config1