-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into custom-auth-code-templates
- Loading branch information
Showing
43 changed files
with
11,357 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 23.12.1 | ||
rev: 24.1.1 | ||
hooks: | ||
- id: black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import pytest | ||
from pytest_httpx import HTTPXMock | ||
import httpx | ||
|
||
|
||
import httpx_auth | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_header_api_key_is_sent_in_x_api_key_by_default(httpx_mock: HTTPXMock): | ||
auth = httpx_auth.HeaderApiKey("my_provided_api_key") | ||
|
||
httpx_mock.add_response( | ||
url="https://authorized_only", | ||
method="GET", | ||
match_headers={"X-API-Key": "my_provided_api_key"}, | ||
) | ||
|
||
async with httpx.AsyncClient() as client: | ||
await client.get("https://authorized_only", auth=auth) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_query_api_key_is_sent_in_api_key_by_default(httpx_mock: HTTPXMock): | ||
auth = httpx_auth.QueryApiKey("my_provided_api_key") | ||
|
||
httpx_mock.add_response( | ||
url="https://authorized_only?api_key=my_provided_api_key", method="GET" | ||
) | ||
|
||
async with httpx.AsyncClient() as client: | ||
await client.get("https://authorized_only", auth=auth) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_header_api_key_can_be_sent_in_a_custom_field_name(httpx_mock: HTTPXMock): | ||
auth = httpx_auth.HeaderApiKey("my_provided_api_key", "X-API-HEADER-KEY") | ||
|
||
httpx_mock.add_response( | ||
url="https://authorized_only", | ||
method="GET", | ||
match_headers={"X-API-HEADER-KEY": "my_provided_api_key"}, | ||
) | ||
|
||
async with httpx.AsyncClient() as client: | ||
await client.get("https://authorized_only", auth=auth) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_query_api_key_can_be_sent_in_a_custom_field_name(httpx_mock: HTTPXMock): | ||
auth = httpx_auth.QueryApiKey("my_provided_api_key", "X-API-QUERY-KEY") | ||
|
||
httpx_mock.add_response( | ||
url="https://authorized_only?X-API-QUERY-KEY=my_provided_api_key", method="GET" | ||
) | ||
|
||
async with httpx.AsyncClient() as client: | ||
await client.get("https://authorized_only", auth=auth) |
Oops, something went wrong.