-
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add tests for Swagger & RapiDoc with CSRF
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 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
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,39 @@ | ||
from litestar import Litestar | ||
from litestar.config.csrf import CSRFConfig | ||
from litestar.openapi.config import OpenAPIConfig | ||
from litestar.openapi.plugins import RapidocRenderPlugin, SwaggerRenderPlugin | ||
from litestar.testing import TestClient | ||
|
||
|
||
def test_rapidoc_csrf() -> None: | ||
app = Litestar( | ||
csrf_config=CSRFConfig(secret="litestar"), | ||
openapi_config=OpenAPIConfig( | ||
title="Litestar Example", | ||
version="0.0.1", | ||
render_plugins=[RapidocRenderPlugin()], | ||
), | ||
) | ||
|
||
with TestClient(app=app) as client: | ||
resp = client.get("/schema/rapidoc") | ||
assert resp.status_code == 200 | ||
assert resp.headers["content-type"] == "text/html; charset=utf-8" | ||
assert ".addEventListener('before-try'," in resp.text | ||
|
||
|
||
def test_swagger_ui_csrf() -> None: | ||
app = Litestar( | ||
csrf_config=CSRFConfig(secret="litestar"), | ||
openapi_config=OpenAPIConfig( | ||
title="Litestar Example", | ||
version="0.0.1", | ||
render_plugins=[SwaggerRenderPlugin()], | ||
), | ||
) | ||
|
||
with TestClient(app=app) as client: | ||
resp = client.get("/schema/swagger") | ||
assert resp.status_code == 200 | ||
assert resp.headers["content-type"] == "text/html; charset=utf-8" | ||
assert "requestInterceptor:" in resp.text |