Skip to content

Commit 4522fae

Browse files
committed
test: add shared materials in clients test
1 parent 5108977 commit 4522fae

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

test/functional/test_f_commitment.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,33 @@ def test_encrypt_with_uncommitting_algorithm_require_decrypt():
225225
with pytest.raises(ActionNotAllowedError) as excinfo:
226226
decrypting_client.decrypt(source=ciphertext, key_provider=key_provider)
227227
excinfo.match("Configuration conflict. Cannot decrypt due to .* requiring only committed messages")
228+
229+
230+
def test_encrypt_with_different_kc_clients_sharing_materials_yield_error():
231+
"""Tests that when two different client configured with CommitmentPolicy REQUIRE_ENCRYPT_REQUIRE_DECRYPT
232+
and FORBID_ENCRYPT_ALLOW_DECRYPT share encryption materials client errors out due to conflicting commitment policies."""
233+
forbid_encrypting_client = aws_encryption_sdk.EncryptionSDKClient(
234+
commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
235+
)
236+
required_encrypting_client = aws_encryption_sdk.EncryptionSDKClient(
237+
commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
238+
)
239+
240+
provider = StaticRawMasterKeyProvider(
241+
wrapping_algorithm=WrappingAlgorithm.AES_256_GCM_IV12_TAG16_NO_PADDING,
242+
encryption_key_type=EncryptionKeyType.SYMMETRIC,
243+
key_bytes=b"\00" * 32,
244+
)
245+
provider.add_master_key("KeyId")
246+
cache = aws_encryption_sdk.LocalCryptoMaterialsCache(capacity=10)
247+
ccmm = aws_encryption_sdk.CachingCryptoMaterialsManager(
248+
master_key_provider=provider, cache=cache, max_age=3600.0, max_messages_encrypted=5
249+
)
250+
plaintext = b"Yellow Submarine"
251+
252+
ciphertext, _ = forbid_encrypting_client.encrypt(source=plaintext, materials_manager=ccmm)
253+
ciphertext2, _ = required_encrypting_client.encrypt(source=plaintext, materials_manager=ccmm)
254+
with pytest.raises(ActionNotAllowedError) as excinfo:
255+
required_encrypting_client.encrypt(source=plaintext, materials_manager=ccmm)
256+
excinfo.match("Configuration conflict. Cannot encrypt due to .* requiring only committed messages")
257+

tox.ini

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,19 @@ commands = pytest --basetemp={envtmpdir} -l {posargs}
6363
[testenv]
6464
passenv =
6565
# Identifies AWS KMS key id to use in integration tests
66-
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID \
66+
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID, \
6767
# Identifies a second AWS KMS key id to use in integration tests
68-
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID_2 \
68+
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID_2, \
6969
# Identifies AWS KMS MRK key id to use in integration tests
70-
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_MRK_KEY_ID_1 \
70+
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_MRK_KEY_ID_1, \
7171
# Identifies a related AWS KMS MRK key id to use in integration tests
72-
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_MRK_KEY_ID_2 \
72+
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_MRK_KEY_ID_2, \
7373
# Pass through AWS credentials
74-
AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN \
74+
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, \
7575
# AWS Role access in CodeBuild is via the contaner URI
76-
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI \
76+
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI, \
7777
# Pass through AWS profile name (useful for local testing)
78-
AWS_PROFILE \
78+
AWS_PROFILE, \
7979
# Pass through custom pip config file settings
8080
PIP_CONFIG_FILE
8181
sitepackages = False

0 commit comments

Comments
 (0)