From daf3307b885c0231e8feb47fed1c820089efce17 Mon Sep 17 00:00:00 2001 From: ugurtafrali Date: Sat, 18 Apr 2026 05:09:58 +0300 Subject: [PATCH] fix: Increase account page size limit to 5000 --- internal/admin/handler_accounts_crud.go | 4 +- internal/admin/handler_accounts_crud_test.go | 53 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 internal/admin/handler_accounts_crud_test.go diff --git a/internal/admin/handler_accounts_crud.go b/internal/admin/handler_accounts_crud.go index 4cbcded..403e4cb 100644 --- a/internal/admin/handler_accounts_crud.go +++ b/internal/admin/handler_accounts_crud.go @@ -21,8 +21,8 @@ func (h *Handler) listAccounts(w http.ResponseWriter, r *http.Request) { if pageSize < 1 { pageSize = 1 } - if pageSize > 100 { - pageSize = 100 + if pageSize > 5000 { + pageSize = 5000 } accounts := h.Store.Snapshot().Accounts reverseAccounts(accounts) diff --git a/internal/admin/handler_accounts_crud_test.go b/internal/admin/handler_accounts_crud_test.go new file mode 100644 index 0000000..2b286a3 --- /dev/null +++ b/internal/admin/handler_accounts_crud_test.go @@ -0,0 +1,53 @@ +package admin + +import ( + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "strings" + "testing" +) + +func TestListAccountsPageSizeCapIs5000(t *testing.T) { + accounts := make([]string, 0, 150) + for i := range 150 { + accounts = append(accounts, fmt.Sprintf(`{"email":"u%d@example.com","password":"pwd"}`, i)) + } + raw := fmt.Sprintf(`{"accounts":[%s]}`, strings.Join(accounts, ",")) + router := newHTTPAdminHarness(t, raw, &testingDSMock{}) + + rec := httptest.NewRecorder() + router.ServeHTTP(rec, adminReq(http.MethodGet, "/accounts?page=1&page_size=200", nil)) + if rec.Code != http.StatusOK { + t.Fatalf("unexpected status: %d body=%s", rec.Code, rec.Body.String()) + } + var payload map[string]any + if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil { + t.Fatalf("decode response: %v", err) + } + items, _ := payload["items"].([]any) + if len(items) != 150 { + t.Fatalf("expected all 150 accounts with page_size=200, got %d", len(items)) + } + if ps, _ := payload["page_size"].(float64); ps != 200 { + t.Fatalf("expected page_size=200 in response, got %v", payload["page_size"]) + } +} + +func TestListAccountsPageSizeAbove5000ClampedTo5000(t *testing.T) { + router := newHTTPAdminHarness(t, `{"accounts":[{"email":"u@example.com","password":"pwd"}]}`, &testingDSMock{}) + + rec := httptest.NewRecorder() + router.ServeHTTP(rec, adminReq(http.MethodGet, "/accounts?page=1&page_size=9999", nil)) + if rec.Code != http.StatusOK { + t.Fatalf("unexpected status: %d body=%s", rec.Code, rec.Body.String()) + } + var payload map[string]any + if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil { + t.Fatalf("decode response: %v", err) + } + if ps, _ := payload["page_size"].(float64); ps != 5000 { + t.Fatalf("expected page_size clamped to 5000, got %v", payload["page_size"]) + } +}