auth_test_helper.py 656 B

12345678910111213141516171819202122
  1. """
  2. Test helper for SSO-based authentication.
  3. Provides utilities to create test tokens by injecting them directly
  4. into the token cache, bypassing SSO center verification.
  5. """
  6. import uuid
  7. from middleware.auth_middleware import token_cache
  8. def create_test_token(user_data: dict) -> str:
  9. """
  10. Create a fake SSO token for testing by injecting it into the token cache.
  11. Args:
  12. user_data: Dict with id, username, email, role
  13. Returns:
  14. A fake token string that will be recognized by the auth middleware.
  15. """
  16. fake_token = f"test_sso_token_{uuid.uuid4().hex}"
  17. token_cache.set(fake_token, user_data)
  18. return fake_token