def test_existing_cert(self): from dcosdeploy.modules.certs import Cert, CertsManager cert = Cert("mycert", "cert_bla", "key_bla", {"CN": "foo"}, list()) from dcosdeploy.adapters.secrets import SecretsAdapter m = mock.Mock() m.side_effect = [True, True] with mock.patch.object(SecretsAdapter, 'get_secret', m): certs = CertsManager() self.assertFalse(certs.deploy(cert, silent=True))
def test_deploy(self, mock_secretsadapter, mock_caadapter): # given mock_caadapter.return_value.generate_key.side_effect = lambda x, y: ("csr", "key") mock_caadapter.return_value.sign_csr.return_value = "cert" mock_secretsadapter.return_value.get_secret.side_effect = lambda x: False # when from dcosdeploy.modules.certs import Cert, CertsManager cert = Cert("mycert", "cert_bla", "key_bla", {"CN": "foo"}, list()) certs = CertsManager() result = certs.deploy(cert, silent=True) # then self.assertTrue(result) mock_secretsadapter.return_value.delete_secret.assert_not_called() mock_secretsadapter.return_value.write_secret.assert_any_call('key_bla', file_content='key', update=False) mock_secretsadapter.return_value.write_secret.assert_any_call('cert_bla', file_content='cert', update=False)
def test_half_existing_cert(self, mock_secretsadapter, mock_caadapter): # given mock_caadapter.return_value.generate_key.side_effect = lambda a, b, x, y: ( "csr", "key") mock_caadapter.return_value.sign_csr.return_value = "cert" mock_secretsadapter.return_value.get_secret.side_effect = lambda name: True if name == "cert_bla" else False # when from dcosdeploy.modules.certs import Cert, CertsManager cert = Cert("mycert", "cert_bla", "key_bla", {"CN": "foo"}, list(), None, None, "rsa", 2048) certs = CertsManager() result = certs.deploy(cert) # then self.assertTrue(result) mock_secretsadapter.return_value.delete_secret.assert_called_with( "cert_bla") mock_secretsadapter.return_value.write_secret.assert_any_call( 'key_bla', file_content='key', update=False) mock_secretsadapter.return_value.write_secret.assert_any_call( 'cert_bla', file_content='cert', update=False)