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.models.account_type
|
||||||
import aurweb.schema
|
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.account_type import AccountType as _AccountType
|
||||||
from aurweb.models.ban import is_banned
|
from aurweb.models.ban import is_banned
|
||||||
from aurweb.models.declarative import Base
|
from aurweb.models.declarative import Base
|
||||||
|
|
||||||
|
logger = logging.get_logger(__name__)
|
||||||
|
|
||||||
SALT_ROUNDS_DEFAULT = 12
|
SALT_ROUNDS_DEFAULT = 12
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,6 +148,7 @@ class User(Base):
|
||||||
if exc:
|
if exc:
|
||||||
detail = ("Unable to generate a unique session ID in "
|
detail = ("Unable to generate a unique session ID in "
|
||||||
f"{tries} iterations.")
|
f"{tries} iterations.")
|
||||||
|
logger.error(str(exc))
|
||||||
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||||
detail=detail)
|
detail=detail)
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,8 @@ def test_login_bad_referer(client: TestClient):
|
||||||
assert "AURSID" not in response.cookies
|
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
|
In this test, we mock up generate_unique_sid() to infinitely return
|
||||||
the same SessionID given to `user`. Within that mocking, we try
|
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"
|
expected = "Unable to generate a unique session ID"
|
||||||
assert expected in response.text
|
assert expected in response.text
|
||||||
assert "500 - Internal Server Error" 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