Skip to main content

Auth Service Tests

Overview​

Integration tests for the auth-service, testing complete user flows against a live service.

Running Tests​

cd /backend
make test auth

Test Configuration​

  • Base URL: http://localhost:80/api/auth (via gateway)
  • Email Domain: @test.vislagps.com (generated per test)
  • Environment: Requires ENVIRONMENT=dev for token extraction

Test Flows​

Test ClassDescription
TestBasicRegistrationFlowhealth β†’ register β†’ verify β†’ login β†’ profile β†’ delete
TestResendVerificationFlowregister β†’ resend β†’ old token fails β†’ new token works
TestUnverifiedLoginFailFlowlogin before verify fails (403) β†’ verify β†’ login succeeds
TestLogoutFlowlogout β†’ token blacklisted β†’ profile fails (401)
TestPasswordResetFlowreset β†’ update password β†’ old fails β†’ new works
TestTwoFactorFlowsetup 2FA β†’ verify β†’ logout β†’ 2FA login required
TestTwoFactorBackupCodeFlow2FA β†’ login with backup code instead of TOTP
TestTwoFactorRegenerateFlowregenerate β†’ old codes fail β†’ new codes work
TestTwoFactorDisableFlowdisable 2FA β†’ login no longer requires 2FA
TestInvalidCredentialsFlowwrong password β†’ 401
TestNonexistentUserFlowlogin nonexistent β†’ 401
TestInvalidTokensFlowinvalid verify/reset tokens β†’ 400
TestWeakPasswordFlowweak password β†’ 400
TestTermsNotAcceptedFlowterms=false β†’ 400

Helper Functions​

Located in tests/helpers.py:

FunctionDescription
check_health(client)Verify service is healthy
register_user(client, email?, password?)Register new user, returns verification token
verify_email(client, token)Verify email with token
resend_verification(client, email)Resend verification email
login_user(client, email, password)Login, handles 2FA response
get_auth_headers(token)Create Authorization: Bearer header
get_profile(client, headers)Get user profile
logout_user(client, headers)Blacklist token
delete_account(client, headers)Delete user account
setup_2fa(client, headers)Start 2FA setup, returns secret
verify_2fa(client, headers, secret)Verify TOTP code, returns backup codes
regenerate_backup_codes(client, headers)Generate new backup codes
disable_2fa(client, headers)Disable 2FA
complete_2fa_login(client, temp_token, secret)Complete 2FA with TOTP
complete_2fa_login_backup(client, temp_token, code)Complete 2FA with backup code
request_password_reset(client, email)Request reset, returns token
update_password(client, token, new_password)Set new password

Development Mode​

In ENVIRONMENT=dev, responses include tokens directly:

{
"message": "...",
"verification_token": "abc123..." // Only in dev mode
}

This allows tests to extract tokens without email access.