oficina / fichas Public

The rail's fold writes no row and returns only to a local path (test)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev aca545beee45cf308ac1a02833b8c15b13b4b3c6 parent 13b4a96
1 file changed, +24 −0
  • internal/fichastest/edit_routes_test.go +24 −0
diff --git a/internal/fichastest/edit_routes_test.go b/internal/fichastest/edit_routes_test.go
index f7d5176..c7d294f 100644
--- a/internal/fichastest/edit_routes_test.go
+++ b/internal/fichastest/edit_routes_test.go
@@ -372,3 +372,27 @@ func dump(t *testing.T, d *db.DB) string {
}
return b.String()
}
+
+// The rail's fold is a preference (§3.2, §9's named exemption): a
+// cookie, no row, no event, and it returns only to a local path.
+func TestTheFoldIsACookieOnly(t *testing.T) {
+ r := newEditRig(t)
+ before := dump(t, r.d)
+ rec := post(t, r.h, "/view/rail", url.Values{"rail": {"rail"}, "return_to": {"/t/t_customer?q=x"}})
+ if rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/t/t_customer?q=x" {
+ t.Fatalf("the fold: %d %q", rec.Code, rec.Header().Get("Location"))
+ }
+ if !strings.Contains(rec.Header().Get("Set-Cookie"), "fichas-rail=rail") {
+ t.Fatal("the fold set no cookie")
+ }
+ if dump(t, r.d) != before {
+ t.Fatal("the fold wrote to the database")
+ }
+ if loc := post(t, r.h, "/view/rail", url.Values{"rail": {"open"}, "return_to": {"https://evil.example/"}}).Header().Get("Location"); loc != "/" {
+ t.Fatalf("the fold returned to %q", loc)
+ }
+ folded := withCookies(t, r.h, "/", rec)
+ if !strings.Contains(folded, `<div fichas-app data-rail="rail">`) {
+ t.Fatal("a folded rail is not drawn folded")
+ }
+}