oficina / calendar Public

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

Plain git — no account needed to clone.

Download

Download this file

1package calendar
2
3// The door's edges Fable probed by hand on #48: a removed member on the
4// other two door routes, a team session that speaks for nobody, an
5// unlinked local account in team mode, a refused session on the door's own
6// outcome states, and sessions the web door must never judge.
7
8import (
9 "net/http"
10 "strings"
11 "testing"
12 "time"
13
14 "amadan.net/oficina/home/connect"
15)
16
17// A removed member at /signin/local sees the removal, and the session ends
18// on that response; at /signin/oficina the session ends and Oficina ID
19// starts afresh, rather than shortcutting a refused session to a page.
20func TestTeamRemovedMemberOnTheOtherDoorRoutes(t *testing.T) {
21 f := newTeamFixture(t)
22 subject := teamSubject('o')
23 f.member(subject, "member")
24 f.dir.Set(subject, "")
25 f.refreshed()
26 cookie := f.app.sessionCookie()
27
28 w := f.get(connect.SigninLocalPath)
29 card := door(t, w.Body.String())
30 if w.Code != http.StatusOK || !strings.Contains(card, signinRemoved) || !clears(w, cookie) || f.sessionCookie() != nil {
31 t.Fatalf("/signin/local for a removed member = %d, cleared %v\n%s", w.Code, clears(w, cookie), card)
32 }
33
34 f.signInHome(subject)
35 if f.sessionCookie() == nil {
36 t.Fatal("re-sign-in minted no session")
37 }
38 start := f.get(connect.SigninOficinaPath)
39 if loc := start.Header().Get("Location"); start.Code != http.StatusSeeOther || !strings.HasPrefix(loc, "/auth/start") {
40 t.Fatalf("/signin/oficina for a removed member = %d %q, want the Home exchange", start.Code, loc)
41 }
42 if !clears(start, cookie) || f.sessionCookie() != nil {
43 t.Error("/signin/oficina kept the removed member's session")
44 }
45}
46
47// A Home session for a subject that speaks for nobody here (no link, no
48// Home-only person) is ended at the door and shown the refusal.
49func TestTeamHomeSessionForNobodyIsRefused(t *testing.T) {
50 f := newTeamFixture(t)
51 f.session(t, teamSubject('n'), connect.HomeMethod, time.Now())
52 w := f.get("/signin")
53 if card := door(t, w.Body.String()); w.Code != http.StatusOK || !strings.Contains(card, signinRefusal) {
54 t.Fatalf("/signin for a Home session of nobody = %d\n%s", w.Code, card)
55 }
56 if !clears(w, f.app.sessionCookie()) {
57 t.Error("the session for nobody was not ended")
58 }
59}
60
61// An unlinked local account in team mode is signed in, not refused: /signin
62// shortcuts it to "/", and "/" sends it on to link (/account/home).
63func TestTeamUnlinkedLocalAccountIsNotRefused(t *testing.T) {
64 f := newTeamFixture(t)
65 f.localSession("alice@example.test")
66 w := f.get("/signin")
67 if strings.Contains(w.Body.String(), signinRefusal) {
68 t.Fatal("an unlinked local account was refused at the door")
69 }
70 redirectsTo(t, w, "/")
71 redirectsTo(t, f.get("/"), "/account/home")
72 if f.sessionCookie() == nil {
73 t.Error("the door ended an unlinked local account's session")
74 }
75}
76
77// A refused session on the door's own outcome states (Sent, a problem) is
78// ended there too, but the state is drawn as it is, without the refusal.
79func TestARefusedSessionOnTheDoorsOutcomeStates(t *testing.T) {
80 for _, path := range []string{"/signin?sent=1", "/signin?err=expired"} {
81 f := newHomeRouterFixture(t)
82 f.session(t, "alice@example.test", "magiclink", time.Now())
83 delete(f.app.home.admitted.addrs, "alice@example.test")
84 w := f.get(path)
85 if w.Code != http.StatusOK || strings.Contains(w.Body.String(), signinRefusal) {
86 t.Errorf("GET %s for a refused session = %d, drew the refusal: %v", path, w.Code, strings.Contains(w.Body.String(), signinRefusal))
87 }
88 if !clears(w, f.app.sessionCookie()) || f.sessionCookie() != nil {
89 t.Errorf("GET %s kept the refused session", path)
90 }
91 }
92}
93
94// Sessions requirePerson cannot speak for (a native app's, a guest's) are
95// never judged by the web door: not refused, not ended, in either mode.
96func TestTheDoorNeverJudgesANativeSession(t *testing.T) {
97 for name, f := range map[string]*homeRouterFixture{"home": newHomeRouterFixture(t), "team": newTeamFixture(t).homeRouterFixture} {
98 for _, method := range []string{connect.NativeMethod, connect.NativeWebMethod, "guest"} {
99 g := f.fresh()
100 g.session(t, teamSubject('v'), method, time.Now())
101 w := g.get("/signin")
102 if strings.Contains(w.Body.String(), signinRefusal) || clears(w, f.app.sessionCookie()) {
103 t.Errorf("%s: the door judged a %s session: %d", name, method, w.Code)
104 }
105 if ad := f.app.admission(g.jarRequest(), true); !ad.signedIn || !ad.admitted {
106 t.Errorf("%s: the probe refused a %s session", name, method)
107 }
108 }
109 }
110}
111