Merge branch 'master' into configurator_tests

This commit is contained in:
James Kasten
2014-12-10 00:34:41 -08:00
3 changed files with 59 additions and 1 deletions
+4
View File
@@ -17,6 +17,10 @@ def make_or_verify_dir(directory, mode=0o755, uid=0):
:raises LetsEncryptClientError: if a directory already exists,
but has wrong permissions or owner
:raises OSError: if invalid or inaccessible file names and
paths, or other arguments that have the correct type,
but are not accepted by the operating system.
"""
try:
os.makedirs(directory, mode)
+53
View File
@@ -4,6 +4,8 @@ import shutil
import tempfile
import unittest
import mock
class MakeOrVerifyDirTest(unittest.TestCase):
"""Tests for letsencrypt.client.le_util.make_or_verify_dir.
@@ -40,6 +42,11 @@ class MakeOrVerifyDirTest(unittest.TestCase):
def test_existing_wrong_mode_fails(self):
self.assertRaises(Exception, self._call, self.path, 0o600)
def test_reraises_os_error(self):
with mock.patch.object(os, 'makedirs') as makedirs:
makedirs.side_effect = OSError()
self.assertRaises(OSError, self._call, 'bar', 12312312)
class CheckPermissionsTest(unittest.TestCase):
"""Tests for letsencrypt.client.le_util.check_permissions.
@@ -69,6 +76,49 @@ class CheckPermissionsTest(unittest.TestCase):
self.assertFalse(self._call(0o600))
class UniqueFileTest(unittest.TestCase):
"""Tests for letsencrypt.class.le_util.unique_file."""
def setUp(self):
self.root_path = tempfile.mkdtemp()
self.default_name = os.path.join(self.root_path, 'foo.txt')
def _call(self, mode=0o600):
from letsencrypt.client.le_util import unique_file
return unique_file(self.default_name, mode)
def test_returns_fd_for_writing(self):
fd, name = self._call()
fd.write('bar')
fd.close()
self.assertEqual(open(name).read(), 'bar')
def test_right_mode(self):
self.assertEqual(0o700, os.stat(self._call(0o700)[1]).st_mode & 0o777)
self.assertEqual(0o100, os.stat(self._call(0o100)[1]).st_mode & 0o777)
def test_default_not_exists(self):
self.assertEqual(self._call()[1], self.default_name)
def test_default_exists(self):
name1 = self._call()[1] # create foo.txt
name2 = self._call()[1]
name3 = self._call()[1]
self.assertNotEqual(name1, name2)
basename2 = os.path.basename(name2)
self.assertEqual(os.path.dirname(name2), self.root_path)
self.assertTrue(basename2.startswith('foo'))
self.assertTrue(basename2.endswith('.txt'))
self.assertNotEqual(name1, name3)
self.assertNotEqual(name2, name3)
basename3 = os.path.basename(name3)
self.assertEqual(os.path.dirname(name3), self.root_path)
self.assertTrue(basename3.startswith('foo'))
self.assertTrue(basename3.endswith('.txt'))
# https://en.wikipedia.org/wiki/Base64#Examples
JOSE_B64_PADDING_EXAMPLES = {
'any carnal pleasure.': ('YW55IGNhcm5hbCBwbGVhc3VyZS4', '='),
@@ -129,6 +179,9 @@ class JOSEB64DecodeTest(unittest.TestCase):
def test_non_ascii_unicode_fails(self):
self.assertRaises(ValueError, self._call, u'\u0105')
def test_type_error_no_unicode_or_str(self):
self.assertRaises(TypeError, self._call, object())
if __name__ == '__main__':
unittest.main()
+2 -1
View File
@@ -6,6 +6,7 @@ install_requires = [
'argparse',
'jsonschema',
'M2Crypto',
'mock',
'pycrypto',
'python-augeas',
'python2-pythondialog',
@@ -21,7 +22,7 @@ testing_extras = [
'mock',
'nose',
'nosexcover',
'pylint',
'pylint<1.4', # py2.6 compat, c.f #97
'tox',
]