Present: admit the presenter's cookie; it drives pre-deploy talks too
The cookie is a capability on the /p/ routes, so it now goes through the same admission as every signed-in route (currentUser: allowlist recheck and offboarding, team roster, Home). mayDrive, pairing, the talk's notes, the window and the slide window all ask admittedPresenter; an address taken off the list is signed out and its talks ended on its first press or pairing. A talk begun before positions, rejoined through Present (no token), is driven by the signed-in presenter by its index: controls on the slide window and the old presenter view, data-drives for present.js's keys, and presentCommand's index path lets the cookie in. Review findings, Important 1 and 5.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 files changed,
+305
−86
internal/slides/credits/assets.json+1 −1internal/slides/home_test.go+1 −1internal/slides/presentation.go+103 −46internal/slides/presenting_position.go+30 −24internal/slides/presenting_position_test.go+3 −3internal/slides/presenting_talk.go+4 −1internal/slides/static/present.js+9 −4internal/slides/team_survivors_test.go+1 −1internal/slides/templates/present.html+1 −0internal/slides/templates/present_notes.html+2 −1internal/slidestest/present_admission_test.go+142 −0internal/slidestest/present_position_test.go+8 −4
diff --git a/internal/slides/credits/assets.json b/internal/slides/credits/assets.json| index 8695eb9..edaa3a7 100644 |
| --- a/internal/slides/credits/assets.json |
| +++ b/internal/slides/credits/assets.json |
| @@ -68,7 +68,7 @@ |
| "internal/slides/static/fonts/LiberationSerif-Regular.woff2": "922f544d0eabdf45ecd389b3bb35367e670b736e40851d01e53c150352c012f2", |
| "internal/slides/static/fontsgate.971e476eab8b8588.js": "971e476eab8b8588be520ac38eb823ab19beb2567db734555a7edc40d58567b2", |
| "internal/slides/static/fontshold.876f3d8d396da42f.js": "876f3d8d396da42f81954539f30b7200edfcde719d2920504707822f176a36ab", |
| - "internal/slides/static/present.js": "a5a6802d7f40986c3692a16029f554d50ec6a14e0168a362697ce1313f964de4", |
| + "internal/slides/static/present.js": "41adf1e16b6352a592bf2c2c5a728af6e19a5c36fa890d67195ec0eeee2f2d6b", |
| "internal/slides/static/presenter.f9e7e410409cef8b.js": "f9e7e410409cef8ba5ebe066ba666b30f6c74a65df4eb2d1878be89dfb216c0a", |
| "internal/slides/static/rastrillo.js": "13a8ca6fa9ac25833f6485ab50a521dff7bd811372025dc5141b96522b60098b", |
| "internal/slides/static/select.js": "e231bad4b964464addfacd52d2260d4bdc0a02938fc033a25fdd9cbeb3671be1", |
diff --git a/internal/slides/home_test.go b/internal/slides/home_test.go| index 2009570..0f238a4 100644 |
| --- a/internal/slides/home_test.go |
| +++ b/internal/slides/home_test.go |
| @@ -129,7 +129,7 @@ func TestHomeExistingIdentityNoCreationAndStableActors(t *testing.T) { |
| if users != 1 || decks != 0 { |
| t.Fatalf("Home created rows users=%d decks=%d", users, decks) |
| } |
| - if got := a.presenterActor(r); got != actorFor(u) { |
| + if got, _ := a.admittedPresenter(httptest.NewRecorder(), r); got != actorFor(u) { |
| t.Fatalf("actor %q", got) |
| } |
| s, _ := a.homeSessions.From(r) |
diff --git a/internal/slides/presentation.go b/internal/slides/presentation.go| index a4f03a1..5134c8f 100644 |
| --- a/internal/slides/presentation.go |
| +++ b/internal/slides/presentation.go |
| @@ -59,11 +59,11 @@ import ( |
| "strings" |
| "time" |
| - "amadan.net/oficina/home/connect" |
| "amadan.net/oficina/slides/internal/slides/deck" |
| "amadan.net/oficina/slides/internal/slides/present" |
| slidehtml "amadan.net/oficina/slides/internal/slides/render" |
| "amadan.net/rastrillo/rastrillo" |
| + "amadan.net/rastrillo/rastrillo/sessions" |
| "github.com/go-chi/chi/v5" |
| "github.com/skip2/go-qrcode" |
| "gorm.io/gorm" |
| @@ -262,37 +262,39 @@ func (a *app) deckOf(w http.ResponseWriter, r *http.Request, p Presentation) (De |
| return Deck{}, false |
| } |
| -// presenterActor is who is signed in on this request, as an actor |
| -// string, or "" for nobody. |
| +// admittedPresenter is who is signed in on this request, as an actor |
| +// string, or "" for nobody, put through the same admission every |
| +// signed-in route makes: currentUser, the allowlist recheck (and |
| +// offboarding), the team roster, a Home identity. The cookie is a |
| +// capability on the /p/ routes (mayDrive, presentPair), so it must not |
| +// be a weaker one than on the routes behind RequireSession. |
| // |
| -// It reads the session cookie DIRECTLY (rauth's SessionFrom) rather |
| -// than through sessions.Current, because every screen in this file is |
| -// mounted outside the signed-in group — RequireSession is what stashes |
| -// a session on the request context, so past it sessions.Current |
| -// answers nothing at all. Nobody being signed in is the ordinary case |
| -// here (a phone, a projector), not a failure. |
| -func (a *app) presenterActor(r *http.Request) string { |
| - if a.auth == nil { |
| - return "" |
| - } |
| - if a.home != nil && a.homeSessions != nil { |
| - if session, ok := a.homeSessions.From(r); ok && session.Method == connect.HomeMethod { |
| - if u, err := a.homeUser(r, session); err == nil { |
| - return actorFor(u) |
| - } |
| - return "" |
| - } |
| - } |
| - id, ok := a.auth.SessionFrom(r) |
| - if !ok || id.Address == "" { |
| - return "" |
| - } |
| - var u User |
| - if err := a.db.G.WithContext(r.Context()). |
| - Where("email = ?", normalizeAddress(id.Address)).Take(&u).Error; err != nil { |
| - return "" |
| - } |
| - return actorFor(u) |
| +// Every screen in this file is mounted outside the signed-in group, so |
| +// the session is read from the cookie here (as optionalViewer reads it) |
| +// and handed to currentUser as RequireSession would hand it. Nobody |
| +// being signed in is the ordinary case (a phone, a projector), not a |
| +// failure. |
| +// |
| +// answered is true when currentUser has already written the answer: an |
| +// address no longer admitted has been signed out and its talks ended |
| +// (auth.go's offboard), or team standing could not be read. The caller |
| +// writes nothing more. |
| +func (a *app) admittedPresenter(w http.ResponseWriter, r *http.Request) (actor string, answered bool) { |
| + if a.auth == nil || a.sessions == nil { |
| + return "", false |
| + } |
| + s, ok := a.sessions.From(r) |
| + if !ok || s.Subject == "" { |
| + return "", false |
| + } |
| + u, outcome := a.currentUser(w, sessions.WithSession(r, s)) |
| + switch outcome { |
| + case sessionOK: |
| + return actorFor(u), false |
| + case sessionOffboarded: |
| + return "", true |
| + } |
| + return "", false |
| } |
| // --- POST /d/{sqid}/present --- |
| @@ -470,8 +472,10 @@ type surfacePage struct { |
| FragmentHref string |
| // Token is present only for a request entitled to drive, and it is |
| // what the script reads to send a keystroke. A page without it is |
| - // read-only in the markup AND in the script. |
| - Token string |
| + // read-only in the markup AND in the script, unless Drives says the |
| + // presenter's own cookie drives it (data-drives). |
| + Token string |
| + Drives bool |
| HasSlide bool |
| Slide template.HTML |
| @@ -543,6 +547,9 @@ type presenterPage struct { |
| DeckTitle string |
| Session string |
| Token string |
| + // Drives: the signed-in presenter drives this view by their cookie |
| + // (data-drives), with no token. |
| + Drives bool |
| Now int |
| Counter string |
| @@ -689,6 +696,16 @@ type surfaceOptions struct { |
| } |
| func (a *app) renderSurface(w http.ResponseWriter, r *http.Request, d Deck, p Presentation, opt surfaceOptions) { |
| + // Who drives from here is decided first: the presenter's cookie is |
| + // put through admission (mayDrive), which may answer for itself. |
| + // The follow view never drives. |
| + drives := false |
| + if !opt.follow { |
| + var answered bool |
| + if drives, _, answered = a.mayDrive(w, r, p, opt.token); answered { |
| + return |
| + } |
| + } |
| h, view, err := a.openDeck(r.Context(), d) |
| if err != nil { |
| a.fail(w, r, "open deck", err) |
| @@ -787,17 +804,19 @@ func (a *app) renderSurface(w http.ResponseWriter, r *http.Request, d Deck, p Pr |
| page.Refresh = true |
| page.BackHref = opt.backHref |
| page.BackLabel = opt.backLabel |
| - case remoteTokenOK(p, opt.token) || (p.Positional && a.mayDrive(r, p, "")): |
| + case drives: |
| // Whoever holds the remote drives the session from here too: |
| // the pager posts commands, so the projector's own next button |
| - // moves the talk rather than only this browser. On a session |
| - // with a position so does the presenter, signed in (S19): the |
| - // slide window they open from the presenter window drives. |
| + // moves the talk rather than only this browser. So does the |
| + // presenter, signed in (S19): the slide window they open from |
| + // the presenter window drives, and so does the one a talk |
| + // begun before positions rejoins on (Present again). |
| token := "" |
| if remoteTokenOK(p, opt.token) { |
| token = opt.token |
| } |
| page.Token = token |
| + page.Drives = true |
| back, next := pressLabels(r, p) |
| page.Controls = &controls{ |
| Action: "/p/" + p.Sqid + "/command", |
| @@ -870,7 +889,11 @@ func (a *app) presenterNotes(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| token := r.URL.Query().Get("t") |
| - if !a.mayDrive(r, p, token) { |
| + drives, actor, answered := a.mayDrive(w, r, p, token) |
| + if answered { |
| + return |
| + } |
| + if !drives { |
| a.notFound(w, r) |
| return |
| } |
| @@ -879,7 +902,16 @@ func (a *app) presenterNotes(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| holder := remoteTokenOK(p, token) |
| - presenter := p.Actor != "" && a.presenterActor(r) == p.Actor |
| + // Let in by the cookie (mayDrive's actor), or, holding the token |
| + // too, signed in as the presenter as well. |
| + presenter := actor != "" |
| + if holder && p.Actor != "" { |
| + signedIn, answered := a.admittedPresenter(w, r) |
| + if answered { |
| + return |
| + } |
| + presenter = signedIn == p.Actor |
| + } |
| d, ok := a.deckOf(w, r, p) |
| if !ok { |
| return |
| @@ -924,11 +956,21 @@ func (a *app) presenterNotes(w http.ResponseWriter, r *http.Request) { |
| page.Next, page.HasNext, page.Notes = shown.Next, shown.HasNext, shown.Notes |
| page.Mode = shown.Mode |
| - if holder { |
| + // The controls are the driver's: the phone's token, or the |
| + // presenter's own cookie on a talk they rejoined (Present again |
| + // issues no token, so a talk begun before positions would otherwise |
| + // come back as a watcher's). |
| + switch { |
| + case holder: |
| page.Token = token |
| page.Controls = commandControls(r, p, token) |
| page.StageHref = "/p/" + p.Sqid + "?t=" + url.QueryEscape(token) |
| page.StageLabel = rastrillo.T(r, "slides.present.stage") |
| + case presenter: |
| + page.Drives = true |
| + page.Controls = commandControls(r, p, "") |
| + page.StageHref = "/p/" + p.Sqid |
| + page.StageLabel = rastrillo.T(r, "slides.present.stage") |
| } |
| // Once, and only to the person presenting: the token is in this |
| // URL, so the pairing block is what that one request is FOR. |
| @@ -1001,7 +1043,15 @@ func (a *app) presentPair(w http.ResponseWriter, r *http.Request) { |
| if !ok { |
| return |
| } |
| - if p.Actor == "" || a.presenterActor(r) != p.Actor { |
| + if p.Actor == "" { |
| + a.notFound(w, r) |
| + return |
| + } |
| + actor, answered := a.admittedPresenter(w, r) |
| + if answered { |
| + return |
| + } |
| + if actor != p.Actor { |
| a.notFound(w, r) |
| return |
| } |
| @@ -1613,11 +1663,13 @@ func (a *app) presentCommand(w http.ResponseWriter, r *http.Request) { |
| a.presentPress(w, r, p) |
| return |
| } |
| - token := r.PostFormValue("t") |
| - if token == "" { |
| - token = bearerToken(r) |
| + // The token, or the presenter's own cookie (mayDrive): a talk |
| + // rejoined through Present is still theirs to drive. |
| + drives, presenter, answered := a.mayDrive(w, r, p, pressToken(r)) |
| + if answered { |
| + return |
| } |
| - if !remoteTokenOK(p, token) { |
| + if !drives { |
| a.notFound(w, r) |
| return |
| } |
| @@ -1696,9 +1748,14 @@ func (a *app) presentCommand(w http.ResponseWriter, r *http.Request) { |
| // `remote:<session>` says what actually authenticated, and the |
| // issuer rides beside it so the trail still reaches somebody |
| // answerable. |
| + // The presenter's own cookie names the presenter. |
| + actor := remoteActor(p) |
| + if presenter != "" { |
| + actor = presenter |
| + } |
| a.logger.Info("slides: presentation command", |
| "session", p.Sqid, "op", op, "slide", updated.Slide, |
| - "actor", remoteActor(p), "issuer", p.Actor) |
| + "actor", actor, "issuer", p.Actor) |
| // A browser form goes back to the page it came from — same-origin |
| // only, checked against the origin the app resolved, so this can |
diff --git a/internal/slides/presenting_position.go b/internal/slides/presenting_position.go| index 8ffbcd0..3c9a679 100644 |
| --- a/internal/slides/presenting_position.go |
| +++ b/internal/slides/presenting_position.go |
| @@ -68,23 +68,30 @@ type positionAnswer struct { |
| number int |
| } |
| -// mayDrive is who may move a Positional session: whoever holds the |
| -// remote token, or the presenter themselves, signed in (S19). The |
| -// cookie being enough is why the app-wide origin check (app.go's |
| -// csrf.Protect) matters here: another site cannot make the presenter's |
| -// browser press. |
| +// mayDrive is who may move a session: whoever holds the remote token, |
| +// or the presenter themselves, signed in and still admitted (S19; |
| +// admittedPresenter). The cookie being enough is why the app-wide origin |
| +// check (app.go's csrf.Protect) matters here: another site cannot make |
| +// the presenter's browser press. A session begun before positions is |
| +// driven the same way, by its index (presentCommand). |
| // |
| -// It answers for the row the request resolved. applyPress asks again, |
| -// of the row its transaction read (drivesRow), because the token can be |
| -// replaced in between. |
| -func (a *app) mayDrive(r *http.Request, p Presentation, token string) bool { |
| +// It answers for the row the request resolved, and says the actor it |
| +// let in by the cookie ("" when the token did it). applyPress asks |
| +// again, of the row its transaction read (drivesRow), because the token |
| +// can be replaced in between. answered is admittedPresenter's: the |
| +// request has been answered, and the caller writes nothing more. |
| +func (a *app) mayDrive(w http.ResponseWriter, r *http.Request, p Presentation, token string) (drives bool, actor string, answered bool) { |
| if remoteTokenOK(p, token) { |
| - return true |
| + return true, "", false |
| } |
| if p.Actor == "" { |
| - return false |
| + return false, "", false |
| } |
| - return a.presenterActor(r) == p.Actor |
| + actor, answered = a.admittedPresenter(w, r) |
| + if answered || actor != p.Actor { |
| + return false, "", answered |
| + } |
| + return true, actor, false |
| } |
| // errNotDriver is a press whose credential no longer drives the session |
| @@ -123,7 +130,11 @@ func withPressIDs(buttons []commandButton) []commandButton { |
| // presentPress is presentCommand for a Positional session. |
| func (a *app) presentPress(w http.ResponseWriter, r *http.Request, p Presentation) { |
| token := pressToken(r) |
| - if !a.mayDrive(r, p, token) { |
| + drives, actor, answered := a.mayDrive(w, r, p, token) |
| + if answered { |
| + return |
| + } |
| + if !drives { |
| a.notFound(w, r) |
| return |
| } |
| @@ -133,7 +144,7 @@ func (a *app) presentPress(w http.ResponseWriter, r *http.Request, p Presentatio |
| return |
| } |
| - answer, err := a.applyPress(r, p, cmd) |
| + answer, err := a.applyPress(r, p, cmd, actor) |
| switch { |
| case err == nil: |
| case errors.Is(err, errNotDriver): |
| @@ -152,8 +163,7 @@ func (a *app) presentPress(w http.ResponseWriter, r *http.Request, p Presentatio |
| // The actor is what authenticated, as presentCommand says: the |
| // remote's capability, or the presenter's own session. |
| - actor := p.Actor |
| - if remoteTokenOK(p, token) { |
| + if actor == "" { |
| actor = remoteActor(p) |
| } |
| a.logger.Info("slides: presentation press", |
| @@ -347,17 +357,13 @@ func pressCommandFrom(r *http.Request) (pressCommand, error) { |
| // |
| // The request's credential is checked again against the row the |
| // transaction read, before anything else: a token replaced after the |
| -// request was let in drives nothing (errNotDriver). |
| -func (a *app) applyPress(r *http.Request, p Presentation, cmd pressCommand) (positionAnswer, error) { |
| +// request was let in drives nothing (errNotDriver). actor is the |
| +// presenter mayDrive admitted by the cookie, or "": who is signed in |
| +// does not change with the row, only the token can. |
| +func (a *app) applyPress(r *http.Request, p Presentation, cmd pressCommand, actor string) (positionAnswer, error) { |
| ctx := r.Context() |
| now := time.Now().UTC() |
| token := pressToken(r) |
| - // Looked up before the transaction, on the read pool: who is |
| - // signed in does not change with the row, only the token can. |
| - actor := "" |
| - if p.Actor != "" { |
| - actor = a.presenterActor(r) |
| - } |
| var updated Presentation |
| var deckSeq int64 |
| moved := false |
diff --git a/internal/slides/presenting_position_test.go b/internal/slides/presenting_position_test.go| index 4971fe8..efb4f3d 100644 |
| --- a/internal/slides/presenting_position_test.go |
| +++ b/internal/slides/presenting_position_test.go |
| @@ -61,12 +61,12 @@ func TestATokenReplacedMidPressDrivesNothing(t *testing.T) { |
| // The same press path untouched works, so the refusal below is the |
| // replaced token and nothing else. |
| - if _, err := a.applyPress(pressRequestWith(token, "next"), p, pressCommand{Op: "next", Press: rand.Text()}); err != nil { |
| + if _, err := a.applyPress(pressRequestWith(token, "next"), p, pressCommand{Op: "next", Press: rand.Text()}, ""); err != nil { |
| t.Fatalf("a press with the paired token: %v", err) |
| } |
| r := pressRequestWith(token, "next") |
| - if !a.mayDrive(r, p, token) { |
| + if drives, _, _ := a.mayDrive(httptest.NewRecorder(), r, p, token); !drives { |
| t.Fatal("the paired token was not let in") |
| } |
| // Re-paired between the request being let in and its write. |
| @@ -74,7 +74,7 @@ func TestATokenReplacedMidPressDrivesNothing(t *testing.T) { |
| Update("remote_token_hash", hashRemoteToken("a-new-phone-token")).Error; err != nil { |
| t.Fatalf("re-pair: %v", err) |
| } |
| - _, err := a.applyPress(r, p, pressCommand{Op: "next", Press: rand.Text()}) |
| + _, err := a.applyPress(r, p, pressCommand{Op: "next", Press: rand.Text()}, "") |
| if !errors.Is(err, errNotDriver) { |
| t.Errorf("a press whose token was replaced mid-flight: err %v, want errNotDriver", err) |
| } |
diff --git a/internal/slides/presenting_talk.go b/internal/slides/presenting_talk.go| index 2bf9736..93799c2 100644 |
| --- a/internal/slides/presenting_talk.go |
| +++ b/internal/slides/presenting_talk.go |
| @@ -43,7 +43,10 @@ func (a *app) presentTalk(w http.ResponseWriter, r *http.Request) { |
| if !ok { |
| return |
| } |
| - withNotes := a.mayDrive(r, p, r.URL.Query().Get("t")) |
| + withNotes, _, answered := a.mayDrive(w, r, p, r.URL.Query().Get("t")) |
| + if answered { |
| + return |
| + } |
| // The tag is the deck's seq, and says whether notes are in the body: |
| // a body without them must not satisfy a request that may have them. |
diff --git a/internal/slides/static/present.js b/internal/slides/static/present.js| index 0d1272d..2ffb5c6 100644 |
| --- a/internal/slides/static/present.js |
| +++ b/internal/slides/static/present.js |
| @@ -8,8 +8,9 @@ |
| // |
| // It sends exactly what those forms send (op, t, slide and a press id, |
| // POSTed to /p/{session}/command), so there is one protocol rather than |
| -// two, and only on a page rendered for whoever holds the remote: the |
| -// token arrives as data-remote-token, and a page without one cannot send. |
| +// two, and only on a page rendered for whoever drives: the token arrives |
| +// as data-remote-token, the signed-in presenter's page says data-drives |
| +// (their cookie is the credential), and a page with neither cannot send. |
| // |
| // Every URL it reads comes down as an attribute (codex 5). The |
| // audience's follow view is served from a share link and stays there — |
| @@ -45,9 +46,13 @@ |
| return btoa(raw).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); |
| } |
| + // A page drives with the remote token, or, rendered for the |
| + // presenter signed in, by their cookie (data-drives) with none. |
| + var drives = !!token || root.hasAttribute('data-drives'); |
| function command(op, slide) { |
| - if (!token || !session) return; |
| - var body = new URLSearchParams({ op: op, t: token, press: pressID() }); |
| + if (!drives || !session) return; |
| + var body = new URLSearchParams({ op: op, press: pressID() }); |
| + if (token) body.set('t', token); |
| if (slide) body.set('slide', slide); |
| fetch('/p/' + session + '/command', { |
| method: 'POST', |
diff --git a/internal/slides/team_survivors_test.go b/internal/slides/team_survivors_test.go| index a789be5..5e973c5 100644 |
| --- a/internal/slides/team_survivors_test.go |
| +++ b/internal/slides/team_survivors_test.go |
| @@ -176,7 +176,7 @@ func TestTeamTheAllowlistDecidesNothingButLocalSignIn(t *testing.T) { |
| for _, c := range f.jar { |
| r.AddCookie(c) |
| } |
| - if got := f.a.presenterActor(r); got == "" { |
| + if got, _ := f.a.admittedPresenter(httptest.NewRecorder(), r); got == "" { |
| t.Fatal("an unlisted linked account is nobody to presentation.go") |
| } |
| if got := f.get("/p/" + session + "/notes"); got.Code != 200 { |
diff --git a/internal/slides/templates/present.html b/internal/slides/templates/present.html| index a14cf0e..674da98 100644 |
| --- a/internal/slides/templates/present.html |
| +++ b/internal/slides/templates/present.html |
| @@ -141,6 +141,7 @@ |
| data-blackout="{{if .Blackout}}true{{else}}false{{end}}" |
| {{- with .Announce}} data-announce="{{.}}"{{end}} |
| {{- if .Token}} data-remote-token="{{.Token}}"{{end}} |
| + {{- if .Drives}} data-drives{{end}} |
| {{- if .NotesHref}} data-notes="{{.NotesHref}}"{{end}} |
| {{- if .Bundle}} data-talk="{{.TalkHref}}" data-command="{{.Controls.Action}}" data-presenter="{{.PresenterHref}}" |
| data-text-progress="{{.ProgressWords}}" data-text-announce="{{.AnnounceWords}}" data-text-waiting="{{.WaitingWords}}"{{end}}> |
diff --git a/internal/slides/templates/present_notes.html b/internal/slides/templates/present_notes.html| index 96176f0..ffe62e2 100644 |
| --- a/internal/slides/templates/present_notes.html |
| +++ b/internal/slides/templates/present_notes.html |
| @@ -102,7 +102,8 @@ |
| data-slide="{{.Now}}" |
| {{- with .Mode}} data-mode="{{.}}"{{end}} |
| data-blackout="{{if .Blackout}}true{{else}}false{{end}}" |
| - {{- if .Token}} data-remote-token="{{.Token}}"{{end}}> |
| + {{- if .Token}} data-remote-token="{{.Token}}"{{end}} |
| + {{- if .Drives}} data-drives{{end}}> |
| <div> |
| <h2>{{.CurrentLabel}}</h2> |
| {{.Current}} |
diff --git a/internal/slidestest/present_admission_test.go b/internal/slidestest/present_admission_test.go| new file mode 100644 |
| index 0000000..dce9210 |
| --- /dev/null |
| +++ b/internal/slidestest/present_admission_test.go |
| @@ -0,0 +1,142 @@ |
| +package slidestest |
| + |
| +// Who may drive a talk by being signed in (spec §6 "Who may drive", |
| +// S19), and the admission that comes first: the presenter's cookie is |
| +// a capability on the /p/ routes, so it is put through the same check |
| +// every signed-in route makes (auth.go's currentUser). An address taken |
| +// off the list neither presses nor pairs, from the first request after |
| +// the restart. And a talk begun before positions, rejoined through |
| +// Present, is still the presenter's to drive. |
| + |
| +import ( |
| + "net/http" |
| + "net/url" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// removedPresenter is a talk under way on the old app, and the same |
| +// database restarted with the presenter's address off the list. |
| +func removedPresenter(t *testing.T) (after *testApp, session string, cookies []*http.Cookie) { |
| + t.Helper() |
| + cfg, mailer := newConfig(t) |
| + d := openTestDB(t, cfg) |
| + before := newAppOver(t, d, cfg, mailer) |
| + cookies = signedIn(t, before, allowedAddress) |
| + session, _ = startPresenting(t, before, stepsDeck(t, before, cookies), cookies) |
| + // The cookie drives while the address is on the list. |
| + press(t, before, session, "", op(t, "next"), cookies) |
| + |
| + gone, _ := newConfig(t) |
| + gone.AllowedAddresses = []string{"someone.else@example.test"} |
| + return newAppOver(t, d, gone, mailer), session, cookies |
| +} |
| + |
| +// remoteHash is the stored hash of the session's remote token. |
| +func remoteHash(t *testing.T, a *testApp, session string) string { |
| + t.Helper() |
| + var h string |
| + if err := a.db.G.Raw("SELECT COALESCE(remote_token_hash, '') FROM presentations WHERE sqid = ?", session).Row().Scan(&h); err != nil { |
| + t.Fatalf("read the remote token of %s: %v", session, err) |
| + } |
| + return h |
| +} |
| + |
| +// TestARemovedPresenterNeitherPressesNorPairs: right after the address |
| +// comes off the list, the presenter's cookie is refused as every |
| +// signed-in route refuses it (403 for a POST, and the talk ended), and |
| +// nothing moves: no press, no fresh token. |
| +func TestARemovedPresenterNeitherPressesNorPairs(t *testing.T) { |
| + t.Run("a press", func(t *testing.T) { |
| + a, session, cookies := removedPresenter(t) |
| + _, stepBefore, seqBefore := rowPosition(t, a, session) |
| + rec := pressRequest(t, a, session, "", op(t, "next"), cookies) |
| + if rec.Code != http.StatusForbidden { |
| + t.Errorf("a press by a removed presenter: status %d, want 403\n%s", rec.Code, rec.Body) |
| + } |
| + if _, step, seq := rowPosition(t, a, session); step != stepBefore || seq != seqBefore { |
| + t.Errorf("a removed presenter's press moved the talk: step %d seq %d, was step %d seq %d", step, seq, stepBefore, seqBefore) |
| + } |
| + if rec := get(t, a, "/p/"+session); rec.Code != http.StatusGone { |
| + t.Errorf("the removed presenter's talk: status %d, want 410", rec.Code) |
| + } |
| + }) |
| + t.Run("pairing", func(t *testing.T) { |
| + a, session, cookies := removedPresenter(t) |
| + before := remoteHash(t, a, session) |
| + rec := post(t, a, "/p/"+session+"/pair", nil, cookies...) |
| + if rec.Code != http.StatusForbidden { |
| + t.Errorf("pairing by a removed presenter: status %d, want 403\n%s", rec.Code, rec.Body) |
| + } |
| + if strings.Contains(rec.Body.String(), "/r/") { |
| + t.Errorf("a removed presenter was shown a remote address:\n%s", rec.Body) |
| + } |
| + if after := remoteHash(t, a, session); after != before { |
| + t.Error("a removed presenter's pairing replaced the remote token") |
| + } |
| + }) |
| + t.Run("the window", func(t *testing.T) { |
| + a, session, cookies := removedPresenter(t) |
| + rec := get(t, a, "/p/"+session+"/notes", cookies...) |
| + if rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/signin?err=removed" { |
| + t.Errorf("a removed presenter's window: status %d to %q, want 303 to /signin?err=removed", rec.Code, rec.Header().Get("Location")) |
| + } |
| + }) |
| +} |
| + |
| +// TestRejoiningAPreDeployTalkKeepsItsControls: a talk begun before |
| +// positions, rejoined through Present, is driven by the signed-in |
| +// presenter from the slide window and the presenter view, by their |
| +// cookie, by its index; the phone already paired still drives too, and |
| +// the row stays an index row. Somebody else signed in only watches. |
| +func TestRejoiningAPreDeployTalkKeepsItsControls(t *testing.T) { |
| + a := newSharedApp(t) |
| + cookies := signedIn(t, a, allowedAddress) |
| + path := sampleDeck(t, a, cookies) |
| + session, token := startPresenting(t, a, path, cookies) |
| + preDeploy(t, a, session) |
| + |
| + // Present again, as the presenter does after a deploy. |
| + rec := post(t, a, path+"/present", nil, cookies...) |
| + if rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/p/"+session { |
| + t.Fatalf("Present on a pre-deploy talk: status %d to %q, want 303 to /p/%s", rec.Code, rec.Header().Get("Location"), session) |
| + } |
| + |
| + surface := mustGet(t, a, "/p/"+session, http.StatusOK, cookies).Body.String() |
| + if !strings.Contains(surface, `action="/p/`+session+`/command"`) || !strings.Contains(surface, `slides-op="next"`) { |
| + t.Fatalf("the rejoined slide window has no controls for its presenter:\n%s", surface) |
| + } |
| + if !strings.Contains(surface, "data-drives") { |
| + t.Error("the rejoined slide window does not tell its script that it drives") |
| + } |
| + notes := mustGet(t, a, "/p/"+session+"/notes", http.StatusOK, cookies).Body.String() |
| + if !strings.Contains(notes, "slides-commands") || !strings.Contains(notes, `slides-op="next"`) { |
| + t.Fatalf("the rejoined presenter view has no controls for its presenter:\n%s", notes) |
| + } |
| + |
| + // The forms post as they are rendered: no token, the cookie. |
| + form := url.Values{"op": {"next"}, "press": {newPressID(t)}} |
| + if rec := post(t, a, "/p/"+session+"/command", form, cookies...); rec.Code != http.StatusNoContent { |
| + t.Fatalf("the presenter's next on a pre-deploy talk: status %d, want 204\n%s", rec.Code, rec.Body) |
| + } |
| + if rec := command(t, a, session, "next", token, "", nil); rec.Code != http.StatusNoContent { |
| + t.Fatalf("the paired phone's next: status %d, want 204", rec.Code) |
| + } |
| + var index int |
| + var positional *bool |
| + if err := a.db.G.Raw("SELECT slide, positional FROM presentations WHERE sqid = ?", session).Row().Scan(&index, &positional); err != nil { |
| + t.Fatalf("read the session: %v", err) |
| + } |
| + if index != 2 || positional != nil { |
| + t.Errorf("after two nexts the row is at index %d, positional %v; want index 2 and no position", index, positional) |
| + } |
| + |
| + // Somebody else signed in watches and drives nothing. |
| + theirs := signedIn(t, a, otherAddress) |
| + if page := mustGet(t, a, "/p/"+session, http.StatusOK, theirs).Body.String(); strings.Contains(page, `slides-op="next"`) { |
| + t.Error("somebody else signed in is given the controls") |
| + } |
| + if rec := post(t, a, "/p/"+session+"/command", url.Values{"op": {"next"}, "press": {newPressID(t)}}, theirs...); rec.Code != http.StatusNotFound { |
| + t.Errorf("somebody else's next: status %d, want 404", rec.Code) |
| + } |
| +} |
diff --git a/internal/slidestest/present_position_test.go b/internal/slidestest/present_position_test.go| index 4803bb9..955705b 100644 |
| --- a/internal/slidestest/present_position_test.go |
| +++ b/internal/slidestest/present_position_test.go |
| @@ -517,10 +517,14 @@ func TestASessionFromBeforeTheDeployKeepsItsIndex(t *testing.T) { |
| t.Errorf("%s on a pre-deploy session: status %d, want 422", name, rec.Code) |
| } |
| } |
| - // The presenter's cookie is not a capability there either: it is |
| - // today's path, and today the token is the whole permission. |
| - if rec := pressRequest(t, a, session, "", op(t, "next"), cookies); rec.Code != http.StatusNotFound { |
| - t.Errorf("a tokenless press on a pre-deploy session: status %d, want 404", rec.Code) |
| + // The presenter's cookie drives it too, by its index: Present |
| + // again rejoins it without a token (S19), and a talk the presenter |
| + // can no longer drive would be no talk at all. |
| + if rec := pressRequest(t, a, session, "", op(t, "prev"), cookies); rec.Code != http.StatusNoContent { |
| + t.Errorf("the presenter's tokenless press on a pre-deploy session: status %d, want 204", rec.Code) |
| + } |
| + if surface := mustGet(t, a, "/p/"+session, http.StatusOK, nil).Body.String(); !strings.Contains(surface, "3 / 8") { |
| + t.Errorf("the presenter's prev from index 3 does not show slide 3:\n%s", surface) |
| } |
| } |