From 35be2f6f044004f1f9ed1760d18cdf0ed1cbf019 Mon Sep 17 00:00:00 2001 From: E069279 Date: Tue, 26 Nov 2024 13:36:04 +0000 Subject: [PATCH] - Adding support for OAG 7.0+ --- client_encryption/api_encryption.py | 5 ++--- tests/test_api_encryption.py | 21 ++------------------- tests/test_api_encryption_jwe.py | 20 +------------------- tests/utils/api_encryption_test_utils.py | 2 ++ 4 files changed, 7 insertions(+), 41 deletions(-) diff --git a/client_encryption/api_encryption.py b/client_encryption/api_encryption.py index 1b58164..6a44650 100644 --- a/client_encryption/api_encryption.py +++ b/client_encryption/api_encryption.py @@ -173,12 +173,11 @@ def _contains_param(param_name, headers): return param_name and param_name in he def add_encryption_layer(api_client, encryption_conf_file, encryption_type='Mastercard'): """Decorate APIClient.call_api with encryption""" + __check_oauth(api_client) # warn the user if authentication layer is missing/not set api_encryption = ApiEncryption(encryption_conf_file, encryption_type) - api_client.request = api_encryption.field_encryption(api_client.request) + api_client.rest_client.request = api_encryption.field_encryption(api_client.rest_client.request) api_client.call_api = api_encryption.field_encryption_call_api(api_client.call_api) - __check_oauth(api_client) # warn the user if authentication layer is missing/not set - def __check_oauth(api_client): try: diff --git a/tests/test_api_encryption.py b/tests/test_api_encryption.py index d786691..327f9b9 100644 --- a/tests/test_api_encryption.py +++ b/tests/test_api_encryption.py @@ -363,25 +363,8 @@ def test_add_encryption_layer_oauth_set(self, __oauth_warn): def test_add_encryption_layer_missing_oauth_layer_warning(self): test_client = Mock() + test_client.rest_client.request = None # no __oauth__ flag with self.assertWarns(UserWarning): - to_test.add_encryption_layer(test_client, self._json_config) - - def test_add_encryption_layer_wrong_oauth_layer_flag_warning(self): - test_client = Mock() - - # __oauth__ is None - test_client.request.__oauth__ = None - with self.assertWarns(UserWarning): - to_test.add_encryption_layer(test_client, self._json_config) - - # __oauth__ is False - test_client.request.__oauth__ = False - with self.assertWarns(UserWarning): - to_test.add_encryption_layer(test_client, self._json_config) - - # __oauth__ is not a boolean - test_client.request.__oauth__ = 5 - with self.assertWarns(UserWarning): - to_test.add_encryption_layer(test_client, self._json_config) + to_test.add_encryption_layer(test_client, self._json_config) \ No newline at end of file diff --git a/tests/test_api_encryption_jwe.py b/tests/test_api_encryption_jwe.py index 1163d09..375a032 100644 --- a/tests/test_api_encryption_jwe.py +++ b/tests/test_api_encryption_jwe.py @@ -366,22 +366,4 @@ def test_add_encryption_layer_missing_oauth_layer_warning(self): # no __oauth__ flag with self.assertWarns(UserWarning): - to_test.add_encryption_layer(test_client, self._json_config) - - def test_add_encryption_layer_wrong_oauth_layer_flag_warning(self): - test_client = Mock() - - # __oauth__ is None - test_client.request.__oauth__ = None - with self.assertWarns(UserWarning): - to_test.add_encryption_layer(test_client, self._json_config) - - # __oauth__ is False - test_client.request.__oauth__ = False - with self.assertWarns(UserWarning): - to_test.add_encryption_layer(test_client, self._json_config) - - # __oauth__ is not a boolean - test_client.request.__oauth__ = 5 - with self.assertWarns(UserWarning): - to_test.add_encryption_layer(test_client, self._json_config) + to_test.add_encryption_layer(test_client, self._json_config) \ No newline at end of file diff --git a/tests/utils/api_encryption_test_utils.py b/tests/utils/api_encryption_test_utils.py index 692c9ad..9eb4fe8 100644 --- a/tests/utils/api_encryption_test_utils.py +++ b/tests/utils/api_encryption_test_utils.py @@ -23,6 +23,7 @@ def __init__(self, api_client=None): if api_client is None: api_client = MockApiClient() self.api_client = api_client + self.api_client.rest_client = api_client def do_something_get(self, **kwargs): return self.api_client.request("GET", "testservice", None, kwargs["headers"]) @@ -60,6 +61,7 @@ def __init__(self, configuration=None, header_name=None, header_value=None, json_config = json.loads(get_mastercard_config_for_test()) json_config["paths"]["$"]["toEncrypt"] = {"data": "encryptedData"} json_config["paths"]["$"]["toDecrypt"] = {"encryptedData": "data"} + self.rest_client = self self._config = encryption_config.FieldLevelEncryptionConfig(json_config) @mock_signing