@@ -227,9 +227,9 @@ def test_encrypt_with_uncommitting_algorithm_require_decrypt():
227227 excinfo .match ("Configuration conflict. Cannot decrypt due to .* requiring only committed messages" )
228228
229229
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. """
230+ def test_encrypt_with_require_policy_fail_when_retrieving_invalid_cmm_materials ():
231+ """Tests that when a client with a require policy shares a cache with a client with a forbid policy
232+ an error gets thrown due to invalid materials retrieved from cmm """
233233 forbid_encrypting_client = aws_encryption_sdk .EncryptionSDKClient (
234234 commitment_policy = CommitmentPolicy .FORBID_ENCRYPT_ALLOW_DECRYPT
235235 )
@@ -254,3 +254,30 @@ def test_encrypt_with_different_kc_clients_sharing_materials_yield_error():
254254 required_encrypting_client .encrypt (source = plaintext , materials_manager = ccmm )
255255 excinfo .match ("Configuration conflict. Cannot encrypt due to .* requiring only committed messages" )
256256
257+
258+ def test_encrypt_with_forbid_policy_fail_when_retrieving_invalid_cmm_materials ():
259+ """Tests that when a client with a forbid policy shares a cache with a client with a require policy
260+ an error gets thrown due to invalid materials retrieved from cmm"""
261+ forbid_encrypting_client = aws_encryption_sdk .EncryptionSDKClient (
262+ commitment_policy = CommitmentPolicy .FORBID_ENCRYPT_ALLOW_DECRYPT
263+ )
264+ required_encrypting_client = aws_encryption_sdk .EncryptionSDKClient (
265+ commitment_policy = CommitmentPolicy .REQUIRE_ENCRYPT_REQUIRE_DECRYPT
266+ )
267+
268+ provider = StaticRawMasterKeyProvider (
269+ wrapping_algorithm = WrappingAlgorithm .AES_256_GCM_IV12_TAG16_NO_PADDING ,
270+ encryption_key_type = EncryptionKeyType .SYMMETRIC ,
271+ key_bytes = b"\00 " * 32 ,
272+ )
273+ provider .add_master_key ("KeyId" )
274+ cache = aws_encryption_sdk .LocalCryptoMaterialsCache (capacity = 10 )
275+ ccmm = aws_encryption_sdk .CachingCryptoMaterialsManager (
276+ master_key_provider = provider , cache = cache , max_age = 3600.0 , max_messages_encrypted = 5
277+ )
278+ plaintext = b"Yellow Submarine"
279+
280+ ciphertext , _ = required_encrypting_client .encrypt (source = plaintext , materials_manager = ccmm )
281+ with pytest .raises (ActionNotAllowedError ) as excinfo :
282+ forbid_encrypting_client .encrypt (source = plaintext , materials_manager = ccmm )
283+ excinfo .match ("Configuration conflict. Cannot encrypt due to .* requiring only non-committed messages." )
0 commit comments