| 1 | package calls |
| 2 | |
| 3 | // The door in team mode: connect's member choice (connect.New requires |
| 4 | // Admit with HomeOnly/Unlinked), a removed member at the door, and the |
| 5 | // roster's answers the door must not read as refusals. |
| 6 | |
| 7 | import ( |
| 8 | "net/http" |
| 9 | "strings" |
| 10 | "testing" |
| 11 | |
| 12 | "amadan.net/oficina/home/connect" |
| 13 | "amadan.net/rastrillo/rastrillo/lastsignin" |
| 14 | ) |
| 15 | |
| 16 | // A roster member with no account here is asked to choose, in connect's |
| 17 | // own English; "I'm new here" signs them in as a Home-only person, who is |
| 18 | // remembered with no address. |
| 19 | func TestTeamAMemberChoosesNewAndIsRememberedWithNoAddress(t *testing.T) { |
| 20 | f := newTeamFixture(t) |
| 21 | subject := teamSubject('n') |
| 22 | f.dir.Set(subject, "member") |
| 23 | f.refreshed() |
| 24 | fin := f.signInHomeChoosing(subject) |
| 25 | redirectsTo(t, fin, connect.ChoosePath) |
| 26 | page := f.get(connect.ChoosePath).Body.String() |
| 27 | for _, want := range []string{"Welcome to the team", "Connect my existing account", "I’m new here — continue with Oficina ID"} { |
| 28 | if !strings.Contains(page, want) { |
| 29 | t.Errorf("the choose page lacks %q", want) |
| 30 | } |
| 31 | } |
| 32 | if w := f.choose("new"); w.Code != http.StatusSeeOther { |
| 33 | t.Fatalf("I'm new here = %d", w.Code) |
| 34 | } |
| 35 | if w := f.get("/"); w.Code != http.StatusOK { |
| 36 | t.Fatalf("the new member's list = %d", w.Code) |
| 37 | } |
| 38 | rec, res := f.remembered() |
| 39 | if res != lastsignin.Valid || rec.Method != lastsignin.MethodFederated || rec.Address != "" { |
| 40 | t.Fatalf("remembered %+v (%v), want Oficina ID with no address", rec, res) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // "Connect my existing account" goes to the email-only door. |
| 45 | func TestTeamAMemberChoosesConnect(t *testing.T) { |
| 46 | f := newTeamFixture(t, "carol@example.test") |
| 47 | subject := teamSubject('o') |
| 48 | f.dir.Set(subject, "member") |
| 49 | f.refreshed() |
| 50 | redirectsTo(t, f.signInHomeChoosing(subject), connect.ChoosePath) |
| 51 | w := f.choose("connect") |
| 52 | if w.Code != http.StatusSeeOther || !strings.HasPrefix(w.Header().Get("Location"), connect.SigninLocalPath) { |
| 53 | t.Fatalf("connect = %d %q, want the email-only door", w.Code, w.Header().Get("Location")) |
| 54 | } |
| 55 | if card := door(t, f.get(w.Header().Get("Location")).Body.String()); strings.Contains(card, oficinaButton) { |
| 56 | t.Fatalf("the connect door offers Oficina ID:\n%s", card) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // A stranger to the roster is offered no choice, and remembered nothing. |
| 61 | func TestTeamAStrangerGetsNoChoice(t *testing.T) { |
| 62 | f := newTeamFixture(t) |
| 63 | if w := f.signInHomeChoosing(teamSubject('s')); w.Code != http.StatusForbidden { |
| 64 | t.Fatalf("a stranger's sign-in = %d %q, want 403", w.Code, w.Header().Get("Location")) |
| 65 | } |
| 66 | if _, res := f.remembered(); res != lastsignin.Absent { |
| 67 | t.Fatal("a stranger was remembered") |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // A removed member's session at the door: the removal, the session ended |
| 72 | // on the door's own response, Oficina ID forgotten. Signing in again |
| 73 | // through Oficina ID remembers nothing (the strict probe refuses the |
| 74 | // minted session, and ends nothing: the first page does, and says why). |
| 75 | func TestTeamARemovedMemberAtTheDoor(t *testing.T) { |
| 76 | f := newTeamFixture(t) |
| 77 | subject := teamSubject('q') |
| 78 | f.member(subject, "member") |
| 79 | if _, res := f.remembered(); res != lastsignin.Valid { |
| 80 | t.Fatal("the member's Oficina ID sign-in was not remembered") |
| 81 | } |
| 82 | f.removed(subject) |
| 83 | rec := f.get("/signin") |
| 84 | if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), signinRemoved) { |
| 85 | t.Fatalf("/signin for a removed member = %d", rec.Code) |
| 86 | } |
| 87 | if !clears(rec, f.app.sessionCookie()) || f.cookies[f.app.sessionCookie()] != nil { |
| 88 | t.Fatal("the door kept the removed member's session") |
| 89 | } |
| 90 | if _, res := f.remembered(); res == lastsignin.Valid { |
| 91 | t.Fatal("the door kept the removed member's Oficina ID") |
| 92 | } |
| 93 | if w := f.signInHome(subject); w.Code != http.StatusSeeOther { |
| 94 | t.Fatalf("a removed member's sign-in = %d", w.Code) |
| 95 | } |
| 96 | if _, res := f.remembered(); res == lastsignin.Valid { |
| 97 | t.Fatal("a removed member's sign-in was remembered") |
| 98 | } |
| 99 | if w := f.get("/"); w.Code != http.StatusSeeOther || !strings.Contains(w.Header().Get("Location"), "err=removed") { |
| 100 | t.Fatalf("the removed member's first page = %d %q", w.Code, w.Header().Get("Location")) |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // An unlinked local account the allowlist admits is no refusal: /signin |
| 105 | // sends it on, and the page sends it to connect its Oficina account. |
| 106 | func TestTeamAnUnlinkedLocalAccountIsNoRefusal(t *testing.T) { |
| 107 | f := newTeamFixture(t, "carol@example.test") |
| 108 | f.localSession("carol@example.test") |
| 109 | redirectsTo(t, f.get("/signin"), "/") |
| 110 | if f.cookies[f.app.sessionCookie()] == nil { |
| 111 | t.Fatal("the door ended an unlinked local account's session") |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // The roster's identity storage unreadable is a 503, never a refusal at |
| 116 | // the door, and the session and its remembered way in are kept. |
| 117 | func TestTeamAnUndecidedDoorRefusesNothing(t *testing.T) { |
| 118 | f := newTeamFixture(t) |
| 119 | f.member(teamSubject('u'), "member") |
| 120 | if _, err := f.app.db.Writer().Exec("ALTER TABLE calls_team_home_persons RENAME TO unavailable_home_persons"); err != nil { |
| 121 | t.Fatal(err) |
| 122 | } |
| 123 | rec := f.get("/signin") |
| 124 | if strings.Contains(rec.Body.String(), signinRemoved) || strings.Contains(rec.Body.String(), signinRefusal) || len(rec.Result().Cookies()) != 0 { |
| 125 | t.Fatalf("the door for an undecided member = %d, cookies %v", rec.Code, rec.Result().Cookies()) |
| 126 | } |
| 127 | if _, res := f.remembered(); res != lastsignin.Valid { |
| 128 | t.Fatal("the door forgot an undecided member's Oficina ID") |
| 129 | } |
| 130 | } |
| 131 | |