fix(auth): startup() no longer clobbers session callback; document per-dir test invocation (ref #120)

- Remove set_session_callback(_handle_session_event) from startup() — it was
  overwriting the Task 13 _on_session_event registration (which uses jwt.jti)
  with the legacy handler (which used secrets.token_hex(8)), breaking jti-keyed
  session lookup in _session_validator.
- Fix comment on module-load set_session_callback registration (line 167).
- Add pytest.ini at worktree root: documents the api/ vs api/ namespace collision
  that prevents combined cross-dir collection; enforces per-directory test runs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
CyberMind-FR 2026-05-13 09:18:47 +02:00
parent 92e22cd48d
commit a8abe9737b
2 changed files with 18 additions and 4 deletions

View File

@ -163,7 +163,7 @@ def _revoke_sessions(username: str) -> int:
set_session_validator(_session_validator)
# set_session_callback already called in startup(); _on_session_event replaces it.
# Module-load registration so secubox_core.auth fires our handler from the first request.
set_session_callback(_on_session_event)
_users_engine.set_revoke_callback(_revoke_sessions)
_users_engine.set_audit_callback(lambda evt, user, d: _append_audit(evt, user, d))
@ -528,11 +528,9 @@ def _handle_session_event(event: str, username: str, details: dict):
@app.on_event("startup")
async def startup():
"""Start background cleanup and register session callback."""
"""Start background cleanup task."""
global _cleanup_task
_cleanup_task = asyncio.create_task(_periodic_cleanup())
# Register callback for login events
set_session_callback(_handle_session_event)
@app.on_event("shutdown")

16
pytest.ini Normal file
View File

@ -0,0 +1,16 @@
[pytest]
# NOTE: Combined test collection across all three directories fails because
# packages/secubox-users/api/ and packages/secubox-auth/api/ are both named
# "api" on sys.path — whichever is added first shadows the other.
# Structural fix (renaming the packages) is deferred to a dedicated cleanup PR.
#
# ALWAYS run tests per-directory:
# python3 -m pytest common/secubox_core/tests -q # 18 tests
# python3 -m pytest packages/secubox-users/tests -q # 44 tests
# python3 -m pytest packages/secubox-auth/tests -q # 8 tests
#
# DO NOT run: python3 -m pytest common/ packages/ -q (api/ collision)
testpaths =
common/secubox_core/tests
packages/secubox-users/tests
packages/secubox-auth/tests