Skip to content

Commit f9d60a8

Browse files
lint
1 parent 7374fcb commit f9d60a8

5 files changed

+32
-17
lines changed

src/aws_encryption_sdk/streaming_client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ def _create_decrypt_materials_request(self, header):
976976
encryption_context=header.encryption_context,
977977
commitment_policy=self.config.commitment_policy,
978978
)
979-
979+
980980
def _validate_parsed_header(
981981
self,
982982
header,
@@ -1096,7 +1096,7 @@ def _read_header(self):
10961096
"Key commitment validation failed. Key identity does not match the identity asserted in the "
10971097
"message. Halting processing of this message."
10981098
)
1099-
1099+
11001100
return self._validate_parsed_header(
11011101
header=header,
11021102
header_auth=header_auth,

test/mpl/unit/test_material_managers_mpl_materials.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_GIVEN_valid_signing_key_WHEN_EncryptionMaterials_get_signing_key_THEN_r
160160
assert output == mock_signing_key
161161

162162

163-
def test_GIVEN_valid_required_encryption_context_keys_WHEN_EncryptionMaterials_get_required_encryption_context_keys_THEN_returns_required_encryption_context_keys():
163+
def test_GIVEN_valid_required_encryption_context_keys_WHEN_EncryptionMaterials_get_required_encryption_context_keys_THEN_returns_required_encryption_context_keys(): # noqa pylint: disable=line-too-long
164164
# Given: valid required encryption context keys
165165
mock_required_encryption_context_keys = MagicMock(__class__=bytes)
166166
mock_mpl_encryption_materials.required_encryption_context_keys = mock_required_encryption_context_keys
@@ -202,7 +202,7 @@ def test_GIVEN_valid_verification_key_WHEN_DecryptionMaterials_get_verification_
202202
assert output == mock_verification_key
203203

204204

205-
def test_GIVEN_valid_encryption_context_WHEN_DecryptionMaterials_get_encryption_context_THEN_returns_encryption_context():
205+
def test_GIVEN_valid_encryption_context_WHEN_DecryptionMaterials_get_encryption_context_THEN_returns_encryption_context(): # noqa pylint: disable=line-too-long
206206
# Given: valid encryption context
207207
mock_encryption_context = MagicMock(__class__=Dict[str, str])
208208
mock_mpl_decrypt_materials.encryption_context = mock_encryption_context
@@ -215,7 +215,7 @@ def test_GIVEN_valid_encryption_context_WHEN_DecryptionMaterials_get_encryption_
215215
assert output == mock_encryption_context
216216

217217

218-
def test_GIVEN_valid_required_encryption_context_keys_WHEN_DecryptionMaterials_get_required_encryption_context_keys_THEN_returns_required_encryption_context_keys():
218+
def test_GIVEN_valid_required_encryption_context_keys_WHEN_DecryptionMaterials_get_required_encryption_context_keys_THEN_returns_required_encryption_context_keys(): # noqa pylint: disable=line-too-long
219219
# Given: valid required encryption context keys
220220
mock_required_encryption_context_keys = MagicMock(__class__=bytes)
221221
mock_mpl_decrypt_materials.required_encryption_context_keys = mock_required_encryption_context_keys

test/unit/test_serialize.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,10 @@ def test_serialize_header_auth_v1_no_signer(self):
169169
)
170170

