feat(auth): make email the unique login identifier
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled
Login is now by email, not username. username still exists internally (JWT sub claim, audit logs, Jira actor attribution, SSO provisioning all still key off it) but is now always kept equal to email everywhere a user is created or their email changes — never a separately-chosen value. - User.email is now unique + NOT NULL (migration b067 backfills any missing/blank email from username first, so existing rows — notably the seeded admin, which historically had none — never violate it). - /auth/login and the (unused but updated for consistency) authenticate_user() now query by email. - create_user (legacy, unreferenced but kept) and create_user_without_password both derive username from email. - update_user keeps username in sync when email changes, and rejects duplicate emails. - seed.py reads ADMIN_EMAIL (new env var, wired through install.sh and docker-compose.prod.yml) for the initial admin; falls back to an email-shaped ADMIN_USERNAME or a placeholder that's flagged for the operator to fix. - admin_config.py's import bundle now matches/creates users by email, skipping (not crashing on) entries with no email. - sso_service.py always sets username = email for SSO-provisioned users. - LoginPage/auth.ts updated to email input/copy (wire field name stays 'username' — that's the OAuth2PasswordRequestForm spec, not the value).
This commit is contained in:
@@ -105,24 +105,35 @@ def test_import_config_rejects_invalid_json(client, auth_headers):
|
||||
def test_import_config_creates_new_user_with_forced_reset(client, db, auth_headers):
|
||||
resp = client.post(
|
||||
"/api/v1/admin/import-config",
|
||||
json={"users": [{"username": "imported_user", "role": "red_tech", "is_active": True}]},
|
||||
json={"users": [{"username": "imported_user", "email": "imported_user@test.com", "role": "red_tech", "is_active": True}]},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["summary"]["users_created"] == 1
|
||||
|
||||
user = db.query(User).filter(User.username == "imported_user").first()
|
||||
user = db.query(User).filter(User.email == "imported_user@test.com").first()
|
||||
assert user is not None
|
||||
assert user.must_change_password is True
|
||||
assert user.role == "red_tech"
|
||||
|
||||
|
||||
def test_import_config_skips_user_with_no_email(client, db, auth_headers):
|
||||
resp = client.post(
|
||||
"/api/v1/admin/import-config",
|
||||
json={"users": [{"username": "no_email_user", "role": "red_tech", "is_active": True}]},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["summary"]["users_skipped_no_email"] == 1
|
||||
assert db.query(User).filter(User.username == "no_email_user").first() is None
|
||||
|
||||
|
||||
def test_import_config_updates_existing_user_role_only(client, db, auth_headers, red_tech_user):
|
||||
original_hash = red_tech_user.hashed_password
|
||||
|
||||
resp = client.post(
|
||||
"/api/v1/admin/import-config",
|
||||
json={"users": [{"username": red_tech_user.username, "role": "red_lead", "is_active": True}]},
|
||||
json={"users": [{"username": red_tech_user.username, "email": red_tech_user.email, "role": "red_lead", "is_active": True}]},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user