Dex error
This commit is contained in:
@@ -274,6 +274,35 @@ class IdentityTests(TestCase):
|
||||
self.assertContains(response, "could not be verified")
|
||||
self.assertNotIn("account_id", self.client.session)
|
||||
|
||||
@patch("members.views.dex")
|
||||
@patch("members.views.link_identity")
|
||||
def test_database_failure_logs_only_safe_sqlstate_and_recovery_hint(self, link, dex):
|
||||
from django.db import ProgrammingError
|
||||
from psycopg.errors import InsufficientPrivilege, UndefinedColumn, UndefinedTable
|
||||
|
||||
dex.return_value.authorize_access_token.return_value = {"id_token": "private-token", "userinfo": self.claims()}
|
||||
for cause, expected, hint in (
|
||||
(UndefinedColumn("private SQL and email alice@example.org"), "42703", "members.0004_dex_login_identity"),
|
||||
(UndefinedTable("private SQL"), "42P01", "undefined_table"),
|
||||
(InsufficientPrivilege("private SQL"), "42501", "insufficient_privilege"),
|
||||
(None, "unknown", "matching application/migration images"),
|
||||
):
|
||||
with self.subTest(sqlstate=expected):
|
||||
error = ProgrammingError("private database details")
|
||||
error.__cause__ = cause
|
||||
link.side_effect = error
|
||||
with self.assertLogs("members.views", level="ERROR") as logs:
|
||||
response = self.client.get("/members/oidc/callback/?code=private-code")
|
||||
self.assertContains(response, "could not be verified")
|
||||
self.assertNotIn("account_id", self.client.session)
|
||||
output = " ".join(logs.output)
|
||||
self.assertIn(f"sqlstate={expected}", output)
|
||||
self.assertIn(hint, output)
|
||||
for private in ("private", "alice@example.org", "Traceback"):
|
||||
self.assertNotIn(private, output)
|
||||
self.assertNotIn("sqlstate", response.content.decode())
|
||||
self.assertFalse(Account.objects.exists())
|
||||
|
||||
@patch("members.views.dex")
|
||||
@patch("members.directory.Connection")
|
||||
@override_settings(LDAP_URL="", LDAP_BIND_DN="", LDAP_BIND_PASSWORD="", LDAP_PASSWORD_SCHEME="{CRYPT}")
|
||||
|
||||
Reference in New Issue
Block a user