oficina / calendar Public

Merge remote-tracking branch 'origin/main' into feat/dashboard-feed

# Conflicts:
#	go.sum
Paul Campbell pushed by paul@keymail.dev 475bc922c573602f3af48e8acf2ff6647f144ef5 parent efafc39parent 5ab1821
11 files changed, +331 −20
  • go.mod +4 −4
  • go.sum +6 −6
  • internal/calendar/app.go +1 −0
  • internal/calendar/config.go +5 −0
  • internal/calendar/handlers.go +5 −0
  • internal/calendar/home.go +53 −2
  • internal/calendar/home_connect_item_test.go +234 −0
  • internal/calendar/home_consumer_test.go +1 −1
  • internal/calendar/home_router_test.go +18 −6
  • internal/calendar/render.go +3 −0
  • internal/calendar/routes.go +1 −1

CI passed — run details

diff --git a/go.mod b/go.mod
index 895b8d7..6a6cc8a 100644
--- a/go.mod
+++ b/go.mod
@@ -5,8 +5,8 @@ go 1.25.0
toolchain go1.26.5
require (
- amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c
- amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489
+ amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d
+ amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d
amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060
github.com/carlosframework/rastrillo v0.23.0
github.com/chromedp/chromedp v0.14.2
@@ -14,14 +14,14 @@ require (
gorm.io/gorm v1.31.2
)
-require amadan.net/oficina/estilo.git v0.0.0-20261024225350-d53b8e9533a1
+require amadan.net/oficina/estilo.git v0.0.0-20261024233714-f14458a4683c
require (
github.com/BurntSushi/toml v1.6.0 // indirect
github.com/chromedp/cdproto v0.0.0-20250724212937-08a3db8b4327
github.com/chromedp/sysutil v1.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
- github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 // indirect
+ github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.4.0 // indirect
diff --git a/go.sum b/go.sum
index 1c8112c..a979ce6 100644
--- a/go.sum
+++ b/go.sum
@@ -1,11 +1,11 @@
-amadan.net/oficina/estilo.git v0.0.0-20261024225350-d53b8e9533a1 h1:Xaidrm9rzFyne6PujFYXiY7nGRy+/KzH7kGBM2+D5LQ=
-amadan.net/oficina/estilo.git v0.0.0-20261024225350-d53b8e9533a1/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw=
-amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c h1:3yxO2D8BxDLMGfFV2o6Sp9Z91yLnjDCIuRKHVWORa8A=
-amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c/go.mod h1:YroavXe43Wietec+po8mtSk4a9Bir2h31Q3iAf4MWxI=
+amadan.net/oficina/estilo.git v0.0.0-20261024233714-f14458a4683c h1:jPbFJwPi7lHe+UNe+Gbj0ivVsy+pLqMSq2EP2Xff/q0=
+amadan.net/oficina/estilo.git v0.0.0-20261024233714-f14458a4683c/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw=
+amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d h1:9sVZBph2xUuejZt73DYaoCfoyvrvZCnuPHcyMsg562E=
+amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d/go.mod h1:ix81eFV87yE9f2SXiRuxYCVM4lAgTRC5YoQMiH3+TDk=
amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816 h1:AFDuOio0MxNxN9ZWVc3lul1QHkNjNUCO56kXpe/Fw3I=
amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816/go.mod h1:+7xsX+QyVFrKy5gDAGh+FZ5+75z4CibWTL0wl9DWAw0=
-amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 h1:RPKtyry/71i06o8L+gjAaUyexbmG56kO1YPs601URAM=
-amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k=
+amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d h1:8RTZkLQnyxvH2g0RMovhN/m2LN9D8qb+kBfqdBeqq+s=
+amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k=
amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3 h1:5EFx7BLJj/+G/rt8bTmeyMWVfF5s5Sns7ajTvX4w/I8=
amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3/go.mod h1:ZaaxeE278dJltdrLwmwpxUjQ5wuKzqDAVSNRet+WupY=
amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 h1:K2PXcCKfm+AYrqgH1ea6cNsFs4sN7MKLvq+uBY11NZE=
diff --git a/internal/calendar/app.go b/internal/calendar/app.go
index 43dccb2..505105a 100644
--- a/internal/calendar/app.go
+++ b/internal/calendar/app.go
@@ -184,6 +184,7 @@ func New(cfg Config) (*App, error) {
}
h.homeEnabled = true
h.directory = homeSettings.Directory
+ h.homeLinked = a.home.bridge.Linked
h.viewerFrom = func(r *http.Request) (rauth.Identity, bool) {
// requirePerson has already resolved the person on every page
// behind it; resolve again only where it has not run (public
diff --git a/internal/calendar/config.go b/internal/calendar/config.go
index 76333cf..a124a26 100644
--- a/internal/calendar/config.go
+++ b/internal/calendar/config.go
@@ -7,6 +7,7 @@ import (
"log/slog"
"net/url"
"strings"
+ "time"
"amadan.net/rastrillo/rastrillo/mail"
)
@@ -71,6 +72,10 @@ type Config struct {
AllowedAddresses string
Logger *slog.Logger
+
+ // homeNow is the Home bridge's clock; nil is time.Now. Unexported:
+ // only this package's tests set it, to age a navigation marker.
+ homeNow func() time.Time
}
// resolveOrigin applies Config.Origin's fail-closed rule: a valid
diff --git a/internal/calendar/handlers.go b/internal/calendar/handlers.go
index 31602b0..f29f383 100644
--- a/internal/calendar/handlers.go
+++ b/internal/calendar/handlers.go
@@ -1,6 +1,7 @@
package calendar
import (
+ "context"
"log/slog"
"net/http"
@@ -29,6 +30,10 @@ type handlers struct {
// passes through. One per app; memory only.
gate *gate
viewerFrom func(*http.Request) (rauth.Identity, bool)
+
+ // homeLinked is Bridge.Linked with Home configured, nil without it:
+ // whether a person already has a stored link (offerHomeConnect).
+ homeLinked func(context.Context, int64) (bool, error)
}
// index serves GET / — the calendar itself.
diff --git a/internal/calendar/home.go b/internal/calendar/home.go
index 32d72cf..746da72 100644
--- a/internal/calendar/home.go
+++ b/internal/calendar/home.go
@@ -6,6 +6,7 @@ import (
"database/sql"
"errors"
"net/http"
+ "time"
"amadan.net/oficina/home/connect"
"amadan.net/oficina/home/connect/linkstore"
@@ -57,7 +58,7 @@ func (a *App) newHome(settings *connect.DecodedCredentials, list allowlist) (*ho
return p, nil
}
page := func(w http.ResponseWriter, r *http.Request, state, label string, status int) {
- data := connect.Page(state, label)
+ data := connect.PageFor(r, state, label)
// Where sign-out lands is the Oficina door, in the door's words.
tree, title, view := pages["home"], data.Title, any(data)
if state == "signedout" {
@@ -74,7 +75,7 @@ func (a *App) newHome(settings *connect.DecodedCredentials, list allowlist) (*ho
w.WriteHeader(status)
_, _ = buf.WriteTo(w)
}
- b, err := connect.New(connect.Config{DB: writer, Origin: a.cfg.Origin, Issuer: settings.Issuer, ConsumerID: settings.ConsumerID, Keys: settings.Keys, DEK: settings.DEK, Namespace: "oficina/calendar", SessionCookie: sess.CookieName(), ReadSession: read, LookupLocalSession: local, LookupPerson: lookup, Render: page, MintHomeSession: func(w http.ResponseWriter, r *http.Request, s connect.Session) error {
+ b, err := connect.New(connect.Config{DB: writer, Origin: a.cfg.Origin, Issuer: settings.Issuer, ConsumerID: settings.ConsumerID, Keys: settings.Keys, DEK: settings.DEK, Namespace: "oficina/calendar", SessionCookie: sess.CookieName(), ReadSession: read, LookupLocalSession: local, LookupPerson: lookup, Render: page, Now: a.cfg.homeNow, MintHomeSession: func(w http.ResponseWriter, r *http.Request, s connect.Session) error {
return sess.SignIn(w, r, sessions.Session{Subject: s.Subject, Method: s.Method, AuthTime: s.AuthTime})
}})
if err != nil {
@@ -87,6 +88,30 @@ func (a *App) newHome(settings *connect.DecodedCredentials, list allowlist) (*ho
return &homeConnection{bridge: b, routes: routes, sessions: sess, admitted: list}, nil
}
+// offerHomeConnect decides the account menu's "Connect your Oficina
+// account". Only with Home configured, only to a person signed in locally
+// (a Home session is linked already), and only while that person has no
+// stored link. The stored link decides, never how this session signed in:
+// a linked person who signed in with an emailed link has nothing to
+// connect, and was offered it anyway (Paul, in Docs, 2026-10-24). The
+// person is requirePerson's, already on the request, so this costs one
+// lookup on the UNIQUE (issuer, person_id) index per menu render. An error
+// means "unknown", and offers nothing.
+func (h *handlers) offerHomeConnect(r *http.Request) bool {
+ if h.homeLinked == nil {
+ return false
+ }
+ if s, ok := sessions.Current(r); !ok || (s.Method != "magiclink" && s.Method != "keymail") {
+ return false
+ }
+ p, ok := CurrentPerson(r)
+ if !ok || p.ID <= 0 {
+ return false
+ }
+ linked, err := h.homeLinked(r.Context(), p.ID)
+ return err == nil && !linked
+}
+
func (a *App) homePerson(r *http.Request) (Person, error) {
p, err := a.home.bridge.ResolveSession(r)
if err != nil {
@@ -135,3 +160,29 @@ func (a *App) homeSignin(w http.ResponseWriter, r *http.Request) {
}
a.home.routes.Signin(w, r)
}
+
+// homeLocalComplete is GET /auth/local/complete with Home configured: where
+// a local sign-in lands. After an Oficina assertion Calendar had no link
+// for, connect resumes the link from here, and that needs the person's
+// people row. A first-ever local sign-in has none yet (requirePerson makes
+// it on the first page), so the resume fell to /account/home, which
+// answered 403 (Astra's review of #31). A fresh, admitted local session
+// gets its person here first, exactly as requirePerson would set it up;
+// any other request is passed on untouched. Never from a Home subject:
+// only the verified local address. Failing costs only the shortcut: the
+// sign-in itself has already succeeded.
+func (a *App) homeLocalComplete(w http.ResponseWriter, r *http.Request) {
+ if s, ok := a.home.sessions.From(r); ok && (s.Method == "magiclink" || s.Method == "keymail") {
+ now := time.Now
+ if a.cfg.homeNow != nil {
+ now = a.cfg.homeNow
+ }
+ address := normalizeAddress(s.Subject)
+ if _, fresh := connect.FreshLocal(connect.Session{Subject: s.Subject, Method: s.Method, AuthTime: s.AuthTime, At: s.At}, now()); fresh && address != "" && a.home.admitted.allows(address) {
+ if _, err := a.store.EnsurePersonSetup(r.Context(), address); err != nil {
+ a.logger.Error("calendar: ensure person before resuming a Home link", "err", err)
+ }
+ }
+ }
+ a.home.routes.LocalComplete(w, r)
+}
diff --git a/internal/calendar/home_connect_item_test.go b/internal/calendar/home_connect_item_test.go
new file mode 100644
index 0000000..85e85fd
--- /dev/null
+++ b/internal/calendar/home_connect_item_test.go
@@ -0,0 +1,234 @@
+package calendar
+
+import (
+ "net/http"
+ "net/url"
+ "regexp"
+ "strings"
+ "testing"
+ "time"
+)
+
+// connectItem is the account menu's "Connect your Oficina account" row, as
+// estilo's menu draws it.
+const connectItem = `<a estilo-menu-item href="/account/home"><span estilo-menu-label>Connect your Oficina account</span></a>`
+
+const freshHomeStart = "/auth/start?return_to=%2Faccount%2Fhome%2Fconfirm"
+
+func (f *homeRouterFixture) offersConnect(t *testing.T) bool {
+ t.Helper()
+ w := f.do("GET", "/day/2026-09-10", "")
+ if w.Code != 200 {
+ t.Fatalf("GET /day: %d", w.Code)
+ }
+ if !strings.Contains(w.Body.String(), "estilo-account") {
+ t.Fatal("GET /day drew no account menu")
+ }
+ return strings.Contains(w.Body.String(), connectItem)
+}
+
+// linkCount is how many stored links the person has: the table itself,
+// not the bridge's answer about it.
+func (f *homeRouterFixture) linkCount(t *testing.T, address string) int64 {
+ t.Helper()
+ var n int64
+ if err := f.app.db.Writer().QueryRowContext(t.Context(), `SELECT COUNT(*) FROM home_identity_links l JOIN people p ON p.id = l.person_id WHERE p.address = ?`, address).Scan(&n); err != nil {
+ t.Fatal(err)
+ }
+ return n
+}
+
+// connectFromMenu runs the menu's link flow for a locally signed-in alice,
+// through the confirm POST, and returns where the POST sent her.
+func (f *homeRouterFixture) connectFromMenu(t *testing.T, subject string) string {
+ t.Helper()
+ // A signed-in page first: requirePerson creates the person the
+ // connection pages look up (TestHomeConnectStartPageNeverNamesHome).
+ if w := f.do("GET", "/day/2026-09-10", ""); w.Code != 200 {
+ t.Fatal("local calendar", w.Code)
+ }
+ if w := f.do("GET", "/account/home", ""); w.Code != 200 {
+ t.Fatal("start page", w.Code, w.Body.String())
+ }
+ start := homeRedirect(t, f.do("POST", "/account/home", ""))
+ if got := homeRedirect(t, f.exchange(t, start, subject)); got != "/account/home/confirm" {
+ t.Fatal("fresh assertion landed on", got)
+ }
+ if w := f.do("GET", "/account/home/confirm", ""); w.Code != 200 || !strings.Contains(w.Body.String(), "Connect these two accounts?") {
+ t.Fatalf("confirm page: %d\n%s", w.Code, w.Body.String())
+ }
+ return homeRedirect(t, f.do("POST", "/account/home/confirm", ""))
+}
+
+// A person signed in with an emailed link, with no stored link, is offered
+// the connection in the account menu.
+func TestConnectItemOfferedToALocalUnlinkedPerson(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ if !f.offersConnect(t) {
+ t.Fatal("a locally signed-in, unlinked person is not offered Connect your Oficina account")
+ }
+}
+
+// Once linked, the item is gone however the session signed in: here a
+// fresh emailed-link sign-in, in a new browser, after the link was stored
+// (Paul's Docs report, 2026-10-24: the item was offered by session method).
+func TestConnectItemNotOfferedToALinkedPersonSignedInLocally(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ f.connectFromMenu(t, "opaque-home-alice")
+ if f.linkCount(t, "alice@example.test") != 1 {
+ t.Fatal("the link flow stored no link")
+ }
+ f.cookies = map[string]*http.Cookie{}
+ f.local(t)
+ if f.offersConnect(t) {
+ t.Fatal("a linked person signed in with an emailed link is still offered Connect your Oficina account")
+ }
+}
+
+func TestConnectItemNotOfferedToAHomeSession(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ f.connectFromMenu(t, "opaque-home-alice")
+ f.cookies = map[string]*http.Cookie{}
+ start := homeRedirect(t, f.do("GET", "/signin", ""))
+ if got := homeRedirect(t, f.exchange(t, start, "opaque-home-alice")); got != "/" {
+ t.Fatal("Home sign-in landed on", got)
+ }
+ if f.offersConnect(t) {
+ t.Fatal("a Home session is offered Connect your Oficina account")
+ }
+}
+
+// Right after the confirm POST, in the same (local) session: "Accounts
+// connected", a stored row, and no item on the next page.
+func TestConfirmLeadsToAccountsConnectedAndRetiresTheItem(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ if !f.offersConnect(t) {
+ t.Fatal("not offered before linking")
+ }
+ next := f.connectFromMenu(t, "opaque-home-alice")
+ u, err := url.Parse(next)
+ if err != nil || u.Path != "/account/home/confirm" || u.Query().Get("connected") != "1" {
+ t.Fatal("confirm POST sent the browser to", next)
+ }
+ w := f.do("GET", next, "")
+ if w.Code != 200 || !strings.Contains(w.Body.String(), "Accounts connected") {
+ t.Fatalf("after confirm: %d, want Accounts connected\n%s", w.Code, w.Body.String())
+ }
+ if n := f.linkCount(t, "alice@example.test"); n != 1 {
+ t.Fatalf("home_identity_links holds %d rows for alice, want 1", n)
+ }
+ if f.offersConnect(t) {
+ t.Fatal("the next page still offers Connect your Oficina account to a now-linked person")
+ }
+}
+
+// The success page's way back is the page the link began from
+// (connect.PageFor), not "/".
+func TestAccountsConnectedReturnsToWhereTheLinkBegan(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ f.connectFromMenu(t, "opaque-home-alice")
+ w := f.do("GET", "/account/home/confirm?connected=1&return_to=%2Fday%2F2026-09-10", "")
+ if w.Code != 200 || !strings.Contains(w.Body.String(), "Accounts connected") {
+ t.Fatalf("success page: %d\n%s", w.Code, w.Body.String())
+ }
+ if !strings.Contains(w.Body.String(), `<a rst-btn="primary" href="/day/2026-09-10">`) {
+ t.Fatalf("Accounts connected does not lead back to /day/2026-09-10:\n%s", w.Body.String())
+ }
+}
+
+// An Oficina sign-in with an unlinked subject shows the unknown page; a
+// local sign-in in the same browser then begins the link itself, through
+// the fresh Home assertion, to the confirm page, and the confirm stores it.
+// "first sign-in" starts with no people row at all (Astra's review of #31):
+// the local sign-in must create the person before connect resumes, or the
+// resume falls to /account/home and that page answers 403.
+func TestUnknownOficinaSigninResumesAfterLocalSignin(t *testing.T) {
+ for _, seeded := range []bool{true, false} {
+ name := "existing person"
+ if !seeded {
+ name = "first sign-in"
+ }
+ t.Run(name, func(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ if seeded {
+ if _, err := f.app.store.EnsurePersonSetup(t.Context(), "alice@example.test"); err != nil {
+ t.Fatal(err)
+ }
+ }
+ unknownThenResume(t, f)
+ })
+ }
+}
+
+func unknownThenResume(t *testing.T, f *homeRouterFixture) {
+ t.Helper()
+ start := homeRedirect(t, f.do("GET", "/signin", ""))
+ unknown := f.exchange(t, start, "opaque-home-alice")
+ if unknown.Code != 403 || !strings.Contains(unknown.Body.String(), "Oficina account not connected") || !strings.Contains(unknown.Body.String(), `<a rst-btn="primary" href="/signin/local">`) {
+ t.Fatalf("unknown assertion: %d, want the unknown page leading to /signin/local\n%s", unknown.Code, unknown.Body.String())
+ }
+ if got := f.local(t); got != freshHomeStart {
+ t.Fatalf("local sign-in after an unknown assertion landed on %q, want %q", got, freshHomeStart)
+ }
+ if f.cookies["__Host-oficina-home-init"] == nil {
+ t.Fatal("the resumed link set no __Host-oficina-home-init")
+ }
+ if got := homeRedirect(t, f.exchange(t, freshHomeStart, "opaque-home-alice")); got != "/account/home/confirm" {
+ t.Fatal("fresh assertion landed on", got)
+ }
+ if w := f.do("GET", "/account/home/confirm", ""); w.Code != 200 || !strings.Contains(w.Body.String(), "Connect these two accounts?") {
+ t.Fatalf("confirm page: %d\n%s", w.Code, w.Body.String())
+ }
+ if f.linkCount(t, "alice@example.test") != 0 {
+ t.Fatal("linked before the confirm click")
+ }
+ homeRedirect(t, f.do("POST", "/account/home/confirm", ""))
+ if n := f.linkCount(t, "alice@example.test"); n != 1 {
+ t.Fatalf("home_identity_links holds %d rows for alice after confirm, want 1", n)
+ }
+ resolved, err := f.app.home.bridge.Resolve(t.Context(), "opaque-home-alice")
+ if err != nil || resolved.Label != "alice@example.test" {
+ t.Fatal("the stored link does not resolve to alice", resolved, err)
+ }
+}
+
+// The remembered unknown assertion lasts ten minutes. Older, and the local
+// sign-in lands as any other does.
+func TestUnknownOficinaSigninExpiresAfterTenMinutes(t *testing.T) {
+ f := newHomeRouterFixture(t, 11*time.Minute)
+ if _, err := f.app.store.EnsurePersonSetup(t.Context(), "alice@example.test"); err != nil {
+ t.Fatal(err)
+ }
+ start := homeRedirect(t, f.do("GET", "/signin", ""))
+ if w := f.exchange(t, start, "opaque-home-alice"); w.Code != 403 {
+ t.Fatal("unknown assertion", w.Code)
+ }
+ if f.cookies["__Host-oficina-local-link-navigation"] == nil {
+ t.Fatal("the unknown assertion left no marker, so this test would prove nothing")
+ }
+ f.behind = 0
+ if got := f.local(t); got != "/" {
+ t.Fatalf("local sign-in after an expired marker landed on %q, want /", got)
+ }
+}
+
+// The connection pages put their buttons in one rst-form-foot row, primary
+// first (estilo's homeconnect).
+func TestConnectPageButtonsShareOneFormFootRow(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ f.do("GET", "/day/2026-09-10", "")
+ w := f.do("GET", "/account/home", "")
+ if w.Code != 200 {
+ t.Fatal(w.Code)
+ }
+ row := regexp.MustCompile(`<div rst-form-foot>\s*<form method="post" action="/account/home"><button rst-btn="primary" type="submit">Connect</button></form>\s*<a rst-btn="ghost" href="/">Back</a>\s*</div>`)
+ if !row.MatchString(w.Body.String()) {
+ t.Fatalf("the start page's buttons are not one rst-form-foot row, primary first:\n%s", w.Body.String())
+ }
+}
diff --git a/internal/calendar/home_consumer_test.go b/internal/calendar/home_consumer_test.go
index 60e16e7..7253e06 100644
--- a/internal/calendar/home_consumer_test.go
+++ b/internal/calendar/home_consumer_test.go
@@ -38,7 +38,7 @@ func newHomeConsumerFixture(t *testing.T, directory string) *homeRouterFixture {
t.Fatal(err)
}
t.Cleanup(func() { a.Close() })
- return &homeRouterFixture{a, key, map[string]*http.Cookie{}}
+ return &homeRouterFixture{app: a, key: key, cookies: map[string]*http.Cookie{}}
}
// Sign out in Calendar ends the id.* session too: the app session ends and
diff --git a/internal/calendar/home_router_test.go b/internal/calendar/home_router_test.go
index da36341..e8243ed 100644
--- a/internal/calendar/home_router_test.go
+++ b/internal/calendar/home_router_test.go
@@ -27,21 +27,31 @@ type homeRouterFixture struct {
app *App
key *assertioncrypto.Keypair
cookies map[string]*http.Cookie
+ behind time.Duration // the Home clock's (and signed assertions') lag
}
-func newHomeRouterFixture(t *testing.T) *homeRouterFixture {
+func (f *homeRouterFixture) now() time.Time { return time.Now().Add(-f.behind) }
+
+// newHomeRouterFixture can start the Home clock behind, from the first
+// request: the hand-off store's clock fence refuses to move backwards.
+func newHomeRouterFixture(t *testing.T, behind ...time.Duration) *homeRouterFixture {
t.Helper()
key, err := assertioncrypto.Generate()
if err != nil {
t.Fatal(err)
}
+ f := &homeRouterFixture{key: key, cookies: map[string]*http.Cookie{}}
+ if len(behind) == 1 {
+ f.behind = behind[0]
+ }
manifest, _ := json.Marshal(map[string]string{"key": base64.StdEncoding.EncodeToString(key.SignPub())})
- a, err := New(Config{DBPath: filepath.Join(t.TempDir(), "calendar.db"), Env: "development", Origin: homeTestOrigin, AllowedAddresses: "alice@example.test,replacement@example.test", Logger: slog.New(slog.NewTextHandler(io.Discard, nil)), Home: &connect.Credentials{Issuer: homeTestIssuer, ConsumerID: "calendar-test", KeysBase64: base64.StdEncoding.EncodeToString(manifest), DEKBase64: base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{7}, 32))}})
+ a, err := New(Config{DBPath: filepath.Join(t.TempDir(), "calendar.db"), Env: "development", Origin: homeTestOrigin, AllowedAddresses: "alice@example.test,replacement@example.test", Logger: slog.New(slog.NewTextHandler(io.Discard, nil)), Home: &connect.Credentials{Issuer: homeTestIssuer, ConsumerID: "calendar-test", KeysBase64: base64.StdEncoding.EncodeToString(manifest), DEKBase64: base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{7}, 32))}, homeNow: f.now})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { a.Close() })
- return &homeRouterFixture{a, key, map[string]*http.Cookie{}}
+ f.app = a
+ return f
}
func (f *homeRouterFixture) do(method, path, body string) *httptest.ResponseRecorder {
r := httptest.NewRequest(method, homeTestOrigin+path, strings.NewReader(body))
@@ -73,7 +83,9 @@ func homeRedirect(t *testing.T, w *httptest.ResponseRecorder) string {
}
return w.Header().Get("Location")
}
-func (f *homeRouterFixture) local(t *testing.T) {
+
+// local signs alice in with an emailed link; it returns her landing.
+func (f *homeRouterFixture) local(t *testing.T) string {
t.Helper()
homeRedirect(t, f.do("POST", "/signin", "address=alice%40example.test&force=1"))
f.app.signinMail.wait()
@@ -94,7 +106,7 @@ func (f *homeRouterFixture) local(t *testing.T) {
if landing != "/auth/local/complete" {
t.Fatal("wrong local landing", landing)
}
- homeRedirect(t, f.do("GET", landing, ""))
+ return homeRedirect(t, f.do("GET", landing, ""))
}
func (f *homeRouterFixture) exchange(t *testing.T, start, subject string) *httptest.ResponseRecorder {
t.Helper()
@@ -104,7 +116,7 @@ func (f *homeRouterFixture) exchange(t *testing.T, start, subject string) *httpt
t.Fatal("bad issuer redirect")
}
nonce := u.Query().Get("nonce")
- now := time.Now().Unix()
+ now := f.now().Unix()
jti, err := assertion.RandomID()
if err != nil {
t.Fatal(err)
diff --git a/internal/calendar/render.go b/internal/calendar/render.go
index fe4d4d2..5e2c580 100644
--- a/internal/calendar/render.go
+++ b/internal/calendar/render.go
@@ -159,6 +159,9 @@ func (h *handlers) page(r *http.Request, title string, data any) PageData {
pd.Address = id.Address
}
pd.Chrome = calendarChrome(r, pd.SignedIn, pd.Address, mode, title, h.directory)
+ if pd.Chrome.Account != nil && h.offerHomeConnect(r) {
+ pd.Chrome.Account.Items = append(pd.Chrome.Account.Items, menu.Item{Href: "/account/home", Label: connect.English["menu_action"]})
+ }
// Every door — the form, its notices, the confirm step an emailed
// link opens on, and the refusal auth answers /auth/* with — shows
// the brand alone: no account menu, no Sign in.
diff --git a/internal/calendar/routes.go b/internal/calendar/routes.go
index 69bf950..c560301 100644
--- a/internal/calendar/routes.go
+++ b/internal/calendar/routes.go
@@ -49,7 +49,7 @@ func (a *App) routes(h *handlers, authPlugin *rauth.Auth, list allowlist, origin
r.Get("/signin", a.homeSignin)
r.Get("/signin/local", h.signin)
r.Get("/signed-out", a.home.routes.SignedOut)
- r.Get(connect.LocalCompletePath, a.home.routes.LocalComplete)
+ r.Get(connect.LocalCompletePath, a.homeLocalComplete)
r.Get(handoff.StartPath, a.home.bridge.Start)
r.Post(handoff.CallbackPath, a.home.bridge.Callback)
r.Get(handoff.FinishPath, a.home.bridge.Finish)