test_mfa_login_response_auth_source.py 892 B

12345678910111213141516171819202122232425262728293031
  1. """A 2FA or SSO login reports the user's real auth source (PC-C9).
  2. mfa.py kept its own copy of the user-response builder, and the copy left out
  3. ``auth_source``: after a 2FA or OIDC login the schema default "local" reached
  4. the page, which then offered an LDAP or OIDC user "Change Password".
  5. """
  6. from datetime import datetime
  7. from types import SimpleNamespace
  8. import pytest
  9. from backend.app.api.routes import mfa
  10. @pytest.mark.parametrize("source", ["ldap", "oidc", "local"])
  11. def test_the_login_response_carries_the_auth_source(source):
  12. user = SimpleNamespace(
  13. id=3,
  14. username="ana",
  15. email=None,
  16. role="user",
  17. is_active=True,
  18. is_admin=False,
  19. auth_source=source,
  20. groups=[],
  21. get_permissions=lambda: set(),
  22. created_at=datetime(2026, 10, 1),
  23. )
  24. assert mfa._user_to_response(user).auth_source == source