@@ -57,7 +57,16 @@ def token_payload() -> dict[str, Any]:
5757
5858
5959def make_key () -> dict [str , Any ]:
60- """Generate a key pair for testing purposes."""
60+ """Generate a key pair for testing purposes.
61+
62+ Create an RSA test key pair and return the private key, public key, and key identifier.
63+
64+ Returns:
65+ dict: A dictionary with the following entries:
66+ - "private_key": the generated private JsonWebKey instance.
67+ - "public_key": the corresponding public JsonWebKey instance.
68+ - "kid": the key identifier (thumbprint) as a string.
69+ """
6170 key = JsonWebKey .generate_key ("RSA" , 2048 , is_private = True )
6271 return {
6372 "private_key" : key ,
@@ -79,8 +88,10 @@ def another_single_key_set() -> list[dict[str, Any]]:
7988 Create a single-key JWK set using a newly generated RSA key.
8089
8190 Returns:
82- list[dict[str, Any]]: A list containing one key dict with keys
83- `private_key`, `public_key`, and `kid`.
91+ list[dict[str, Any]]: A list containing one dict with keys:
92+ - `private_key`: the generated private JsonWebKey
93+ - `public_key`: the corresponding public JsonWebKey
94+ - `kid`: the key identifier (thumbprint)
8495 """
8596 return [make_key ()]
8697
@@ -114,7 +125,11 @@ def valid_token(
114125
115126@pytest .fixture (autouse = True )
116127def clear_jwk_cache () -> Generator :
117- """Clear the global JWK cache before each test."""
128+ """Clear the global JWK cache before each test.
129+
130+ This autouse fixture ensures the module-level `_jwk_cache` is emptied at
131+ setup and teardown to prevent cross-test interference.
132+ """
118133 _jwk_cache .clear ()
119134 yield
120135 _jwk_cache .clear ()
@@ -497,6 +512,9 @@ def no_user_id_token(
497512 `single_key_set`; the supplied `token_payload` is modified in-place to
498513 remove `user_id`.
499514
515+ Parameters:
516+ token_payload (dict): Payload to encode; will be mutated to remove `user_id`.
517+
500518 Returns:
501519 jwt (str): Encoded JWT as a string that does not contain the `user_id` claim.
502520 """
@@ -637,7 +655,11 @@ async def test_custom_claims(
637655 mocked_signing_keys_server : Any ,
638656 custom_claims_token : str ,
639657) -> None :
640- """Test with a token that has custom claims."""
658+ """Test with a token that has custom claims.
659+
660+ Asserts the returned auth tuple matches the expected user id, username,
661+ skip flag, and original token.
662+ """
641663 _ = mocked_signing_keys_server
642664
643665 dependency = JwkTokenAuthDependency (custom_claims_configuration )
@@ -650,7 +672,15 @@ async def test_custom_claims(
650672
651673@pytest .fixture
652674def token_header_256_1 (multi_key_set : list [dict [str , Any ]]) -> dict [str , Any ]:
653- """A sample token header for RS256 using multi_key_set."""
675+ """A sample token header for RS256 using multi_key_set.
676+
677+ Parameters:
678+ multi_key_set (list[dict[str, Any]]): List of JWK dictionaries; the
679+ header's `kid` is taken from multi_key_set[0]["kid"].
680+
681+ Returns:
682+ dict[str, Any]: JWT header containing "alg", "typ", and "kid".
683+ """
654684 return {"alg" : "RS256" , "typ" : "JWT" , "kid" : multi_key_set [0 ]["kid" ]}
655685
656686
@@ -727,7 +757,7 @@ def multi_key_set() -> list[dict[str, Any]]:
727757 by tests (e.g., `private_key`, `public_key`, and `kid`).
728758
729759 Returns:
730- key_set ( list[dict]) : A list of three signing key dictionaries.
760+ list[dict[str, Any]] : A list of three signing key dictionaries.
731761 """
732762 return [make_key (), make_key (), make_key ()]
733763
0 commit comments