@@ -52,7 +52,33 @@ def test_secure_auth_produces_verifiable_signature():
5252 signature_b64 = headers ["Authorization" ].split (":" , 1 )[1 ]
5353 signature = base64 .b64decode (signature_b64 )
5454 body_hash = hashlib .sha256 (body ).hexdigest ()
55- expected = f"/api/test?foo=bar|{ body_hash } |2024-02-20T18:00:00Z" .encode ("utf-8" )
55+ expected = f"/api/test|{ body_hash } |2024-02-20T18:00:00Z" .encode ("utf-8" )
56+ public_obj .verify (signature , expected , ec .ECDSA (hashes .SHA256 ()))
57+
58+
59+ def test_secure_auth_ignores_query_params_in_signature ():
60+ public_key , private_key , public_obj = _generate_keys ()
61+ fixed_time = dt .datetime (2024 , 2 , 20 , 18 , 0 , 0 , tzinfo = dt .timezone .utc )
62+ auth = SecureKeyAuth (
63+ public_key = public_key , private_key = private_key , clock = lambda : fixed_time
64+ )
65+ body = b""
66+ request = RequestData (
67+ method = "GET" ,
68+ url = "https://example.com/v1/env/folders/tree/item/?path=benchmark_jobs" ,
69+ path = "/v1/env/folders/tree/item/?path=benchmark_jobs" ,
70+ body = body ,
71+ )
72+ headers = auth .build_headers (request )
73+
74+ signature_b64 = headers ["Authorization" ].split (":" , 1 )[1 ]
75+ signature = base64 .b64decode (signature_b64 )
76+ body_hash = hashlib .sha256 (body ).hexdigest ()
77+ expected = (
78+ f"/v1/env/folders/tree/item/|{ body_hash } |2024-02-20T18:00:00Z" .encode (
79+ "utf-8"
80+ )
81+ )
5682 public_obj .verify (signature , expected , ec .ECDSA (hashes .SHA256 ()))
5783
5884
0 commit comments