oficina / calendar Public

Smart door: Fable's fixes on #48

- The view toolbar no longer gains 18px: rastrillo v0.42 gives the
  segmented tabs a bottom margin, zeroed inside [cal-bar] as its own
  comment asks. Checked against main at 1280 and 390.
- The door's probe judges only the methods requirePerson speaks for
  (Home on the web, emailed link, Keymail), as homeSignin and teamSignin
  did; a native or guest session is never refused by the web door.
- Tests: a removed member at /signin/local and /signin/oficina, a team
  Home session for nobody, an unlinked local account in team mode, a
  refused session on Sent and a problem, and native/guest sessions.
- TestNoZoomOnTap names the booking page's zone in the URL, so the page's
  own zone-guess submit no longer races the test's reload (chromedp v0.21
  reports the aborted load that v0.14 hid).
- Nits: App.Close back in app.go (NextDue and Handler move to
  serving.go for the line cap); stale signin.go references; AGENTS.md
  spacing; the Makefile finds Chrome for Testing as well as Chromium.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 5dde63b8c602e45f70ade9e6f690c60fe7fcdca2 parent 567381e
12 files changed, +202 −60
  • AGENTS.md +4 −2
  • Makefile +5 −1
  • internal/calendar/app.go +19 −23
  • internal/calendar/home.go +3 −3
  • internal/calendar/person.go +1 −1
  • internal/calendar/serving.go +15 −0
  • internal/calendar/signin.go +10 −0
  • internal/calendar/signin_admission.go +21 −27
  • internal/calendar/signin_door_gaps_test.go +110 −0
  • internal/calendar/static/calendar.css +8 −0
  • internal/calendar/team_access.go +1 −1
  • internal/calendartest/zoom_browser_test.go +5 −2

CI passed — run details

