Skip to content

Commit 139ea81

Browse files
author
Andres Sanchez
committed
Removed unit tests not corresponding to this branch
1 parent aa3df87 commit 139ea81

5 files changed

+49
-66
lines changed

test/unit/test_deserialize.py

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""Unit test suite for aws_encryption_sdk.deserialize"""
1414
import io
1515
import struct
16+
import unittest
1617

1718
import pytest
1819
import six
@@ -55,9 +56,8 @@ def test_deserialize_tag():
5556
assert parsed_tag == tag
5657

5758

58-
class TestDeserialize(object):
59-
@pytest.fixture(autouse=True)
60-
def apply_fixtures(self):
59+
class TestDeserialize(unittest.TestCase):
60+
def setUp(self):
6161
self.mock_wrapping_algorithm = MagicMock()
6262
self.mock_wrapping_algorithm.algorithm.iv_len = VALUES["iv_len"]
6363

@@ -109,32 +109,29 @@ def test_validate_header_invalid(self):
109109
as expected for a valid header.
110110
"""
111111
self.mock_decrypt.side_effect = InvalidTag()
112-
with pytest.raises(SerializationError) as excinfo:
112+
with six.assertRaisesRegex(self, SerializationError, "Header authorization failed"):
113113
aws_encryption_sdk.internal.formatting.deserialize.validate_header(
114114
header=VALUES["deserialized_header_block"],
115115
header_auth=VALUES["deserialized_header_auth_block"],
116116
raw_header=VALUES["header"],
117117
data_key=VALUES["data_key_obj"],
118118
)
119-
excinfo.match("Header authorization failed")
120119

121120
def test_deserialize_header_unknown_object_type(self):
122121
"""Validate that the deserialize_header function behaves
123122
as expected for an unknown object type.
124123
"""
125-
with pytest.raises(NotSupportedError) as excinfo:
124+
with six.assertRaisesRegex(self, NotSupportedError, "Unsupported type *"):
126125
stream = io.BytesIO(VALUES["serialized_header_invalid_object_type"])
127126
aws_encryption_sdk.internal.formatting.deserialize.deserialize_header(stream)
128-
excinfo.match("Unsupported type *")
129127

130128
def test_deserialize_header_unknown_version(self):
131129
"""Validate that the deserialize_header function behaves
132130
as expected for an unknown message version.
133131
"""
134-
with pytest.raises(NotSupportedError) as excinfo:
132+
with six.assertRaisesRegex(self, NotSupportedError, "Unsupported version *"):
135133
stream = io.BytesIO(VALUES["serialized_header_invalid_version"])
136134
aws_encryption_sdk.internal.formatting.deserialize.deserialize_header(stream)
137-
excinfo.match("Unsupported version *")
138135

