Fix patches for acme_handler tests

This commit is contained in:
Mathias Petermann 2020-10-23 15:29:09 +02:00
parent 3b20a47603
commit 30c10b93f8
1 changed files with 17 additions and 13 deletions

View File

@ -2,12 +2,12 @@ import unittest
from unittest.mock import patch, Mock from unittest.mock import patch, Mock
from cryptography.x509 import DNSName from cryptography.x509 import DNSName
from lemur.plugins.lemur_acme import plugin from lemur.plugins.lemur_acme import acme_handlers
class TestAcmeHandler(unittest.TestCase): class TestAcmeHandler(unittest.TestCase):
def setUp(self): def setUp(self):
self.acme = plugin.AcmeHandler() self.acme = acme_handlers.AcmeHandler()
def test_strip_wildcard(self): def test_strip_wildcard(self):
expected = ("example.com", False) expected = ("example.com", False)
@ -19,8 +19,8 @@ class TestAcmeHandler(unittest.TestCase):
self.assertEqual(expected, result) self.assertEqual(expected, result)
def test_authz_record(self): def test_authz_record(self):
a = plugin.AuthorizationRecord("host", "authz", "challenge", "id") a = acme_handlers.AuthorizationRecord("host", "authz", "challenge", "id")
self.assertEqual(type(a), plugin.AuthorizationRecord) self.assertEqual(type(a), acme_handlers.AuthorizationRecord)
def test_setup_acme_client_fail(self): def test_setup_acme_client_fail(self):
mock_authority = Mock() mock_authority = Mock()
@ -40,7 +40,7 @@ class TestAcmeHandler(unittest.TestCase):
self.assertTrue(self.acme.reuse_account(mock_authority)) self.assertTrue(self.acme.reuse_account(mock_authority))
@patch("lemur.plugins.lemur_acme.plugin.current_app") @patch("lemur.plugins.lemur_acme.acme_handlers.current_app")
def test_reuse_account_from_config(self, mock_current_app): def test_reuse_account_from_config(self, mock_current_app):
mock_authority = Mock() mock_authority = Mock()
mock_authority.options = '[{"name": "mock_name", "value": "mock_value"}]' mock_authority.options = '[{"name": "mock_name", "value": "mock_value"}]'
@ -48,7 +48,7 @@ class TestAcmeHandler(unittest.TestCase):
self.assertTrue(self.acme.reuse_account(mock_authority)) self.assertTrue(self.acme.reuse_account(mock_authority))
@patch("lemur.plugins.lemur_acme.plugin.current_app") @patch("lemur.plugins.lemur_acme.acme_handlers.current_app")
def test_reuse_account_no_configuration(self, mock_current_app): def test_reuse_account_no_configuration(self, mock_current_app):
mock_authority = Mock() mock_authority = Mock()
mock_authority.options = '[{"name": "mock_name", "value": "mock_value"}]' mock_authority.options = '[{"name": "mock_name", "value": "mock_value"}]'
@ -56,11 +56,14 @@ class TestAcmeHandler(unittest.TestCase):
self.assertFalse(self.acme.reuse_account(mock_authority)) self.assertFalse(self.acme.reuse_account(mock_authority))
@patch("lemur.plugins.lemur_acme.plugin.BackwardsCompatibleClientV2")
@patch("lemur.plugins.lemur_acme.plugin.current_app") @patch("lemur.plugins.lemur_acme.acme_handlers.authorities_service")
def test_setup_acme_client_success(self, mock_current_app, mock_acme): @patch("lemur.plugins.lemur_acme.acme_handlers.BackwardsCompatibleClientV2")
@patch("lemur.plugins.lemur_acme.acme_handlers.current_app")
def test_setup_acme_client_success(self, mock_current_app, mock_acme, mock_authorities_service):
mock_authority = Mock() mock_authority = Mock()
mock_authority.options = '[{"name": "mock_name", "value": "mock_value"}]' mock_authority.options = '[{"name": "mock_name", "value": "mock_value"}, ' \
'{"name": "store_account", "value": false}]'
mock_client = Mock() mock_client = Mock()
mock_registration = Mock() mock_registration = Mock()
mock_registration.uri = "http://test.com" mock_registration.uri = "http://test.com"
@ -69,16 +72,17 @@ class TestAcmeHandler(unittest.TestCase):
mock_acme.return_value = mock_client mock_acme.return_value = mock_client
mock_current_app.config = {} mock_current_app.config = {}
result_client, result_registration = self.acme.setup_acme_client(mock_authority) result_client, result_registration = self.acme.setup_acme_client(mock_authority)
mock_authorities_service.update_options.assert_not_called()
assert result_client assert result_client
assert result_registration assert result_registration
@patch('lemur.plugins.lemur_acme.plugin.current_app') @patch('lemur.plugins.lemur_acme.acme_handlers.current_app')
def test_get_domains_single(self, mock_current_app): def test_get_domains_single(self, mock_current_app):
options = {"common_name": "test.netflix.net"} options = {"common_name": "test.netflix.net"}
result = self.acme.get_domains(options) result = self.acme.get_domains(options)
self.assertEqual(result, [options["common_name"]]) self.assertEqual(result, [options["common_name"]])
@patch("lemur.plugins.lemur_acme.plugin.current_app") @patch("lemur.plugins.lemur_acme.acme_handlers.current_app")
def test_get_domains_multiple(self, mock_current_app): def test_get_domains_multiple(self, mock_current_app):
options = { options = {
"common_name": "test.netflix.net", "common_name": "test.netflix.net",
@ -91,7 +95,7 @@ class TestAcmeHandler(unittest.TestCase):
result, [options["common_name"], "test2.netflix.net", "test3.netflix.net"] result, [options["common_name"], "test2.netflix.net", "test3.netflix.net"]
) )
@patch("lemur.plugins.lemur_acme.plugin.current_app") @patch("lemur.plugins.lemur_acme.acme_handlers.current_app")
def test_get_domains_san(self, mock_current_app): def test_get_domains_san(self, mock_current_app):
options = { options = {
"common_name": "test.netflix.net", "common_name": "test.netflix.net",