From 787c64c5465c6b50a250b417efba365470203a35 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Tue, 12 May 2015 22:08:00 +0000 Subject: [PATCH 1/5] Fix references to letsencrypt.client --- MANIFEST.in | 3 +-- docs/api/client/proof_of_possession.rst | 5 ----- docs/api/proof_of_possession.rst | 5 +++++ letsencrypt/continuity_auth.py | 4 ++-- letsencrypt_nginx/configurator.py | 2 +- letsencrypt_nginx/dvsni.py | 4 ++-- 6 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 docs/api/client/proof_of_possession.rst create mode 100644 docs/api/proof_of_possession.rst diff --git a/MANIFEST.in b/MANIFEST.in index b628121e1..f9364d64f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,8 +3,7 @@ include CHANGES.rst include CONTRIBUTING.md include linter_plugin.py include letsencrypt/EULA - -recursive-include letsencrypt/client/tests/testdata * +recursive-include letsencrypt/tests/testdata * recursive-include acme/schemata *.json recursive-include acme/jose/testdata * diff --git a/docs/api/client/proof_of_possession.rst b/docs/api/client/proof_of_possession.rst deleted file mode 100644 index 9f1ea0793..000000000 --- a/docs/api/client/proof_of_possession.rst +++ /dev/null @@ -1,5 +0,0 @@ -:mod:`letsencrypt.client.proof_of_possession` --------------------------------------------------- - -.. automodule:: letsencrypt.client.proof_of_possession - :members: diff --git a/docs/api/proof_of_possession.rst b/docs/api/proof_of_possession.rst new file mode 100644 index 000000000..db8c6c563 --- /dev/null +++ b/docs/api/proof_of_possession.rst @@ -0,0 +1,5 @@ +:mod:`letsencrypt.proof_of_possession` +-------------------------------------- + +.. automodule:: letsencrypt.proof_of_possession + :members: diff --git a/letsencrypt/continuity_auth.py b/letsencrypt/continuity_auth.py index 8bfc0bfeb..739e33d43 100644 --- a/letsencrypt/continuity_auth.py +++ b/letsencrypt/continuity_auth.py @@ -19,7 +19,7 @@ class ContinuityAuthenticator(object): :ivar proof_of_pos: Performs "proofOfPossession" challenges. :type proof_of_pos: - :class:`letsencrypt.client.proof_of_possession.Proof_of_Possession` + :class:`letsencrypt.proof_of_possession.Proof_of_Possession` """ zope.interface.implements(interfaces.IAuthenticator) @@ -32,7 +32,7 @@ class ContinuityAuthenticator(object): :type config: :class:`letsencrypt.interfaces.IConfig` :param installer: Let's Encrypt Installer. - :type installer: :class:`letsencrypt.client.interfaces.IInstaller` + :type installer: :class:`letsencrypt.interfaces.IInstaller` """ self.rec_token = recovery_token.RecoveryToken( diff --git a/letsencrypt_nginx/configurator.py b/letsencrypt_nginx/configurator.py index ffb9bd3b2..d2deee15a 100644 --- a/letsencrypt_nginx/configurator.py +++ b/letsencrypt_nginx/configurator.py @@ -271,7 +271,7 @@ class NginxConfigurator(common.Plugin): the existing one? :param vhost: The vhost to add SSL to. - :type vhost: :class:`~letsencrypt.client.plugins.nginx.obj.VirtualHost` + :type vhost: :class:`~letsencrypt_nginx.obj.VirtualHost` """ ssl_block = [['listen', '443 ssl'], diff --git a/letsencrypt_nginx/dvsni.py b/letsencrypt_nginx/dvsni.py index 534c5a8d3..5c188099c 100644 --- a/letsencrypt_nginx/dvsni.py +++ b/letsencrypt_nginx/dvsni.py @@ -78,7 +78,7 @@ class NginxDvsni(ApacheDvsni): """Modifies Nginx config to include challenge server blocks. :param list ll_addrs: list of lists of - :class:`letsencrypt.client.plugins.apache.obj.Addr` to apply + :class:`letsencrypt_nginx.obj.Addr` to apply :raises errors.LetsEncryptMisconfigurationError: Unable to find a suitable HTTP block to include DVSNI hosts. @@ -115,7 +115,7 @@ class NginxDvsni(ApacheDvsni): """Creates a server block for a DVSNI challenge. :param achall: Annotated DVSNI challenge. - :type achall: :class:`letsencrypt.client.achallenges.DVSNI` + :type achall: :class:`letsencrypt.achallenges.DVSNI` :param list addrs: addresses of challenged domain :class:`list` of type :class:`~nginx.obj.Addr` From a2767d30a1af3d262501c1eed99236fbea1c693b Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Wed, 13 May 2015 07:21:21 +0000 Subject: [PATCH 2/5] Remove dead code --- letsencrypt/tests/auth_handler_test.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/letsencrypt/tests/auth_handler_test.py b/letsencrypt/tests/auth_handler_test.py index 17ac970e2..f7c7a888f 100644 --- a/letsencrypt/tests/auth_handler_test.py +++ b/letsencrypt/tests/auth_handler_test.py @@ -156,14 +156,6 @@ class GetAuthorizationsTest(unittest.TestCase): self.assertRaises(errors.AuthorizationError, self.handler.get_authorizations, ["0"]) - def _get_exp_response(self, domain, path, challs): - # pylint: disable=no-self-use - exp_resp = [None] * len(challs) - for i in path: - exp_resp[i] = TRANSLATE[challs[i].typ] + str(domain) - - return exp_resp - def _validate_all(self, unused_1, unused_2): for dom in self.handler.authzr.keys(): azr = self.handler.authzr[dom] @@ -443,19 +435,5 @@ def gen_dom_authzr(domain, unused_new_authzr_uri, challs): [messages2.STATUS_PENDING]*len(challs)) -def gen_path(required, challs): - """Generate a combination by picking ``required`` from ``challs``. - - :param required: Required types of challenges (subclasses of - :class:`~acme.challenges.Challenge`). - :param challs: Sequence of ACME challenge messages, corresponding to - :attr:`acme.messages.Challenge.challenges`. - - :return: :class:`list` of :class:`int` - - """ - return [challs.index(chall) for chall in required] - - if __name__ == "__main__": unittest.main() # pragma: no cover From 484fd8fe9e064b729019b8279b4c11cad65052c1 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Thu, 14 May 2015 21:03:10 +0000 Subject: [PATCH 3/5] Fix randomly created mock_dir --- letsencrypt/tests/network2_test.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/letsencrypt/tests/network2_test.py b/letsencrypt/tests/network2_test.py index b078c7516..9a3c22eb7 100644 --- a/letsencrypt/tests/network2_test.py +++ b/letsencrypt/tests/network2_test.py @@ -3,6 +3,8 @@ import datetime import httplib import os import pkg_resources +import shutil +import tempfile import unittest import M2Crypto @@ -49,6 +51,8 @@ class NetworkTest(unittest.TestCase): self.identifier = messages2.Identifier( typ=messages2.IDENTIFIER_FQDN, value='example.com') + self.config = mock.Mock(accounts_dir=tempfile.mkdtemp()) + # Registration self.contact = ('mailto:cert-admin@example.com', 'tel:+12025551212') reg = messages2.Registration( @@ -79,6 +83,9 @@ class NetworkTest(unittest.TestCase): uri='https://www.letsencrypt-demo.org/acme/cert/1', cert_chain_uri='https://www.letsencrypt-demo.org/ca') + def tearDown(self): + shutil.rmtree(self.config.accounts_dir) + def _mock_post_get(self): # pylint: disable=protected-access self.net._post = mock.MagicMock(return_value=self.response) @@ -200,8 +207,8 @@ class NetworkTest(unittest.TestCase): def test_register_from_account(self): self.net.register = mock.Mock() acc = account.Account( - mock.Mock(accounts_dir='mock_dir'), 'key', - email='cert-admin@example.com', phone='+12025551212') + self.config, 'key', email='cert-admin@example.com', + phone='+12025551212') self.net.register_from_account(acc) @@ -210,9 +217,8 @@ class NetworkTest(unittest.TestCase): def test_register_from_account_partial_info(self): self.net.register = mock.Mock() acc = account.Account( - mock.Mock(accounts_dir='mock_dir'), 'key', - email='cert-admin@example.com') - acc2 = account.Account(mock.Mock(accounts_dir='mock_dir'), 'key') + self.config, 'key', email='cert-admin@example.com') + acc2 = account.Account(self.config, 'key') self.net.register_from_account(acc) self.net.register.assert_called_with( From 82bd808ab303122e094e91b6b63eeb570a893553 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Thu, 14 May 2015 21:16:38 +0000 Subject: [PATCH 4/5] 100% coverage for network2_test --- letsencrypt/tests/network2_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/letsencrypt/tests/network2_test.py b/letsencrypt/tests/network2_test.py index 9a3c22eb7..d7f50328a 100644 --- a/letsencrypt/tests/network2_test.py +++ b/letsencrypt/tests/network2_test.py @@ -100,7 +100,7 @@ class NetworkTest(unittest.TestCase): return self.value @classmethod def from_json(cls, value): - return cls(value) + pass # pragma: no cover # pylint: disable=protected-access jws = self.net._wrap_in_jws(MockJSONDeSerializable('foo')) self.assertEqual(jose.JWS.json_loads(jws).payload, '"foo"') From 0bc5791a55c9d34d09aad39885a52678719ae428 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Thu, 14 May 2015 21:44:36 +0000 Subject: [PATCH 5/5] More tests for cli.py --- letsencrypt/tests/cli_test.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/letsencrypt/tests/cli_test.py b/letsencrypt/tests/cli_test.py index 5a6418085..9bb8084d5 100644 --- a/letsencrypt/tests/cli_test.py +++ b/letsencrypt/tests/cli_test.py @@ -12,10 +12,11 @@ class CLITest(unittest.TestCase): def _call(cls, args): from letsencrypt import cli args = ['--text'] + args - with mock.patch("letsencrypt.cli.sys.stdout") as stdout: - with mock.patch("letsencrypt.cli.sys.stderr") as stderr: - ret = cli.main(args) - return ret, stdout, stderr + with mock.patch('letsencrypt.cli.sys.stdout') as stdout: + with mock.patch('letsencrypt.cli.sys.stderr') as stderr: + with mock.patch('letsencrypt.cli.client') as client: + ret = cli.main(args) + return ret, stdout, stderr, client def test_no_flags(self): self.assertRaises(SystemExit, self._call, []) @@ -23,6 +24,18 @@ class CLITest(unittest.TestCase): def test_help(self): self.assertRaises(SystemExit, self._call, ['--help']) + def test_rollback(self): + _, _, _, client = self._call(['rollback']) + client.rollback.assert_called_once() + + _, _, _, client = self._call(['rollback', '--checkpoints', '123']) + client.rollback.assert_called_once_with( + mock.ANY, 123, mock.ANY, mock.ANY) + + def test_config_changes(self): + _, _, _, client = self._call(['config_changes']) + client.view_config_changes.assert_called_once() + def test_plugins(self): flags = ['--init', '--prepare', '--authenticators', '--installers'] for args in itertools.chain(