def test_get_oneview_cert_unexpected_error(self, _get_ov_ca_cert_base64data, get_oneview_client, config_mock): config_mock.get_config.return_value = { 'ssl': { 'SSLCertFile': 'cert_file.crt' } } # Certs Generated with success oneview_client = mock.MagicMock() e = HPOneViewException({ 'errorCode': 'UNEXPECTED ERROR', 'message': 'Unexpected error.', }) hp_ov_exception_msg = "Unexpected error." oneview_client.certificate_authority.get.return_value = "CA CERT" oneview_client.certificate_rabbitmq.generate.return_value = True oneview_client.certificate_rabbitmq.get_key_pair.side_effect = e get_oneview_client.return_value = oneview_client oneview_client.connection = 'con' _get_ov_ca_cert_base64data.return_value = "CA CERT" with self.assertRaises(HPOneViewException) as hp_exception: scmb_thread = SCMB('1.1.1.1', 'cred', 'token') scmb_thread.get_scmb_certs() test_exception = hp_exception.exception self.assertEqual(hp_ov_exception_msg, test_exception.msg) self.assertEqual(e.oneview_response, test_exception.oneview_response)
def test_generate_new_cert_for_oneview(self, get_oneview_client, _is_cert_working_with_scmb, config_mock, _get_ov_ca_cert): config_mock.get_config.return_value = { 'ssl': { 'SSLCertFile': 'cert_file.crt' } } cert_key_pair = { 'base64SSLCertData': 'Client CERT', 'base64SSLKeyData': 'Client Key' } # Certs Generated with success oneview_client = mock.MagicMock() e = HPOneViewException({ 'errorCode': 'RESOURCE_NOT_FOUND', 'message': 'Resource not found.', }) oneview_client.certificate_authority.get.return_value = "CA CERT" oneview_client.certificate_rabbitmq.generate.return_value = True oneview_client.certificate_rabbitmq.get_key_pair.side_effect = \ [e, cert_key_pair] get_oneview_client.return_value = oneview_client _is_cert_working_with_scmb.return_value = True _get_ov_ca_cert.return_value = { 'type': 'CAInfo', 'members': [{ 'certificateDetails': { 'base64Data': 'CA CERT' } }] } scmb_thread = SCMB('1.1.1.1', 'cred', 'token') scmb_thread.get_scmb_certs() self.assertTrue(scmb_thread._has_valid_certificates()) # Return None if cert is not a dict _get_ov_ca_cert.return_value = [] cert = scmb_thread._get_ov_ca_cert_base64data(oneview_client) self.assertEqual(cert, None)
def test_get_cert_already_exists(self, _get_ov_ca_cert_base64data, get_oneview_client, config_mock, _is_cert_working_with_scmb): config_mock.get_config.return_value = { 'ssl': { 'SSLCertFile': 'cert_file.crt' } } os.makedirs(name='scmb', exist_ok=True) self.addCleanup(shutil.rmtree, 'scmb') # Certs Generated with success oneview_client = mock.MagicMock() oneview_client.certificate_authority.get.return_value = "CA CERT" oneview_client.certificate_rabbitmq.generate.return_value = True oneview_client.certificate_rabbitmq.get_key_pair.return_value = { 'base64SSLCertData': 'Client CERT', 'base64SSLKeyData': 'Client Key' } get_oneview_client.return_value = oneview_client _is_cert_working_with_scmb.return_value = True # Certs already exist e = HPOneViewException({ 'errorCode': 'RABBITMQ_CLIENTCERT_CONFLICT', 'message': 'certs already exist', }) oneview_client.certificate_rabbitmq.generate.side_effect = e oneview_client.connection = 'con' _get_ov_ca_cert_base64data.return_value = "CA CERT" scmb_thread = SCMB('1.1.1.1', 'cred', 'token') scmb_thread.get_scmb_certs() self.assertTrue(scmb_thread._has_valid_certificates())
def test_get_oneview_cert_unexpected_error(self, scmb_connect, resource_client, _get_ov_ca_cert_base64data, get_oneview_client, config_mock): config_mock.get_config.return_value = { 'ssl': { 'SSLCertFile': 'cert_file.crt' } } # Certs Generated with success oneview_client = mock.MagicMock() e = HPOneViewException({ 'errorCode': 'UNEXPECTED ERROR', 'message': 'Unexpected error.', }) hp_ov_exception_msg = "Unexpected error." oneview_client.certificate_authority.get.return_value = "CA CERT" oneview_client.certificate_rabbitmq.generate.return_value = True oneview_client.certificate_rabbitmq.get_key_pair.side_effect = e get_oneview_client.return_value = oneview_client oneview_client.connection = 'con' _get_ov_ca_cert_base64data.return_value = "CA CERT" with self.assertRaises(HPOneViewException) as hp_exception: scmb_thread = SCMB('1.1.1.1', 'cred', 'token') scmb_thread.get_scmb_certs() test_exception = hp_exception.exception self.assertEqual(hp_ov_exception_msg, test_exception.msg) self.assertEqual(e.oneview_response, test_exception.oneview_response) scmb_connect.side_effect = e scmb_thread._listen_scmb() # test get certificate exception _get_ov_ca_cert_base64data.return_value = None with self.assertRaises(OneViewRedfishException) as redfish_exception: scmb_thread.get_scmb_certs() test_exception = redfish_exception.exception.msg self.assertEqual(test_exception, "Failed to fetch OneView CA Certificate") e = HPOneViewException({ 'errorCode': 'RABBITMQ_CLIENTCERT_CONFLICT', 'message': 'RABBITMQ_CLIENTCERT_CONFLICT', }) oneview_client.certificate_rabbitmq.generate.side_effect = e scmb_thread._generate_certificate_in_oneview(oneview_client) resource_client.get.return_value = "Cert" scmb_thread._get_ov_ca_cert(oneview_client) # test certificate generation exception e = HPOneViewException({ 'errorCode': 'NOT_FOUND', 'message': 'NOT_FOUND', }) oneview_client.certificate_rabbitmq.generate.side_effect = e with self.assertRaises(HPOneViewException) as hp_exception: scmb_thread._generate_certificate_in_oneview(oneview_client) test_exception = hp_exception.exception.msg self.assertEqual(test_exception, "NOT_FOUND")