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

@@ -175,15 +175,32 @@ class AccessSettingsTests(unittest.TestCase):
self.assertEqual(response.status_code, 500)
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": True})
def test_internal_update_refuses_a_short_or_placeholder_secret(self) -> None:
for secret in ("short", "change-me-to-a-long-random-value"):
with self.subTest(secret=secret):
store = _FakeStore(login_required=True)
client = TestClient(
_build_app(store, _FakeClient(setup_required=False), internal_secret=secret)
)
response = client.put(
"/api/auth/access/internal",
headers={"X-Internal-Auth": secret},
json={"loginRequired": False},
)
self.assertEqual(response.status_code, 401)
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": True})
def test_internal_update_disables_login_and_uses_admin_identity(self) -> None:
store = _FakeStore(login_required=True)
client = TestClient(
_build_app(store, _FakeClient(setup_required=False), internal_secret="secret")
_build_app(
store, _FakeClient(setup_required=False), internal_secret="internal-test-secret"
)
)
response = client.put(
"/api/auth/access/internal",
headers={"X-Internal-Auth": "secret"},
headers={"X-Internal-Auth": "internal-test-secret"},
json={"loginRequired": False},
)
self.assertEqual(response.status_code, 200)
@@ -244,6 +261,97 @@ class _RoleClient(_FakeClient):
return PublicUser(id=1, username="a", email="a@b.com", role=roles[token])
class _ProfileClient(_RoleClient):
def __init__(self, *, totp_enabled: bool = False) -> None:
super().__init__()
self.totp_enabled = totp_enabled
self.login_calls: list[tuple[str, str, str]] = []
self.update_calls: list[dict[str, object]] = []
async def me(self, token: str) -> PublicUser:
if token != "admin-token":
raise APIError(401, "unauthenticated")
return PublicUser(
id=1,
username="admin",
email="admin@example.com",
role="superadmin",
totp_enabled=self.totp_enabled,
)
async def login(self, username_or_email: str, password: str, totp_token: str = ""):
self.login_calls.append((username_or_email, password, totp_token))
if password != "current-password":
raise APIError(401, "invalid credentials")
return SessionResult(
user=PublicUser(id=1, username="admin", email="admin@example.com", role="superadmin"),
cookies=["auth_session=reauth-token; Path=/; HttpOnly"],
)
async def update_managed_user(self, token: str, user_id: int, **kwargs) -> None:
self.update_calls.append({"token": token, "user_id": user_id, **kwargs})
class ProfileReauthenticationTests(unittest.TestCase):
def _put(self, fake: _ProfileClient, body: dict[str, str]):
client = TestClient(_build_app(_FakeStore(), fake))
return client.put(
"/api/auth/me",
headers={"Cookie": f"{DEFAULT_COOKIE_NAME}=admin-token"},
json=body,
)
def test_password_update_requires_current_password_and_totp_when_enabled(self) -> None:
no_totp = _ProfileClient()
response = self._put(
no_totp,
{"username": "admin", "email": "admin@example.com", "password": "new-password"},
)
self.assertEqual(response.status_code, 400)
self.assertEqual(no_totp.login_calls, [])
totp = _ProfileClient(totp_enabled=True)
response = self._put(
totp,
{
"username": "admin",
"email": "admin@example.com",
"password": "new-password",
"currentPassword": "current-password",
},
)
self.assertEqual(response.status_code, 400)
self.assertEqual(totp.login_calls, [])
def test_password_update_reauthenticates_and_cleans_up_temporary_session(self) -> None:
fake = _ProfileClient(totp_enabled=True)
response = self._put(
fake,
{
"username": "admin",
"email": "admin@example.com",
"password": "new-password",
"currentPassword": "current-password",
"totpToken": "123456",
},
)
self.assertEqual(response.status_code, 200, response.text)
self.assertEqual(fake.login_calls, [("admin", "current-password", "123456")])
self.assertEqual(
fake.update_calls,
[
{
"token": "admin-token",
"user_id": 1,
"username": "admin",
"email": "admin@example.com",
"password": "new-password",
}
],
)
self.assertIn("reauth-token", fake.logged_out)
class EnabledModeSetupAndLoginTests(unittest.TestCase):
"""Exercises the real (client is not None) path, including the
setup-claim flag's interaction with the store."""