package calendartest import ( "net/http" "net/url" "regexp" "strings" "testing" ) // The sign-in pages are the Oficina door (estilo chrome, Paul // 2026-09-29): one card on the suite's sky, Calendar's mark and name at // its head. Only the drawing changed — the form still posts "address" to // /signin and gets the same answer it always did. func TestSignInPageIsTheDoor(t *testing.T) { app := newApp(t) h := app.Handler() rec := get(t, h, "/signin") if rec.Code != http.StatusOK { t.Fatalf("GET /signin: status %d, want 200", rec.Code) } body := rec.Body.String() for _, want := range []string{ "estilo-door", "Calendar", `
Sign in · Calendar", // Paul, 2026-10-01: the door's button says "Sign in". ``, "We’ll email you a link that signs you in. It works once and expires in 15 minutes.", } { if !strings.Contains(body, want) { t.Errorf("sign-in page is missing %q:\n%s", want, body) } } // The door owns its words (Paul, 2026-10-01): the submit is "Sign in", // and Calendar's own lede and button copy are gone. for _, gone := range []string{"Email me a link", "There is no password", "A calendar for one team"} { if strings.Contains(body, gone) { t.Errorf("sign-in page still says %q", gone) } } // The sky: an inline placeholder, and served layers reachable signed // out through estilo's handler, not the app's /static/ one. if !regexp.MustCompile(`]*src="data:image/png;base64,`).MatchString(body) { t.Errorf("sign-in page has no inline estilo-sky-layer placeholder:\n%s", body) } layer := regexp.MustCompile(`]*src="(/static/estilo/sky/v1/[^"]+)"`).FindStringSubmatch(body) if layer == nil { t.Fatalf("sign-in page links no served estilo-sky-layer img:\n%s", body) } if got := get(t, h, layer[1]); got.Code != http.StatusOK || got.Header().Get("Content-Type") != "image/svg+xml" { t.Errorf("GET %s signed out: %d %q, want 200 image/svg+xml", layer[1], got.Code, got.Header().Get("Content-Type")) } // The door's own styles are linked and served. for _, name := range []string{"chrome", "sky"} { href := regexp.MustCompile(`/static/` + name + `\.[0-9a-f]{16}\.css`).FindString(body) if href == "" { t.Errorf("sign-in page does not link static/%s.css", name) continue } if got := get(t, h, href); got.Code != http.StatusOK { t.Errorf("GET %s: status %d, want 200", href, got.Code) } } // POST address= still begins sign-in exactly as before. posted := post(t, h, "/signin", url.Values{"address": {"someone@example.com"}}) if posted.Code != http.StatusSeeOther || posted.Header().Get("Location") != "/signin?sent=1" { t.Fatalf("POST /signin: %d to %q, want 303 to /signin?sent=1", posted.Code, posted.Header().Get("Location")) } if mail, err := app.LastMailForTest(); err != nil || !strings.Contains(mail, "/auth/verify?token=") { t.Fatalf("POST /signin address= mailed no link (err %v)", err) } } // Every outcome the auth plugin redirects back with keeps its sentence; // a bad address is the field's own error, the rest are the page's. func TestSignInDoorOutcomes(t *testing.T) { h := newApp(t).Handler() for query, want := range map[string][]string{ "sent=1": {"estilo-door", "Check your email · Calendar", "Check your email", "If that address can sign in here, we’ve sent it a link. It works once and expires in 15 minutes.", `href="/signin"`, "Use a different address"}, "err=rate": {"estilo-signin-form", `role="alert"`, "Too many attempts. Wait a few minutes, then try again."}, "err=expired": {"estilo-signin-form", "That link has expired. Ask for a new one."}, "err=nope": {"estilo-signin-form", "That link did not work. Ask for a new one."}, "err=expired&sent=1": {"estilo-signin-form", "Sign in · Calendar", "That link has expired. Ask for a new one.", "If that address can sign in here, we’ve sent it a link."}, "err=address": {`rst-field-error id="estilo-signin-address-error" role="alert">That does not look like an email address.`}, } { body := get(t, h, "/signin?"+query).Body.String() for _, w := range want { if !strings.Contains(body, w) { t.Errorf("/signin?%s is missing %q:\n%s", query, w, body) } } } if body := get(t, h, "/signin?sent=1").Body.String(); strings.Contains(body, "estilo-signin-form") { t.Error("/signin?sent=1 still draws the form; the check-your-email card replaces it") } for _, query := range []string{"sent=1", "err=expired&sent=1"} { body := get(t, h, "/signin?"+query).Body.String() for _, gone := range []string{"expires shortly", "Send another link"} { if strings.Contains(body, gone) { t.Errorf("/signin?%s still says %q", query, gone) } } } }