mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 12:30:13 +03:00
tests: sign class-scoped client tokens with the default JWT secret
Since aef337e86 the config loader generates a random JWT secret even without a main config file, so the class-scoped client/authorized_client fixtures signed their tokens with a key that the autouse run_around_tests fixture would immediately replace with the default one for every test function. Every controller API test using those fixtures was failing with 401 (BadSignature). Sign both fixtures explicitly with DEFAULT_JWT_SECRET_KEY to match the secret enforced at request time.
This commit is contained in:
parent
7e8c515a3c
commit
38742ad4b6
@ -155,7 +155,10 @@ def unauthorized_client(base_client: AsyncClient, test_user: User) -> AsyncClien
|
||||
@pytest_asyncio.fixture(loop_scope="class", scope="class")
|
||||
def authorized_client(base_client: AsyncClient, test_user: User) -> AsyncClient:
|
||||
|
||||
access_token = auth_service.create_access_token(test_user.username)
|
||||
# Sign with the default secret key: the class-scoped token must stay valid
|
||||
# across every test, but "run_around_tests" resets the config and forces
|
||||
# jwt_secret_key back to the default for each test function.
|
||||
access_token = auth_service.create_access_token(test_user.username, secret_key=DEFAULT_JWT_SECRET_KEY)
|
||||
base_client.headers = {
|
||||
**base_client.headers,
|
||||
"Authorization": f"Bearer {access_token}",
|
||||
@ -168,7 +171,9 @@ async def client(base_client: AsyncClient) -> AsyncClient:
|
||||
|
||||
# The super admin is automatically created when the users table is created
|
||||
# this account that can access all endpoints without restrictions.
|
||||
access_token = auth_service.create_access_token("admin")
|
||||
# Sign with the default secret key so the token matches the one enforced
|
||||
# by "run_around_tests" when the config is reset for each test function.
|
||||
access_token = auth_service.create_access_token("admin", secret_key=DEFAULT_JWT_SECRET_KEY)
|
||||
base_client.headers = {
|
||||
**base_client.headers,
|
||||
"Authorization": f"Bearer {access_token}",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user