oficina / home Public

Prove add-apps adoption and independent confirmed-team scope

codex agent, operated by paul@keymail.dev pushed by paul@keymail.dev 8b2792ff3ef0d397730fa5361ae2ca3c4a5a915d parent aa96949
1 file changed, +90 −3
  • internal/operator/existing_test.go +90 −3

CI passed — run details

diff --git a/internal/operator/existing_test.go b/internal/operator/existing_test.go
index 611fa85..e38f059 100644
--- a/internal/operator/existing_test.go
+++ b/internal/operator/existing_test.go
@@ -8,6 +8,7 @@ import (
"time"
"amadan.net/oficina/home/internal/home/directorydata"
+ "amadan.net/oficina/home/roster"
family "amadan.net/rastrillo/rastrillo/crypto"
"github.com/go-json-experiment/json"
)
@@ -217,8 +218,17 @@ func TestExistingActivationDiscoveryAndRevocation(t *testing.T) {
}
func openCredentialAdoption(t *testing.T, f *httpCredential) {
+ openCredentialAdoptionPlan(t, f, "create-team", "Uk", "docs")
+}
+
+func openCredentialAdoptionPlan(t *testing.T, f *httpCredential, kind, team string, apps ...string) {
t.Helper()
- p := Plan{Version: 1, Purpose: "operator-plan", Role: "credential", Origin: f.auth.Origin, Installation: token(1), Registry: token(2), Device: token(3), PlanID: token(120), Kind: "create-team", Apps: []string{"docs"}, Owner: ownerCanary, ExistingTeam: "Uk", Issued: f.now.Unix(), Expires: f.now.Unix() + 600}
+ p := Plan{Version: 1, Purpose: "operator-plan", Role: "credential", Origin: f.auth.Origin, Installation: token(1), Registry: token(2), Device: token(3), PlanID: token(f.attempt + 100), Kind: kind, Apps: apps, ExistingTeam: team, Issued: f.now.Unix(), Expires: f.now.Unix() + 600}
+ index := ""
+ if kind == "create-team" {
+ p.Owner = ownerCanary
+ index = credentialIndex(f.pepper, ownerCanary)
+ }
raw, e := SignPlan(f.key, p, httpApps)
if e != nil {
t.Fatal(e)
@@ -227,12 +237,89 @@ func openCredentialAdoption(t *testing.T, f *httpCredential) {
if e != nil {
t.Fatal(e)
}
- if e = f.plans.Submit(context.Background(), p, credentialIndex(f.pepper, ownerCanary), *f.now); e != nil {
+ if e = f.plans.Submit(context.Background(), p, index, *f.now); e != nil {
t.Fatal(e)
}
- if _, e = f.plans.Open(context.Background(), p.PlanID, *f.now, func(v PlanView) bool { return v.ExistingTeam == "Uk" }); e != nil {
+ if _, e = f.plans.Open(context.Background(), p.PlanID, *f.now, func(v PlanView) bool { return v.ExistingTeam == team && (kind != "add-apps" || v.OwnerIndex == "") }); e != nil {
+ t.Fatal(e)
+ }
+}
+
+func TestExistingAddAppsKeepsTeamAndRegistrations(t *testing.T) {
+ f, _ := adoptionPending(t)
+ *f.now = f.now.Add(WindowLifetime * time.Second)
+ f.openPlan(t, func(p *Plan) {
+ p.Kind, p.Label, p.DisplayName, p.ExistingTeam, p.Apps = "add-apps", "oficina", "", "Uk", []string{"sheets"}
+ })
+ out, e := f.run(t, "directory.provision-consumer", func(b InputBase) any {
+ return ProvisionInput{b, token(10), "Uk", "sheets", "sheets", "https://sheets.oficina.works", 0}
+ })
+ if e != nil {
+ t.Fatal("add canonical app", e)
+ }
+ if countRows(t, f.db, "teams") != 1 || countRows(t, f.db, "memberships") != 1 || countRows(t, f.db, "team_instances") != 2 {
+ t.Fatal("add apps replaced the team")
+ }
+ var result Result
+ if json.Unmarshal(out, &result) != nil {
+ t.Fatal("provision result")
+ }
+ c := newHTTPCredential(t)
+ c.http.env["sheets"] = "https://sheets.oficina.works"
+ openCredentialAdoption(t, c)
+ if _, e = c.run(t, "credential.owner-seed", ownerSeedInput(ownerCanary, true)); e != nil {
t.Fatal(e)
}
+ *c.now = c.now.Add(WindowLifetime * time.Second)
+ openCredentialAdoptionPlan(t, c, "add-apps", "Uk", "sheets")
+ // Use the actual directory record and signer. Both fixtures share the
+ // canonical issuer/directory; this tests derivative verification too.
+ c.http.provisioning = []roster.Key{{ID: keyID(f.directory.signer.SignPub()), Public: base64.RawURLEncoding.EncodeToString(f.directory.signer.SignPub())}}
+ out, e = c.run(t, "credential.register-consumer", func(b InputBase) any { return RegisterInput{b, result.Record} })
+ if e != nil {
+ t.Fatal("existing sheets registration", e)
+ }
+ var registered Result
+ if json.Unmarshal(out, &registered) != nil {
+ t.Fatal("register result")
+ }
+ want, _ := ManifestDigest(c.http.env)
+ if registered.Manifest != want || countRows(t, c.db, "consumers") != 0 {
+ t.Fatal("add-apps modified registry")
+ }
+}
+
+func TestExistingConfirmedTeamScopeIsIndependentOfStoredTeam(t *testing.T) {
+ t.Run("seed", func(t *testing.T) {
+ f := adoptionDirectory(t)
+ *f.now = f.now.Add(WindowLifetime * time.Second)
+ f.openPlan(t, func(p *Plan) { p.Label, p.ExistingTeam = "oficina", "gb" })
+ if _, e := f.seedHTTP(t, 1, "oficina", "PRIVATE-TEAM-NAME-CANARY"); e != ErrRefused {
+ t.Fatal("valid next team escaped confirmed scope", e)
+ }
+ })
+ t.Run("provision", func(t *testing.T) {
+ f, _ := adoptionPending(t)
+ *f.now = f.now.Add(WindowLifetime * time.Second)
+ f.openPlan(t, func(p *Plan) {
+ p.Kind, p.Label, p.DisplayName, p.ExistingTeam, p.Apps = "add-apps", "oficina", "", "gb", []string{"sheets"}
+ })
+ if _, e := f.run(t, "directory.provision-consumer", func(b InputBase) any {
+ return ProvisionInput{b, token(10), "Uk", "sheets", "sheets", "https://sheets.oficina.works", 0}
+ }); e != ErrRefused {
+ t.Fatal("valid stored team escaped confirmed scope", e)
+ }
+ })
+ t.Run("verify", func(t *testing.T) {
+ f, in := adoptionPending(t)
+ *f.now = f.now.Add(WindowLifetime * time.Second)
+ f.openPlan(t, func(p *Plan) { p.Kind, p.Label, p.DisplayName, p.ExistingTeam = "add-apps", "oficina", "", "gb" })
+ in.Issued = f.now.Unix()
+ in.Expires = in.Issued + 600
+ if _, e := f.run(t, "directory.verify-consumer", func(b InputBase) any { in.InputBase = b; return in }); e != ErrRefused {
+ t.Fatal("valid pending binding escaped confirmed scope", e)
+ }
+ })
}
func TestExistingRegistrationPreservesManifestAndOwnerScope(t *testing.T) {