171171
@patch("aws_encryption_sdk.internal.formatting.serialize.header_auth_iv")
172-
def test_GIVEN_required_ec_bytes_WHEN_serialize_header_auth_v1_THEN_aad_has_required_ec_bytes(self, mock_header_auth_iv):
172+
def test_GIVEN_required_ec_bytes_WHEN_serialize_header_auth_v1_THEN_aad_has_required_ec_bytes(
173+
self,
174+
mock_header_auth_iv,
175+
):
173176
"""Validate that the _create_header_auth function
174177
behaves as expected for SerializationVersion.V1
175178
when required_ec_bytes are provided.
@@ -230,7 +233,10 @@ def test_serialize_header_auth_v2_no_signer(self):
230233
)
231234

232235
@patch("aws_encryption_sdk.internal.formatting.serialize.header_auth_iv")
233-
def test_GIVEN_required_ec_bytes_WHEN_serialize_header_auth_v2_THEN_aad_has_required_ec_bytes(self, mock_header_auth_iv):
236+
def test_GIVEN_required_ec_bytes_WHEN_serialize_header_auth_v2_THEN_aad_has_required_ec_bytes(
237+
self,
238+
mock_header_auth_iv,
239+
):
234240
"""Validate that the _create_header_auth function
235241
behaves as expected for SerializationVersion.V2.
236242
"""

test/unit/test_streaming_client_stream_decryptor.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
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.streaming_client.StreamDecryptor"""
14+
# noqa pylint: disable=too-many-lines
1415
import io
1516

1617
import pytest
@@ -1011,7 +1012,7 @@ def test_GIVEN_config_has_EC_WHEN_create_decrypt_materials_request_THEN_provide_
10111012
assert hasattr(output, "reproduced_encryption_context")
10121013
assert output.reproduced_encryption_context == mock_reproduced_encryption_context
10131014

