Skip to content

Commit 2955c9c

Browse files
committed
Added test to encrypt&decrypt from logs in e2e tests
1 parent 5b794f7 commit 2955c9c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

tests/e2e/data_masking/test_data_masking.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,35 +91,39 @@ def test_encryption_no_context_fail(data_masker):
9191

9292
# TODO: metaclass?
9393
@pytest.mark.xdist_group(name="data_masking")
94-
def test_encryption_key_fail(kms_key2_arn, data_masker):
94+
def test_encryption_key_fail(data_masker, kms_key2_arn):
9595
# GIVEN an instantiation of DataMasking with the AWS encryption provider with a certain key
9696

9797
# WHEN encrypting and then decrypting the encrypted data
9898
value = bytes(str([1, 2, "string", 4.5]), "utf-8")
9999
encrypted_data = data_masker.encrypt(value)
100100

101+
# THEN when decrypting with a different key it should fail
101102
data_masker_key2 = DataMasking(provider=AwsEncryptionSdkProvider(keys=[kms_key2_arn]))
102103

103104
with pytest.raises(DecryptKeyError):
104105
data_masker_key2.decrypt(encrypted_data)
105106

106107

107108
@pytest.mark.xdist_group(name="data_masking")
108-
def test_masked_in_logs(basic_handler_fn, basic_handler_fn_arn):
109+
def test_encrypted_in_logs(data_masker, basic_handler_fn, basic_handler_fn_arn):
109110
# GIVEN an instantiation of DataMasking with the AWS encryption provider
110-
data_masker = DataMasking(provider=AwsEncryptionSdkProvider(keys=[kms_key1_arn]))
111111

112-
# WHEN masking a value and logging it
113-
masked_data = data_masker.mask([1, 2, "string", 4.5])
114-
message = masked_data
112+
# WHEN encrypting a value and logging it
113+
value = bytes(str([1, 2, "string", 4.5]), "utf-8")
114+
encrypted_data = data_masker.encrypt(value)
115+
message = encrypted_data
115116
custom_key = "order_id"
116117
additional_keys = {custom_key: f"{uuid4()}"}
117118
payload = json.dumps({"message": message, "append_keys": additional_keys})
118119

119120
_, execution_time = data_fetcher.get_lambda_response(lambda_arn=basic_handler_fn_arn, payload=payload)
120121
data_fetcher.get_lambda_response(lambda_arn=basic_handler_fn_arn, payload=payload)
121122

122-
# THEN the logs should show only the obfuscated data
123123
logs = data_fetcher.get_logs(function_name=basic_handler_fn, start_time=execution_time, minimum_log_entries=2)
124124

125-
assert logs.have_keys("message") is True
125+
# THEN decrypting it from the logs should show the original value
126+
for log in logs.get_log(key=custom_key):
127+
encrypted_data = log.message
128+
decrypted_data = data_masker.decrypt(encrypted_data)
129+
assert decrypted_data == value

0 commit comments

Comments
 (0)