feat(sync): paginate Android sync with change tokens
Lint / Lint (push) Successful in 1m8s
Tests / Go backend (push) Failing after 1m23s
Tests / Dashboard checks (push) Failing after 38s
Docker / Docker Build & Push (push) Failing after 6m29s

This commit is contained in:
Gabriel20xx committed 2026-10-20 15:27:53 +00:00
1 parent 0ff94f9b10
commit 97c237be80
76 files changed
+3401 -851

No files matched your search

@@ -29,7 +29,7 @@ class _FakeDatabase:
async def fetchrow(self, query: str, *args):
self.fetched.append((query, args))
if "totp_enabled" in query:
return {"secret": "S", "enabled": self.totp_enabled}
return {"secret": "S", "enabled": self.totp_enabled, "last_used_step": -1}
for condition, row in self.rows_by_condition.items():
if condition in query:
return row
@@ -60,6 +60,9 @@ class AuthStoreHardeningTests(unittest.IsolatedAsyncioTestCase):
self.assertIn("lower(username)", statements)
# The index is created only while no clashing pair exists.
self.assertIn("HAVING count(*) > 1", statements)
self.assertIn(
"ADD COLUMN IF NOT EXISTS last_used_step BIGINT NOT NULL DEFAULT -1", statements
)
async def test_set_totp_secret_refuses_while_enabled(self) -> None:
self.db.execute_status = "UPDATE 0"
@@ -73,6 +76,52 @@ class AuthStoreHardeningTests(unittest.IsolatedAsyncioTestCase):
self.db.execute_status = "UPDATE 0" # no such user: nothing to refuse
await self.store.set_totp_secret(2, "NEWSECRET")
async def test_totp_enrollment_records_its_step_and_replay_is_rejected(self) -> None:
class ReplayDatabase(_FakeDatabase):
def __init__(self) -> None:
super().__init__()
self.state = {
"secret": "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
"enabled": False,
"last_used_step": -1,
}
async def fetchrow(self, query: str, *args):
if "FROM auth_users WHERE id = $1" in query and "totp_enabled" in query:
return dict(self.state)
return await super().fetchrow(query, *args)
async def execute(self, query: str, *args) -> str:
self.executed.append((query, args))
step, _, secret = args
if "SET totp_enabled = true" in query:
if (
not self.state["enabled"]
and secret == self.state["secret"]
and self.state["last_used_step"] < step
):
self.state["enabled"] = True
self.state["last_used_step"] = step
return "UPDATE 1"
return "UPDATE 0"
if "SET last_used_step = $1" in query:
if (
self.state["enabled"]
and secret == self.state["secret"]
and self.state["last_used_step"] < step
):
self.state["last_used_step"] = step
return "UPDATE 1"
return "UPDATE 0"
return await super().execute(query, *args)
database = ReplayDatabase()
store = AuthStore(database) # type: ignore[arg-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))
self.assertEqual(database.state["last_used_step"], 1)
async def test_credential_writes_refuse_an_empty_hash_and_an_at_username(self) -> None:
writes = [
lambda u, h: self.store.create_user(u, "", h),