handle permission denied during cleanup

if the .well-known/acme-challenge was created before and the user has no
permissions to delete it, it failed at cleanup.
This commit is contained in:
Benjamin Neff
2016-03-16 14:52:51 +01:00
parent 8985c4684e
commit 1390c96e65
2 changed files with 17 additions and 2 deletions
+3
View File
@@ -152,5 +152,8 @@ to serve all files under specified web root ({0})."""
if exc.errno == errno.ENOTEMPTY:
logger.debug("Challenges cleaned up but %s not empty",
root_path)
elif exc.errno == errno.EACCES:
logger.debug("Challenges cleaned up but no permissions for %s",
root_path)
else:
raise
+14 -2
View File
@@ -158,7 +158,7 @@ class AuthenticatorTest(unittest.TestCase):
os.rmdir(leftover_path)
@mock.patch('os.rmdir')
def test_cleanup_oserror(self, mock_rmdir):
def test_cleanup_permission_denied(self, mock_rmdir):
self.auth.prepare()
self.auth.perform([self.achall])
@@ -166,10 +166,22 @@ class AuthenticatorTest(unittest.TestCase):
os_error.errno = errno.EACCES
mock_rmdir.side_effect = os_error
self.auth.cleanup([self.achall])
self.assertFalse(os.path.exists(self.validation_path))
self.assertTrue(os.path.exists(self.root_challenge_path))
@mock.patch('os.rmdir')
def test_cleanup_oserror(self, mock_rmdir):
self.auth.prepare()
self.auth.perform([self.achall])
os_error = OSError()
os_error.errno = errno.ENOENT
mock_rmdir.side_effect = os_error
self.assertRaises(OSError, self.auth.cleanup, [self.achall])
self.assertFalse(os.path.exists(self.validation_path))
self.assertTrue(os.path.exists(self.root_challenge_path))
if __name__ == "__main__":
unittest.main() # pragma: no cover