oficina / docs Public

WIP: stale-link and Guard standing tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev b25f7bade42e382f2f527447c903d70f05ccd5f3 parent 992a428
2 files changed, +51 −0
  • internal/docs/home_links_move_test.go +18 −0
  • internal/docs/team_access_test.go +33 −0
diff --git a/internal/docs/home_links_move_test.go b/internal/docs/home_links_move_test.go
index e75c969..e0f0270 100644
--- a/internal/docs/home_links_move_test.go
+++ b/internal/docs/home_links_move_test.go
@@ -609,4 +609,22 @@ func TestTeamStandingNeedsALinkConnectResolves(t *testing.T) {
if _, err := f.app.store.team.home.bridge.Resolve(t.Context(), teamSubject('a')); !errors.Is(err, connectlinks.ErrRefused) {
t.Fatal("fixture: connect resolved the stale link", err)
}
+ // Nor does a Home session for that subject sign in as Alice.
+ token, err := f.sessions.Mint(sessions.Session{Subject: teamSubject('a'), Method: "home-assertion", AuthTime: time.Now()})
+ if err != nil {
+ t.Fatal(err)
+ }
+ home := f.browser()
+ home.cookies[f.sessions.CookieName()] = &http.Cookie{Name: f.sessions.CookieName(), Value: token}
+ if page := home.do("GET", "/", ""); page.Code == 200 {
+ t.Fatal("a Home session signed in through a link connect refuses")
+ }
+ // The control: a link connect made does give standing.
+ other := f.browser()
+ other.localSignin(t, "bob@example.com")
+ other.linkProof(t, teamSubject('b'), "bob@example.com")
+ routerRedirect(t, other.do("POST", "/account/home/confirm", ""), connectedURL("/"))
+ if page := other.do("POST", "/documents", "title=Team+rung"); page.Code != 303 {
+ t.Fatal("a link connect made gave no team standing", page.Code)
+ }
}
diff --git a/internal/docs/team_access_test.go b/internal/docs/team_access_test.go
index 7b9b49c..72729c5 100644
--- a/internal/docs/team_access_test.go
+++ b/internal/docs/team_access_test.go
@@ -18,6 +18,7 @@ import (
"gorm.io/gorm"
"io"
"net/http"
+ "net/http/httptest"
"strings"
"sync"
"testing"
@@ -488,3 +489,35 @@ func TestTeamPermissionContentionCannotRecoverIntoPermanentDenial(t *testing.T)
t.Fatal("uncertainty leaked into a new request")
}
}
+
+// Admission carries the request's Access to teammode as well as to Docs'
+// own key, so Guard, inside ownerMutation's transaction, is handed the
+// real latched standing rather than Unknown.
+func TestTeamAdmissionCarriesTheAccessToGuard(t *testing.T) {
+ app := newSampleDocumentsInternalTestApp(t, "0")
+ s := app.Store()
+ person, e := s.EnsurePerson(t.Context(), "member@example.com")
+ if e != nil {
+ t.Fatal(e)
+ }
+ rt, _, subject := testTeamRoster(t, s, app)
+ id := requestIdentity{Actor: localActor(person, "member@example.com"), HomeSubject: subject}
+ r := httptest.NewRequest("GET", "https://docs.example/", nil)
+ r = r.WithContext(context.WithValue(r.Context(), identityContextKey{}, id))
+ reached := false
+ rt.admission(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ reached = true
+ a, ok := r.Context().Value(accessContextKey{}).(*requestAccess)
+ carried, found := teammode.FromContext(r.Context())
+ if !ok || !found || carried != a.Access || teammode.Standing(r.Context()) != roster.Member {
+ t.Fatal("Guard would not see the request's standing", teammode.Standing(r.Context()))
+ }
+ var standing roster.State
+ if e := teammode.Guard(r.Context(), func(st roster.State) error { standing = st; return nil }, func() error { return nil }); e != nil || standing != roster.Member {
+ t.Fatal("Guard was handed", standing, e)
+ }
+ })).ServeHTTP(httptest.NewRecorder(), r)
+ if !reached {
+ t.Fatal("admission refused a member")
+ }
+}