package calls // Signed out, and forgetting: "Forget me on this device" on the signed-out // page, chained on to Oficina ID's own Forget with Home. import ( "net/http" "strings" "testing" "amadan.net/rastrillo/rastrillo/lastsignin" ) func TestTheSignedOutPageOffersForget(t *testing.T) { doorModes(t, func(t *testing.T, f *homeRouterFixture) { body := f.get("/signed-out").Body.String() for _, want := range []string{"You’re signed out", `
`, "Forget me on this device"} { if !strings.Contains(body, want) { t.Errorf("the signed-out page lacks %q", want) } } chained := strings.Contains(body, `name="chain" value="oficina"`) if chained != (f.app.home != nil) { t.Errorf("chain=oficina on the signed-out page: %v, want it with Home only", chained) } }) } // With Home, Forget with chain=oficina forgets here and goes on to Oficina // ID's Forget, which returns to this origin's signed-out page; without the // chain (the door's "Use a different email") it stays on the door; a // cross-site post is refused and chains nowhere. func TestForgetChainsOnToOficinaID(t *testing.T) { f := newHomeRouterFixture(t) f.remember(t, lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "alice@example.test"}) w := f.do(http.MethodPost, signinForgetPath, "chain=oficina") redirectsTo(t, w, homeTestIssuer+"/forget?return=https%3A%2F%2Fmeet.example.test%2Fsigned-out") if _, res := f.remembered(); res == lastsignin.Valid { t.Fatal("Forget kept the record") } f.remember(t, lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "alice@example.test"}) w = f.do(http.MethodPost, signinForgetPath, "way=email") if loc := w.Header().Get("Location"); w.Code != http.StatusSeeOther || !strings.HasPrefix(loc, "/signin") { t.Fatalf("Use a different email = %d %q, want the door", w.Code, loc) } cross := f.doWith(http.MethodPost, signinForgetPath, "chain=oficina", http.Header{"Origin": {"https://evil.example"}, "Sec-Fetch-Site": {"cross-site"}}) if cross.Code == http.StatusSeeOther && strings.Contains(cross.Header().Get("Location"), homeTestIssuer) { t.Fatal("a cross-site Forget chained on to Oficina ID") } // Standalone there is no Oficina ID to chain to. s := newStandaloneDoor(t) if loc := s.do(http.MethodPost, signinForgetPath, "chain=oficina").Header().Get("Location"); strings.Contains(loc, "forget?return") { t.Fatalf("standalone Forget chained to %q", loc) } }