File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def authorization_header(
2626 access_key : str ,
2727 secret_key : str ,
2828 method : str ,
29- content : bytes ,
29+ content : str | bytes | None ,
3030 content_type : str ,
3131 date : str ,
3232 request_path : str ,
@@ -59,6 +59,13 @@ def authorization_header(
5959 """
6060 # Ignore a warning that MD5 is insecure - VWS requires it.
6161 hashed = hashlib .md5 () # noqa: S324
62+
63+ if content is None :
64+ content = b""
65+
66+ if isinstance (content , str ):
67+ content = content .encode (encoding = "utf-8" )
68+
6269 hashed .update (content )
6370 content_md5_hex = hashed .hexdigest ()
6471
Original file line number Diff line number Diff line change 33import datetime
44from zoneinfo import ZoneInfo
55
6+ import pytest
67import vws_auth_tools
78from freezegun import freeze_time
89
@@ -36,7 +37,8 @@ def test_rfc_1123_date() -> None:
3637 assert result == "Thu, 05 Feb 2015 14:55:12 GMT"
3738
3839
39- def test_authorization_header () -> None :
40+ @pytest .mark .parametrize ("content" , [b"some_bytes" , "some_bytes" ])
41+ def test_authorization_header (content : bytes | str ) -> None :
4042 """The Authorization header is constructed as documented.
4143
4244 This example has been run on known-working code and so any refactor should
@@ -46,7 +48,6 @@ def test_authorization_header() -> None:
4648 # Ignore "Possible hardcoded password" as it is appropriate here.
4749 secret_key = "my_secret_key" # noqa: S105
4850 method = "HTTPMETHOD"
49- content = b"some_bytes"
5051 content_type = "some/content/type"
5152 date = "some_date_string"
5253 request_path = "/foo"
You can’t perform that action at this time.
0 commit comments