Skip to content

Account for update in vws-auth-tools #2164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/mock_vws/_database_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ def get_database_matching_client_keys(
"""
content_type = request_headers.get("Content-Type", "").split(";")[0]
auth_header = request_headers.get("Authorization")
content = request_body or b""
date = request_headers.get("Date", "")

for database in databases:
expected_authorization_header = authorization_header(
access_key=database.client_access_key,
secret_key=database.client_secret_key,
method=request_method,
content=content,
content=request_body,
content_type=content_type,
date=date,
request_path=request_path,
Expand Down Expand Up @@ -85,15 +84,14 @@ def get_database_matching_server_keys(
"""
content_type = request_headers.get("Content-Type", "").split(";")[0]
auth_header = request_headers.get("Authorization")
content = request_body or b""
date = request_headers.get("Date", "")

for database in databases:
expected_authorization_header = authorization_header(
access_key=database.server_access_key,
secret_key=database.server_secret_key,
method=request_method,
content=content,
content=request_body,
content_type=content_type,
date=date,
request_path=request_path,
Expand Down
36 changes: 12 additions & 24 deletions tests/mock_vws/test_date_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ def test_no_date_header(endpoint: Endpoint) -> None:
A `BAD_REQUEST` response is returned when no `Date` header is given.
"""
endpoint_headers = dict(endpoint.prepared_request.headers)
content = endpoint.prepared_request.body or b""
assert isinstance(content, bytes)

authorization_string = authorization_header(
access_key=endpoint.access_key,
secret_key=endpoint.secret_key,
method=str(endpoint.prepared_request.method),
content=content,
method=endpoint.prepared_request.method or "",
content=endpoint.prepared_request.body,
content_type=endpoint.auth_header_content_type,
date="",
request_path=endpoint.prepared_request.path_url,
Expand Down Expand Up @@ -112,14 +110,12 @@ def test_incorrect_date_format(endpoint: Endpoint) -> None:
date_incorrect_format = now.strftime("%a %b %d %H:%M:%S")

endpoint_headers = dict(endpoint.prepared_request.headers)
content = endpoint.prepared_request.body or b""
assert isinstance(content, bytes)

authorization_string = authorization_header(
access_key=endpoint.access_key,
secret_key=endpoint.secret_key,
method=str(endpoint.prepared_request.method),
content=content,
method=endpoint.prepared_request.method or "",
content=endpoint.prepared_request.body,
content_type=endpoint.auth_header_content_type,
date=date_incorrect_format,
request_path=endpoint.prepared_request.path_url,
Expand Down Expand Up @@ -185,14 +181,12 @@ def test_date_out_of_range_after(endpoint: Endpoint) -> None:
date = rfc_1123_date()

endpoint_headers = dict(endpoint.prepared_request.headers)
content = endpoint.prepared_request.body or b""
assert isinstance(content, bytes)

authorization_string = authorization_header(
access_key=endpoint.access_key,
secret_key=endpoint.secret_key,
method=str(endpoint.prepared_request.method),
content=content,
method=endpoint.prepared_request.method or "",
content=endpoint.prepared_request.body,
content_type=endpoint.auth_header_content_type,
date=date,
request_path=endpoint.prepared_request.path_url,
Expand Down Expand Up @@ -251,14 +245,12 @@ def test_date_out_of_range_before(endpoint: Endpoint) -> None:
date = rfc_1123_date()

endpoint_headers = dict(endpoint.prepared_request.headers)
content = endpoint.prepared_request.body or b""
assert isinstance(content, bytes)

authorization_string = authorization_header(
access_key=endpoint.access_key,
secret_key=endpoint.secret_key,
method=str(endpoint.prepared_request.method),
content=content,
method=endpoint.prepared_request.method or "",
content=endpoint.prepared_request.body,
content_type=endpoint.auth_header_content_type,
date=date,
request_path=endpoint.prepared_request.path_url,
Expand Down Expand Up @@ -316,14 +308,12 @@ def test_date_in_range_after(endpoint: Endpoint) -> None:
date = rfc_1123_date()

endpoint_headers = dict(endpoint.prepared_request.headers)
content = endpoint.prepared_request.body or b""
assert isinstance(content, bytes)

authorization_string = authorization_header(
access_key=endpoint.access_key,
secret_key=endpoint.secret_key,
method=str(endpoint.prepared_request.method),
content=content,
method=endpoint.prepared_request.method or "",
content=endpoint.prepared_request.body,
content_type=endpoint.auth_header_content_type,
date=date,
request_path=endpoint.prepared_request.path_url,
Expand Down Expand Up @@ -372,14 +362,12 @@ def test_date_in_range_before(endpoint: Endpoint) -> None:
date = rfc_1123_date()

endpoint_headers = dict(endpoint.prepared_request.headers)
content = endpoint.prepared_request.body or b""
assert isinstance(content, bytes)

authorization_string = authorization_header(
access_key=endpoint.access_key,
secret_key=endpoint.secret_key,
method=str(endpoint.prepared_request.method),
content=content,
method=endpoint.prepared_request.method or "",
content=endpoint.prepared_request.body,
content_type=endpoint.auth_header_content_type,
date=date,
request_path=endpoint.prepared_request.path_url,
Expand Down
4 changes: 2 additions & 2 deletions tests/mock_vws/test_invalid_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_invalid_json(endpoint: Endpoint) -> None:
authorization_string = authorization_header(
access_key=endpoint.access_key,
secret_key=endpoint.secret_key,
method=str(endpoint.prepared_request.method),
method=endpoint.prepared_request.method or "",
content=content,
content_type=endpoint.auth_header_content_type,
date=date,
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_invalid_json_with_skewed_time(endpoint: Endpoint) -> None:
authorization_string = authorization_header(
access_key=endpoint.access_key,
secret_key=endpoint.secret_key,
method=str(endpoint.prepared_request.method),
method=endpoint.prepared_request.method or "",
content=content,
content_type=endpoint.auth_header_content_type,
date=date,
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_vws/test_unexpected_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_does_not_take_data(endpoint: Endpoint) -> None:
authorization_string = authorization_header(
access_key=endpoint.access_key,
secret_key=endpoint.secret_key,
method=str(endpoint.prepared_request.method),
method=endpoint.prepared_request.method or "",
content=content,
content_type=content_type,
date=date,
Expand Down