Skip to content

Commit 5a1bc29

Browse files
committed
chore: bump to Canaille 0.0.75
1 parent 88e7551 commit 5a1bc29

File tree

4 files changed

+642
-628
lines changed

4 files changed

+642
-628
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
Versions follow [Semantic Versioning](https://semver.org/>) (<major>.<minor>.<patch>).
99

10+
## [0.2.1] - Unreleased
11+
12+
### Fixed
13+
14+
- Support for Canaille 0.0.75.
15+
1016
## [0.2.0] - 2025-04-24
1117

1218
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ documentation = "https://pytest-iam.readthedocs.io/en/latest/"
3131

3232
requires-python = ">=3.10"
3333
dependencies = [
34-
"canaille[oidc]>=0.0.74",
34+
"canaille[oidc]>=0.0.75",
3535
"portpicker>=1.6.0",
3636
"pytest>=7.0.0",
3737
"faker>=21.0.0",

pytest_iam/__init__.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
import pytest
1212
from canaille import create_app
1313
from canaille.app import models
14+
from canaille.app.session import SessionObject
1415
from canaille.backends import Backend
1516
from canaille.core.models import Group
1617
from canaille.core.models import User
1718
from canaille.core.populate import fake_groups
1819
from canaille.core.populate import fake_users
1920
from canaille.oidc.basemodels import Token
20-
from canaille.oidc.installation import generate_keypair
2121
from flask import Flask
2222
from flask import g
23+
from joserfc.jwk import JWKRegistry
2324
from werkzeug.test import Client
2425

2526

@@ -55,25 +56,21 @@ def __init__(self, app: Flask, port: int, backend: Backend, logging: bool = Fals
5556
)
5657
self.models = models
5758
self.logged_user = None
58-
self.login_datetime = None
5959

6060
@self.app.before_request
61-
def logged_user():
61+
def login():
6262
if self.logged_user:
63-
g.user = self.logged_user
64-
else:
65-
try:
66-
del g.user
67-
except AttributeError:
68-
pass
69-
70-
if self.login_datetime:
71-
g.last_login_datetime = self.login_datetime
72-
else:
73-
try:
74-
del g.last_login_datetime
75-
except AttributeError:
76-
pass
63+
now = datetime.datetime.now(datetime.timezone.utc)
64+
g.session = SessionObject(
65+
user=self.logged_user, last_login_datetime=now
66+
)
67+
68+
@self.app.after_request
69+
def logout(response):
70+
if self.logged_user:
71+
g.session = None
72+
73+
return response
7774

7875
def _make_request_handler(self):
7976
server = self
@@ -144,12 +141,10 @@ def login(self, user: User):
144141
This allows to skip the connection screen.
145142
"""
146143
self.logged_user = user
147-
self.login_datetime = datetime.datetime.now(datetime.timezone.utc)
148144

149145
def logout(self):
150146
"""Close the current user session if existing."""
151147
self.logged_user = None
152-
self.login_datetime = None
153148

154149
def consent(self, user: User, client: Client | None = None):
155150
"""Make a user consent to share data with OIDC clients.
@@ -188,13 +183,17 @@ def iam_server_port():
188183
@pytest.fixture(scope="session")
189184
def iam_configuration(tmp_path_factory, iam_server_port) -> dict[str, Any]:
190185
"""Fixture for editing the configuration of :meth:`~pytest_iam.iam_server`."""
191-
private_key, public_key = generate_keypair()
192186
os.environ["AUTHLIB_INSECURE_TRANSPORT"] = "1"
187+
188+
jwk = JWKRegistry.generate_key("RSA", 1024)
189+
jwk.ensure_kid()
190+
193191
return {
194192
"TESTING": True,
195193
"ENV_FILE": None,
196194
"SECRET_KEY": str(uuid.uuid4()),
197195
"WTF_CSRF_ENABLED": False,
196+
"PREFERRED_URL_SCHEME": "http",
198197
"SERVER_NAME": f"localhost:{iam_server_port}",
199198
"CANAILLE": {
200199
"ENABLE_REGISTRATION": True,
@@ -222,10 +221,7 @@ def iam_configuration(tmp_path_factory, iam_server_port) -> dict[str, Any]:
222221
},
223222
"CANAILLE_OIDC": {
224223
"DYNAMIC_CLIENT_REGISTRATION_OPEN": True,
225-
"JWT": {
226-
"PUBLIC_KEY": public_key,
227-
"PRIVATE_KEY": private_key,
228-
},
224+
"ACTIVE_JWKS": [jwk.as_dict()],
229225
},
230226
}
231227

0 commit comments

Comments
 (0)