mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(fastapi): log out IntegrityError from failed SID generation
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
806a19b91a
commit
81f8c23265
2 changed files with 9 additions and 2 deletions
|
@ -15,11 +15,13 @@ import aurweb.config
|
|||
import aurweb.models.account_type
|
||||
import aurweb.schema
|
||||
|
||||
from aurweb import db, schema
|
||||
from aurweb import db, logging, schema
|
||||
from aurweb.models.account_type import AccountType as _AccountType
|
||||
from aurweb.models.ban import is_banned
|
||||
from aurweb.models.declarative import Base
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
SALT_ROUNDS_DEFAULT = 12
|
||||
|
||||
|
||||
|
@ -146,6 +148,7 @@ class User(Base):
|
|||
if exc:
|
||||
detail = ("Unable to generate a unique session ID in "
|
||||
f"{tries} iterations.")
|
||||
logger.error(str(exc))
|
||||
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail=detail)
|
||||
|
||||
|
|
|
@ -285,7 +285,8 @@ def test_login_bad_referer(client: TestClient):
|
|||
assert "AURSID" not in response.cookies
|
||||
|
||||
|
||||
def test_generate_unique_sid_exhausted(client: TestClient, user: User):
|
||||
def test_generate_unique_sid_exhausted(client: TestClient, user: User,
|
||||
caplog: pytest.LogCaptureFixture):
|
||||
"""
|
||||
In this test, we mock up generate_unique_sid() to infinitely return
|
||||
the same SessionID given to `user`. Within that mocking, we try
|
||||
|
@ -328,3 +329,6 @@ def test_generate_unique_sid_exhausted(client: TestClient, user: User):
|
|||
expected = "Unable to generate a unique session ID"
|
||||
assert expected in response.text
|
||||
assert "500 - Internal Server Error" in response.text
|
||||
|
||||
# Make sure an IntegrityError from the DB got logged out.
|
||||
assert "IntegrityError" in caplog.text
|
||||
|
|
Loading…
Add table
Reference in a new issue