mirror of
https://github.com/CyberMind-FR/secubox-deb.git
synced 2026-07-29 11:12:29 +00:00
- Add PendingStore (JSON+TTL) for in-progress TOTP enrollment secrets - Inject _users_api package loader (importlib) to side-step api/ name collision - Register _session_validator, _on_session_event, _revoke_sessions callbacks - POST /auth/login now branches: setup / mfa-challenge / totp-enroll / access - POST /auth/login/mfa: verifies TOTP code or backup code, issues full JWT - POST /auth/totp/enroll: generates secret, stores in PendingStore, returns URI - POST /auth/totp/confirm: verifies code, calls engine.enroll_totp, returns JWT - POST /auth/set-password: handles set-password scope and full-JWT change - Mount _login_router before auth_router so /auth/login override wins - Fix conftest sys.path order so secubox-auth/api takes priority for auth tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
"""Shared fixtures for secubox-auth integration tests."""
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
sys.path.insert(0, str(ROOT / "common"))
|
|
# secubox-users must be reachable for the engine/totp modules, but secubox-auth's
|
|
# own api/ package must take priority for `from api import …` in auth tests.
|
|
# Insert auth LAST so it lands at index 0 (highest priority).
|
|
sys.path.insert(0, str(ROOT / "packages" / "secubox-users"))
|
|
sys.path.insert(0, str(ROOT / "packages" / "secubox-auth"))
|
|
|
|
|
|
@pytest.fixture
|
|
def auth_data_dir(tmp_path: Path) -> Path:
|
|
"""Stand-in for /var/lib/secubox/auth/."""
|
|
d = tmp_path / "auth"
|
|
d.mkdir(exist_ok=True)
|
|
(d / "sessions.json").write_text("[]")
|
|
(d / "audit.log").write_text("")
|
|
return d
|
|
|
|
|
|
@pytest.fixture
|
|
def env_files(tmp_path: Path, monkeypatch) -> dict:
|
|
"""Set env vars so modules pick up tempdir paths."""
|
|
users = tmp_path / "users.json"
|
|
users.write_text(json.dumps({"version": 2, "users": [], "groups": []}))
|
|
monkeypatch.setenv("USERS_FILE", str(users))
|
|
monkeypatch.setenv("SECUBOX_AUTH_DATA_DIR", str(tmp_path / "auth"))
|
|
(tmp_path / "auth").mkdir(exist_ok=True)
|
|
return {"users": users, "data_dir": tmp_path / "auth"}
|