From 833eab04af6e5c24f950133fe4ac9f3b01442609 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 10 Nov 2026 14:42:45 +0100 Subject: [PATCH] Sync shared snapshot from 74942e5 Co-Authored-By: Claude Haiku 5.5 --- .../python-backend/tests/test_contract.py | 4 +--- .../python-backend/tests/test_core.py | 22 ++++++++++++------- .../python-backend/tests/test_coreconfig.py | 7 +++++- .../python-backend/tests/test_store.py | 6 +++-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/shared/packages/python-backend/tests/test_contract.py b/shared/packages/python-backend/tests/test_contract.py index eace12a..cbd9d6e 100644 --- a/shared/packages/python-backend/tests/test_contract.py +++ b/shared/packages/python-backend/tests/test_contract.py @@ -42,9 +42,7 @@ class AuthContractTests(unittest.TestCase): if "python" in entry.get("needsUpgrade", {}): want = entry["needsUpgrade"]["python"] self.assertEqual(password_hash_needs_upgrade(entry["hash"]), want) - valid, upgraded = verify_and_upgrade_password( - plaintext, entry["hash"] - ) + valid, upgraded = verify_and_upgrade_password(plaintext, entry["hash"]) self.assertTrue(valid) self.assertEqual(upgraded is not None, want) if upgraded is not None: diff --git a/shared/packages/python-backend/tests/test_core.py b/shared/packages/python-backend/tests/test_core.py index e196b97..ae248c3 100644 --- a/shared/packages/python-backend/tests/test_core.py +++ b/shared/packages/python-backend/tests/test_core.py @@ -48,15 +48,14 @@ class SharedBackendTests(unittest.TestCase): self.assertFalse(password_hash_needs_upgrade(password_hash)) def test_unprefixed_legacy_bcrypt_hashes_still_verify_and_are_upgraded(self): - legacy = bcrypt.hashpw( - b"correct horse battery staple", bcrypt.gensalt(rounds=12) - ).decode() + legacy = bcrypt.hashpw(b"correct horse battery staple", bcrypt.gensalt(rounds=12)).decode() self.assertTrue(verify_password("correct horse battery staple", legacy)) self.assertFalse(verify_password("wrong password", legacy)) self.assertTrue(password_hash_needs_upgrade(legacy)) valid, upgraded = verify_and_upgrade_password("correct horse battery staple", legacy) self.assertTrue(valid) + assert upgraded is not None self.assertTrue(upgraded.startswith("bcrypt$$2b$12$")) self.assertTrue(verify_password("correct horse battery staple", upgraded)) self.assertFalse(password_hash_needs_upgrade(upgraded)) @@ -70,14 +69,16 @@ class SharedBackendTests(unittest.TestCase): legacy = f"{salt}:{expected}" valid, upgraded = verify_and_upgrade_password(password, legacy) self.assertTrue(valid) + assert upgraded is not None self.assertTrue(upgraded.startswith("bcrypt-sha256$$2b$12$")) self.assertTrue(verify_password(password, upgraded)) self.assertFalse(verify_password(password + "x", upgraded)) def test_a_cost_below_the_current_policy_is_upgraded(self): - low_cost = "bcrypt$" + bcrypt.hashpw( - b"correct horse battery staple", bcrypt.gensalt(rounds=4) - ).decode() + low_cost = ( + "bcrypt$" + + bcrypt.hashpw(b"correct horse battery staple", bcrypt.gensalt(rounds=4)).decode() + ) self.assertTrue(password_hash_needs_upgrade(low_cost)) valid, upgraded = verify_and_upgrade_password("correct horse battery staple", low_cost) self.assertTrue(valid) @@ -107,6 +108,7 @@ class SharedBackendTests(unittest.TestCase): async def run(): valid, upgraded = await verify_and_upgrade_password_async(password, legacy) self.assertTrue(valid) + assert upgraded is not None self.assertTrue(await verify_password_async(password, upgraded)) asyncio.run(run()) @@ -127,8 +129,12 @@ class SharedBackendTests(unittest.TestCase): return len(attempts) self.assertTrue(is_transient_connection_error(ConnectionRefusedError())) - self.assertTrue(is_transient_connection_error(asyncpg.exceptions.ConnectionDoesNotExistError("closed"))) - self.assertFalse(is_transient_connection_error(asyncpg.exceptions.InvalidPasswordError("bad"))) + self.assertTrue( + is_transient_connection_error(asyncpg.exceptions.ConnectionDoesNotExistError("closed")) + ) + self.assertFalse( + is_transient_connection_error(asyncpg.exceptions.InvalidPasswordError("bad")) + ) self.assertFalse(is_transient_connection_error(ValueError("bad"))) self.assertEqual(asyncio.run(retry_with(ValueError("bad"))), 1) self.assertEqual(asyncio.run(retry_with(ConnectionRefusedError())), 3) diff --git a/shared/packages/python-backend/tests/test_coreconfig.py b/shared/packages/python-backend/tests/test_coreconfig.py index 8aef2a1..43e4b7b 100644 --- a/shared/packages/python-backend/tests/test_coreconfig.py +++ b/shared/packages/python-backend/tests/test_coreconfig.py @@ -104,7 +104,12 @@ class InternalSecretTests(unittest.TestCase): class UrlValidationTests(unittest.TestCase): def test_rejects_urls_that_are_not_http_or_https_with_a_host(self): store = Store(Info(auth_guard_url="http://auth.example.com")) - for bad in ["javascript:alert(1)", "auth.example.com", "ftp://carrier.example.com", "http://"]: + for bad in [ + "javascript:alert(1)", + "auth.example.com", + "ftp://carrier.example.com", + "http://", + ]: with self.subTest(url=bad), self.assertRaises(ValueError): store.set(Info(auth_guard_url=bad)) with self.assertRaises(ValueError): diff --git a/shared/packages/python-backend/tests/test_store.py b/shared/packages/python-backend/tests/test_store.py index 8b42248..ad809f1 100644 --- a/shared/packages/python-backend/tests/test_store.py +++ b/shared/packages/python-backend/tests/test_store.py @@ -51,7 +51,7 @@ def _user_row(username: str, email: str = "") -> dict: class AuthStoreHardeningTests(unittest.IsolatedAsyncioTestCase): def setUp(self) -> None: self.db = _FakeDatabase() - self.store = AuthStore(self.db, single_user=False) # type: ignore[arg-type] + self.store = AuthStore(self.db, single_user=False) # ty: ignore[invalid-argument-type] async def test_ensure_schema_requests_the_case_insensitive_username_index(self) -> None: await self.store.ensure_schema() @@ -116,7 +116,7 @@ class AuthStoreHardeningTests(unittest.IsolatedAsyncioTestCase): return await super().execute(query, *args) database = ReplayDatabase() - store = AuthStore(database) # type: ignore[arg-type] + store = AuthStore(database) # ty: ignore[invalid-argument-type] self.assertTrue(await store.enable_totp(1, "287082", 59.0)) self.assertEqual(database.state["last_used_step"], 1) self.assertFalse(await store.consume_totp_code(1, "287082", 59.0)) @@ -148,11 +148,13 @@ class AuthStoreHardeningTests(unittest.IsolatedAsyncioTestCase): "lower(email) = lower($1)": _user_row("owner", "owner@example.com"), } found = await self.store.find_by_identifier("owner@example.com") + assert found is not None self.assertEqual(found.username, "owner@example.com") self.assertEqual(len(self.db.fetched), 1) del self.db.rows_by_condition["username = $1"] found = await self.store.find_by_identifier("owner@example.com") + assert found is not None self.assertEqual(found.username, "owner")