| index aa7ace9c9..bdf79bc63 100644 |
| --- a/internal/console/stepup_test.go |
| +++ b/internal/console/stepup_test.go |
| @@ -7,6 +7,7 @@ package console |
| // becomes an oracle telling a stranger which accounts exist. |
| |
| import ( |
| + "html" |
| "net/http" |
| "net/url" |
| "strconv" |
| @@ -399,3 +400,61 @@ func TestSignOutClearsPresence(t *testing.T) { |
| t.Fatal("presence outlived the session it was proved for") |
| } |
| } |
| + |
| +// TestPendingActionStashCap: a parked form is at most pendingFormMax bytes |
| +// as stored (its URL encoding). A larger one is not stashed, the gate |
| +// answers as for any stash that failed, and nothing is applied; the largest |
| +// legitimate form, the letterhead with a logo at its limit, still parks. |
| +func TestPendingActionStashCap(t *testing.T) { |
| + fx, c, csrf := memberFixture(t) |
| + now := time.Now() |
| + |
| + if _, err := fx.st.StashPendingAction(csrf, "paul@keymail.dev", "POST", fx.path("/members/remove"), |
| + strings.Repeat("a", pendingFormMax), now); err != nil { |
| + t.Fatalf("a form at the cap was refused: %v", err) |
| + } |
| + if _, err := fx.st.StashPendingAction(csrf, "paul@keymail.dev", "POST", fx.path("/members/remove"), |
| + strings.Repeat("a", pendingFormMax+1), now); err == nil { |
| + t.Fatal("a form over the cap was stashed") |
| + } |
| + if _, err := fx.st.db.Exec(`DELETE FROM pending_actions`); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + // Through the gate: a removal padded past the cap. |
| + status, loc, body := postForm(t, c, fx.u("/members/remove"), url.Values{"csrf": {csrf}, |
| + "address": {"kim@keymail.dev"}, "pad": {strings.Repeat("a", pendingFormMax)}}) |
| + if status != http.StatusInternalServerError || strings.HasPrefix(loc, fx.fk.srv.URL) || |
| + !strings.Contains(html.UnescapeString(body), stepUpHoldFailed) { |
| + t.Fatalf("oversize removal = %d %q, want the stash-failed refusal:\n%s", status, loc, body) |
| + } |
| + var stashed int |
| + fx.st.db.QueryRow(`SELECT COUNT(*) FROM pending_actions`).Scan(&stashed) |
| + if stashed != 0 { |
| + t.Fatalf("%d pending actions parked for an oversize form", stashed) |
| + } |
| + if role, _ := fx.st.Role(OpsAccountID, "kim@keymail.dev"); role != RoleMember { |
| + t.Fatalf("an oversize form was applied (role %q)", role) |
| + } |
| +} |
| + |
| +// TestPendingActionStashCapFitsLetterhead: the letterhead form with a logo |
| +// at letterheadLogoMax (about 273 KB as base64) parks under the cap. |
| +func TestPendingActionStashCapFitsLetterhead(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInOperator(t, fx) |
| + logo := append(oplPNG(t), make([]byte, letterheadLogoMax)...)[:letterheadLogoMax] |
| + fields := oplLetterheadFields() |
| + for _, k := range []string{"office", "footer"} { |
| + fields[k] = strings.Repeat("é", letterheadLong) |
| + } |
| + status, loc, body := oplPostLetterhead(t, fx, c, fields, logo) |
| + if status != http.StatusSeeOther || !strings.HasPrefix(loc, fx.fk.srv.URL) { |
| + t.Fatalf("letterhead at its limits = %d %q, want 303 to Keymail:\n%s", status, loc, body) |
| + } |
| + var size int |
| + fx.st.db.QueryRow(`SELECT LENGTH(form) FROM pending_actions`).Scan(&size) |
| + if size == 0 || size > pendingFormMax/2 { |
| + t.Fatalf("parked letterhead is %d bytes, want well under %d", size, pendingFormMax) |
| + } |
| +} |