Skip to content

Commit

Permalink
Ensure the behavior of include_headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin-b committed Feb 4, 2024
1 parent 969d8bc commit f0ab969
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/aws_signature_v4/test_aws4auth_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,46 @@ async def test_aws_auth_excludes_x_amz_client_context_header(
)


@time_machine.travel("2018-10-11T15:05:05.663979+00:00", tick=False)
@pytest.mark.asyncio
async def test_aws_auth_allows_to_include_custom_and_default_forbidden_header(
httpx_mock: HTTPXMock,
):
auth = httpx_auth.AWS4Auth(
access_id="access_id",
secret_key="wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
region="us-east-1",
service="iam",
include_headers=[
"Host",
"content-type",
"date",
"cusTom",
"x-aMz-client-context",
"x-amz-*",
],
)

httpx_mock.add_response(
url="https://authorized_only",
method="POST",
match_headers={
"x-amz-content-sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"Authorization": "AWS4-HMAC-SHA256 Credential=access_id/20181011/us-east-1/iam/aws4_request, SignedHeaders=custom;host;x-amz-client-context;x-amz-content-sha256;x-amz-date, Signature=215c8030c2f238163ddfb291abcd9e5a02112a0db1363aa7cdb27ba1f646d987",
"x-amz-date": "20181011T150505Z",
"Custom": "Custom",
"x-amz-Client-Context": "Context",
},
)

async with httpx.AsyncClient() as client:
await client.post(
"https://authorized_only",
headers={"Custom": "Custom", "x-amz-Client-Context": "Context"},
auth=auth,
)


@time_machine.travel("2018-10-11T15:05:05.663979+00:00", tick=False)
@pytest.mark.asyncio
async def test_aws_auth_with_security_token_and_content_in_request(
Expand Down
39 changes: 39 additions & 0 deletions tests/aws_signature_v4/test_aws4auth_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,45 @@ def test_aws_auth_excludes_x_amz_client_context_header(
)


@time_machine.travel("2018-10-11T15:05:05.663979+00:00", tick=False)
def test_aws_auth_allows_to_include_custom_and_default_forbidden_header(
httpx_mock: HTTPXMock,
):
auth = httpx_auth.AWS4Auth(
access_id="access_id",
secret_key="wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
region="us-east-1",
service="iam",
include_headers=[
"Host",
"content-type",
"date",
"cusTom",
"x-aMz-client-context",
"x-amz-*",
],
)

httpx_mock.add_response(
url="https://authorized_only",
method="POST",
match_headers={
"x-amz-content-sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"Authorization": "AWS4-HMAC-SHA256 Credential=access_id/20181011/us-east-1/iam/aws4_request, SignedHeaders=custom;host;x-amz-client-context;x-amz-content-sha256;x-amz-date, Signature=215c8030c2f238163ddfb291abcd9e5a02112a0db1363aa7cdb27ba1f646d987",
"x-amz-date": "20181011T150505Z",
"Custom": "Custom",
"x-amz-Client-Context": "Context",
},
)

with httpx.Client() as client:
client.post(
"https://authorized_only",
headers={"Custom": "Custom", "x-amz-Client-Context": "Context"},
auth=auth,
)


@time_machine.travel("2018-10-11T15:05:05.663979+00:00", tick=False)
def test_aws_auth_with_security_token_and_content_in_request(httpx_mock: HTTPXMock):
auth = httpx_auth.AWS4Auth(
Expand Down

0 comments on commit f0ab969

Please sign in to comment.