fix: log a failed password migration instead of swallowing it
Build and Push Image / Build and push image (push) Canceled after 0s
Build and Push Image / Unit tests (push) Canceled after 8m35s

The round-2 review noted that `_upgrade_password` catches `PyMongoError`
without logging it. A failed upgrade is harmless to the login itself - the
user still gets in - but it leaves the password stored in plain text, and
that is exactly the kind of thing an operator needs to know about. It is now
logged as a warning with the username and the traceback.

A test covers the path: the migration write is forced to fail, the login
still succeeds, and the warning is emitted.
This commit is contained in:
2026-11-09 10:31:03 +10:00
parent 1828dcb81d
commit 6e1189e319
2 changed files with 35 additions and 2 deletions
+12 -2
View File
@@ -17,6 +17,7 @@ Two collections are used:
from __future__ import annotations
import logging
import os
from typing import Any
@@ -28,6 +29,8 @@ from brewing import Run
__all__ = ["BeerRepository", "get_repository"]
logger = logging.getLogger(__name__)
class BeerRepository:
"""Thin, testable wrapper around the two Mongo collections."""
@@ -89,8 +92,15 @@ class BeerRepository:
}},
)
except PyMongoError:
# A failed upgrade must not stop the login succeeding.
pass
# A failed upgrade must not stop the login succeeding — but the
# operator needs to know the password is still stored in plain
# text, so log it rather than swallowing the error silently.
logger.warning(
"Could not upgrade the password for user %r to a hashed value; "
"it is still stored in plain text",
doc.get("username"),
exc_info=True,
)
# -- readings ----------------------------------------------------------- #