package calls // The contract between estilo's door and rastrillo's screen. import ( "fmt" "net/http" "regexp" "strings" "testing" "time" "amadan.net/oficina/home/connect" "amadan.net/rastrillo/rastrillo/lastsignin" ) // The contract estilo's review asked for: estilo-signin-screen over // rastrillo's real sign-in states. HideBrand drops the partial's brand // column (estilo's door draws Calls' mark and name around the card), so // [estilo-signin-screen] > section has the door as its only element child, // in every state, both modes, the refusal, the removal, the join cookie's // door and the confirm step included. func TestSmartDoorScreenHoldsOnlyTheDoor(t *testing.T) { f := newHomeRouterFixture(t) oficina := &lastsignin.Record{Method: lastsignin.MethodFederated, Provider: lastsignin.ProviderOficina, Address: "alice@example.test"} email := &lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "bob@example.test"} for _, c := range []struct { name, path string record *lastsignin.Record }{ {"first visit", "/signin", nil}, {"Oficina ID remembered", "/signin", oficina}, {"email remembered", "/signin", email}, {"keymail remembered", "/signin", &lastsignin.Record{Method: lastsignin.MethodKeymail, Address: "bob@example.test"}}, {"the chooser", "/signin?ways=1", email}, {"problem", "/signin?err=expired", email}, {"the removal", "/signin?err=removed", nil}, {"sent", "/signin?sent=1", email}, {"step-up", "/signin?reauth=1", oficina}, {"email only", "/signin/local", nil}, } { t.Run(c.name, func(t *testing.T) { br := f.fresh() if c.record != nil { br.remember(t, *c.record) } rec := br.get(c.path) if rec.Code != http.StatusOK { t.Fatalf("GET %s: %d", c.path, rec.Code) } screenOnlyHoldsTheDoor(t, rec.Body.String()) }) } // The refusal (a session the signed-in routes refuse), standalone. refused := newStandaloneDoor(t) refused.session(t, "opaque-home-person", connect.HomeMethod, time.Now()) body := refused.get("/signin").Body.String() if !strings.Contains(body, signinRefusal) { t.Fatal("the refusal case drew no refusal") } screenOnlyHoldsTheDoor(t, body) // The join cookie's email-only door. joining := f.fresh() _, token := doorMeeting(t, joining, true) joining.get("/j/" + token) screenOnlyHoldsTheDoor(t, joining.get("/signin").Body.String()) // The confirm step an emailed link opens (auth's RenderConfirm). br := f.fresh() f.mail.body = "" br.do(http.MethodPost, "/signin", "address=alice%40example.test") link := signinLink.FindString(f.mailBody()) confirm := br.get(strings.TrimPrefix(link, homeTestOrigin)) if confirm.Code != http.StatusOK { t.Fatalf("confirm: %d", confirm.Code) } screenOnlyHoldsTheDoor(t, confirm.Body.String()) // Standalone, too. screenOnlyHoldsTheDoor(t, newStandaloneDoor(t).get("/signin").Body.String()) } // startTag is one start or end tag. var startTag = regexp.MustCompile(`<(/?)([a-zA-Z][a-zA-Z0-9-]*)([^>]*)>`) // voidElements have no end tag. var voidElements = map[string]bool{"area": true, "base": true, "br": true, "col": true, "embed": true, "hr": true, "img": true, "input": true, "link": true, "meta": true, "source": true, "track": true, "wbr": true} // screenOnlyHoldsTheDoor checks that the first section inside // [estilo-signin-screen] is rastrillo's [rst-signin] and that its only // element child is the door, [rst-signin-door]. func screenOnlyHoldsTheDoor(t *testing.T, body string) { t.Helper() children, err := screenChildren(body) if err != nil { t.Fatal(err) } if len(children) != 1 || !strings.HasPrefix(children[0], "
Calls