-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor/feat: add
scheme_name
to Security() and refactor security …
…/ binders (#40)
- Loading branch information
Showing
60 changed files
with
567 additions
and
400 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,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "xpresso" | ||
version = "0.9.4" | ||
version = "0.10.0" | ||
description = "A developer centric, performant Python web framework" | ||
authors = ["Adrian Garcia Badaracco <[email protected]>"] | ||
readme = "README.md" | ||
|
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,80 @@ | ||
from typing import Any, Dict | ||
|
||
from xpresso import App, Path, Security | ||
from xpresso.security import APIKeyHeader | ||
from xpresso.testclient import TestClient | ||
from xpresso.typing import Annotated | ||
|
||
|
||
def test_duplicate_scheme_name_resolution() -> None: | ||
|
||
api_key1 = APIKeyHeader(name="key1") | ||
api_key2 = APIKeyHeader(name="key2") | ||
|
||
def endpoint( | ||
key1: Annotated[str, Security(api_key1)], | ||
key2: Annotated[str, Security(api_key2)], | ||
) -> None: | ||
... | ||
|
||
app = App([Path("/", get=endpoint)]) | ||
|
||
openapi_schema: Dict[str, Any] = { | ||
"openapi": "3.0.3", | ||
"info": {"title": "API", "version": "0.1.0"}, | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"responses": {"200": {"description": "Successful Response"}}, | ||
"security": [{"APIKeyHeader_1": []}, {"APIKeyHeader_2": []}], | ||
} | ||
} | ||
}, | ||
"components": { | ||
"securitySchemes": { | ||
"APIKeyHeader_1": {"type": "apiKey", "name": "key1", "in": "header"}, | ||
"APIKeyHeader_2": {"type": "apiKey", "name": "key2", "in": "header"}, | ||
} | ||
}, | ||
} | ||
|
||
client = TestClient(app) | ||
|
||
response = client.get("/openapi.json") | ||
assert response.status_code == 200, response.text | ||
assert response.json() == openapi_schema, response.json() | ||
|
||
|
||
def test_scheme_name() -> None: | ||
api_key = APIKeyHeader(name="key1") | ||
|
||
def endpoint( | ||
key: Annotated[str, Security(api_key, scheme_name="foobarbaz")], | ||
) -> None: | ||
... | ||
|
||
app = App([Path("/", get=endpoint)]) | ||
|
||
openapi_schema: Dict[str, Any] = { | ||
"openapi": "3.0.3", | ||
"info": {"title": "API", "version": "0.1.0"}, | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"responses": {"200": {"description": "Successful Response"}}, | ||
"security": [{"foobarbaz": []}], | ||
} | ||
} | ||
}, | ||
"components": { | ||
"securitySchemes": { | ||
"foobarbaz": {"type": "apiKey", "name": "key1", "in": "header"} | ||
} | ||
}, | ||
} | ||
|
||
client = TestClient(app) | ||
|
||
response = client.get("/openapi.json") | ||
assert response.status_code == 200, response.text | ||
assert response.json() == openapi_schema |
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
File renamed without changes.
File renamed without changes.
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
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
File renamed without changes.
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
Oops, something went wrong.