139136
@patch("aws_encryption_sdk.internal.formatting.deserialize.AlgorithmSuite.get_by_id")
140137
def test_deserialize_header_unsupported_data_encryption_algorithm(self, mock_algorithm_get):
@@ -144,70 +141,65 @@ def test_deserialize_header_unsupported_data_encryption_algorithm(self, mock_alg
144141
mock_unsupported_algorithm = MagicMock()
145142
mock_unsupported_algorithm.allowed = False
146143
mock_algorithm_get.return_value = mock_unsupported_algorithm
147-
with pytest.raises(NotSupportedError) as excinfo:
144+
with six.assertRaisesRegex(self, NotSupportedError, "Unsupported algorithm *"):
148145
stream = io.BytesIO(VALUES["serialized_header_disallowed_algorithm"])
149146
aws_encryption_sdk.internal.formatting.deserialize.deserialize_header(stream)
150-
excinfo.match("Unsupported algorithm *")
151147

152148
@patch("aws_encryption_sdk.internal.formatting.deserialize.AlgorithmSuite.get_by_id")
153149
def test_deserialize_header_unknown_data_encryption_algorithm(self, mock_algorithm_get):
154150
"""Validate that the deserialize_header function behaves
155151
as expected for an unknown algorithm.
156152
"""
157153
mock_algorithm_get.side_effect = KeyError()
158-
with pytest.raises(UnknownIdentityError) as excinfo:
154+
with six.assertRaisesRegex(self, UnknownIdentityError, "Unknown algorithm *"):
159155
stream = io.BytesIO(VALUES["serialized_header_invalid_algorithm"])
160156
aws_encryption_sdk.internal.formatting.deserialize.deserialize_header(stream)
161-
excinfo.match("Unknown algorithm *")
162157

163158
def test_deserialize_header_unknown_content_type(self):
164159
"""Validate that the deserialize_header function behaves
165160
as expected for an unknown content type.
166161
"""
167-
with pytest.raises(UnknownIdentityError) as excinfo:
162+
with six.assertRaisesRegex(self, UnknownIdentityError, "Unknown content type *"):
168163
stream = io.BytesIO(VALUES["serialized_header_unknown_content_type"])
169164
aws_encryption_sdk.internal.formatting.deserialize.deserialize_header(stream)
170-
excinfo.match("Unknown content type *")
171165

172166
def test_deserialize_header_invalid_reserved_space(self):
173167
"""Validate that the deserialize_header function behaves
174168
as expected for an invalid value in the reserved
175169
space (formerly content AAD).
176170
"""
177-
with pytest.raises(SerializationError) as excinfo:
171+
with six.assertRaisesRegex(
172+
self, SerializationError, "Content AAD length field is currently unused, its value must be always 0"
173+
):
178174
stream = io.BytesIO(VALUES["serialized_header_bad_reserved_space"])
179175
aws_encryption_sdk.internal.formatting.deserialize.deserialize_header(stream)
180-
excinfo.match("Content AAD length field is currently unused, its value must be always 0")
181176

182177
def test_deserialize_header_bad_iv_len(self):
183178
"""Validate that the deserialize_header function behaves
184179
as expected for bad IV length (incompatible with
185180
specified algorithm).
186181
"""
187-
with pytest.raises(SerializationError) as excinfo:
182+
with six.assertRaisesRegex(self, SerializationError, "Specified IV length *"):
188183
stream = io.BytesIO(VALUES["serialized_header_bad_iv_len"])
189184
aws_encryption_sdk.internal.formatting.deserialize.deserialize_header(stream)
190-
excinfo.match("Specified IV length *")
191185

192186
def test_deserialize_header_framed_bad_frame_length(self):
193187
"""Validate that the deserialize_header function behaves
194188
as expected for bad frame length values (greater than
195189
the default maximum).
196190
"""
197-
with pytest.raises(SerializationError) as excinfo:
191+
with six.assertRaisesRegex(self, SerializationError, "Specified frame length larger than allowed maximum: *"):
198192
stream = io.BytesIO(VALUES["serialized_header_bad_frame_len"])
199193
aws_encryption_sdk.internal.formatting.deserialize.deserialize_header(stream)
200-
excinfo.match("Specified frame length larger than allowed maximum: *")
201194

202195
def test_deserialize_header_non_framed_bad_frame_length(self):
203196
"""Validate that the deserialize_header function behaves
204197
as expected for bad frame length values for non-framed
205198
messages (non-zero).
206199
"""
207-
with pytest.raises(SerializationError) as excinfo:
200+
with six.assertRaisesRegex(self, SerializationError, "Non-zero frame length found for non-framed message"):
208201
stream = io.BytesIO(VALUES["serialized_non_framed_header_bad_frame_len"])
209202
aws_encryption_sdk.internal.formatting.deserialize.deserialize_header(stream)
210-
excinfo.match("Non-zero frame length found for non-framed message")
211203

212204
def test_deserialize_header_valid(self):
213205
"""Validate that the deserialize_header function behaves
@@ -255,11 +247,10 @@ def test_deserialize_body_frame_final_invalid_final_frame_length(self):
255247
behaves as expected for a valid final body frame.
256248
"""
257249
stream = io.BytesIO(VALUES["serialized_final_frame_bad_length"])
258-
with pytest.raises(SerializationError) as excinfo:
250+
with six.assertRaisesRegex(self, SerializationError, "Invalid final frame length: *"):
259251
aws_encryption_sdk.internal.formatting.deserialize.deserialize_frame(
260252
stream=stream, header=VALUES["deserialized_header_frame"]
261253
)
262-
excinfo.match("Invalid final frame length: *")
263254

264255
def test_deserialize_footer_no_verifier(self):
265256
"""Vaidate that the deserialize_footer function behaves
@@ -284,9 +275,8 @@ def test_deserialize_footer_verifier_no_footer(self):
284275
with no footer.
285276
"""
286277
stream = io.BytesIO(b"")
287-
with pytest.raises(SerializationError) as excinfo:
278+
with six.assertRaisesRegex(self, SerializationError, "No signature found in message"):
288279
aws_encryption_sdk.internal.formatting.deserialize.deserialize_footer(stream, self.mock_verifier)
289-
excinfo.match("No signature found in message")
290280

291281
@patch("aws_encryption_sdk.internal.formatting.deserialize.struct")
292282
def test_unpack_values(self, mock_struct):
@@ -338,65 +328,59 @@ def test_deserialize_wrapped_key_symmetric(self):
338328
)
339329

