@@ -225,3 +225,59 @@ 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_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"""
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 .REQUIRE_ENCRYPT_REQUIRE_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+ _ , _ = forbid_encrypting_client .encrypt (source = plaintext , materials_manager = ccmm )
253+ with pytest .raises (ActionNotAllowedError ) as excinfo :
254+ required_encrypting_client .encrypt (source = plaintext , materials_manager = ccmm )
255+ excinfo .match ("Configuration conflict. Cannot encrypt due to .* requiring only committed messages" )
256+
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+ _ , _ = 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