oficina / home Public

Clone
git clone https://amadan.net/oficina/home

Plain git — no account needed to clone.

Download

Download this file

1package home
2
3import (
4 "net/http"
5 "net/http/httptest"
6 "strings"
7 "testing"
8)
9
10// The door's words. The sign-in door itself is rastrillo's one-way screen
11// (smart-door spec: "Unless marked new, all copy is rastrillo's approved
12// copy"; on id.* the field's submit is Continue, which the spec's door
13// table names and which supersedes, for this door, the 2026-10-01 "Sign
14// in" ruling for estilo's form). The pages around it keep estilo's
15// chrome.English. Both are pinned here as literals, not read back from
16// the libraries, so a change upstream shows up as a red test on the hub
17// rather than as silently different copy.
18const (
19 doorSentBody = "We sent a link to your inbox. The link works once and expires soon."
20)
21
22func getCredential(t *testing.T, app *testApp, path string) string {
23 t.Helper()
24 req := httptest.NewRequest(http.MethodGet, path, nil)
25 req.Host = credentialHost
26 w := httptest.NewRecorder()
27 app.Router().ServeHTTP(w, req)
28 if w.Code != http.StatusOK {
29 t.Fatalf("GET %s: %d", path, w.Code)
30 }
31 return w.Body.String()
32}
33
34func mustContain(t *testing.T, page, body string, wants ...string) {
35 t.Helper()
36 for _, want := range wants {
37 if !strings.Contains(body, want) {
38 t.Errorf("%s: missing %q", page, want)
39 }
40 }
41}
42
43func mustNotContain(t *testing.T, page, body string, nots ...string) {
44 t.Helper()
45 for _, not := range nots {
46 if strings.Contains(body, not) {
47 t.Errorf("%s: still says %q", page, not)
48 }
49 }
50}
51
52func TestDoorSpeaksTheSuiteCopy(t *testing.T) {
53 app := newTestApp(t)
54
55 form := getCredential(t, app, "/signin")
56 mustContain(t, "/signin", form,
57 "<title>Sign in to Oficina ID</title>",
58 `<h1 id="rst-signin-heading">Sign in to Oficina ID</h1>`,
59 `>Email</label>`,
60 `<button rst-btn="primary block" type="submit">Continue</button>`,
61 "<span>Other ways to sign in</span>")
62 mustNotContain(t, "/signin", form, "Email me a link", "Home")
63
64 sent := getCredential(t, app, "/signin/sent")
65 mustContain(t, "/signin/sent", sent,
66 "<title>Check your email to sign in to Oficina ID</title>",
67 `<h1 id="rst-signin-heading">Check your email</h1>`,
68 doorSentBody,
69 `<form rst-signin-form method="post" action="/signin/forget">`,
70 "<span>Use a different email</span>")
71 mustNotContain(t, "/signin/sent", sent, "fifteen", "Check your mail", "Home")
72
73 failed := redeem(t, app, "not-a-token").Body.String()
74 mustContain(t, "signin failed", failed, "Sign-in links work once and expire after 15 minutes.")
75 mustNotContain(t, "signin failed", failed, "fifteen")
76
77 f := newMountedChooser(t)
78 out := f.request("GET", "/signed-out", "", "", nil)
79 if out.Code != http.StatusOK {
80 t.Fatalf("GET /signed-out: %d", out.Code)
81 }
82 mustContain(t, "/signed-out", out.Body.String(),
83 "<title>Signed out · Oficina</title>",
84 "<h1>You’re signed out</h1>",
85 "You are signed out of the directory in this browser.",
86 `rst-btn="primary" estilo-signin-action>Sign in</a>`)
87 mustNotContain(t, "/signed-out", out.Body.String(), "You’ve signed out of Oficina on this device.", "Home")
88}
89
90// The hub builds its own signin.Flow, so it sets the email itself: the
91// suite's subject, and a body that says how long the link lasts rather
92// than keymaildev's default "expires shortly".
93func TestSigninEmailSpeaksTheSuiteCopy(t *testing.T) {
94 app := newTestApp(t)
95 signIn(t, app, "someone@example.com")
96 mail, ok := app.mailer.last()
97 if !ok {
98 t.Fatal("no mail was sent")
99 }
100 if mail.Subject != "Sign in to Oficina" {
101 t.Errorf("subject = %q", mail.Subject)
102 }
103 for _, want := range []string{"Here’s your link to sign in to Oficina:", Origin + linkPath + "?token=", "It works once and expires in 15 minutes."} {
104 if !strings.Contains(mail.Body, want) {
105 t.Errorf("body missing %q:\n%s", want, mail.Body)
106 }
107 }
108 if strings.Contains(mail.Body, "shortly") || strings.Contains(mail.Body, "Home") {
109 t.Errorf("body is not the suite's copy:\n%s", mail.Body)
110 }
111}
112
113// Never name the hub to people (Paul, 2026-09-23): the suite is Oficina.
114func TestHubNeverCallsItselfHome(t *testing.T) {
115 f := newMountedChooser(t)
116 page := f.request("GET", "/", "", "", f.session(t, chooserPerson))
117 mustNotContain(t, "directory", page.Body.String(), "to Home")
118 for _, app := range directoryCatalog(Runtime{}) {
119 if strings.Contains(app.Status, "Home") {
120 t.Errorf("%s: status %q names Home", app.Name, app.Status)
121 }
122 }
123 files, err := templatesFS.ReadDir("templates")
124 if err != nil {
125 t.Fatal(err)
126 }
127 for _, e := range files {
128 b, err := templatesFS.ReadFile("templates/" + e.Name())
129 if err != nil {
130 t.Fatal(err)
131 }
132 for _, bad := range []string{"Back to Home", "Return to Home", "to Home"} {
133 if strings.Contains(string(b), bad) {
134 t.Errorf("%s says %q", e.Name(), bad)
135 }
136 }
137 }
138}
139