test(ariadne): cover account rotation routes
This commit is contained in:
parent
8fec20e816
commit
a8a9f04c44
@ -137,3 +137,60 @@ def test_firefly_reset_handles_find_user_error(monkeypatch) -> None:
|
||||
headers={"Authorization": "Bearer token"},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
def test_firefly_reset_uses_default_mailu_email(monkeypatch) -> None:
|
||||
ctx = AuthContext(username="alice", email="", groups=["dev"], claims={})
|
||||
client = _client(monkeypatch, ctx)
|
||||
captured = {}
|
||||
|
||||
monkeypatch.setattr(app_module.keycloak_admin, "ready", lambda: True)
|
||||
monkeypatch.setattr(app_module.keycloak_admin, "find_user", lambda username: {})
|
||||
monkeypatch.setattr(app_module.keycloak_admin, "set_user_attribute", lambda *args, **kwargs: None)
|
||||
|
||||
def fake_sync_user(email, password, wait=True):
|
||||
captured["email"] = email
|
||||
return {"status": "ok"}
|
||||
|
||||
monkeypatch.setattr(app_module.firefly, "sync_user", fake_sync_user)
|
||||
|
||||
resp = client.post(
|
||||
"/api/account/firefly/reset",
|
||||
headers={"Authorization": "Bearer token"},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert captured["email"] == f"alice@{app_module.settings.mailu_domain}"
|
||||
|
||||
|
||||
def test_firefly_rotation_check(monkeypatch) -> None:
|
||||
ctx = AuthContext(username="alice", email="", groups=["dev"], claims={})
|
||||
client = _client(monkeypatch, ctx)
|
||||
|
||||
monkeypatch.setattr(app_module.keycloak_admin, "ready", lambda: True)
|
||||
monkeypatch.setattr(app_module.firefly, "check_rotation_for_user", lambda username: {"status": "ok", "username": username})
|
||||
|
||||
resp = client.post(
|
||||
"/api/account/firefly/rotation/check",
|
||||
headers={"Authorization": "Bearer token"},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json() == {"status": "ok", "username": "alice"}
|
||||
|
||||
|
||||
def test_firefly_rotation_check_error(monkeypatch) -> None:
|
||||
ctx = AuthContext(username="alice", email="", groups=["dev"], claims={})
|
||||
client = _client(monkeypatch, ctx)
|
||||
|
||||
monkeypatch.setattr(app_module.keycloak_admin, "ready", lambda: True)
|
||||
monkeypatch.setattr(
|
||||
app_module.firefly,
|
||||
"check_rotation_for_user",
|
||||
lambda username: {"status": "error", "detail": "expired"},
|
||||
)
|
||||
|
||||
resp = client.post(
|
||||
"/api/account/firefly/rotation/check",
|
||||
headers={"Authorization": "Bearer token"},
|
||||
)
|
||||
assert resp.status_code == 502
|
||||
assert resp.json()["detail"] == "expired"
|
||||
|
||||
@ -55,6 +55,7 @@ def test_rotate_mailu_password_sync_error(monkeypatch) -> None:
|
||||
|
||||
monkeypatch.setattr(app_module.keycloak_admin, "ready", lambda: True)
|
||||
monkeypatch.setattr(app_module.keycloak_admin, "set_user_attribute", lambda *args, **kwargs: None)
|
||||
monkeypatch.setattr(app_module.mailu, "ready", lambda: True)
|
||||
monkeypatch.setattr(app_module.mailu, "sync", lambda *args, **kwargs: (_ for _ in ()).throw(RuntimeError("fail")))
|
||||
monkeypatch.setattr(app_module.nextcloud, "sync_mail", lambda *args, **kwargs: (_ for _ in ()).throw(RuntimeError("fail")))
|
||||
|
||||
|
||||
@ -137,3 +137,37 @@ def test_wger_reset_handles_find_user_error(monkeypatch) -> None:
|
||||
headers={"Authorization": "Bearer token"},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
def test_wger_rotation_check(monkeypatch) -> None:
|
||||
ctx = AuthContext(username="alice", email="", groups=["dev"], claims={})
|
||||
client = _client(monkeypatch, ctx)
|
||||
|
||||
monkeypatch.setattr(app_module.keycloak_admin, "ready", lambda: True)
|
||||
monkeypatch.setattr(app_module.wger, "check_rotation_for_user", lambda username: {"status": "ok", "username": username})
|
||||
|
||||
resp = client.post(
|
||||
"/api/account/wger/rotation/check",
|
||||
headers={"Authorization": "Bearer token"},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json() == {"status": "ok", "username": "alice"}
|
||||
|
||||
|
||||
def test_wger_rotation_check_error(monkeypatch) -> None:
|
||||
ctx = AuthContext(username="alice", email="", groups=["dev"], claims={})
|
||||
client = _client(monkeypatch, ctx)
|
||||
|
||||
monkeypatch.setattr(app_module.keycloak_admin, "ready", lambda: True)
|
||||
monkeypatch.setattr(
|
||||
app_module.wger,
|
||||
"check_rotation_for_user",
|
||||
lambda username: {"status": "error", "detail": "stale"},
|
||||
)
|
||||
|
||||
resp = client.post(
|
||||
"/api/account/wger/rotation/check",
|
||||
headers={"Authorization": "Bearer token"},
|
||||
)
|
||||
assert resp.status_code == 502
|
||||
assert resp.json()["detail"] == "stale"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user