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.