340330
def test_deserialize_wrapped_key_symmetric_wrapping_key_mismatch(self):
341-
with pytest.raises(SerializationError) as excinfo:
331+
with six.assertRaisesRegex(self, SerializationError, "Master Key mismatch for wrapped data key"):
342332
aws_encryption_sdk.internal.formatting.deserialize.deserialize_wrapped_key(
343333
wrapping_algorithm=self.mock_wrapping_algorithm,
344334
wrapping_key_id=b"asifuhasjaskldjfhlsakdfj",
345335
wrapped_encrypted_key=VALUES["wrapped_keys"]["structures"]["wrapped_encrypted_data_key_asymmetric"],
346336
)
347-
excinfo.match("Master Key mismatch for wrapped data key")
348337

349338
def test_deserialize_wrapped_key_symmetric_wrapping_algorithm_incomplete_info(self):
350-
with pytest.raises(SerializationError) as excinfo:
339+
with six.assertRaisesRegex(self, SerializationError, "Malformed key info: key info missing data"):
351340
aws_encryption_sdk.internal.formatting.deserialize.deserialize_wrapped_key(
352341
wrapping_algorithm=self.mock_wrapping_algorithm,
353342
wrapping_key_id=VALUES["wrapped_keys"]["raw"]["key_info"],
354343
wrapped_encrypted_key=VALUES["wrapped_keys"]["structures"][
355344
"wrapped_encrypted_data_key_symmetric_incomplete_info"
356345
],
357346
)
358-
excinfo.match("Malformed key info: key info missing data")
359347

360348
def test_deserialize_wrapped_key_symmetric_wrapping_algorithm_iv_len_mismatch(self):
361-
with pytest.raises(SerializationError) as excinfo:
349+
with six.assertRaisesRegex(self, SerializationError, "Wrapping AlgorithmSuite mismatch for wrapped data key"):
362350
aws_encryption_sdk.internal.formatting.deserialize.deserialize_wrapped_key(
363351
wrapping_algorithm=self.mock_wrapping_algorithm,
364352
wrapping_key_id=VALUES["wrapped_keys"]["raw"]["key_info"],
365353
wrapped_encrypted_key=VALUES["wrapped_keys"]["structures"][
366354
"wrapped_encrypted_data_key_symmetric_bad_iv_len"
367355
],
368356
)
369-
excinfo.match("Wrapping AlgorithmSuite mismatch for wrapped data key")
370357

371358
def test_deserialize_wrapped_key_symmetric_wrapping_algorithm_incomplete_iv(self):
372-
with pytest.raises(SerializationError) as excinfo:
359+
with six.assertRaisesRegex(self, SerializationError, "Malformed key info: incomplete iv"):
373360
aws_encryption_sdk.internal.formatting.deserialize.deserialize_wrapped_key(
374361
wrapping_algorithm=self.mock_wrapping_algorithm,
375362
wrapping_key_id=VALUES["wrapped_keys"]["raw"]["key_info"],
376363
wrapped_encrypted_key=VALUES["wrapped_keys"]["structures"][
377364
"wrapped_encrypted_data_key_symmetric_incomplete_iv"
378365
],
379366
)
380-
excinfo.match("Malformed key info: incomplete iv")
381367

382368
def test_deserialize_wrapped_key_symmetric_wrapping_algorithm_incomplete_tag(self):
383-
with pytest.raises(SerializationError) as excinfo:
369+
with six.assertRaisesRegex(self, SerializationError, "Malformed key info: incomplete ciphertext or tag"):
384370
aws_encryption_sdk.internal.formatting.deserialize.deserialize_wrapped_key(
385371
wrapping_algorithm=self.mock_wrapping_algorithm,
386372
wrapping_key_id=VALUES["wrapped_keys"]["raw"]["key_info"],
387373
wrapped_encrypted_key=VALUES["wrapped_keys"]["structures"][
388374
"wrapped_encrypted_data_key_symmetric_incomplete_tag"
389375
],
390376
)
391-
excinfo.match("Malformed key info: incomplete ciphertext or tag")
392377