CI log
=== vet ===
go vet ./...
go vet -tags browser ./internal/calendartest/ ./internal/calendar/
=== fmt ===
=== test ===
go test ./...
ok  	amadan.net/oficina/calendar/cmd/calendar	0.123s
?   	amadan.net/oficina/calendar/cmd/calendar-contract	[no test files]
ok  	amadan.net/oficina/calendar/internal/calendar	28.020s
?   	amadan.net/oficina/calendar/internal/calendar/icons	[no test files]
?   	amadan.net/oficina/calendar/internal/calendar/keymailtest	[no test files]
?   	amadan.net/oficina/calendar/internal/calendar/seal	[no test files]
?   	amadan.net/oficina/calendar/internal/calendar/teamstate	[no test files]
ok  	amadan.net/oficina/calendar/internal/calendartest	3.966s
ok  	amadan.net/oficina/calendar/internal/guardstest	0.094s
?   	amadan.net/oficina/calendar/scripts/writeestilo	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
diff --git a/AGENTS.md b/AGENTS.md
index 8cef111..98b833f 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -261,7 +261,6 @@ relying on remembering one, make it a test instead.
- **rastrillo needs its English pack linked** (serving.go's
`_ ".../locales/en"`): from v0.29 a language with no pack is refused at
start, by Serve and Handler alike, and the door's words come from it.
-
- **An emailed link confirms before it is spent.** GET /auth/verify draws
the door with one Sign in button (`App.renderConfirm`) and spends
nothing, so a mail scanner cannot burn it; the POST redeems. Both are
@@ -290,7 +289,9 @@ home/connect MIGRATING.md)
refuses is ended on that response and shown the refusal (or the
removal), with a remembered Oficina ID forgotten; any 5xx is undecided
and refuses nothing. The probe ends nothing itself (offboard skips its
- sign-out under it).
+ sign-out under it), and judges only the three methods requirePerson
+ speaks for (`doorJudges`): a native or guest session is never refused
+ by the web door.
- **The refusal is on the plain door only**: `?ways=` and `?way=` are how
a refused person reaches another way in. It is never read from the
query; the removal is, as it always was.
@@ -307,6 +308,7 @@ home/connect MIGRATING.md)
- **Team mode passes connect's `Admit`** (`teamAdmit`): a roster Member
with no account here gets connect's choose page
(`/account/home/choose`), in connect's own English.
+
**Logs**
- **No title, place, note or address in any log line, error string or
metric label.** `carlos logs` is platform-held storage we cannot grep
diff --git a/Makefile b/Makefile
index 4f1a182..520efa3 100644
--- a/Makefile
+++ b/Makefile
@@ -159,7 +159,11 @@ browser:
RASTRILLO_CHROME="$(RASTRILLO_CHROME)" go test -tags browser -run 'InARealBrowser|OnTap|OnANarrowScreen|SurviveTheProductionCSP' ./internal/calendartest/
RASTRILLO_CHROME="$(RASTRILLO_CHROME)" go test -tags browser -run 'SmartDoorInABrowser' ./internal/calendar/
-RASTRILLO_CHROME ?= $(firstword $(wildcard $(HOME)/Library/Caches/ms-playwright/chromium-*/chrome-mac*/Chromium.app/Contents/MacOS/Chromium))
+# The Playwright cache's Chromium: older caches hold Chromium.app, newer
+# ones "Google Chrome for Testing.app". The path has spaces, so it is found
+# by the shell (make's wildcard and firstword split on them) and quoted
+# where it is used.
+RASTRILLO_CHROME ?= $(shell ls -d "$(HOME)"/Library/Caches/ms-playwright/chromium-*/chrome-mac*/Chromium.app/Contents/MacOS/Chromium "$(HOME)"/Library/Caches/ms-playwright/chromium-*/chrome-mac*/"Google Chrome for Testing.app"/Contents/MacOS/"Google Chrome for Testing" 2>/dev/null | tail -1)
.PHONY: credits
credits:
diff --git a/internal/calendar/app.go b/internal/calendar/app.go
index f4503d6..82bb753 100644
--- a/internal/calendar/app.go
+++ b/internal/calendar/app.go
@@ -11,7 +11,6 @@ import (
"log/slog"
"net/http"
"sync"
- "time"
rauth "amadan.net/rastrillo/rastrillo/auth"
"amadan.net/rastrillo/rastrillo/db"
@@ -51,10 +50,8 @@ type App struct {
// real sign-in does, rather than by writing a session row by hand.
auth *rauth.Auth
- // sessions is Home's, or standalone one over auth's table and cookie:
- // where the door ends a refused session (signin_admission.go).
- sessions *sessions.Sessions
- returns *returnMemory // with Home only (signin_return.go)
+ sessions *sessions.Sessions // Home's, or one over auth's (signin_admission.go)
+ returns *returnMemory // with Home only (signin_return.go)
// h is held for the test harness; requests reach it through mux.
h *handlers
@@ -184,13 +181,8 @@ func New(cfg Config) (*App, error) {
store := NewStore(d.G, sealer, logger)
store.team = team != nil
h := &handlers{store: store, logger: logger, origin: origin, mailer: mailer, gate: newGate()}
- // auth's Refused and RenderConfirm are the door, App's (signin.go),
- // bound once it exists; h.viewerFrom is auth's, set just after.
- var app *App
- door := authPages{
- refused: func(w http.ResponseWriter, r *http.Request, id rauth.Identity) { app.refused(w, r, id) },
- confirm: func(w http.ResponseWriter, r *http.Request, d rauth.ConfirmPageData) { app.renderConfirm(w, r, d) },
- }
+ // auth's two pages are the door's (doorPages); viewerFrom is set below.
+ door, bindDoor := doorPages()
authPlugin, err := newAuthPlugin(origin, writer, instanceKey, signinMail, list, logger, homeSettings != nil, door)
if err != nil {
signinMail.close()
@@ -210,7 +202,7 @@ func New(cfg Config) (*App, error) {
teamOn: team,
}
a.h = h
- app = a
+ bindDoor(a)
if homeSettings != nil {
a.home, err = a.newHome(homeSettings, list)
if err != nil {
@@ -285,14 +277,18 @@ func New(cfg Config) (*App, error) {
return a, nil
}
-// NextDue answers the platform's scheduled-wake poll: the next moment
-// this instance has work. rastrillo mounts it as GET /api/next-due,
-// outside app middleware, and the activator asks before hibernating.
-func (a *App) NextDue() time.Time {
- return a.scheduled.probe()
+// Close releases the database. Safe to call on a partially built app.
+func (a *App) Close() error {
+ a.closeOnce.Do(func() {
+ if a.signinMail != nil {
+ a.signinMail.close()
+ }
+ if a.scheduled != nil {
+ a.scheduled.close()
+ }
+ if a.db != nil {
+ a.closeErr = a.db.Close()
+ }
+ })
+ return a.closeErr
}
-
-// Handler is the app's router, for rastrillo.Options.Mux and for
-// tests. It is typed *http.ServeMux rather than http.Handler because
-// Options.Mux is typed that way.
-func (a *App) Handler() *http.ServeMux { return a.mux }
diff --git a/internal/calendar/home.go b/internal/calendar/home.go
index b3322f7..68fbc67 100644
--- a/internal/calendar/home.go
+++ b/internal/calendar/home.go
@@ -22,7 +22,7 @@ type homeConnection struct {
sessions *sessions.Sessions
admitted allowlist
// issuer is Home's issuer (id.oficina.works): where the signed-out
- // page's Forget chains on to (signin.go's forget).
+ // page's Forget chains on to (signin_out.go's forget).
issuer string
}
@@ -70,7 +70,7 @@ func (a *App) newHome(settings *connect.DecodedCredentials, list allowlist) (*ho
page := func(w http.ResponseWriter, r *http.Request, state, label string, status int) {
if state == "signedout" {
// Where sign-out lands is the Oficina door, in the door's
- // words, with Forget (signin.go's renderSignedOut).
+ // words, with Forget (signin_out.go's renderSignedOut).
a.renderSignedOut(w, r, status)
return
}
@@ -112,7 +112,7 @@ func (a *App) newHome(settings *connect.DecodedCredentials, list allowlist) (*ho
return err
}
// The smart door remembers Oficina ID, for an admitted session
- // only (signin.go's rememberOficina). It never fails the sign-in.
+ // only (signin_admission.go's rememberOficina). It never fails the sign-in.
a.rememberOficina(w, r)
return nil
}}
diff --git a/internal/calendar/person.go b/internal/calendar/person.go
index 6201d16..30ea942 100644
--- a/internal/calendar/person.go
+++ b/internal/calendar/person.go
@@ -42,7 +42,7 @@ func (a *App) requirePerson(next http.Handler) http.Handler {
p, err := a.homePerson(r)
if homeUnavailable(err) {
// Storage, not identity: never a 404, which the sign-in
- // door would read as a refusal (signin.go's admission).
+ // door would read as a refusal (signin_admission.go's admission).
w.Header().Set("Cache-Control", "no-store")
a.h.errorPage(w, r, http.StatusServiceUnavailable, "")
return
diff --git a/internal/calendar/serving.go b/internal/calendar/serving.go
index cdb84b1..263a764 100644
--- a/internal/calendar/serving.go
+++ b/internal/calendar/serving.go
@@ -1,6 +1,9 @@
package calendar
import (
+ "net/http"
+ "time"
+
"amadan.net/rastrillo/rastrillo"
// The pack for rastrillo's one language here: from rastrillo v0.29.0
@@ -61,3 +64,15 @@ func containsHTML(accept string) bool {
}
return false
}
+
+// NextDue answers the platform's scheduled-wake poll: the next moment
+// this instance has work. rastrillo mounts it as GET /api/next-due,
+// outside app middleware, and the activator asks before hibernating.
+func (a *App) NextDue() time.Time {
+ return a.scheduled.probe()
+}
+
+// Handler is the app's router, for rastrillo.Options.Mux and for
+// tests. It is typed *http.ServeMux rather than http.Handler because
+// Options.Mux is typed that way.
+func (a *App) Handler() *http.ServeMux { return a.mux }
diff --git a/internal/calendar/signin.go b/internal/calendar/signin.go
index d052337..32b8264 100644
--- a/internal/calendar/signin.go
+++ b/internal/calendar/signin.go
@@ -134,6 +134,16 @@ func signinTitle(screen chrome.SignInScreen) (string, error) {
return strings.TrimSpace(html.UnescapeString(b.String())), nil
}
+// doorPages are auth's two pages, Refused and RenderConfirm, for an App
+// that New builds after the plugin: bind hands them the App.
+func doorPages() (authPages, func(*App)) {
+ var app *App
+ return authPages{
+ refused: func(w http.ResponseWriter, r *http.Request, id rauth.Identity) { app.refused(w, r, id) },
+ confirm: func(w http.ResponseWriter, r *http.Request, d rauth.ConfirmPageData) { app.renderConfirm(w, r, d) },
+ }, func(a *App) { app = a }
+}
+
// renderConfirm is auth's RenderConfirm, the page an emailed link opens on
// (GET /auth/verify): the door, whose SigninState answers StepConfirm on
// this request alone, with one Sign in button that POSTs the token back,
diff --git a/internal/calendar/signin_admission.go b/internal/calendar/signin_admission.go
index ecedca7..015e671 100644
--- a/internal/calendar/signin_admission.go
+++ b/internal/calendar/signin_admission.go
@@ -106,22 +106,24 @@ func (a *App) admission(r *http.Request, strict bool) admissionResult {
probe.URL = &url.URL{Path: "/"}
probe.RequestURI = "/"
probe.Body = http.NoBody
+ // The session is read from the probe's own cookie, never from the
+ // context the app-wide middleware filled: admittedAs asks about a
+ // session minted on this very response.
+ s, ok := a.sessions.From(probe)
+ if !ok {
+ return admissionResult{}
+ }
+ if !doorJudges(s.Method) {
+ // Not the web door's to judge (a native app's session, a guest):
+ // signed in, as the old /signin checks left it, and never refused.
+ return admissionResult{signedIn: true, admitted: true}
+ }
reached := false
gate := a.requirePerson(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { reached = true }))
rec := &bufferedResponse{header: make(http.Header)}
if a.home != nil {
- // The session is read from the probe's own cookie, never from the
- // context the app-wide middleware filled: admittedAs asks about a
- // session minted on this very response.
- s, ok := a.home.sessions.From(probe)
- if !ok {
- return admissionResult{}
- }
gate.ServeHTTP(rec, withSession(probe, s))
} else {
- if _, ok := a.auth.SessionFrom(probe); !ok {
- return admissionResult{}
- }
a.auth.RequireSession(gate).ServeHTTP(rec, probe)
}
undecided := rec.status >= http.StatusInternalServerError
@@ -132,6 +134,14 @@ func (a *App) admission(r *http.Request, strict bool) admissionResult {
}
}
+// doorJudges reports whether the door's probe judges a session signed in
+// by method: the three requirePerson speaks for (a Home sign-in on the web,
+// an emailed link, Keymail), as homeSignin and teamSignin did. Any other
+// (connect's native methods, a guest) is never refused by the web door.
+func doorJudges(method string) bool {
+ return method == connect.HomeMethod || method == "magiclink" || method == "keymail"
+}
+
// probingKey marks the admission probe's request, so the gate it runs
// answers without ending anything (offboard).
type probingKey struct{}
@@ -245,23 +255,7 @@ func (a *App) sessionStore() *sessions.Sessions { return a.sessions }
func (a *App) sessionCookie() string { return a.sessions.CookieName() }
// withSession is r carrying s as the current session, in place of any the
-// app-wide middleware put there (signin.go's admission).
+// app-wide middleware put there (admission, above).
func withSession(r *http.Request, s sessions.Session) *http.Request {
return sessions.WithSession(r, s)
}
-
-// Close releases the database. Safe to call on a partially built app.
-func (a *App) Close() error {
- a.closeOnce.Do(func() {
- if a.signinMail != nil {
- a.signinMail.close()
- }
- if a.scheduled != nil {
- a.scheduled.close()
- }
- if a.db != nil {
- a.closeErr = a.db.Close()
- }
- })
- return a.closeErr
-}
diff --git a/internal/calendar/signin_door_gaps_test.go b/internal/calendar/signin_door_gaps_test.go
new file mode 100644
index 0000000..68f1e86
--- /dev/null
+++ b/internal/calendar/signin_door_gaps_test.go
@@ -0,0 +1,110 @@
+package calendar
+
+// The door's edges Fable probed by hand on #48: a removed member on the
+// other two door routes, a team session that speaks for nobody, an
+// unlinked local account in team mode, a refused session on the door's own
+// outcome states, and sessions the web door must never judge.
+
+import (
+ "net/http"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/home/connect"
+)
+
+// A removed member at /signin/local sees the removal, and the session ends
+// on that response; at /signin/oficina the session ends and Oficina ID
+// starts afresh, rather than shortcutting a refused session to a page.
+func TestTeamRemovedMemberOnTheOtherDoorRoutes(t *testing.T) {
+ f := newTeamFixture(t)
+ subject := teamSubject('o')
+ f.member(subject, "member")
+ f.dir.Set(subject, "")
+ f.refreshed()
+ cookie := f.app.sessionCookie()
+
+ w := f.get(connect.SigninLocalPath)
+ card := door(t, w.Body.String())
+ if w.Code != http.StatusOK || !strings.Contains(card, signinRemoved) || !clears(w, cookie) || f.sessionCookie() != nil {
+ t.Fatalf("/signin/local for a removed member = %d, cleared %v\n%s", w.Code, clears(w, cookie), card)
+ }
+
+ f.signInHome(subject)
+ if f.sessionCookie() == nil {
+ t.Fatal("re-sign-in minted no session")
+ }
+ start := f.get(connect.SigninOficinaPath)
+ if loc := start.Header().Get("Location"); start.Code != http.StatusSeeOther || !strings.HasPrefix(loc, "/auth/start") {
+ t.Fatalf("/signin/oficina for a removed member = %d %q, want the Home exchange", start.Code, loc)
+ }
+ if !clears(start, cookie) || f.sessionCookie() != nil {
+ t.Error("/signin/oficina kept the removed member's session")
+ }
+}
+
+// A Home session for a subject that speaks for nobody here (no link, no
+// Home-only person) is ended at the door and shown the refusal.
+func TestTeamHomeSessionForNobodyIsRefused(t *testing.T) {
+ f := newTeamFixture(t)
+ f.session(t, teamSubject('n'), connect.HomeMethod, time.Now())
+ w := f.get("/signin")
+ if card := door(t, w.Body.String()); w.Code != http.StatusOK || !strings.Contains(card, signinRefusal) {
+ t.Fatalf("/signin for a Home session of nobody = %d\n%s", w.Code, card)
+ }
+ if !clears(w, f.app.sessionCookie()) {
+ t.Error("the session for nobody was not ended")
+ }
+}
+
+// An unlinked local account in team mode is signed in, not refused: /signin
+// shortcuts it to "/", and "/" sends it on to link (/account/home).
+func TestTeamUnlinkedLocalAccountIsNotRefused(t *testing.T) {
+ f := newTeamFixture(t)
+ f.localSession("alice@example.test")
+ w := f.get("/signin")
+ if strings.Contains(w.Body.String(), signinRefusal) {
+ t.Fatal("an unlinked local account was refused at the door")
+ }
+ redirectsTo(t, w, "/")
+ redirectsTo(t, f.get("/"), "/account/home")
+ if f.sessionCookie() == nil {
+ t.Error("the door ended an unlinked local account's session")
+ }
+}
+
+// A refused session on the door's own outcome states (Sent, a problem) is
+// ended there too, but the state is drawn as it is, without the refusal.
+func TestARefusedSessionOnTheDoorsOutcomeStates(t *testing.T) {
+ for _, path := range []string{"/signin?sent=1", "/signin?err=expired"} {
+ f := newHomeRouterFixture(t)
+ f.session(t, "alice@example.test", "magiclink", time.Now())
+ delete(f.app.home.admitted.addrs, "alice@example.test")
+ w := f.get(path)
+ if w.Code != http.StatusOK || strings.Contains(w.Body.String(), signinRefusal) {
+ t.Errorf("GET %s for a refused session = %d, drew the refusal: %v", path, w.Code, strings.Contains(w.Body.String(), signinRefusal))
+ }
+ if !clears(w, f.app.sessionCookie()) || f.sessionCookie() != nil {
+ t.Errorf("GET %s kept the refused session", path)
+ }
+ }
+}
+
+// Sessions requirePerson cannot speak for (a native app's, a guest's) are
+// never judged by the web door: not refused, not ended, in either mode.
+func TestTheDoorNeverJudgesANativeSession(t *testing.T) {
+ for name, f := range map[string]*homeRouterFixture{"home": newHomeRouterFixture(t), "team": newTeamFixture(t).homeRouterFixture} {
+ for _, method := range []string{connect.NativeMethod, connect.NativeWebMethod, "guest"} {
+ g := f.fresh()
+ g.session(t, teamSubject('v'), method, time.Now())
+ w := g.get("/signin")
+ if strings.Contains(w.Body.String(), signinRefusal) || clears(w, f.app.sessionCookie()) {
+ t.Errorf("%s: the door judged a %s session: %d", name, method, w.Code)
+ }
+ if ad := f.app.admission(g.jarRequest(), true); !ad.signedIn || !ad.admitted {
+ t.Errorf("%s: the probe refused a %s session", name, method)
+ }
+ }
+ }
+}
diff --git a/internal/calendar/static/calendar.css b/internal/calendar/static/calendar.css
index 8aaa9a8..2f6bad0 100644
--- a/internal/calendar/static/calendar.css
+++ b/internal/calendar/static/calendar.css
@@ -42,6 +42,14 @@ html { scroll-padding-block-start: var(--estilo-bar-block-size); }
margin-block-end: var(--rst-sp-4);
}
+/* rastrillo v0.42's tokens.css gives the segmented tabs a bottom margin
+ * for a switcher standing alone, and says a row of controls should zero
+ * it: the toolbar's own margin is the gap, so the grid starts where it did.
+ * The view switcher is the toolbar's one nav (layout.html). */
+[cal-bar] > nav {
+ margin-block-end: 0;
+}
+
[cal-bar-steps] {
display: flex;
gap: var(--rst-sp-2);
diff --git a/internal/calendar/team_access.go b/internal/calendar/team_access.go
index fe94c94..68bd8a7 100644
--- a/internal/calendar/team_access.go
+++ b/internal/calendar/team_access.go
@@ -206,7 +206,7 @@ const offboardPath = "/signin?err=removed"
// the sign-in door, which says so. A 303, so a form POST lands on a page
// too.
//
-// Under the sign-in door's admission probe (signin.go) it only answers: the
+// Under the sign-in door's admission probe (signin_admission.go) it only answers: the
// probe decides what to end, and must not revoke a session it was merely
// asked about, such as the one MintHomeSession has just stored, which then
// lands on its first page and is offboarded there, told why.
diff --git a/internal/calendartest/zoom_browser_test.go b/internal/calendartest/zoom_browser_test.go
index ae1eb90..9c47759 100644
--- a/internal/calendartest/zoom_browser_test.go
+++ b/internal/calendartest/zoom_browser_test.go
@@ -83,7 +83,10 @@ func TestNoZoomOnTap(t *testing.T) {
if err := st.PublishBookingPage(ctx, host.ID, page.ID, true); err != nil {
t.Fatal(err)
}
- public := "/book/paul/" + page.Code
+ // The zone named in the URL, so the page does not submit its own zone
+ // guess on load (booking.js setupZone): that self-navigation raced
+ // measure's reload, which chromedp v0.21 reports as an aborted load.
+ public := "/book/paul/" + page.Code + "?zone=UTC"
run := func(what string, actions ...chromedp.Action[chromedp.Void]) {
t.Helper()
@@ -164,7 +167,7 @@ func TestNoZoomOnTap(t *testing.T) {
// The stranger's side: the zone picker, then a day, then a slot,
// which is where the name, address and note fields are.
- measure(public, `select[name="zone"]`)
+ measure(public, `select[name="zone"][data-chosen]`)
var day string
run("a booking day",
chromedp.Navigate(rig.Origin+public),