package calls // The door in team mode: connect's member choice (connect.New requires // Admit with HomeOnly/Unlinked), a removed member at the door, and the // roster's answers the door must not read as refusals. import ( "net/http" "strings" "testing" "amadan.net/oficina/home/connect" "amadan.net/rastrillo/rastrillo/lastsignin" ) // A roster member with no account here is asked to choose, in connect's // own English; "I'm new here" signs them in as a Home-only person, who is // remembered with no address. func TestTeamAMemberChoosesNewAndIsRememberedWithNoAddress(t *testing.T) { f := newTeamFixture(t) subject := teamSubject('n') f.dir.Set(subject, "member") f.refreshed() fin := f.signInHomeChoosing(subject) redirectsTo(t, fin, connect.ChoosePath) page := f.get(connect.ChoosePath).Body.String() for _, want := range []string{"Welcome to the team", "Connect my existing account", "I’m new here — continue with Oficina ID"} { if !strings.Contains(page, want) { t.Errorf("the choose page lacks %q", want) } } if w := f.choose("new"); w.Code != http.StatusSeeOther { t.Fatalf("I'm new here = %d", w.Code) } if w := f.get("/"); w.Code != http.StatusOK { t.Fatalf("the new member's list = %d", w.Code) } rec, res := f.remembered() if res != lastsignin.Valid || rec.Method != lastsignin.MethodFederated || rec.Address != "" { t.Fatalf("remembered %+v (%v), want Oficina ID with no address", rec, res) } } // "Connect my existing account" goes to the email-only door. func TestTeamAMemberChoosesConnect(t *testing.T) { f := newTeamFixture(t, "carol@example.test") subject := teamSubject('o') f.dir.Set(subject, "member") f.refreshed() redirectsTo(t, f.signInHomeChoosing(subject), connect.ChoosePath) w := f.choose("connect") if w.Code != http.StatusSeeOther || !strings.HasPrefix(w.Header().Get("Location"), connect.SigninLocalPath) { t.Fatalf("connect = %d %q, want the email-only door", w.Code, w.Header().Get("Location")) } if card := door(t, f.get(w.Header().Get("Location")).Body.String()); strings.Contains(card, oficinaButton) { t.Fatalf("the connect door offers Oficina ID:\n%s", card) } } // A stranger to the roster is offered no choice, and remembered nothing. func TestTeamAStrangerGetsNoChoice(t *testing.T) { f := newTeamFixture(t) if w := f.signInHomeChoosing(teamSubject('s')); w.Code != http.StatusForbidden { t.Fatalf("a stranger's sign-in = %d %q, want 403", w.Code, w.Header().Get("Location")) } if _, res := f.remembered(); res != lastsignin.Absent { t.Fatal("a stranger was remembered") } } // A removed member's session at the door: the removal, the session ended // on the door's own response, Oficina ID forgotten. Signing in again // through Oficina ID remembers nothing (the strict probe refuses the // minted session, and ends nothing: the first page does, and says why). func TestTeamARemovedMemberAtTheDoor(t *testing.T) { f := newTeamFixture(t) subject := teamSubject('q') f.member(subject, "member") if _, res := f.remembered(); res != lastsignin.Valid { t.Fatal("the member's Oficina ID sign-in was not remembered") } f.removed(subject) rec := f.get("/signin") if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), signinRemoved) { t.Fatalf("/signin for a removed member = %d", rec.Code) } if !clears(rec, f.app.sessionCookie()) || f.cookies[f.app.sessionCookie()] != nil { t.Fatal("the door kept the removed member's session") } if _, res := f.remembered(); res == lastsignin.Valid { t.Fatal("the door kept the removed member's Oficina ID") } if w := f.signInHome(subject); w.Code != http.StatusSeeOther { t.Fatalf("a removed member's sign-in = %d", w.Code) } if _, res := f.remembered(); res == lastsignin.Valid { t.Fatal("a removed member's sign-in was remembered") } if w := f.get("/"); w.Code != http.StatusSeeOther || !strings.Contains(w.Header().Get("Location"), "err=removed") { t.Fatalf("the removed member's first page = %d %q", w.Code, w.Header().Get("Location")) } } // An unlinked local account the allowlist admits is no refusal: /signin // sends it on, and the page sends it to connect its Oficina account. func TestTeamAnUnlinkedLocalAccountIsNoRefusal(t *testing.T) { f := newTeamFixture(t, "carol@example.test") f.localSession("carol@example.test") redirectsTo(t, f.get("/signin"), "/") if f.cookies[f.app.sessionCookie()] == nil { t.Fatal("the door ended an unlinked local account's session") } } // The roster's identity storage unreadable is a 503, never a refusal at // the door, and the session and its remembered way in are kept. func TestTeamAnUndecidedDoorRefusesNothing(t *testing.T) { f := newTeamFixture(t) f.member(teamSubject('u'), "member") if _, err := f.app.db.Writer().Exec("ALTER TABLE calls_team_home_persons RENAME TO unavailable_home_persons"); err != nil { t.Fatal(err) } rec := f.get("/signin") if strings.Contains(rec.Body.String(), signinRemoved) || strings.Contains(rec.Body.String(), signinRefusal) || len(rec.Result().Cookies()) != 0 { t.Fatalf("the door for an undecided member = %d, cookies %v", rec.Code, rec.Result().Cookies()) } if _, res := f.remembered(); res != lastsignin.Valid { t.Fatal("the door forgot an undecided member's Oficina ID") } }