mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-22 21:59:59 +00:00
## Problem `TYPE_CHECKING` is used inconsistently across Python tests. ## Summary of changes - Update `ruff`: 0.7.0 -> 0.11.2 - Enable TC (flake8-type-checking): https://docs.astral.sh/ruff/rules/#flake8-type-checking-tc - (auto)fix all new issues
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
import json
|
|
|
|
import pytest
|
|
from fixtures.neon_fixtures import NeonAuthBroker
|
|
from jwcrypto import jwk, jwt
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_auth_broker_happy(
|
|
static_auth_broker: NeonAuthBroker,
|
|
neon_authorize_jwk: jwk.JWK,
|
|
):
|
|
"""
|
|
Signs a JWT and uses it to authorize a query to local_proxy.
|
|
"""
|
|
|
|
token = jwt.JWT(
|
|
header={"kid": neon_authorize_jwk.key_id, "alg": "RS256"}, claims={"sub": "user1"}
|
|
)
|
|
token.make_signed_token(neon_authorize_jwk)
|
|
res = await static_auth_broker.query("foo", ["arg1"], user="anonymous", token=token.serialize())
|
|
|
|
# local proxy mock just echos back the request
|
|
# check that we forward the correct data
|
|
|
|
assert res["headers"]["authorization"] == f"Bearer {token.serialize()}", (
|
|
"JWT should be forwarded"
|
|
)
|
|
|
|
assert "anonymous" in res["headers"]["neon-connection-string"], (
|
|
"conn string should be forwarded"
|
|
)
|
|
|
|
assert json.loads(res["body"]) == {
|
|
"query": "foo",
|
|
"params": ["arg1"],
|
|
}, "Query body should be forwarded"
|