Skip to content

Commit fbec254

Browse files
committed
hawk token test rev
1 parent 7d457e7 commit fbec254

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

docs/src/tools/make_hawk_token.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `make_hawk_token.py`
1+
# Documentation for `make_hawk_token.py`
22

33
## Summary
44

tools/hawk/make_hawk_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
valid_header_with_querystring.
88
99
The latter modifies the query string which changes the mac/nonce and
10-
potentially its values (in the Hawk header).
10+
potentially `ts` values (in the Hawk header).
1111
"""
1212

1313
import argparse

tools/hawk/test_make_hawk_token.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ def test_metrics_hash_strips_email_domain() -> None:
5151

5252

5353
def 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

6971
def 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

7579
def test_create_token_expires_approximately_correct() -> None:

0 commit comments

Comments
 (0)