oficina / memoria Public

The Oficina connect item follows the stored link, not the session

The account menu offered "Connect your Oficina account" to every local
(magic link / Keymail) session, so a person whose account was already
linked, but who signed in with Memoria's own email link, was still
offered it. offersHomeLink now asks the link store: it finds the
viewer's local identity row (one indexed lookup on address_lookup) and
then asks Bridge.Linked (one on home_identity_links' UNIQUE
(issuer, person_id)). No row means no link can exist, so it offers; an
error on either lookup offers nothing; a Home session is the link.

Bumps home/connect to 08bbcf3 (fix/connect-item-when-linked), which
brings estilo 0b375d5:
- the unknown-assertion flow: a local sign-in after an Oficina
  assertion with no link resumes the link. That needs the local
  identity row, which only /account/home allocated, so somebody who had
  never opened it fell back to the Connect page. /auth/local/complete
  (localComplete) now allocates it first for a fresh local sign-in
  carrying connect's navigation marker; other sign-ins allocate nothing.
- "Accounts connected" after the confirm POST, rendered with
  connect.PageFor so its way back is the page the link began from.
- the connect page's buttons in one rst-form-foot row, primary first.
- WireHome passes a.now as the bridge's clock (production: time.Now),
  so a test can age the ten-minute marker.

Memoria's copy names the app on the confirm and unknown pages.
static/chrome.css regenerated from the new estilo (writeestilo).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev c5ff381316f21d2537b7c68f9b606d8bfb5317c5 parent 81f7fe9
10 files changed, +457 −20
  • go.mod +2 −2
  • go.sum +4 −4
  • internal/memoria/app.go +1 −1
  • internal/memoria/chrome.go +22 −6
  • internal/memoria/home.go +29 −1
  • internal/memoria/home_identity.go +18 −0
  • internal/memoria/home_linked_test.go +328 −0
  • internal/memoria/home_render.go +4 −1
  • internal/memoria/home_router_test.go +19 −5
  • internal/memoria/static/chrome.css +30 −0

CI passed — run details

