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

+32 -1
View File
@@ -406,6 +406,12 @@ func TestTOTPInitiateAndStatus(t *testing.T) {
func TestUpdateMeValidatesAndForwardsToAuthGuard(t *testing.T) {
guard := newFakeAuthGuard(t)
guard.handle("POST /api/login", func(w http.ResponseWriter, _ map[string]any) {
w.Header().Add("Set-Cookie", authclient.DefaultCookieName+"=reauth-token; Path=/; HttpOnly")
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]any{"user": map[string]any{"id": 7, "username": "boss", "email": "boss@example.com", "role": "admin"}})
})
guard.reply("POST /api/logout", http.StatusOK, map[string]any{"ok": true})
guard.reply("PUT /api/admin/users/7", http.StatusOK, map[string]any{})
guard.reply("GET /api/me", http.StatusOK, map[string]any{"user": map[string]any{"id": 7, "username": "boss", "email": "boss@example.com", "role": "admin"}})
service, _ := guard.service(t)
@@ -418,7 +424,7 @@ func TestUpdateMeValidatesAndForwardsToAuthGuard(t *testing.T) {
service.UpdateMe(rec, req)
return rec
}
manager := &ProxyUser{ID: 7, Role: "admin"}
manager := &ProxyUser{ID: 7, Username: "boss", Role: "admin", MFAEnabled: true}
if rec := update(nil, `{}`); rec.Code != http.StatusUnauthorized {
t.Fatalf("no session user: status = %d, want 401", rec.Code)
@@ -431,6 +437,8 @@ func TestUpdateMeValidatesAndForwardsToAuthGuard(t *testing.T) {
"at in username": `{"email":"a@b.com","username":"a@b.com"}`,
"short password": `{"email":"a@b.com","username":"boss","password":"short"}`,
"long password": `{"email":"a@b.com","username":"boss","password":"` + strings.Repeat("a", 73) + `"}`,
"missing current password": `{"email":"a@b.com","username":"boss","password":"new-password"}`,
"missing current totp": `{"email":"a@b.com","username":"boss","password":"new-password","currentPassword":"current-password"}`,
"not JSON": `nope`,
} {
if rec := update(manager, body); rec.Code != http.StatusBadRequest {
@@ -452,6 +460,29 @@ func TestUpdateMeValidatesAndForwardsToAuthGuard(t *testing.T) {
if _, sent := calls[0].Body["password"]; sent {
t.Fatal("an update without a password sent one to AuthGuard")
}
rec = update(manager, `{"email":"boss@example.com","username":"boss","password":"new-password","currentPassword":"current-password","totpToken":"123456"}`)
if rec.Code != http.StatusOK {
t.Fatalf("password update status = %d, body %s", rec.Code, rec.Body.String())
}
loginCalls := guard.callsTo("POST /api/login")
if len(loginCalls) != 1 || loginCalls[0].Body["username_or_email"] != "boss" || loginCalls[0].Body["password"] != "current-password" || loginCalls[0].Body["totp_token"] != "123456" {
t.Fatalf("reauthentication request = %+v", loginCalls)
}
calls = guard.callsTo("PUT /api/admin/users/7")
if len(calls) != 2 || calls[1].Body["password"] != "new-password" {
t.Fatalf("password update request = %+v", calls)
}
if _, sent := calls[1].Body["currentPassword"]; sent {
t.Fatal("current password was forwarded to the managed-user API")
}
if _, sent := calls[1].Body["totpToken"]; sent {
t.Fatal("TOTP code was forwarded to the managed-user API")
}
logoutCalls := guard.callsTo("POST /api/logout")
if len(logoutCalls) != 1 || logoutCalls[0].Authorization != "Bearer reauth-token" {
t.Fatalf("temporary login session was not removed: %+v", logoutCalls)
}
if user := decodeBody(t, rec)["user"].(map[string]any); user["username"] != "boss" {
t.Fatalf("response user = %v", user)
}