@@ -42,36 +42,36 @@ def test_encryption(data_masker):
42
42
# GIVEN an instantiation of DataMasking with the AWS encryption provider
43
43
44
44
# AWS Encryption SDK encrypt method only takes in bytes or strings
45
- value = bytes ( str ( [1 , 2 , "string" , 4.5 ]), "utf-8" )
45
+ value = [1 , 2 , "string" , 4.5 ]
46
46
47
47
# WHEN encrypting and then decrypting the encrypted data
48
48
encrypted_data = data_masker .encrypt (value )
49
49
decrypted_data = data_masker .decrypt (encrypted_data )
50
50
51
51
# THEN the result is the original input data
52
- assert decrypted_data == value
52
+ assert decrypted_data == str ( value )
53
53
54
54
55
55
@pytest .mark .xdist_group (name = "data_masking" )
56
56
def test_encryption_context (data_masker ):
57
57
# GIVEN an instantiation of DataMasking with the AWS encryption provider
58
58
59
- value = bytes ( str ( [1 , 2 , "string" , 4.5 ]), "utf-8" )
59
+ value = [1 , 2 , "string" , 4.5 ]
60
60
context = {"this" : "is_secure" }
61
61
62
62
# WHEN encrypting and then decrypting the encrypted data with an encryption_context
63
63
encrypted_data = data_masker .encrypt (value , encryption_context = context )
64
64
decrypted_data = data_masker .decrypt (encrypted_data , encryption_context = context )
65
65
66
66
# THEN the result is the original input data
67
- assert decrypted_data == value
67
+ assert decrypted_data == str ( value )
68
68
69
69
70
70
@pytest .mark .xdist_group (name = "data_masking" )
71
71
def test_encryption_context_mismatch (data_masker ):
72
72
# GIVEN an instantiation of DataMasking with the AWS encryption provider
73
73
74
- value = bytes ( str ( [1 , 2 , "string" , 4.5 ]), "utf-8" )
74
+ value = [1 , 2 , "string" , 4.5 ]
75
75
76
76
# WHEN encrypting with a encryption_context
77
77
encrypted_data = data_masker .encrypt (value , encryption_context = {"this" : "is_secure" })
@@ -85,7 +85,7 @@ def test_encryption_context_mismatch(data_masker):
85
85
def test_encryption_no_context_fail (data_masker ):
86
86
# GIVEN an instantiation of DataMasking with the AWS encryption provider
87
87
88
- value = bytes ( str ( [1 , 2 , "string" , 4.5 ]), "utf-8" )
88
+ value = [1 , 2 , "string" , 4.5 ]
89
89
90
90
# WHEN encrypting with no encryption_context
91
91
encrypted_data = data_masker .encrypt (value )
@@ -100,7 +100,7 @@ def test_encryption_decryption_key_mismatch(data_masker, kms_key2_arn):
100
100
# GIVEN an instantiation of DataMasking with the AWS encryption provider with a certain key
101
101
102
102
# WHEN encrypting and then decrypting the encrypted data
103
- value = bytes ( str ( [1 , 2 , "string" , 4.5 ]), "utf-8" )
103
+ value = [1 , 2 , "string" , 4.5 ]
104
104
encrypted_data = data_masker .encrypt (value )
105
105
106
106
# THEN when decrypting with a different key it should fail
@@ -114,12 +114,14 @@ def test_encryption_provider_singleton(data_masker, kms_key1_arn, kms_key2_arn):
114
114
data_masker_2 = DataMasking (provider = AwsEncryptionSdkProvider (keys = [kms_key1_arn ]))
115
115
assert data_masker .provider is data_masker_2 .provider
116
116
117
+ value = [1 , 2 , "string" , 4.5 ]
118
+
117
119
# WHEN encrypting and then decrypting the encrypted data
118
- encrypted_data = data_masker .encrypt ("string" )
120
+ encrypted_data = data_masker .encrypt (value )
119
121
decrypted_data = data_masker_2 .decrypt (encrypted_data )
120
122
121
123
# THEN the result is the original input data
122
- assert decrypted_data == bytes ( "string" , "utf-8" )
124
+ assert decrypted_data == str ( value )
123
125
124
126
data_masker_3 = DataMasking (provider = AwsEncryptionSdkProvider (keys = [kms_key2_arn ]))
125
127
assert data_masker_2 .provider is not data_masker_3 .provider
@@ -130,7 +132,7 @@ def test_encryption_in_logs(data_masker, basic_handler_fn, basic_handler_fn_arn)
130
132
# GIVEN an instantiation of DataMasking with the AWS encryption provider
131
133
132
134
# WHEN encrypting a value and logging it
133
- value = bytes ( str ( [1 , 2 , "string" , 4.5 ]), "utf-8" )
135
+ value = [1 , 2 , "string" , 4.5 ]
134
136
encrypted_data = data_masker .encrypt (value )
135
137
message = encrypted_data
136
138
custom_key = "order_id"
@@ -146,7 +148,7 @@ def test_encryption_in_logs(data_masker, basic_handler_fn, basic_handler_fn_arn)
146
148
for log in logs .get_log (key = custom_key ):
147
149
encrypted_data = log .message
148
150
decrypted_data = data_masker .decrypt (encrypted_data )
149
- assert decrypted_data == value
151
+ assert decrypted_data == str ( value )
150
152
151
153
152
154
# NOTE: This test is failing currently, need to find a fix for building correct dependencies
@@ -162,4 +164,4 @@ def test_encryption_in_handler(basic_handler_fn_arn, kms_key1_arn):
162
164
decrypted_data = data_masker .decrypt (encrypted_data )
163
165
164
166
# THEN decrypting the encrypted data from the response should result in the original value
165
- assert decrypted_data == bytes ( str ([1 , 2 , "string" , 4.5 ]), "utf-8" )
167
+ assert decrypted_data == str ([1 , 2 , "string" , 4.5 ])
0 commit comments