393378
def test_deserialize_wrapped_key_symmetric_wrapping_algorithm_incomplete_tag2(self):
394-
with pytest.raises(SerializationError) as excinfo:
379+
with six.assertRaisesRegex(self, SerializationError, "Malformed key info: incomplete ciphertext or tag"):
395380
aws_encryption_sdk.internal.formatting.deserialize.deserialize_wrapped_key(
396381
wrapping_algorithm=self.mock_wrapping_algorithm,
397382
wrapping_key_id=VALUES["wrapped_keys"]["raw"]["key_info"],
398383
wrapped_encrypted_key=VALUES["wrapped_keys"]["structures"][
399384
"wrapped_encrypted_data_key_symmetric_incomplete_tag2"
400385
],
401386
)
402-
excinfo.match("Malformed key info: incomplete ciphertext or tag")

test/unit/test_providers_kms_master_key.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Unit test suite for aws_encryption_sdk.key_providers.kms.KMSMasterKey"""
14+
import unittest
15+
1416
import botocore.client
1517
import pytest
16-
18+
import six
1719
from botocore.exceptions import ClientError
1820
from mock import MagicMock, patch, sentinel
1921

@@ -28,9 +30,8 @@
2830
pytestmark = [pytest.mark.unit, pytest.mark.local]
2931

3032

31-
class TestKMSMasterKey(object):
32-
@pytest.fixture(autouse=True)
33-
def apply_fixture(self):
33+
class TestKMSMasterKey(unittest.TestCase):
34+
def setUp(self):
3435
self.mock_client = MagicMock()
3536
self.mock_client.__class__ = botocore.client.BaseClient
3637
self.mock_client.generate_data_key.return_value = {
@@ -110,16 +111,14 @@ def test_generate_data_key_with_grant_tokens(self):
110111
def test_generate_data_key_unsuccessful_clienterror(self):
111112
self.mock_client.generate_data_key.side_effect = ClientError({"Error": {}}, "This is an error!")
112113
test = KMSMasterKey(config=self.mock_kms_mkc_3)
113-
with pytest.raises(GenerateKeyError) as excinfo:
114+
with six.assertRaisesRegex(self, GenerateKeyError, "Master Key .* unable to generate data key"):
114115
test._generate_data_key(self.mock_algorithm)
115-
excinfo.match("Master Key .* unable to generate data key")
116116

117117
def test_generate_data_key_unsuccessful_keyerror(self):
118118
self.mock_client.generate_data_key.side_effect = KeyError
119119
test = KMSMasterKey(config=self.mock_kms_mkc_3)
120-
with pytest.raises(GenerateKeyError) as excinfo:
120+
with six.assertRaisesRegex(self, GenerateKeyError, "Master Key .* unable to generate data key"):
121121
test._generate_data_key(self.mock_algorithm)
122-
excinfo.match("Master Key .* unable to generate data key")
123122

124123
def test_encrypt_data_key(self):
125124
test = KMSMasterKey(config=self.mock_kms_mkc_3)
@@ -147,16 +146,14 @@ def test_encrypt_data_key_with_grant_tokens(self):
147146
def test_encrypt_data_key_unsuccessful_clienterror(self):
148147
self.mock_client.encrypt.side_effect = ClientError({"Error": {}}, "This is an error!")
149148
test = KMSMasterKey(config=self.mock_kms_mkc_3)
150-
with pytest.raises(EncryptKeyError) as excinfo:
149+
with six.assertRaisesRegex(self, EncryptKeyError, "Master Key .* unable to encrypt data key"):
151150
test._encrypt_data_key(self.mock_data_key, self.mock_algorithm)
152-
excinfo.match("Master Key .* unable to encrypt data key")
153151

154152
def test_encrypt_data_key_unsuccessful_keyerror(self):
155153
self.mock_client.encrypt.side_effect = KeyError
156154
test = KMSMasterKey(config=self.mock_kms_mkc_3)
157-
with pytest.raises(EncryptKeyError) as excinfo:
155+
with six.assertRaisesRegex(self, EncryptKeyError, "Master Key .* unable to encrypt data key"):
158156
test._encrypt_data_key(self.mock_data_key, self.mock_algorithm)
159-
excinfo.match("Master Key .* unable to encrypt data key")
160157

161158
def test_decrypt_data_key(self):
162159
test = KMSMasterKey(config=self.mock_kms_mkc_1)
@@ -189,13 +186,11 @@ def test_decrypt_data_key_with_grant_tokens(self):
189186
def test_decrypt_data_key_unsuccessful_clienterror(self):
190187
self.mock_client.decrypt.side_effect = ClientError({"Error": {}}, "This is an error!")
191188
test = KMSMasterKey(config=self.mock_kms_mkc_3)
192-
with pytest.raises(DecryptKeyError) as excinfo:
189+
with six.assertRaisesRegex(self, DecryptKeyError, "Master Key .* unable to decrypt data key"):
193190
test._decrypt_data_key(encrypted_data_key=self.mock_encrypted_data_key, algorithm=sentinel.algorithm)
194-
excinfo.match("Master Key .* unable to decrypt data key")
195191

196192
def test_decrypt_data_key_unsuccessful_keyerror(self):
197193
self.mock_client.decrypt.side_effect = KeyError
198194
test = KMSMasterKey(config=self.mock_kms_mkc_3)
199-
with pytest.raises(DecryptKeyError) as excinfo:
195+
with six.assertRaisesRegex(self, DecryptKeyError, "Master Key .* unable to decrypt data key"):
200196
test._decrypt_data_key(encrypted_data_key=self.mock_encrypted_data_key, algorithm=sentinel.algorithm)
201-
excinfo.match("Master Key .* unable to decrypt data key")

test/unit/test_providers_kms_master_key_provider.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Unit test suite from aws_encryption_sdk.key_providers.kms.KMSMasterKeyProvider"""
14+
import unittest
15+
1416
import botocore.client
1517
import pytest
1618
import six
@@ -30,9 +32,8 @@ def test_init_with_regionless_key_ids_and_region_names():
3032
assert provider.master_key("alias/key_1").config.client.meta.region_name == region_names[0]
3133

