Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions client_encryption/api_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 2 additions & 19 deletions tests/test_api_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 1 addition & 19 deletions tests/test_api_encryption_jwe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions tests/utils/api_encryption_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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
Expand Down