Skip to content

Commit

Permalink
Asserting error messages and _encrypted_data_with_faulty_key_algo
Browse files Browse the repository at this point in the history
  • Loading branch information
chadgates committed May 2, 2024
1 parent 0d6765a commit 5a29efb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pyas2lib/tests/test_cms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
).dump()


def encrypted_data_with_faulty_key_algo():
def _encrypted_data_with_faulty_key_algo():
with open(os.path.join(TEST_DIR, "cert_test_public.pem"), "rb") as fp:
encrypt_cert = asymmetric.load_certificate(fp.read())
enc_alg_list = "rc4_128_cbc".split("_")
Expand Down Expand Up @@ -180,10 +180,15 @@ def test_encryption():
cms.decrypt_message(encrypted_data, decrypt_key)

# Test faulty key encryption algorithm
with pytest.raises(AS2Exception):
with pytest.raises(
AS2Exception, match="Unsupported Key Encryption Scheme: des_64_cbc"
):
cms.encrypt_message(b"data", "rc2_128_cbc", encrypt_cert, "des_64_cbc")

# Test unsupported key encryption algorithm
encrypted_data = encrypted_data_with_faulty_key_algo()
with pytest.raises(AS2Exception):
encrypted_data = _encrypted_data_with_faulty_key_algo()
with pytest.raises(
AS2Exception,
match="Failed to decrypt the payload: Could not extract decryption key.",
):
cms.decrypt_message(encrypted_data, decrypt_key)

0 comments on commit 5a29efb

Please sign in to comment.