test: update all tests to include CSRF tokens
This commit is contained in:
parent
9e5773f52f
commit
f648422227
12 changed files with 105 additions and 26 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
from collections.abc import AsyncIterator
|
||||
|
||||
import pytest
|
||||
|
|
@ -18,3 +19,15 @@ async def client(settings: Settings) -> AsyncIterator[AsyncClient]:
|
|||
transport = ASGITransport(app=app)
|
||||
async with app.router.lifespan_context(app), AsyncClient(transport=transport, base_url=settings.issuer) as ac:
|
||||
yield ac
|
||||
|
||||
|
||||
async def get_csrf_token(client: AsyncClient) -> str:
|
||||
"""Get a CSRF token by visiting the login page.
|
||||
|
||||
Returns the token string. The session cookie is automatically stored
|
||||
in the client's cookie jar (httpx.AsyncClient persists cookies).
|
||||
"""
|
||||
resp = await client.get("/login")
|
||||
match = re.search(r'name="csrf-token" content="([^"]+)"', resp.text)
|
||||
assert match, "CSRF meta tag not found in page"
|
||||
return match.group(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue