@@ -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+
0 commit comments