1014-
def test_GIVEN_config_does_not_have_EC_WHEN_create_decrypt_materials_request_THEN_request_does_not_have_reproduced_EC(
1015+
def test_GIVEN_config_does_not_have_EC_WHEN_create_decrypt_materials_request_THEN_request_does_not_have_reproduced_EC( # noqa pylint: disable=line-too-long
10151016
self,
10161017
):
10171018
self.mock_header.content_type = ContentType.FRAMED_DATA
@@ -1066,7 +1067,7 @@ def test_GIVEN_materials_has_no_required_encryption_context_keys_attr_WHEN_read_
10661067
@patch("aws_encryption_sdk.streaming_client.derive_data_encryption_key")
10671068
@patch("aws_encryption_sdk.streaming_client.DecryptionMaterialsRequest")
10681069
@patch("aws_encryption_sdk.streaming_client.Verifier")
1069-
def test_GIVEN_materials_has_required_encryption_context_keys_attr_WHEN_read_header_THEN_creates_correct_required_EC(
1070+
def test_GIVEN_materials_has_required_encryption_context_keys_attr_WHEN_read_header_THEN_creates_correct_required_EC( # noqa pylint: disable=line-too-long
10701071
self,
10711072
mock_verifier,
10721073
*_
@@ -1106,9 +1107,9 @@ def test_GIVEN_materials_has_required_encryption_context_keys_attr_WHEN_read_hea
11061107
# Given: decryption_materials has required_encryption_context_keys
11071108
self.mock_decrypt_materials.required_encryption_context_keys = \
11081109
required_encryption_context_keys
1109-
1110+
11101111
for encryption_context in encryption_context_values:
1111-
1112+
11121113
self.mock_decrypt_materials.encryption_context = encryption_context
11131114

11141115
mock_verifier_instance = MagicMock()
@@ -1130,6 +1131,7 @@ def test_GIVEN_materials_has_required_encryption_context_keys_attr_WHEN_read_hea
11301131
if k in required_encryption_context_keys:
11311132
# ... its EC is in the StreamEncryptor._required_encryption_context
11321133
assert k in test_decryptor._required_encryption_context
1134+
assert test_decryptor._required_encryption_context[k] == encryption_context[k]
11331135
# If a key is NOT in required_encryption_context_keys, then ...
11341136
else:
11351137
# ... its EC is NOT in the StreamEncryptor._required_encryption_context

test/unit/test_streaming_client_stream_encryptor.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
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.streaming_client.StreamEncryptor"""
14+
# noqa pylint: disable=too-many-lines
1415
import io
1516

1617
import pytest
@@ -453,7 +454,9 @@ def test_GIVEN_has_mpl_AND_has_MPLCMM_AND_uses_signer_WHEN_prep_message_THEN_sig
453454

454455
# Given: has MPL
455456
@pytest.mark.skipif(not HAS_MPL, reason="Test should only be executed with MPL in installation")
456-
def test_GIVEN_has_mpl_AND_encryption_materials_has_required_EC_keys_WHEN_prep_message_THEN_paritions_stored_and_required_EC(self):
457+
def test_GIVEN_has_mpl_AND_encryption_materials_has_required_EC_keys_WHEN_prep_message_THEN_paritions_stored_and_required_EC( # noqa pylint: disable=line-too-long
458+
self
459+
):
457460
# Create explicit values to explicitly test logic in smaller cases
458461
required_encryption_context_keys_values = [
459462
# Case of empty encryption context list is not allowed;
@@ -492,7 +495,7 @@ def test_GIVEN_has_mpl_AND_encryption_materials_has_required_EC_keys_WHEN_prep_m
492495
# Given: encryption context has required_encryption_context_keys
493496
self.mock_encryption_materials.required_encryption_context_keys = \
494497
required_encryption_context_keys
495-
498+
496499
for encryption_context in encryption_context_values:
497500
self.mock_encryption_materials.encryption_context = encryption_context
498501

@@ -514,6 +517,7 @@ def test_GIVEN_has_mpl_AND_encryption_materials_has_required_EC_keys_WHEN_prep_m
514517
if k in required_encryption_context_keys:
515518
# 1) Its EC is in the StreamEncryptor._required_encryption_context
516519
assert k in test_encryptor._required_encryption_context
520+
assert test_encryptor._required_encryption_context[k] == encryption_context[k]
517521
# 2) Its EC is NOT in the StreamEncryptor._stored_encryption_context
518522
assert k not in test_encryptor._stored_encryption_context
519523
# If a key is NOT in required_encryption_context_keys, then
@@ -522,16 +526,19 @@ def test_GIVEN_has_mpl_AND_encryption_materials_has_required_EC_keys_WHEN_prep_m
522526
assert k not in test_encryptor._required_encryption_context
523527
# 2) Its EC is in the StreamEncryptor._stored_encryption_context
524528
assert k in test_encryptor._stored_encryption_context
525-
529+
assert test_encryptor._stored_encryption_context[k] == encryption_context[k]
530+
526531
# Assert size(stored_EC) + size(required_EC) == size(EC)
527532
# (i.e. every EC was sorted into one or the other)
528533
assert len(test_encryptor._required_encryption_context) \
529534
+ len(test_encryptor._stored_encryption_context) \
530535
== len(encryption_context)
531-
536+
532537
# Given: has MPL
533538
@pytest.mark.skipif(not HAS_MPL, reason="Test should only be executed with MPL in installation")
534-
def test_GIVEN_has_mpl_AND_encryption_materials_does_not_have_required_EC_keys_WHEN_prep_message_THEN_stored_EC_is_EC(self):
539+
def test_GIVEN_has_mpl_AND_encryption_materials_does_not_have_required_EC_keys_WHEN_prep_message_THEN_stored_EC_is_EC( # noqa pylint: disable=line-too-long
540+
self
541+
):
535542

536543
self.mock_encryption_materials.algorithm = Algorithm.AES_128_GCM_IV12_TAG16
537544

@@ -557,7 +564,7 @@ def test_GIVEN_has_mpl_AND_encryption_materials_does_not_have_required_EC_keys_W
557564
assert test_encryptor._stored_encryption_context == mock_encryption_context
558565
# Then: _required_encryption_context is None
559566
assert test_encryptor._required_encryption_context is None
560-
567+
561568
def test_prep_message_no_signer(self):
562569
self.mock_encryption_materials.algorithm = Algorithm.AES_128_GCM_IV12_TAG16
563570
test_encryptor = StreamEncryptor(

0 commit comments

Comments
 (0)