-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtest_api_key_utils.py
31 lines (22 loc) · 1.31 KB
/
test_api_key_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pytest
from cryptography.hazmat.primitives.asymmetric import ec, ed25519
from cdp.api_key_utils import _parse_private_key
def test_parse_private_key_pem_ec(dummy_key_factory):
"""Test that a PEM-encoded ECDSA key is parsed correctly using a dummy key from the factory."""
dummy_key = dummy_key_factory("ecdsa")
parsed_key = _parse_private_key(dummy_key)
assert isinstance(parsed_key, ec.EllipticCurvePrivateKey)
def test_parse_private_key_ed25519_32(dummy_key_factory):
"""Test that a base64-encoded 32-byte Ed25519 key is parsed correctly using a dummy key from the factory."""
dummy_key = dummy_key_factory("ed25519-32")
parsed_key = _parse_private_key(dummy_key)
assert isinstance(parsed_key, ed25519.Ed25519PrivateKey)
def test_parse_private_key_ed25519_64(dummy_key_factory):
"""Test that a base64-encoded 64-byte input is parsed correctly by taking the first 32 bytes using a dummy key from the factory."""
dummy_key = dummy_key_factory("ed25519-64")
parsed_key = _parse_private_key(dummy_key)
assert isinstance(parsed_key, ed25519.Ed25519PrivateKey)
def test_parse_private_key_invalid():
"""Test that an invalid key string raises a ValueError."""
with pytest.raises(ValueError, match="Could not parse the private key"):
_parse_private_key("invalid_key")