-
Notifications
You must be signed in to change notification settings - Fork 0
fix(api): harden API — strip PII/Stripe IDs, unify pagination, normalise cents naming #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f0ac32a
fix(api): harden API — strip PII/Stripe IDs, unify pagination, normal…
mlehotskylf 680ee52
fix(review): use donor type constants, record span errors, add missin…
mlehotskylf 7d32243
fix(review): address second-round Copilot review suggestions
mlehotskylf 599a266
Merge branch 'main' into fix/api-hardening-pii-pagination-naming
mlehotskylf a269174
fix(frontend): import computed in useInitiativeTransactions
mlehotskylf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package handler | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestParsePaginationParams_ValidLimitOffset(t *testing.T) { | ||
| r := httptest.NewRequest(http.MethodGet, "/?limit=20&offset=40", nil) | ||
| w := httptest.NewRecorder() | ||
|
|
||
| limit, offset, ok := parsePaginationParams(w, r) | ||
|
|
||
| if !ok { | ||
| t.Fatal("expected ok=true, got false") | ||
| } | ||
| if limit != 20 { | ||
| t.Errorf("limit = %d, want 20", limit) | ||
| } | ||
| if offset != 40 { | ||
| t.Errorf("offset = %d, want 40", offset) | ||
| } | ||
| } | ||
|
|
||
| func TestParsePaginationParams_AbsentParams_ZeroDefaults(t *testing.T) { | ||
| r := httptest.NewRequest(http.MethodGet, "/", nil) | ||
| w := httptest.NewRecorder() | ||
|
|
||
| limit, offset, ok := parsePaginationParams(w, r) | ||
|
|
||
| if !ok { | ||
| t.Fatal("expected ok=true for absent params") | ||
| } | ||
| if limit != 0 || offset != 0 { | ||
| t.Errorf("expected 0,0 for absent params, got %d,%d", limit, offset) | ||
| } | ||
| } | ||
|
|
||
| func TestParsePaginationParams_InvalidLimit_Returns400(t *testing.T) { | ||
| r := httptest.NewRequest(http.MethodGet, "/?limit=abc", nil) | ||
| w := httptest.NewRecorder() | ||
|
|
||
| _, _, ok := parsePaginationParams(w, r) | ||
|
|
||
| if ok { | ||
| t.Fatal("expected ok=false for non-integer limit") | ||
| } | ||
| if w.Code != http.StatusBadRequest { | ||
| t.Errorf("status = %d, want 400", w.Code) | ||
| } | ||
| } | ||
|
|
||
| func TestParsePaginationParams_InvalidOffset_Returns400(t *testing.T) { | ||
| r := httptest.NewRequest(http.MethodGet, "/?offset=xyz", nil) | ||
| w := httptest.NewRecorder() | ||
|
|
||
| _, _, ok := parsePaginationParams(w, r) | ||
|
|
||
| if ok { | ||
| t.Fatal("expected ok=false for non-integer offset") | ||
| } | ||
| if w.Code != http.StatusBadRequest { | ||
| t.Errorf("status = %d, want 400", w.Code) | ||
| } | ||
| } | ||
|
|
||
| func TestParsePaginationParams_LimitFloatRejected(t *testing.T) { | ||
| r := httptest.NewRequest(http.MethodGet, "/?limit=1.5", nil) | ||
| w := httptest.NewRecorder() | ||
|
|
||
| _, _, ok := parsePaginationParams(w, r) | ||
|
|
||
| if ok { | ||
| t.Fatal("expected ok=false for float limit") | ||
| } | ||
| if w.Code != http.StatusBadRequest { | ||
| t.Errorf("status = %d, want 400", w.Code) | ||
| } | ||
| } | ||
|
|
||
| func TestParsePaginationParams_NegativeValues_Accepted(t *testing.T) { | ||
| // Negative values are syntactically valid integers; clamping is the handler's job. | ||
| r := httptest.NewRequest(http.MethodGet, "/?limit=-1&offset=-5", nil) | ||
| w := httptest.NewRecorder() | ||
|
|
||
| limit, offset, ok := parsePaginationParams(w, r) | ||
|
|
||
| if !ok { | ||
| t.Fatal("expected ok=true for negative integers") | ||
| } | ||
| if limit != -1 || offset != -5 { | ||
| t.Errorf("expected -1,-5, got %d,%d", limit, offset) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.