diff --git a/go.mod b/go.mod
index ac69207..efdee94 100644
--- a/go.mod
+++ b/go.mod
@@ -5,8 +5,8 @@ go 1.26
toolchain go1.26.5
require (
- amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768
- amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c
+ amadan.net/oficina/estilo.git v0.0.0-20261024215431-0b375d59ca32
+ amadan.net/oficina/home/connect v0.0.0-20261024220045-08bbcf31e483
amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489
amadan.net/oficina/suite v0.0.0-20260905215529-60b01a8a0d6d
amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3
diff --git a/go.sum b/go.sum
index 55f5156..25e284a 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,7 @@
-amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768 h1:bVscoa9fH5LdLDjlyecZhrX7JzWPT0blb57MH0FIm2U=
-amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768/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-20261024215431-0b375d59ca32 h1:YJhvKpW6eTejjvXRbb+CHrgmF6Pms7N2q2/73dbm3iA=
+amadan.net/oficina/estilo.git v0.0.0-20261024215431-0b375d59ca32/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw=
+amadan.net/oficina/home/connect v0.0.0-20261024220045-08bbcf31e483 h1:AX1ATw/weILU5pjHHo1XD01gz9EJAp/9xq3J4OftR3E=
+amadan.net/oficina/home/connect v0.0.0-20261024220045-08bbcf31e483/go.mod h1:MWe3bFg0xGr1btEom2snMLhEZeRIfw0Iv6vKUyOsu18=
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/suite v0.0.0-20260905215529-60b01a8a0d6d h1:x6Bq9+QzpFYAyV+zRzgyHwD/RmZ4Hy4biwtxK7CdaSs=
diff --git a/internal/memoria/app.go b/internal/memoria/app.go
index 370732f..21ba6f9 100644
--- a/internal/memoria/app.go
+++ b/internal/memoria/app.go
@@ -229,7 +229,7 @@ func (a *app) MountAuth(mux *http.ServeMux, origin string) {
r.Get("/auth/start", a.home.bridge.Start)
r.Post("/auth/assertion", a.home.bridge.Callback)
r.Get("/auth/finish", a.home.bridge.Finish)
- r.Get("/auth/local/complete", a.landedAfter(a.home.routes.LocalComplete))
+ r.Get("/auth/local/complete", a.landedAfter(a.localComplete))
}
mux.Handle("/auth/", r)
mux.Handle("POST /signout", r)
diff --git a/internal/memoria/chrome.go b/internal/memoria/chrome.go
index cdfaef2..ad29825 100644
--- a/internal/memoria/chrome.go
+++ b/internal/memoria/chrome.go
@@ -237,18 +237,34 @@ func (a *app) account(r *http.Request, v viewer, ret string) *chrome.Account {
if v.address != "" {
acc.TriggerLabel = "Account: " + v.address
}
- if a.offersHomeLink(v) {
+ if a.offersHomeLink(r, v) {
acc.Items = []estilomenu.Item{{Href: "/account/home", Label: "Connect your Oficina account"}}
}
return acc
}
// offersHomeLink is whether the account menu offers to connect the
-// person's Oficina account: only when Home is configured, and never to
-// somebody who signed in through Home, whose account already is the
-// connection (spec §12.1 item 4).
-func (a *app) offersHomeLink(v viewer) bool {
- return a.home != nil && v.ok && (v.method == "magiclink" || v.method == "keymail")
+// person's Oficina account: only when Home is configured, to somebody
+// signed in locally whose account has NO stored link (spec §12.1 item 4).
+// The stored link decides, not how this session signed in: a linked
+// person who used Memoria's own email link is still linked (Paul,
+// 2026-10-24). A Home session is the link itself. Anything that cannot be
+// determined offers nothing. One indexed lookup per menu render, two once
+// the person has a local identity row.
+func (a *app) offersHomeLink(r *http.Request, v viewer) bool {
+ if a.home == nil || !v.ok || (v.method != "magiclink" && v.method != "keymail") {
+ return false
+ }
+ id, found, err := a.homeLocalID(r.Context(), v.address)
+ if err != nil {
+ return false
+ }
+ if !found {
+ // No local identity row, so no link can name this person.
+ return true
+ }
+ linked, err := a.home.bridge.Linked(r.Context(), id)
+ return err == nil && !linked
}
// switcher is the app switcher, or nil when no hub directory is
diff --git a/internal/memoria/home.go b/internal/memoria/home.go
index b7d5afc..b5d6c94 100644
--- a/internal/memoria/home.go
+++ b/internal/memoria/home.go
@@ -54,7 +54,7 @@ func (a *app) WireHome(mux *http.ServeMux, cfg Config) error {
},
LookupPerson: func(ctx context.Context, q linkstore.Queryer, id int64) (string, error) {
return a.lookupHomeLocalIdentity(ctx, q, id)
- }, Render: a.renderHome,
+ }, Render: a.renderHome, Now: a.now,
})
if err != nil {
return errHomeIdentity
@@ -99,6 +99,34 @@ func (a *app) signin(w http.ResponseWriter, r *http.Request) {
a.localSignin(w, r)
}
+// homeNavigationCookie is connect's sealed navigation marker (unexported
+// there): set by the account menu's Connect, and by an Oficina assertion
+// this app has no link for. Only its presence is read here; connect opens
+// it. TestUnknownOficinaAccountResumesTheLinkAfterLocalSignin fails if
+// the name drifts.
+const homeNavigationCookie = "__Host-oficina-local-link-navigation"
+
+// localComplete is GET /auth/local/complete, where a local sign-in lands
+// with Home configured. After an Oficina assertion this app had no link
+// for, connect begins the link from here, and that needs the person's
+// local identity row, which only /account/home allocated before: someone
+// who had never opened it could not resume, and fell back to the Connect
+// page. So a fresh local sign-in that carries the marker allocates it
+// first, as /account/home does; any other sign-in allocates nothing, as
+// before. Failing costs only the shortcut; the sign-in has succeeded.
+func (a *app) localComplete(w http.ResponseWriter, r *http.Request) {
+ if _, err := r.Cookie(homeNavigationCookie); err != nil {
+ a.home.routes.LocalComplete(w, r)
+ return
+ }
+ if s, ok := a.home.sessions.From(r); ok {
+ if _, fresh := connect.FreshLocal(connect.Session{Subject: s.Subject, Method: s.Method, AuthTime: s.AuthTime, At: s.At}, a.now()); fresh {
+ _, _, _ = a.ensureHomeLocalIdentity(r.Context(), s)
+ }
+ }
+ a.home.routes.LocalComplete(w, r)
+}
+
func (a *app) homeAccount(w http.ResponseWriter, r *http.Request) {
s, ok := a.home.sessions.From(r)
if ok {
diff --git a/internal/memoria/home_identity.go b/internal/memoria/home_identity.go
index 6de6942..39160f3 100644
--- a/internal/memoria/home_identity.go
+++ b/internal/memoria/home_identity.go
@@ -92,6 +92,24 @@ func (a *app) lookupHomeLocalIdentity(ctx context.Context, q homeIdentityQueryer
return address, nil
}
+// homeLocalID is the local identity row's ID for address, read-only.
+// found is false when the person has no row, which every link needs: a
+// link names the row's ID, and IDs are never reused.
+func (a *app) homeLocalID(ctx context.Context, address string) (id int64, found bool, err error) {
+ fingerprint, err := a.store.sealer.Fingerprint(homeAddressFingerprintPurpose, []byte(normaliseAddress(address)))
+ if err != nil {
+ return 0, false, errHomeIdentity
+ }
+ err = a.db.Writer().QueryRowContext(ctx, "SELECT id FROM memoria_home_local_identities WHERE address_lookup=?", fingerprint).Scan(&id)
+ if errors.Is(err, sql.ErrNoRows) {
+ return 0, false, nil
+ }
+ if err != nil {
+ return 0, false, errHomeIdentity
+ }
+ return id, true, nil
+}
+
// localHomeIdentity is read-only: resolving a browser session during a Home
// exchange cannot allocate an identity or change the account being linked.
func (a *app) localHomeIdentity(ctx context.Context, session sessions.Session) (int64, string, error) {
diff --git a/internal/memoria/home_linked_test.go b/internal/memoria/home_linked_test.go
new file mode 100644
index 0000000..280e636
--- /dev/null
+++ b/internal/memoria/home_linked_test.go
@@ -0,0 +1,328 @@
+package memoria
+
+import (
+ "bytes"
+ "html"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/home/connect"
+ assertioncrypto "amadan.net/rastrillo/rastrillo/crypto"
+)
+
+// The account menu's "Connect your Oficina account" follows the STORED
+// link, not how this session signed in (Paul hit it on 2026-10-24: linked,
+// signed in with Memoria's own email link, and still offered the item).
+//
+// Each test below was seen to fail with the fix reverted; the comment on
+// each says what was reverted and what went red.
+
+const unlinkedSubject = "opaque-unlinked-alice"
+
+// offersConnect is whether a page's account menu offers the connection.
+func offersConnect(body string) bool {
+ return strings.Contains(body, `href="/account/home"`) && strings.Contains(body, "Connect your Oficina account")
+}
+
+// signedInPage is GET / for a signed-in viewer, or the test fails.
+func (f *homeRouterFixture) signedInPage(t *testing.T) string {
+ t.Helper()
+ w := f.do("GET", "/", "")
+ b := w.Body.String()
+ if w.Code != http.StatusOK || !strings.Contains(b, "estilo-account") {
+ t.Fatalf("GET / = %d, not signed in:\n%s", w.Code, b)
+ }
+ return b
+}
+
+// linkFromMenu runs the menu's link flow for the signed-in local session
+// against subject, up to and including the confirm POST, and returns the
+// POST's answer.
+func (f *homeRouterFixture) linkFromMenu(t *testing.T, subject string) *httptest.ResponseRecorder {
+ t.Helper()
+ if w := f.do("GET", "/account/home", ""); w.Code != http.StatusOK {
+ t.Fatal("link 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("wrong proof landing", got)
+ }
+ if w := f.do("GET", "/account/home/confirm", ""); w.Code != http.StatusOK {
+ t.Fatal("confirm page", w.Code, w.Body.String())
+ }
+ return f.do("POST", "/account/home/confirm", "")
+}
+
+// linkRows counts home_identity_links rows for subject.
+func (f *homeRouterFixture) linkRows(t *testing.T, subject string) int {
+ t.Helper()
+ var n int
+ if err := f.app.db.Writer().QueryRow("SELECT COUNT(*) FROM home_identity_links WHERE subject=?", subject).Scan(&n); err != nil {
+ t.Fatal(err)
+ }
+ return n
+}
+
+// formFoot is the one rst-form-foot row of a connect page, or the test
+// fails. The row holds a form and a link, never a div, so it ends at the
+// first </div>.
+func formFoot(t *testing.T, page string) string {
+ t.Helper()
+ if n := strings.Count(page, "<div rst-form-foot>"); n != 1 {
+ t.Fatalf("%d rst-form-foot rows, want one:\n%s", n, page)
+ }
+ i := strings.Index(page, "<div rst-form-foot>")
+ j := strings.Index(page[i:], "</div>")
+ return page[i : i+j]
+}
+
+// The presence half. Never linked: offered, before /account/home has
+// allocated the local identity row (an ordinary local sign-in allocates
+// none) and after. Seen red with offersHomeLink answering false when no
+// identity row exists, and again when it answered false for a row with no
+// link (mutations of the fix, since the bug was an absence, not a
+// presence).
+func TestConnectItemOfferedToAnUnlinkedLocalSession(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ rows := func() int {
+ var n int
+ if err := f.app.db.Writer().QueryRow("SELECT COUNT(*) FROM memoria_home_local_identities").Scan(&n); err != nil {
+ t.Fatal(err)
+ }
+ return n
+ }
+ if rows() != 0 {
+ t.Fatal("an ordinary local sign-in allocated a local identity")
+ }
+ if !offersConnect(f.signedInPage(t)) {
+ t.Error("no identity row: a local session is not offered the connection")
+ }
+ if w := f.do("GET", "/account/home", ""); w.Code != http.StatusOK {
+ t.Fatal("link page", w.Code)
+ }
+ if rows() != 1 {
+ t.Fatal("the link page did not allocate the local identity")
+ }
+ if !offersConnect(f.signedInPage(t)) {
+ t.Error("identity row, no link: a local session is not offered the connection")
+ }
+}
+
+// The bug. Linked, then signed in again with Memoria's own email link: no
+// item. Seen red with offersHomeLink restored to the session-method test:
+// "a linked account signed in locally is still offered the connection".
+func TestConnectItemNotOfferedOnceLinkedToALocalSession(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ homeRedirect(t, f.linkFromMenu(t, "opaque-home-alice"))
+ if f.linkRows(t, "opaque-home-alice") != 1 {
+ t.Fatal("the link was not stored")
+ }
+ f.cookies = map[string]*http.Cookie{}
+ f.local(t)
+ if offersConnect(f.signedInPage(t)) {
+ t.Error("a linked account signed in locally is still offered the connection")
+ }
+}
+
+// Unknown is not "not linked": when either lookup fails, nothing is
+// offered (a count that fails is not a count of zero). Each table is
+// dropped in turn to make its lookup fail. Seen red with offersHomeLink
+// offering on a Linked error, and on a homeLocalID error.
+func TestConnectItemNotOfferedWhenTheLinkIsUnknown(t *testing.T) {
+ for _, table := range []string{"home_identity_links", "memoria_home_local_identities"} {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ // The identity row, so the Linked lookup is the one reached.
+ if w := f.do("GET", "/account/home", ""); w.Code != http.StatusOK {
+ t.Fatal("link page", w.Code)
+ }
+ if !offersConnect(f.signedInPage(t)) {
+ t.Fatal("not offered before the lookup broke")
+ }
+ if _, err := f.app.db.Writer().Exec("DROP TABLE " + table); err != nil {
+ t.Fatal(err)
+ }
+ if offersConnect(f.signedInPage(t)) {
+ t.Errorf("%s unreadable: still offered the connection", table)
+ }
+ }
+}
+
+// A Home session is the link itself. Seen red with offersHomeLink answering
+// true for any signed-in viewer.
+func TestConnectItemNotOfferedToAHomeSession(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ homeRedirect(t, f.linkFromMenu(t, "opaque-home-alice"))
+ f.cookies = map[string]*http.Cookie{}
+ start := homeRedirect(t, f.do("GET", "/signin", ""))
+ homeRedirect(t, f.exchange(t, start, "opaque-home-alice"))
+ if offersConnect(f.signedInPage(t)) {
+ t.Error("a Home session is offered to connect the account it signed in with")
+ }
+}
+
+// Right after the confirm POST, in the same (local) session: "Accounts
+// connected", the row is stored, and the very next page's menu has no
+// item. Seen red with the session-method test restored: the last check.
+func TestConfirmSaysConnectedAndTheItemGoesInTheSameSession(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ if !offersConnect(f.signedInPage(t)) {
+ t.Fatal("not offered before linking")
+ }
+ res := f.linkFromMenu(t, "opaque-home-alice").Result()
+ loc := res.Header.Get("Location")
+ if res.StatusCode != http.StatusSeeOther || !strings.HasPrefix(loc, "/account/home/confirm?connected=1") {
+ t.Fatalf("confirm POST = %d to %q, want the connected page", res.StatusCode, loc)
+ }
+ w := f.do("GET", loc, "")
+ b := html.UnescapeString(w.Body.String())
+ if w.Code != http.StatusOK || !strings.Contains(b, "Accounts connected") {
+ t.Fatalf("connected page = %d:\n%s", w.Code, b)
+ }
+ if f.linkRows(t, "opaque-home-alice") != 1 {
+ t.Fatal("the confirm POST did not store the link")
+ }
+ if offersConnect(f.signedInPage(t)) {
+ t.Error("the same session is still offered the connection right after connecting")
+ }
+}
+
+// An Oficina sign-in this app has no link for shows the unknown page; a
+// local sign-in in the same browser then goes straight to Home's
+// freshness check, the confirm step, and on to a stored link, landing back
+// where the person was headed. Seen red without the ensureHomeLocalIdentity
+// call on /auth/local/complete (localComplete): a person who had never
+// opened /account/home has no local identity row, so the resume could not
+// bind, and the sign-in fell back to the Connect page, /account/home.
+func TestUnknownOficinaAccountResumesTheLinkAfterLocalSignin(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ start := homeRedirect(t, f.do("GET", "/signin?return_to=%2Fsearch%3Fq%3Dnebula", ""))
+ w := f.exchange(t, start, unlinkedSubject)
+ b := html.UnescapeString(w.Body.String())
+ if w.Code != http.StatusForbidden || !strings.Contains(b, "Sign in to your Memoria account once to connect it to your Oficina account.") {
+ t.Fatalf("unknown page = %d:\n%s", w.Code, b)
+ }
+ if foot := formFoot(t, b); !strings.Contains(foot, `<a rst-btn="primary" href="/signin/local">`) {
+ t.Errorf("the unknown page's button does not go to /signin/local:\n%s", foot)
+ }
+
+ landing := f.localAs(t, "alice@example.test")
+ if landing != "/auth/start?return_to=%2Faccount%2Fhome%2Fconfirm" {
+ t.Fatalf("local sign-in after an unknown assertion landed on %q, want Home's freshness start", landing)
+ }
+ if f.cookies["__Host-oficina-home-init"] == nil {
+ t.Fatal("no link initiation cookie")
+ }
+ if got := homeRedirect(t, f.exchange(t, landing, unlinkedSubject)); got != "/account/home/confirm" {
+ t.Fatal("fresh assertion landed on", got)
+ }
+ w = f.do("GET", "/account/home/confirm", "")
+ b = html.UnescapeString(w.Body.String())
+ for _, want := range []string{
+ "Connect these two accounts?",
+ "Your Oficina account is confirmed. Connect it to the Memoria account below, and you can sign in to Memoria with Oficina from now on.",
+ "alice@example.test",
+ } {
+ if w.Code != http.StatusOK || !strings.Contains(b, want) {
+ t.Errorf("confirm page (%d) lacks %q", w.Code, want)
+ }
+ }
+ foot := formFoot(t, b)
+ p, g := strings.Index(foot, `<button rst-btn="primary" type="submit">`), strings.Index(foot, `<a rst-btn="ghost" href="/">`)
+ if p < 0 || g < 0 || p > g {
+ t.Errorf("confirm buttons are not one row, primary first:\n%s", foot)
+ }
+ if f.linkRows(t, unlinkedSubject) != 0 {
+ t.Fatal("linked before the confirm click")
+ }
+ res := f.do("POST", "/account/home/confirm", "").Result()
+ loc := res.Header.Get("Location")
+ if res.StatusCode != http.StatusSeeOther || !strings.HasPrefix(loc, "/account/home/confirm?connected=1") {
+ t.Fatalf("confirm POST = %d to %q", res.StatusCode, loc)
+ }
+ if f.linkRows(t, unlinkedSubject) != 1 {
+ t.Fatal("the confirm POST did not store the link")
+ }
+ w = f.do("GET", loc, "")
+ b = w.Body.String()
+ if w.Code != http.StatusOK || !strings.Contains(b, "Accounts connected") {
+ t.Fatalf("connected page = %d:\n%s", w.Code, b)
+ }
+ // PageFor: the way back is the page the sign-in was headed for.
+ if !strings.Contains(formFoot(t, b), `<a rst-btn="primary" href="/search?q=nebula">`) {
+ t.Errorf("the connected page does not lead back to /search?q=nebula:\n%s", formFoot(t, b))
+ }
+ if offersConnect(f.signedInPage(t)) {
+ t.Error("still offered the connection after connecting")
+ }
+ // And the Oficina account now signs in as alice.
+ f.cookies = map[string]*http.Cookie{}
+ start = homeRedirect(t, f.do("GET", "/signin", ""))
+ homeRedirect(t, f.exchange(t, start, unlinkedSubject))
+ if !strings.Contains(f.signedInPage(t), "alice@example.test") {
+ t.Error("the linked Oficina account does not sign in as alice")
+ }
+}
+
+// The unknown marker lives ten minutes. Inside them the local sign-in
+// resumes the link; past them it lands as before (on "/", nothing begun).
+// The app's clock is the bridge's (WireHome passes a.now), so the
+// assertion is issued at the shifted time; the nine-minute row is the
+// proof the shifted clock reaches the marker at all (were it not, the
+// eleven-minute row would resume too). Seen red: the nine-minute row,
+// without localComplete's allocation. The expiry check itself is home's
+// (navigation.marker), and tested there.
+func TestUnknownMarkerExpiresAfterTenMinutes(t *testing.T) {
+ for _, tc := range []struct {
+ ago time.Duration
+ resume bool
+ }{{9 * time.Minute, true}, {11 * time.Minute, false}} {
+ // The link store keeps a high-water clock and refuses to go back,
+ // so the app starts on the shifted clock and only moves forward.
+ at := time.Now().Add(-tc.ago)
+ key, err := assertioncrypto.Generate()
+ if err != nil {
+ t.Fatal(err)
+ }
+ f := newHomeRouterFixtureWith(t, key, Config{Origin: homeTestOrigin, Home: &connect.DecodedCredentials{Issuer: homeTestIssuer, ConsumerID: "memoria-test", Keys: map[string][]byte{"key": key.SignPub()}, DEK: bytes.Repeat([]byte{7}, 32)}},
+ func(a *app) { a.clock = func() time.Time { return at } })
+ start := homeRedirect(t, f.do("GET", "/signin", ""))
+ if w := f.exchangeAt(t, start, unlinkedSubject, at); w.Code != http.StatusForbidden {
+ t.Fatalf("%v ago: unknown page = %d", tc.ago, w.Code)
+ }
+ f.app.clock = nil
+ landing := f.localAs(t, "alice@example.test")
+ resumed := landing == "/auth/start?return_to=%2Faccount%2Fhome%2Fconfirm"
+ if resumed != tc.resume || (!tc.resume && landing != "/") {
+ t.Errorf("marker %v old: local sign-in landed on %q, resume want %v", tc.ago, landing, tc.resume)
+ }
+ if !tc.resume && f.cookies["__Host-oficina-home-init"] != nil {
+ t.Errorf("marker %v old: a link was begun", tc.ago)
+ }
+ }
+}
+
+// The connect page's two buttons are one rst-form-foot row, primary first
+// (estilo 0b375d5). Seen red with estilo pinned back to 530cb93, whose
+// template stacked them with no row.
+func TestConnectPageButtonsAreOneRowPrimaryFirst(t *testing.T) {
+ f := newHomeRouterFixture(t)
+ f.local(t)
+ w := f.do("GET", "/account/home", "")
+ if w.Code != http.StatusOK {
+ t.Fatal(w.Code)
+ }
+ foot := formFoot(t, w.Body.String())
+ p := strings.Index(foot, `<form method="post" action="/account/home"><button rst-btn="primary" type="submit">Connect</button></form>`)
+ g := strings.Index(foot, `<a rst-btn="ghost" href="/">`)
+ if p < 0 || g < 0 || p > g {
+ t.Errorf("the Connect and Cancel buttons are not one row, primary first:\n%s", foot)
+ }
+}
diff --git a/internal/memoria/home_render.go b/internal/memoria/home_render.go
index ad86052..12b7f1e 100644
--- a/internal/memoria/home_render.go
+++ b/internal/memoria/home_render.go
@@ -20,7 +20,7 @@ func (a *app) renderHome(w http.ResponseWriter, r *http.Request, state, label st
a.signedOut(w, r)
return
}
- data := connect.Page(state, label, func(k string) string { return homeCopy[k] })
+ data := connect.PageFor(r, state, label, func(k string) string { return homeCopy[k] })
pg := a.pageFor(r, titled(data.Title))
var body bytes.Buffer
if err := pages["home"].ExecuteTemplate(&body, "layout", homePage{page: pg, Home: data}); err != nil {
@@ -44,5 +44,8 @@ var homeCopy = func() map[string]string {
}
out["start_body"] = "Use your Oficina account to sign in to this account. What Memoria holds stays as it is."
out["documents_action"] = "Back to Memoria"
+ out["confirm_title"] = "Connect these two accounts?"
+ out["confirm_body"] = "Your Oficina account is confirmed. Connect it to the Memoria account below, and you can sign in to Memoria with Oficina from now on."
+ out["unknown_body"] = "Sign in to your Memoria account once to connect it to your Oficina account."
return out
}()
diff --git a/internal/memoria/home_router_test.go b/internal/memoria/home_router_test.go
index cbde102..60d3737 100644
--- a/internal/memoria/home_router_test.go
+++ b/internal/memoria/home_router_test.go
@@ -55,8 +55,9 @@ func newHomeRouterFixtureDir(t *testing.T, directory string) *homeRouterFixture
}
// newHomeRouterFixtureWith wires Home from cfg, signed by key under the
-// key ID "key".
-func newHomeRouterFixtureWith(t *testing.T, key *assertioncrypto.Keypair, cfg Config) *homeRouterFixture {
+// key ID "key". Each before runs on the app before Home is wired (a clock
+// the link store must start on, for one).
+func newHomeRouterFixtureWith(t *testing.T, key *assertioncrypto.Keypair, cfg Config, before ...func(*app)) *homeRouterFixture {
t.Helper()
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
d, err := db.Open(filepath.Join(t.TempDir(), "memoria.db"), logger)
@@ -80,6 +81,9 @@ func newHomeRouterFixtureWith(t *testing.T, key *assertioncrypto.Keypair, cfg Co
t.Fatal(err)
}
a.UseAuth(auth)
+ for _, fn := range before {
+ fn(a)
+ }
if err = a.WireHome(mux, cfg); err != nil {
t.Fatal(err)
}
@@ -167,7 +171,10 @@ func homeRedirect(t *testing.T, w *httptest.ResponseRecorder) string {
return w.Header().Get("Location")
}
func (f *homeRouterFixture) local(t *testing.T) { f.localAs(t, "alice@example.test") }
-func (f *homeRouterFixture) localAs(t *testing.T, address string) {
+
+// localAs signs address in with the app's own email link and returns
+// where /auth/local/complete sent the browser.
+func (f *homeRouterFixture) localAs(t *testing.T, address string) string {
t.Helper()
homeRedirect(t, f.do("POST", "/auth/begin", "address="+url.QueryEscape(address)+"&force=1"))
link := regexp.MustCompile(`https://[^\s<>\"]+/auth/verify\?[^\s<>\"]+`).FindString(f.mail.body)
@@ -179,9 +186,16 @@ func (f *homeRouterFixture) localAs(t *testing.T, address string) {
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()
+ return f.exchangeAt(t, start, subject, time.Now())
+}
+
+// exchangeAt is exchange with the assertion issued at at, for a test that
+// has set the app's clock to it.
+func (f *homeRouterFixture) exchangeAt(t *testing.T, start, subject string, at time.Time) *httptest.ResponseRecorder {
t.Helper()
target := homeRedirect(t, f.do("GET", start, ""))
u, err := url.Parse(target)
@@ -189,7 +203,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 := at.Unix()
jti, err := assertion.RandomID()
if err != nil {
t.Fatal(err)
diff --git a/internal/memoria/static/chrome.css b/internal/memoria/static/chrome.css
index 74bd3d7..71c0490 100644
--- a/internal/memoria/static/chrome.css
+++ b/internal/memoria/static/chrome.css
@@ -208,6 +208,36 @@
[estilo-menu-identity-name] + [estilo-menu-identity-address] { font-size: var(--rst-fs-xs); }
[estilo-bar-signin] { flex: none; }
+/* The account at a sidebar rail's foot (Account.Rail), for an app whose
+ chrome is a rail rather than the bar. The trigger is a row the rail's
+ width: the avatar, then who is signed in, cut short with an ellipsis.
+ It stays in the page flow, so its highlight stays square. The panel is
+ the foot's own width, edge to edge with the trigger: hung from the
+ inline end of a foot narrower than the bar's 15rem panel it ran off
+ the window's start edge, and from the inline start it ran past the
+ rail, whose overflow-y: auto clips it (Fichas' first screenshot). */
+[estilo-account~="rail"] > [estilo-bar-trigger] {
+ justify-content: flex-start;
+ gap: var(--rst-sp-2);
+ inline-size: 100%;
+ block-size: auto;
+ min-block-size: 2.5rem;
+ color: var(--rst-text);
+}
+[estilo-account-who] { min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+[estilo-account~="rail"] > [estilo-account-panel] { inset-inline: 0; inline-size: auto; min-inline-size: 0; max-inline-size: none; }
+/* A drop-up where the rail is the viewport's height (rastrillo's shell
+ breakpoint): below the foot there is only the window's edge. Below
+ 800px the rail is a disclosure at the top of the page, with the page
+ under it and too little above, so the panel opens downward there. */
+@media (min-width: 800px) {
+ [estilo-account~="rail"] > [estilo-account-panel] {
+ inset-block-start: auto;
+ inset-block-end: calc(100% + 4px);
+ max-block-size: max(calc(100dvh - 5rem), 8rem);
+ }
+}
+
/* Visually hidden, still announced. */
[estilo-visually-hidden] { position: absolute; clip-path: inset(50%); inline-size: 1px; block-size: 1px; overflow: hidden; white-space: nowrap; }