Coverage for src/backend/InvenTree/InvenTree/helpers_mfa.py: 0%
8 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1"""Helper functions for allauth MFA testing."""
3from allauth.mfa.recovery_codes.internal.auth import RecoveryCodes
4from allauth.mfa.totp.internal import auth as allauth_totp_auth
7def get_codes(user):
8 """Generate active TOTP and recovery codes for a user.
10 Args:
11 user: User instance
13 Returns:
14 Tuple of (TOTP Authenticator instance, list of recovery codes, TOTP secret)
15 """
16 secret = allauth_totp_auth.generate_totp_secret()
17 totp_auth = allauth_totp_auth.TOTP.activate(user, secret).instance
18 rc_auth = RecoveryCodes.activate(user).instance
20 # Get usable codes
21 rc_codes = rc_auth.wrap().get_unused_codes()
22 return totp_auth, rc_codes, secret