Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/web/apiv2/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ async def oidc_callback(request: Request) -> RedirectResponse:
detail="User account disabled. Please contact your server admin.",
)

# Also covers every login after the first, until an admin enables the user.
if not db_user.enabled:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="User account disabled. Please contact your server admin.",
)

access_token = create_access_token(
data={"sub": db_user.username, "enabled": db_user.enabled},
expires_delta=BROWSER_TOKEN_EXPIRE_DELTA,
Expand Down
14 changes: 14 additions & 0 deletions tests/apiv2/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,20 @@ def test_unverified_email(self) -> None:
response.json()["detail"],
)

def test_disabled_user_gets_no_session(self) -> None:
"""A first login creates a disabled user. Until an admin enables it,
every later login is refused as well, with no session cookie."""
for attempt in ("first", "second"):
with self.subTest(login=attempt):
response = self.browser_login({"email": "bob@example.com"})
self.assertEqual(response.status_code, 401)
self.assertNotIn("set-cookie", response.headers)
self.assertEqual(
response.json()["detail"],
"User account disabled. Please contact your server admin.",
)
self.assertFalse(UserSensitive.find(username="bob@example.com").enabled)

def test_unverified_email_creates_no_user(self) -> None:
self.browser_login({"email": "mallory@example.com", "email_verified": False})
self.assertIsNone(UserSensitive.find(username="mallory@example.com"))
Loading