mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 02:44:21 +02:00
Merge branch 'master' into configurator_tests
This commit is contained in:
@@ -17,6 +17,10 @@ def make_or_verify_dir(directory, mode=0o755, uid=0):
|
|||||||
:raises LetsEncryptClientError: if a directory already exists,
|
:raises LetsEncryptClientError: if a directory already exists,
|
||||||
but has wrong permissions or owner
|
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:
|
try:
|
||||||
os.makedirs(directory, mode)
|
os.makedirs(directory, mode)
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
|
|
||||||
class MakeOrVerifyDirTest(unittest.TestCase):
|
class MakeOrVerifyDirTest(unittest.TestCase):
|
||||||
"""Tests for letsencrypt.client.le_util.make_or_verify_dir.
|
"""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):
|
def test_existing_wrong_mode_fails(self):
|
||||||
self.assertRaises(Exception, self._call, self.path, 0o600)
|
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):
|
class CheckPermissionsTest(unittest.TestCase):
|
||||||
"""Tests for letsencrypt.client.le_util.check_permissions.
|
"""Tests for letsencrypt.client.le_util.check_permissions.
|
||||||
@@ -69,6 +76,49 @@ class CheckPermissionsTest(unittest.TestCase):
|
|||||||
self.assertFalse(self._call(0o600))
|
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
|
# https://en.wikipedia.org/wiki/Base64#Examples
|
||||||
JOSE_B64_PADDING_EXAMPLES = {
|
JOSE_B64_PADDING_EXAMPLES = {
|
||||||
'any carnal pleasure.': ('YW55IGNhcm5hbCBwbGVhc3VyZS4', '='),
|
'any carnal pleasure.': ('YW55IGNhcm5hbCBwbGVhc3VyZS4', '='),
|
||||||
@@ -129,6 +179,9 @@ class JOSEB64DecodeTest(unittest.TestCase):
|
|||||||
def test_non_ascii_unicode_fails(self):
|
def test_non_ascii_unicode_fails(self):
|
||||||
self.assertRaises(ValueError, self._call, u'\u0105')
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ install_requires = [
|
|||||||
'argparse',
|
'argparse',
|
||||||
'jsonschema',
|
'jsonschema',
|
||||||
'M2Crypto',
|
'M2Crypto',
|
||||||
|
'mock',
|
||||||
'pycrypto',
|
'pycrypto',
|
||||||
'python-augeas',
|
'python-augeas',
|
||||||
'python2-pythondialog',
|
'python2-pythondialog',
|
||||||
@@ -21,7 +22,7 @@ testing_extras = [
|
|||||||
'mock',
|
'mock',
|
||||||
'nose',
|
'nose',
|
||||||
'nosexcover',
|
'nosexcover',
|
||||||
'pylint',
|
'pylint<1.4', # py2.6 compat, c.f #97
|
||||||
'tox',
|
'tox',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user