11import base64
22import time
3- import pytest
43from unittest .mock import patch
54
65from aleph .toolkit .ecdsa import (
6+ create_auth_token ,
77 generate_key_pair ,
88 generate_key_pair_from_private_key ,
99 sign_message ,
10- verify_signature ,
11- create_auth_token ,
1210 verify_auth_token ,
11+ verify_signature ,
1312)
1413
1514
@@ -28,12 +27,14 @@ def test_generate_key_pair():
2827 assert len (public_key ) == 66
2928
3029 # Public key should start with 02 or 03 (compressed format)
31- assert public_key .startswith (('02' , '03' ))
30+ assert public_key .startswith (("02" , "03" ))
3231
3332
3433def test_generate_key_pair_from_private_key ():
3534 """Test key pair generation from existing private key."""
36- test_private_key = "646fa150ca94320b8eca3bd28d106703f3602dfb13b6b982cc17d17fd1182f85"
35+ test_private_key = (
36+ "646fa150ca94320b8eca3bd28d106703f3602dfb13b6b982cc17d17fd1182f85"
37+ )
3738
3839 private_key , public_key = generate_key_pair_from_private_key (test_private_key )
3940
@@ -43,7 +44,7 @@ def test_generate_key_pair_from_private_key():
4344 # Public key should be correctly derived
4445 assert isinstance (public_key , str )
4546 assert len (public_key ) == 66
46- assert public_key .startswith (('02' , '03' ))
47+ assert public_key .startswith (("02" , "03" ))
4748
4849
4950def test_sign_and_verify_message ():
@@ -121,7 +122,7 @@ def test_verify_auth_token_expired():
121122 # Mock time to create an old token
122123 old_timestamp = int (time .time ()) - 600 # 10 minutes ago
123124
124- with patch (' aleph.toolkit.ecdsa.time.time' , return_value = old_timestamp ):
125+ with patch (" aleph.toolkit.ecdsa.time.time" , return_value = old_timestamp ):
125126 token = create_auth_token (private_key )
126127
127128 # Should fail with default max_age (5 minutes)
@@ -140,7 +141,7 @@ def test_verify_auth_token_future_timestamp():
140141 # Mock time to create a future token
141142 future_timestamp = int (time .time ()) + 60 # 1 minute in future
142143
143- with patch (' aleph.toolkit.ecdsa.time.time' , return_value = future_timestamp ):
144+ with patch (" aleph.toolkit.ecdsa.time.time" , return_value = future_timestamp ):
144145 token = create_auth_token (private_key )
145146
146147 # Should pass as it uses abs() for time difference
@@ -184,8 +185,12 @@ def test_verify_signature_with_invalid_inputs():
184185def test_token_roundtrip_with_known_values ():
185186 """Test token creation and verification with known test values."""
186187 # Use known values for reproducible testing
187- test_private_key = "50b44756efbcb9266d974af8a8bcecb97d960fd8ddaadd31ecf2082c757fcaad"
188- test_public_key = "023d3b6f2e92e5d30b8d75291087051f6ef9425abbb626bebc3a5b358bce6007ee"
188+ test_private_key = (
189+ "50b44756efbcb9266d974af8a8bcecb97d960fd8ddaadd31ecf2082c757fcaad"
190+ )
191+ test_public_key = (
192+ "023d3b6f2e92e5d30b8d75291087051f6ef9425abbb626bebc3a5b358bce6007ee"
193+ )
189194
190195 # Create token
191196 token = create_auth_token (test_private_key )
@@ -197,4 +202,4 @@ def test_token_roundtrip_with_known_values():
197202 # Verify with wrong key fails
198203 _ , wrong_key = generate_key_pair ()
199204 is_valid_wrong = verify_auth_token (token , wrong_key )
200- assert is_valid_wrong is False
205+ assert is_valid_wrong is False
0 commit comments