oficina / meet Public

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

Plain git — no account needed to clone.

Download

Download this file

1package calls
2
3// Signed out, and forgetting: "Forget me on this device" on the signed-out
4// page, chained on to Oficina ID's own Forget with Home.
5
6import (
7 "net/http"
8 "strings"
9 "testing"
10
11 "amadan.net/rastrillo/rastrillo/lastsignin"
12)
13
14func TestTheSignedOutPageOffersForget(t *testing.T) {
15 doorModes(t, func(t *testing.T, f *homeRouterFixture) {
16 body := f.get("/signed-out").Body.String()
17 for _, want := range []string{"You’re signed out", `<form estilo-signin-forget method="post" action="/signin/forget">`, "Forget me on this device"} {
18 if !strings.Contains(body, want) {
19 t.Errorf("the signed-out page lacks %q", want)
20 }
21 }
22 chained := strings.Contains(body, `name="chain" value="oficina"`)
23 if chained != (f.app.home != nil) {
24 t.Errorf("chain=oficina on the signed-out page: %v, want it with Home only", chained)
25 }
26 })
27}
28
29// With Home, Forget with chain=oficina forgets here and goes on to Oficina
30// ID's Forget, which returns to this origin's signed-out page; without the
31// chain (the door's "Use a different email") it stays on the door; a
32// cross-site post is refused and chains nowhere.
33func TestForgetChainsOnToOficinaID(t *testing.T) {
34 f := newHomeRouterFixture(t)
35 f.remember(t, lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "alice@example.test"})
36 w := f.do(http.MethodPost, signinForgetPath, "chain=oficina")
37 redirectsTo(t, w, homeTestIssuer+"/forget?return=https%3A%2F%2Fmeet.example.test%2Fsigned-out")
38 if _, res := f.remembered(); res == lastsignin.Valid {
39 t.Fatal("Forget kept the record")
40 }
41 f.remember(t, lastsignin.Record{Method: lastsignin.MethodMagicLink, Address: "alice@example.test"})
42 w = f.do(http.MethodPost, signinForgetPath, "way=email")
43 if loc := w.Header().Get("Location"); w.Code != http.StatusSeeOther || !strings.HasPrefix(loc, "/signin") {
44 t.Fatalf("Use a different email = %d %q, want the door", w.Code, loc)
45 }
46 cross := f.doWith(http.MethodPost, signinForgetPath, "chain=oficina", http.Header{"Origin": {"https://evil.example"}, "Sec-Fetch-Site": {"cross-site"}})
47 if cross.Code == http.StatusSeeOther && strings.Contains(cross.Header().Get("Location"), homeTestIssuer) {
48 t.Fatal("a cross-site Forget chained on to Oficina ID")
49 }
50 // Standalone there is no Oficina ID to chain to.
51 s := newStandaloneDoor(t)
52 if loc := s.do(http.MethodPost, signinForgetPath, "chain=oficina").Header().Get("Location"); strings.Contains(loc, "forget?return") {
53 t.Fatalf("standalone Forget chained to %q", loc)
54 }
55}
56