Skip to content

Commit e67ba88

Browse files
committed
Update dependencies
1 parent fa16540 commit e67ba88

File tree

4 files changed

+168
-115
lines changed

4 files changed

+168
-115
lines changed

pyproject.toml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ exclude = ["docs", "tests"]
6565

6666
[project.optional-dependencies]
6767
server = [
68-
"fastapi>=0.128,<0.130",
69-
"uvicorn~=0.40.0",
68+
"fastapi>=0.129",
69+
"uvicorn~=0.41.0",
7070
"starlette-exporter~=0.23.0",
7171
"asgi-correlation-id~=4.3.4",
7272
"pyjwt~=2.11.0",
7373
"itsdangerous~=2.2.0",
7474
"python-multipart~=0.0.20",
75-
"python-keycloak~=7.0.3",
75+
"python-keycloak>=7.0.3,<7.2.0",
7676
]
7777
consumer = [
7878
"faststream[kafka,cli]~=0.6.6",
7979
"cramjam~=2.11.0",
8080
]
8181
http2kafka = [
82-
"fastapi>=0.128,<0.130",
83-
"uvicorn~=0.40.0",
82+
"fastapi>=0.129",
83+
"uvicorn~=0.41.0",
8484
"starlette-exporter~=0.23.0",
8585
"asgi-correlation-id~=4.3.4",
8686
"faststream[kafka,cli]~=0.6.5",
@@ -133,7 +133,7 @@ docs = [
133133
"towncrier~=25.8.0",
134134
"sphinx-issues~=5.0.1",
135135
"sphinx-design~=0.7.0",
136-
"sphinx-favicon~=1.0.1",
136+
"sphinx-favicon~=1.1.0",
137137
"sphinx-last-updated-by-git~=0.3.8",
138138
# uncomment after https://github.com/zqmillet/sphinx-plantuml/pull/4
139139
# "sphinx-plantuml~=1.0.0",
@@ -150,10 +150,13 @@ markers = [
150150
"consumer: tests for consumer (require running database and kafka)",
151151
"http2kafka: tests for consumer (require running database and kafka)",
152152
"db: tests for db structure and migrations",
153-
"lineage: tests for lineage endpoints (require running database)"
153+
"lineage: tests for lineage endpoints (require running database)",
154154
]
155155
asyncio_default_fixture_loop_scope = "session"
156156
asyncio_default_test_loop_scope = "session"
157+
filterwarnings = [
158+
"ignore:Module already imported so cannot be rewritten:pytest.PytestAssertRewriteWarning",
159+
]
157160

158161
[tool.coverage.run]
159162
source_pkgs = ["data_rentgen"]

tests/test_server/fixtures/keycloak.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import base64
12
import json
3+
import secrets
24
import time
35
from base64 import b64encode
46

@@ -194,3 +196,37 @@ def mock_keycloak_logout_bad_request(server_app_settings, respx_mock):
194196
status_code=400,
195197
content_type="application/json",
196198
)
199+
200+
201+
@pytest.fixture
202+
def mock_keycloak_certs(server_app_settings, rsa_keys, respx_mock):
203+
keycloak_settings = KeycloakSettings.model_validate(server_app_settings.auth.keycloak)
204+
server_url = keycloak_settings.server_url
205+
realm_name = keycloak_settings.realm_name
206+
realm_url = f"{server_url}/realms/{realm_name}"
207+
openid_url = f"{realm_url}/protocol/openid-connect"
208+
209+
def encode_number_base64(n: int):
210+
return base64.b64encode(n.to_bytes((n.bit_length() + 7) // 8, byteorder="big")).decode("utf-8")
211+
212+
# return public key in Keycloak JWK format
213+
# https://github.com/marcospereirampj/python-keycloak/pull/704/changes
214+
public_key = rsa_keys["public_key"]
215+
payload = {
216+
"keys": [
217+
{
218+
"kid": secrets.token_hex(16),
219+
"kty": "RSA",
220+
"alg": "RS256",
221+
"use": "sig",
222+
"n": encode_number_base64(public_key.public_numbers().n),
223+
"e": encode_number_base64(public_key.public_numbers().e),
224+
},
225+
]
226+
}
227+
228+
respx_mock.post(f"{openid_url}/certs").respond(
229+
status_code=200,
230+
json=payload,
231+
content_type="application/json",
232+
)

tests/test_server/test_auth/test_keycloak_auth.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ async def test_keycloak_auth(
6868
create_session_cookie,
6969
mock_keycloak_well_known,
7070
mock_keycloak_realm,
71+
mock_keycloak_certs,
7172
):
7273
session_cookie = create_session_cookie(user)
7374
headers = {
@@ -103,6 +104,7 @@ async def test_keycloak_auth_refresh_access_token(
103104
create_session_cookie,
104105
mock_keycloak_well_known,
105106
mock_keycloak_realm,
107+
mock_keycloak_certs,
106108
mock_keycloak_token_refresh,
107109
):
108110
session_cookie = create_session_cookie(user, expire_in_msec=-100000000) # expired access token
@@ -168,6 +170,7 @@ async def test_keycloak_auth_logout(
168170
create_session_cookie,
169171
mock_keycloak_well_known,
170172
mock_keycloak_realm,
173+
mock_keycloak_certs,
171174
mock_keycloak_token_refresh,
172175
mock_keycloak_logout,
173176
):
@@ -218,6 +221,7 @@ async def test_keycloak_auth_logout_bad_request(
218221
create_session_cookie,
219222
mock_keycloak_well_known,
220223
mock_keycloak_realm,
224+
mock_keycloak_certs,
221225
mock_keycloak_token_refresh,
222226
mock_keycloak_logout_bad_request,
223227
):

0 commit comments

Comments
 (0)