def test_register_on_operation_failure(self): """ Test that a KmipOperationFailure exception is raised when the backend fails to register a key. """ status = enums.ResultStatus.OPERATION_FAILED reason = enums.ResultReason.GENERAL_FAILURE message = "Test failure message" result = results.OperationResult(contents.ResultStatus(status), contents.ResultReason(reason), contents.ResultMessage(message)) error_msg = str(KmipOperationFailure(status, reason, message)) # Key encoding obtained from Section 14.2 of the KMIP 1.1 test # documentation. key_value = ( b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E' b'\x0F') key = objects.SymmetricKey(enums.CryptographicAlgorithm.AES, 128, key_value) client = ProxyKmipClient() client.open() client.proxy.register.return_value = result args = [key] self.assertRaisesRegexp(KmipOperationFailure, error_msg, client.register, *args)
def test_mac_on_operation_failure(self): """ Test that a KmipOperationFailure exception is raised when the backend fails to generate MAC. """ uuid = 'aaaaaaaa-1111-2222-3333-ffffffffffff' algorithm = enums.CryptographicAlgorithm.HMAC_SHA256 data = (b'\x00\x01\x02\x03\x04') status = enums.ResultStatus.OPERATION_FAILED reason = enums.ResultReason.GENERAL_FAILURE message = "Test failure message" result = results.OperationResult(contents.ResultStatus(status), contents.ResultReason(reason), contents.ResultMessage(message)) error_msg = str(KmipOperationFailure(status, reason, message)) client = ProxyKmipClient() client.open() client.proxy.mac.return_value = result args = [uuid, algorithm, data] self.assertRaisesRegexp(KmipOperationFailure, error_msg, client.mac, *args)
def test_init(self): """ Test that a KmipOperationFailure exception can be instantiated. """ exc = KmipOperationFailure(ResultStatus.OPERATION_FAILED, ResultReason.GENERAL_FAILURE, "Test error message.") self.assertIsInstance(exc, Exception)
def test_message(self): """ Test that a KmipOperationFailure exception message can be set properly. """ status = ResultStatus.OPERATION_FAILED reason = ResultReason.GENERAL_FAILURE exc = KmipOperationFailure(status, reason, "Test error message.") msg = "{0}: {1} - {2}".format(status.name, reason.name, "Test error message.") self.assertEqual(msg, str(exc))
def test_destroy_on_operation_failure(self): """ Test that a KmipOperationFailure exception is raised when the backend fails to destroy a secret. """ status = enums.ResultStatus.OPERATION_FAILED reason = enums.ResultReason.GENERAL_FAILURE message = "Test failure message" result = results.OperationResult(contents.ResultStatus(status), contents.ResultReason(reason), contents.ResultMessage(message)) error_msg = str(KmipOperationFailure(status, reason, message)) client = ProxyKmipClient() client.open() client.proxy.destroy.return_value = result args = ['id'] self.assertRaisesRegexp(KmipOperationFailure, error_msg, client.destroy, *args)
def test_get_attribute_list_on_operation_failure(self): """ Test that a KmipOperationFailure exception is raised when the backend fails to retrieve the attribute names of a managed object. """ status = enums.ResultStatus.OPERATION_FAILED reason = enums.ResultReason.GENERAL_FAILURE message = "Test failure message" result = results.OperationResult(contents.ResultStatus(status), contents.ResultReason(reason), contents.ResultMessage(message)) error_msg = str(KmipOperationFailure(status, reason, message)) client = ProxyKmipClient() client.open() client.proxy.get_attribute_list.return_value = result args = ['id'] self.assertRaisesRegexp(KmipOperationFailure, error_msg, client.get_attribute_list, *args)
def test_create_key_pair_on_operation_failure(self): """ Test that a KmipOperationFailure exception is raised when the backend fails to create an asymmetric key pair. """ status = enums.ResultStatus.OPERATION_FAILED reason = enums.ResultReason.GENERAL_FAILURE message = "Test failure message" result = results.OperationResult(contents.ResultStatus(status), contents.ResultReason(reason), contents.ResultMessage(message)) error_msg = str(KmipOperationFailure(status, reason, message)) client = ProxyKmipClient() client.open() client.proxy.create_key_pair.return_value = result args = [enums.CryptographicAlgorithm.RSA, 2048] self.assertRaisesRegexp(KmipOperationFailure, error_msg, client.create_key_pair, *args)