test_verify_at_time.py
1 """Tests for time-pinned verification (fn-25.1).""" 2 3 import pytest 4 5 from auths import Auths, verify_at_time, verify_at_time_with_capability 6 7 8 class TestVerifyAtTimeFFI: 9 10 def test_invalid_rfc3339_raises_value_error(self): 11 with pytest.raises(ValueError) as exc_info: 12 verify_at_time("{}", "a" * 64, "not-a-date") 13 msg = str(exc_info.value) 14 assert "RFC 3339" in msg 15 assert "not-a-date" in msg 16 17 def test_timezone_naive_string_raises_with_hint(self): 18 with pytest.raises(ValueError) as exc_info: 19 verify_at_time("{}", "a" * 64, "2024-06-15 00:00:00") 20 msg = str(exc_info.value) 21 assert "RFC 3339" in msg 22 assert "2024-06-15 00:00:00" in msg 23 24 def test_future_timestamp_raises_value_error(self): 25 with pytest.raises(ValueError) as exc_info: 26 verify_at_time("{}", "a" * 64, "2099-01-01T00:00:00Z") 27 msg = str(exc_info.value) 28 assert "future" in msg.lower() 29 30 def test_valid_timestamp_with_invalid_attestation(self): 31 result = verify_at_time("{}", "a" * 64, "2024-06-15T00:00:00Z") 32 assert not result.valid 33 assert result.error is not None 34 35 def test_invalid_hex_raises_value_error(self): 36 with pytest.raises(ValueError) as exc_info: 37 verify_at_time("{}", "not-hex", "2024-06-15T00:00:00Z") 38 assert "hex" in str(exc_info.value).lower() 39 40 def test_wrong_key_length_raises_value_error(self): 41 with pytest.raises(ValueError) as exc_info: 42 verify_at_time("{}", "abcd", "2024-06-15T00:00:00Z") 43 assert "length" in str(exc_info.value).lower() 44 45 46 class TestVerifyAtTimeWithCapabilityFFI: 47 48 def test_invalid_timestamp_raises(self): 49 with pytest.raises(ValueError) as exc_info: 50 verify_at_time_with_capability("{}", "a" * 64, "bad", "sign") 51 assert "RFC 3339" in str(exc_info.value) 52 53 def test_valid_timestamp_invalid_attestation(self): 54 result = verify_at_time_with_capability( 55 "{}", "a" * 64, "2024-06-15T00:00:00Z", "sign" 56 ) 57 assert not result.valid 58 59 def test_future_timestamp_raises(self): 60 with pytest.raises(ValueError) as exc_info: 61 verify_at_time_with_capability( 62 "{}", "a" * 64, "2099-01-01T00:00:00Z", "sign" 63 ) 64 assert "future" in str(exc_info.value).lower() 65 66 67 class TestClientVerifyAtTime: 68 69 def test_verify_with_at_parameter(self): 70 auths = Auths() 71 result = auths.verify("{}", "a" * 64, at="2024-06-15T00:00:00Z") 72 assert not result.valid 73 74 def test_verify_with_at_and_capability(self): 75 auths = Auths() 76 result = auths.verify( 77 "{}", "a" * 64, 78 at="2024-06-15T00:00:00Z", 79 required_capability="sign", 80 ) 81 assert not result.valid 82 83 def test_verify_with_invalid_at_raises(self): 84 auths = Auths() 85 with pytest.raises(Exception): 86 auths.verify("{}", "a" * 64, at="not-a-date") 87 88 89 class TestImports: 90 91 def test_verify_at_time_importable_from_verify_module(self): 92 from auths.verify import verify_at_time as vat 93 assert vat is not None 94 95 def test_verify_at_time_with_capability_importable(self): 96 from auths.verify import verify_at_time_with_capability as vatc 97 assert vatc is not None 98 99 def test_importable_from_top_level(self): 100 from auths import verify_at_time, verify_at_time_with_capability 101 assert verify_at_time is not None 102 assert verify_at_time_with_capability is not None