@@ -51,10 +51,12 @@ def test_metrics_hash_strips_email_domain() -> None:
5151
5252
5353def test_metrics_hash_str_hmac_key_coerced_to_bytes () -> None :
54- """A string hmac_key is coerced to bytes in-place before hashing."""
54+ """A string hmac_key is coerced to bytes and produces the correct HMAC-SHA256 digest."""
55+ # Expected: HMAC-SHA256(key=b"foo", msg=b"value") via hmac.new(b'foo', b'value', hashlib.sha256).hexdigest())
56+ expected = "40036668289b3e3257fd7653c09d3c0611d5f6e813b674c2b3984005e5736019"
5557 args = make_args (hmac_key = "foo" )
5658 result = metrics_hash (args , "value" )
57- assert isinstance ( result , str )
59+ assert result == expected
5860 assert args .hmac_key == b"foo"
5961
6062
@@ -67,9 +69,11 @@ def test_create_token_returns_four_tuple() -> None:
6769
6870
6971def test_create_token_expires_in_future () -> None :
70- """The expiry timestamp is strictly after the current time."""
71- _ , _ , expires , _ = create_token (make_args ())
72- assert expires > int (time .time ())
72+ """The expiry timestamp embedded in the token is after the current time."""
73+ args = make_args ()
74+ token , _ , _ , _ = create_token (args )
75+ decoded = tokenlib .parse_token (token , secret = args .secret )
76+ assert decoded ["expires" ] > int (time .time ())
7377
7478
7579def test_create_token_expires_approximately_correct () -> None :
0 commit comments