3234

33-
class TestKMSMasterKeyProvider(object):
34-
@pytest.fixture(autouse=True)
35-
def apply_fixtures(self):
35+
class TestKMSMasterKeyProvider(unittest.TestCase):
36+
def setUp(self):
3637
self.mock_botocore_session_patcher = patch("aws_encryption_sdk.key_providers.kms.botocore.session.Session")
3738
self.mock_botocore_session = self.mock_botocore_session_patcher.start()
3839
self.mock_boto3_session_patcher = patch("aws_encryption_sdk.key_providers.kms.boto3.session.Session")
@@ -129,9 +130,10 @@ def test_client_no_region_name_with_default(self, mock_add_client):
129130

130131
def test_client_no_region_name_without_default(self):
131132
test = KMSMasterKeyProvider()
132-
with pytest.raises(UnknownRegionError) as excinfo:
133+
with six.assertRaisesRegex(
134+
self, UnknownRegionError, "No default region found and no region determinable from key id: *"
135+
):
133136
test._client("")
134-
excinfo.match("No default region found and no region determinable from key id: *")
135137

136138
@patch("aws_encryption_sdk.key_providers.kms.KMSMasterKeyProvider._client")
137139
def test_new_master_key(self, mock_client):

test/unit/test_providers_raw_master_key.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Test suite for aws_encryption_sdk.key_providers.raw.RawMasterKey"""
14+
import unittest
15+
1416
import pytest
1517
from mock import MagicMock, patch, sentinel
1618

@@ -25,9 +27,8 @@
2527
pytestmark = [pytest.mark.unit, pytest.mark.local]
2628

2729

28-
class TestRawMasterKey(object):
29-
@pytest.fixture(autouse=True)
30-
def apply_fixtures(self):
30+
class TestRawMasterKey(unittest.TestCase):
31+
def setUp(self):
3132
self.mock_algorithm = MagicMock()
3233
self.mock_algorithm.__class__ = Algorithm
3334
self.mock_algorithm.data_key_len = sentinel.data_key_len

0 commit comments

Comments
 (0)