oficina / meet Public

Guard Calls responses with current membership and exact invitation authority

codex agent, operated by paul@keymail.dev pushed by paul@keymail.dev a91e4d00c03243c8872e5fa612d23d92f5dbfb5d parent 87acaae
13 files changed, +358 −9
  • docs/superpowers/specs/2026-10-25-agent-response-authorization.md +13 −0
  • go.mod +1 −1
  • go.sum +2 −0
  • internal/calls/delegated.go +13 −2
  • internal/calls/delegated_authority.go +2 −1
  • internal/calls/delegated_authority_test.go +1 −1
  • internal/calls/delegated_boundaries_test.go +2 −2
  • internal/calls/delegated_create.go +1 −0
  • internal/calls/delegated_read.go +5 −0
  • internal/calls/delegated_recorder_test.go +12 −0
  • internal/calls/delegated_response.go +70 −0
  • internal/calls/delegated_response_test.go +234 −0
  • internal/calls/delegated_test.go +2 −2

CI passed — run details

diff --git a/docs/superpowers/specs/2026-10-25-agent-response-authorization.md b/docs/superpowers/specs/2026-10-25-agent-response-authorization.md
new file mode 100644
index 0000000..2b0364f
--- /dev/null
+++ b/docs/superpowers/specs/2026-10-25-agent-response-authorization.md
@@ -0,0 +1,13 @@
+# Guarded app HTTP responses
+
+Status: bounded design approved by GPT-6 Astra with the explicit continuity and fail-closed requirements below; implementation/evidence review pending. Follow-up to close the legacy adapters' response-emission gap. Docs, Sheets and Slides already have app-owned guarded emission; Calendar, Calls and Memoria still use direct Registry.HTTP output.
+
+Add a separate Registry.HTTPGuarded(initial Verifier, recheck Verifier, guard ResponseGuard) entry point. Existing HTTP behavior stays for the connection gateway and compatibility. A nonnil app guard is mandatory. Initial verification may include local admission and one rate-limit charge. Rechecks use the original underlying credential verifier, never the rate-limiting wrapper. Preserve the exact bearer and Subject/Client/Grant; require the original operation's scope and input team on each check. Discovery must retain the originally disclosed team/scope set (revoked facts cannot be emitted). Registry.Call and schemas remain the single invocation path, executed exactly once.
+
+Before serializing success, bound it to MaxPayload. The app callback receives the request context, original principal, operation name, input and result, and revalidates current local identity plus permissions for every returned resource. It must not execute a write, refresh a token or replay the operation. Call original-verifier plus app guard immediately before headers and each at-most-64-KiB write with a five-second context/write deadline (shortened to caller deadline). Fail safely before headers; abort partial HTTP bodies with ErrAbortHandler and exact Content-Length. Do not silently tolerate a transport without write-deadline support. Failure bodies contain no app result. Check the elapsed context deadline after every verifier and guard callback, including callbacks that return nil.
+
+Adapter state is per request, captured before domain execution, and retains stable local person ID/address plus the returned resource set. Calendar rechecks current calendar readability and archive state; event reads/creation capture the event and calendar IDs, then re-read the live event and reject deletion or any change to its captured calendar coordinate, and free/busy must carry calendar provenance from the same range expansion that produced its spans. Calls rechecks local membership and meeting existence; invitation responses additionally require the exact originally returned invitation to remain live and its meeting unended. Memoria checks current Home/local admission, exact live chunk/document pairs, and current sibling custody for the returned revisions. Sibling checks use the existing custody interface without replaying search or recording duplicate breaker statistics. Locally owned created notes require the same current document/receipt identity. Missing or incomplete resource provenance fails closed. Memoria freezes the original sibling item/revision coordinates; current coordinates must still match, and every original candidate must receive an explicit VISIBLE/renderable custody disposition. Missing, short, or non-renderable dispositions fail closed. Never filter a selected response midway through emission. No second model call and no repeated mutation.
+
+Tests use actual HTTP transport to prove revocation/permission loss after the first chunk truncates the body, plus preheader rejection, successful-principal continuity, metadata revocation, deadline failure/timeout, single domain invocation, and one Calls rate charge. App tests distinguish loss of local identity, item permission, invitation revocation, missing/stale chunks and changed sibling visibility. Writer-boundary regression tests must remain discriminating now that a later response guard could mask a missing transaction guard. Effective mutants omit preheader versus chunk checks independently and each app's resource guard. Run full shared and affected app CI/race checks, independent source/evidence review, then exact module pins.
+
+Consumer pins shared module 4b94ff9. Design approval: GPT-6 Astra. App implementation/evidence review is recorded in the existing agent-access branch discussion. Source and tests are additive to the already reviewed create/retry authority boundary; direct completed-retry tests prevent later HTTP checks masking missing transaction checks.
diff --git a/go.mod b/go.mod
index aeab612..631f46f 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module amadan.net/oficina/calls
go 1.26.0
require (
- amadan.net/oficina/agent-access.git v0.0.0-20261024232549-8ed8ba826000
+ amadan.net/oficina/agent-access.git v0.0.0-20261025011012-4b94ff9e8a8d
amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768
amadan.net/oficina/home/connect v0.0.0-20261025004522-7430dd23a847
amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489
diff --git a/go.sum b/go.sum
index 0749a50..1b34f5b 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,7 @@
amadan.net/oficina/agent-access.git v0.0.0-20261024232549-8ed8ba826000 h1:L07nc+dmLI7c1PBkSkbnrjOK5f8p6OBbA/yTxznxCAw=
amadan.net/oficina/agent-access.git v0.0.0-20261024232549-8ed8ba826000/go.mod h1:Ph9PIa3VE1IEaUzZiQH6D+IQ6HThWWGfVr0ecMMgrFA=
+amadan.net/oficina/agent-access.git v0.0.0-20261025011012-4b94ff9e8a8d h1:bSsf1NXVhXTfLLB9J7a5v9CqzdKj8CALHZ6W3H7A/4M=
+amadan.net/oficina/agent-access.git v0.0.0-20261025011012-4b94ff9e8a8d/go.mod h1:Ph9PIa3VE1IEaUzZiQH6D+IQ6HThWWGfVr0ecMMgrFA=
amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768 h1:bVscoa9fH5LdLDjlyecZhrX7JzWPT0blb57MH0FIm2U=
amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw=
amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c h1:3yxO2D8BxDLMGfFV2o6Sp9Z91yLnjDCIuRKHVWORa8A=
diff --git a/internal/calls/delegated.go b/internal/calls/delegated.go
index 0951a75..14c7299 100644
--- a/internal/calls/delegated.go
+++ b/internal/calls/delegated.go
@@ -56,7 +56,7 @@ func (a *app) mountDelegated(v access.Verifier, issuer, team string) error {
if err != nil {
return err
}
- a.delegated = a.delegatedBoundary(v, reg.HTTP(access.VerifyFunc(func(ctx context.Context, token string) (access.Principal, error) {
+ a.delegated = a.delegatedBoundary(v, reg.HTTPGuarded(access.VerifyFunc(func(ctx context.Context, token string) (access.Principal, error) {
p, err := v.Verify(ctx, token)
if err != nil {
return access.Principal{}, err
@@ -73,7 +73,7 @@ func (a *app) mountDelegated(v access.Verifier, issuer, team string) error {
return access.Principal{}, access.Fail("rate_limited", "Calls request limit reached. Try again later.")
}
return p, nil
- })))
+ }), v, a.delegatedResponse))
return nil
}
func (a *app) delegatedPerson(ctx context.Context, p access.Principal, team string) (Person, error) {
@@ -98,6 +98,12 @@ func (a *app) delegatedPerson(ctx context.Context, p access.Principal, team stri
if !ok || person.Email != linked.Label || !a.isMember(person) {
return Person{}, access.Fail("forbidden", "This account cannot access Calls.")
}
+ if state, ok := ctx.Value(delegatedResponseKey{}).(*delegatedResponseState); ok {
+ if state.person.ID != 0 && (state.person.ID != person.ID || state.person.Email != person.Email) {
+ return Person{}, access.Fail("forbidden", "The linked identity changed.")
+ }
+ state.person = person
+ }
return person, nil
}
func delegatedFailure(err error) error {
@@ -126,6 +132,11 @@ func (a *app) delegatedGuard(team, scope string, fn func(context.Context, access
return nil, err
}
out, err := fn(ctx, p, person, raw)
+ if err == nil {
+ if state, ok := ctx.Value(delegatedResponseKey{}).(*delegatedResponseState); ok {
+ state.selected = true
+ }
+ }
return out, delegatedFailure(err)
}
}
diff --git a/internal/calls/delegated_authority.go b/internal/calls/delegated_authority.go
index e4f2966..33c78e3 100644
--- a/internal/calls/delegated_authority.go
+++ b/internal/calls/delegated_authority.go
@@ -33,7 +33,8 @@ func (a *app) delegatedBoundary(verifier access.Verifier, next http.Handler) htt
}
return nil
})
- next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), delegatedBoundaryKey{}, check)))
+ ctx := context.WithValue(r.Context(), delegatedResponseKey{}, &delegatedResponseState{})
+ next.ServeHTTP(w, r.WithContext(context.WithValue(ctx, delegatedBoundaryKey{}, check)))
})
}
func (a *app) bindDelegated(tx *gorm.DB) error {
diff --git a/internal/calls/delegated_authority_test.go b/internal/calls/delegated_authority_test.go
index e334380..9e48a2a 100644
--- a/internal/calls/delegated_authority_test.go
+++ b/internal/calls/delegated_authority_test.go
@@ -145,7 +145,7 @@ func TestDelegatedRejectsMalformedUnicode(t *testing.T) {
r.Header.Set("Content-Type", "application/json")
r.Header.Set("Authorization", "Bearer fixture")
w := httptest.NewRecorder()
- f.app.delegated.ServeHTTP(w, r)
+ f.app.delegated.ServeHTTP(responseRecorder{w}, r)
if w.Code != 422 {
t.Fatal("malformed meeting Unicode", w.Code)
}
diff --git a/internal/calls/delegated_boundaries_test.go b/internal/calls/delegated_boundaries_test.go
index 7637177..986e75a 100644
--- a/internal/calls/delegated_boundaries_test.go
+++ b/internal/calls/delegated_boundaries_test.go
@@ -85,14 +85,14 @@ func TestDelegatedProductionRoutesStayOutsideBrowserAndLegacyAuth(t *testing.T)
}
r := httptest.NewRequest(method, homeTestOrigin+path, strings.NewReader(`{}`))
w := httptest.NewRecorder()
- mux.ServeHTTP(w, r)
+ mux.ServeHTTP(responseRecorder{w}, r)
if w.Code != 401 || !strings.Contains(w.Body.String(), `"code":"unauthenticated"`) {
t.Fatal("delegated route intercepted", w.Code, w.Body.String())
}
}
r := httptest.NewRequest("GET", homeTestOrigin+"/api/v1/meetings", nil)
w := httptest.NewRecorder()
- mux.ServeHTTP(w, r)
+ mux.ServeHTTP(responseRecorder{w}, r)
if w.Code != 401 || !strings.Contains(w.Body.String(), `"error":"unauthorized"`) {
t.Fatal("legacy route changed", w.Code, w.Body.String())
}
diff --git a/internal/calls/delegated_create.go b/internal/calls/delegated_create.go
index 364ed3e..d1a740f 100644
--- a/internal/calls/delegated_create.go
+++ b/internal/calls/delegated_create.go
@@ -105,6 +105,7 @@ func (a *app) delegatedCreate(ctx context.Context, p access.Principal, person Pe
if err != nil {
return nil, err
}
+ captureDelegatedMeeting(ctx, meeting)
return map[string]any{"sqid": meeting.Sqid, "url": a.cfg.Origin + "/m/" + meeting.Sqid, "invitations_sent": false}, nil
}
func (s *store) delegatedActor(ctx context.Context, p access.Principal, homeIssuer, issuer, team string, operator Person) (string, error) {
diff --git a/internal/calls/delegated_read.go b/internal/calls/delegated_read.go
index 14f8d13..61eecd2 100644
--- a/internal/calls/delegated_read.go
+++ b/internal/calls/delegated_read.go
@@ -46,6 +46,7 @@ func (a *app) delegatedMeeting(ctx context.Context, m Meeting) (any, error) {
if err != nil {
return nil, err
}
+ captureDelegatedMeeting(ctx, m)
return map[string]any{"sqid": m.Sqid, "title": title, "starts_at": apiTime(m.StartsAt), "ended_at": apiTime(m.EndedAt), "created_by": a.store.creatorLabel(ctx, m.CreatedBy), "url": a.cfg.Origin + "/m/" + m.Sqid}, nil
}
func (a *app) delegatedLookup(ctx context.Context, raw json.RawMessage) (Meeting, error) {
@@ -91,6 +92,10 @@ func (a *app) delegatedJoinLink(ctx context.Context, _ access.Principal, _ Perso
if err != nil {
return nil, err
}
+ captureDelegatedMeeting(ctx, m)
+ if state, ok := ctx.Value(delegatedResponseKey{}).(*delegatedResponseState); ok {
+ state.invitation = &link
+ }
return map[string]any{"sqid": m.Sqid, "join_url": a.linkURL(token)}, nil
}
diff --git a/internal/calls/delegated_recorder_test.go b/internal/calls/delegated_recorder_test.go
new file mode 100644
index 0000000..b7e6c32
--- /dev/null
+++ b/internal/calls/delegated_recorder_test.go
@@ -0,0 +1,12 @@
+package calls
+
+import (
+ "net/http/httptest"
+ "time"
+)
+
+// Unit request fixtures use an in-memory transport. Real HTTP deadline and
+// truncation behavior is exercised separately.
+type responseRecorder struct{ *httptest.ResponseRecorder }
+
+func (responseRecorder) SetWriteDeadline(time.Time) error { return nil }
diff --git a/internal/calls/delegated_response.go b/internal/calls/delegated_response.go
new file mode 100644
index 0000000..130cd93
--- /dev/null
+++ b/internal/calls/delegated_response.go
@@ -0,0 +1,70 @@
+package calls
+
+import (
+ access "amadan.net/oficina/agent-access.git"
+ "bytes"
+ "context"
+ "encoding/json"
+ "errors"
+ "gorm.io/gorm"
+)
+
+type delegatedResponseKey struct{}
+type delegatedResponseState struct {
+ person Person
+ selected bool
+ meetings []Meeting
+ invitation *MeetingLink
+}
+
+func captureDelegatedMeeting(ctx context.Context, m Meeting) {
+ if s, ok := ctx.Value(delegatedResponseKey{}).(*delegatedResponseState); ok {
+ s.meetings = append(s.meetings, m)
+ }
+}
+func (a *app) delegatedResponse(ctx context.Context, p access.Principal, name string, _ json.RawMessage, result any) error {
+ s, ok := ctx.Value(delegatedResponseKey{}).(*delegatedResponseState)
+ if !ok || s.person.ID == 0 || name != "" && !s.selected {
+ return access.Fail("forbidden", "Response authority is unavailable.")
+ }
+ if name != "" {
+ value, ok := result.(map[string]any)
+ if !ok {
+ return access.Fail("forbidden", "Meeting provenance is unavailable.")
+ }
+ if name == "calls_list_meetings" {
+ rows, ok := value["meetings"].([]any)
+ if !ok || len(rows) != len(s.meetings) {
+ return access.Fail("forbidden", "Meeting provenance is unavailable.")
+ }
+ } else if len(s.meetings) != 1 {
+ return access.Fail("forbidden", "Meeting provenance is unavailable.")
+ }
+ }
+ if _, err := a.delegatedPerson(ctx, p, a.agentTeam); err != nil {
+ return err
+ }
+ for _, selected := range s.meetings {
+ m, ok, err := a.store.meetingBySqid(ctx, selected.Sqid)
+ if err != nil {
+ return delegatedFailure(err)
+ }
+ if !ok || m.ID != selected.ID {
+ return access.Fail("not_found", "This meeting is unavailable.")
+ }
+ }
+ if name == "calls_get_join_link" && s.invitation == nil {
+ return access.Fail("forbidden", "Invitation authority is unavailable.")
+ }
+ if selected := s.invitation; selected != nil {
+ var link MeetingLink
+ err := a.store.g.WithContext(ctx).Table("meeting_links").Select("meeting_links.*").Joins("JOIN meetings ON meetings.id=meeting_links.meeting_id").Where("meeting_links.id=? AND meeting_links.meeting_id=? AND meeting_links.revoked_at IS NULL AND meetings.ended_at IS NULL", selected.ID, selected.MeetingID).Take(&link).Error
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return delegatedFailure(err)
+ }
+ if err != nil || !bytes.Equal(link.TokenSealed, selected.TokenSealed) {
+ return access.Fail("not_found", "This invitation is unavailable.")
+ }
+ }
+ return nil
+}
diff --git a/internal/calls/delegated_response_test.go b/internal/calls/delegated_response_test.go
new file mode 100644
index 0000000..dd828ab
--- /dev/null
+++ b/internal/calls/delegated_response_test.go
@@ -0,0 +1,234 @@
+package calls
+
+import (
+ access "amadan.net/oficina/agent-access.git"
+ "amadan.net/oficina/calls/internal/calls/seal"
+ "bytes"
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "sync/atomic"
+ "testing"
+ "time"
+)
+
+type delegatedStreamWriter struct {
+ http.ResponseWriter
+ after func()
+}
+
+func (w delegatedStreamWriter) Unwrap() http.ResponseWriter { return w.ResponseWriter }
+func (w delegatedStreamWriter) Write(b []byte) (int, error) {
+ n, e := w.ResponseWriter.Write(b)
+ w.after()
+ return n, e
+}
+func delegatedLiveCall(t *testing.T, h http.Handler, name string, input any) (int, []byte, error) {
+ t.Helper()
+ server := httptest.NewServer(h)
+ defer server.Close()
+ raw, _ := json.Marshal(input)
+ req, _ := http.NewRequest("POST", server.URL+"/api/v1/operations/"+name, bytes.NewReader(raw))
+ req.Header.Set("Authorization", "Bearer fixture")
+ req.Header.Set("Content-Type", "application/json")
+ resp, e := server.Client().Do(req)
+ if e != nil {
+ t.Fatal(e)
+ }
+ defer resp.Body.Close()
+ body, e := io.ReadAll(resp.Body)
+ return resp.StatusCode, body, e
+}
+func TestDelegatedResponseExactInvitation(t *testing.T) {
+ for _, kind := range []string{"revoked-with-another-live", "ended", "ciphertext", "unlink", "deleted"} {
+ t.Run(kind, func(t *testing.T) {
+ f, p := linkedDelegated(t)
+ w := delegatedCall(f.app, "calls_create_meeting", delegatedInputForTest())
+ if w.Code != 200 {
+ t.Fatal(w.Code, w.Body.String())
+ }
+ var created struct{ Sqid string }
+ json.Unmarshal(w.Body.Bytes(), &created)
+ var selected MeetingLink
+ if e := f.app.db.G.Order("id DESC").First(&selected).Error; e != nil {
+ t.Fatal(e)
+ }
+ var checks atomic.Int32
+ v := access.VerifyFunc(func(context.Context, string) (access.Principal, error) {
+ if checks.Add(1) == 2 {
+ var e error
+ switch kind {
+ case "revoked-with-another-live":
+ e = f.app.db.G.Exec("UPDATE meeting_links SET revoked_at=? WHERE id=?", time.Now(), selected.ID).Error
+ replacement := selected
+ replacement.ID = 0
+ replacement.TokenHash = "different-live-link"
+ if e == nil {
+ e = f.app.db.G.Create(&replacement).Error
+ }
+ case "ended":
+ e = f.app.db.G.Exec("UPDATE meetings SET ended_at=? WHERE id=?", time.Now(), selected.MeetingID).Error
+ case "ciphertext":
+ sealed, err := f.app.sealer.SealString(seal.PurposeMeetingLink, "new-token")
+ if err != nil {
+ return access.Principal{}, err
+ }
+ e = f.app.db.G.Exec("UPDATE meeting_links SET token_sealed=? WHERE id=?", sealed, selected.ID).Error
+ case "unlink":
+ e = f.app.db.G.Exec("DELETE FROM home_identity_links").Error
+ case "deleted":
+ e = f.app.db.G.Exec("DELETE FROM meeting_links WHERE id=?", selected.ID).Error
+ }
+ if e != nil {
+ return access.Principal{}, e
+ }
+ }
+ return *p, nil
+ })
+ if e := f.app.mountDelegated(v, f.app.agentIssuer, "acme"); e != nil {
+ t.Fatal(e)
+ }
+ status, body, e := delegatedLiveCall(t, f.app.delegated, "calls_get_join_link", map[string]any{"team": "acme", "sqid": created.Sqid})
+ if e != nil || status != 403 && status != 404 || strings.Contains(string(body), "join_url") {
+ t.Fatalf("%d %s %v", status, body, e)
+ }
+ })
+ }
+}
+func TestDelegatedResponseStreamRechecksMembership(t *testing.T) {
+ f, _ := linkedDelegated(t)
+ w := delegatedCall(f.app, "calls_create_meeting", delegatedInputForTest())
+ if w.Code != 200 {
+ t.Fatal(w.Code, w.Body.String())
+ }
+ var m Meeting
+ if e := f.app.db.G.First(&m).Error; e != nil {
+ t.Fatal(e)
+ }
+ title, e := f.app.sealer.SealString(seal.PurposeMeetingTitle, strings.Repeat("🗓", 200))
+ if e != nil {
+ t.Fatal(e)
+ }
+ for i := 0; i < 100; i++ {
+ clone := m
+ clone.ID = 0
+ clone.Sqid = fmt.Sprintf("%010d", i+1)
+ clone.TitleSealed = title
+ if e := f.app.db.G.Create(&clone).Error; e != nil {
+ t.Fatal(e)
+ }
+ }
+ var writes atomic.Int32
+ h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ f.app.delegated.ServeHTTP(delegatedStreamWriter{w, func() {
+ if writes.Add(1) == 1 {
+ if e := f.app.db.G.Exec("DELETE FROM home_identity_links").Error; e != nil {
+ t.Error(e)
+ }
+ }
+ }}, r)
+ })
+ status, body, e := delegatedLiveCall(t, h, "calls_list_meetings", map[string]any{"team": "acme", "limit": 100})
+ if status != 200 || e == nil || len(body) != 64<<10 {
+ t.Fatalf("%d %d %v", status, len(body), e)
+ }
+}
+
+func TestDelegatedRetryFinalGuardWithoutResponseMask(t *testing.T) {
+ f, p := linkedDelegated(t)
+ input := delegatedInputForTest()
+ if w := delegatedCall(f.app, "calls_create_meeting", input); w.Code != 200 {
+ t.Fatal(w.Code)
+ }
+ person, err := f.app.delegatedPerson(t.Context(), *p, "acme")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var checks int
+ ctx := context.WithValue(t.Context(), delegatedBoundaryKey{}, delegatedRecheck(func(context.Context, access.Principal) error {
+ checks++
+ if checks == 2 {
+ return access.Fail("unauthenticated", "Revoked.")
+ }
+ return nil
+ }))
+ raw, _ := json.Marshal(input)
+ _, err = f.app.delegatedCreate(ctx, *p, person, raw)
+ if err == nil || access.SafeFailure(err).Code != "unauthenticated" || checks != 2 {
+ t.Fatalf("retry final guard: %v checks=%d", err, checks)
+ }
+}
+
+func TestDelegatedDiscoveryRechecksLocalIdentity(t *testing.T) {
+ for _, path := range []string{"connection", "operations"} {
+ t.Run(path, func(t *testing.T) {
+ f, p := linkedDelegated(t)
+ var checks atomic.Int32
+ v := access.VerifyFunc(func(context.Context, string) (access.Principal, error) {
+ if checks.Add(1) == 2 {
+ if err := f.app.db.G.Exec("DELETE FROM home_identity_links").Error; err != nil {
+ return access.Principal{}, err
+ }
+ }
+ return *p, nil
+ })
+ if err := f.app.mountDelegated(v, f.app.agentIssuer, "acme"); err != nil {
+ t.Fatal(err)
+ }
+ server := httptest.NewServer(f.app.delegated)
+ defer server.Close()
+ req, _ := http.NewRequest("GET", server.URL+"/api/v1/"+path, nil)
+ req.Header.Set("Authorization", "Bearer fixture")
+ resp, err := server.Client().Do(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer resp.Body.Close()
+ body, _ := io.ReadAll(resp.Body)
+ if resp.StatusCode != 403 || strings.Contains(string(body), "acme") || strings.Contains(string(body), "operations") {
+ t.Fatalf("%d %s", resp.StatusCode, body)
+ }
+ })
+ }
+}
+
+func TestDelegatedResponseMeetingDeletion(t *testing.T) {
+ for _, name := range []string{"calls_get_meeting", "calls_list_meetings"} {
+ t.Run(name, func(t *testing.T) {
+ f, p := linkedDelegated(t)
+ w := delegatedCall(f.app, "calls_create_meeting", delegatedInputForTest())
+ if w.Code != 200 {
+ t.Fatal(w.Code)
+ }
+ var created struct{ Sqid string }
+ json.Unmarshal(w.Body.Bytes(), &created)
+ var checks atomic.Int32
+ v := access.VerifyFunc(func(context.Context, string) (access.Principal, error) {
+ if checks.Add(1) == 2 {
+ if err := f.app.db.G.Exec("DELETE FROM meeting_links").Error; err != nil {
+ return access.Principal{}, err
+ }
+ if err := f.app.db.G.Exec("DELETE FROM meetings").Error; err != nil {
+ return access.Principal{}, err
+ }
+ }
+ return *p, nil
+ })
+ if err := f.app.mountDelegated(v, f.app.agentIssuer, "acme"); err != nil {
+ t.Fatal(err)
+ }
+ input := map[string]any{"team": "acme"}
+ if name == "calls_get_meeting" {
+ input["sqid"] = created.Sqid
+ }
+ status, body, err := delegatedLiveCall(t, f.app.delegated, name, input)
+ if err != nil || status != 404 || strings.Contains(string(body), "delegated_title") {
+ t.Fatalf("%d %s %v", status, body, err)
+ }
+ })
+ }
+}
diff --git a/internal/calls/delegated_test.go b/internal/calls/delegated_test.go
index 35d9af2..a3ca17d 100644
--- a/internal/calls/delegated_test.go
+++ b/internal/calls/delegated_test.go
@@ -30,7 +30,7 @@ func delegatedCall(a *app, name string, input any) *httptest.ResponseRecorder {
r.Header.Set("Authorization", "Bearer fixture")
r.Header.Set("Content-Type", "application/json")
w := httptest.NewRecorder()
- a.delegated.ServeHTTP(w, r)
+ a.delegated.ServeHTTP(responseRecorder{w}, r)
return w
}
func delegatedInputForTest() map[string]any {
@@ -191,7 +191,7 @@ func TestDelegatedIdentityScopeAndCurrentMembership(t *testing.T) {
r.AddCookie(c)
}
w = httptest.NewRecorder()
- f.app.delegated.ServeHTTP(w, r)
+ f.app.delegated.ServeHTTP(responseRecorder{w}, r)
if w.Code != http.StatusUnauthorized {
t.Fatal("cookie authorized", w.Code)
}