From c2630695a5bc94010352b4cf79768e49c90c0feb Mon Sep 17 00:00:00 2001 From: Chris Burr Date: Fri, 13 Dec 2024 15:38:27 +0100 Subject: [PATCH] fix(tests): enhance key comparison and error handling in credential tests --- diracx-core/tests/test_secrets.py | 10 +++++++++- diracx-core/tests/test_utils.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/diracx-core/tests/test_secrets.py b/diracx-core/tests/test_secrets.py index d6b95ea5..1518af3d 100644 --- a/diracx-core/tests/test_secrets.py +++ b/diracx-core/tests/test_secrets.py @@ -9,7 +9,15 @@ def compare_keys(key1, key2): """Compare two keys by checking their public keys.""" - assert key1.public_key() == key2.public_key() + key1_public = key1.public_key().public_bytes( + encoding=serialization.Encoding.PEM, + format=serialization.PublicFormat.SubjectPublicKeyInfo, + ) + key2_public = key2.public_key().public_bytes( + encoding=serialization.Encoding.PEM, + format=serialization.PublicFormat.SubjectPublicKeyInfo, + ) + assert key1_public == key2_public def test_token_signing_key(tmp_path): diff --git a/diracx-core/tests/test_utils.py b/diracx-core/tests/test_utils.py index aebd55ad..e1e3f683 100644 --- a/diracx-core/tests/test_utils.py +++ b/diracx-core/tests/test_utils.py @@ -139,7 +139,7 @@ def test_read_credentials_missing_file(tmp_path): def test_write_credentials_unavailable_path(): """Test that write_credentials raises error when it can't create path.""" wrong_path = Path("/wrong/path/file.txt") - with pytest.raises(PermissionError): + with pytest.raises((PermissionError, OSError)): write_credentials(TokenResponse(**TOKEN_RESPONSE_DICT), location=wrong_path)