homeop: existing_team; canonical values in Alta's helpers
Plan.ExistingTeam, ExistingActivationPolicy and CanonicalOrigin mirror Home. PublicHost/ConsumerID answer Home's canonical tuple for label oficina and are unchanged for every other label; TeamKeyNames lists the team-mode keys. fakehome follows Home's plan validity, routeScope, verify-only register and window-chosen activation policy, and logs committed requests in order. Makefile gains check and compat-check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+783
−13
Makefile+12 −2homeop/fakehome/fakehome.go+119 −7homeop/fakehome/fakehome_test.go+499 −0homeop/protocol.go+22 −2homeop/protocol_test.go+45 −0provision/apps.go+33 −2provision/apps_test.go+53 −0
diff --git a/Makefile b/Makefile| index 0c30350..5ef907d 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -1,5 +1,5 @@ |
| export GOTOOLCHAIN := go1.26.5 |
| -export GOPRIVATE := $(GOPRIVATE),amadan.net/oficina/estilo.git |
| +export GOPRIVATE := $(GOPRIVATE),amadan.net/oficina/estilo.git,amadan.net/oficina/agent-access.git |
| APP := alta |
| @@ -13,7 +13,7 @@ RELEASE_BIN := releases/$(APP)-$(RELEASE_GOOS)-$(RELEASE_GOARCH) |
| # forever, and the deploy check can then never fail. |
| VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null) |
| -.PHONY: build release version-check deps test vet fmt-check compat ci |
| +.PHONY: build release version-check deps test vet fmt-check compat ci check compat-check |
| build: |
| CGO_ENABLED=0 go build ./... |
| @@ -56,6 +56,16 @@ fmt-check: |
| compat: |
| cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./... |
| +# check runs one package's tests: make check PKG=./homeop/... RUN=TestX |
| +# PKG is required. Use this, never bare `go test`: it pins the toolchain. |
| +check: |
| + @test -n "$(PKG)" || { echo "make check: PKG is required, e.g. make check PKG=./provision/... RUN=TestX"; exit 1; } |
| + CGO_ENABLED=0 go test $(PKG) -run '$(RUN)' -count=1 |
| + |
| +# compat-check is check for homecompat, which is its own module. |
| +compat-check: |
| + cd homecompat && CGO_ENABLED=0 go test ./... -run '$(RUN)' -count=1 |
| + |
| # ci is the one gate: what the runner executes and what you run before |
| # pushing. No migration-check: Alta has no GORM models, only SQL |
| # migrations under provision/migrations. |
diff --git a/homeop/fakehome/fakehome.go b/homeop/fakehome/fakehome.go| index 6fa014f..902e548 100644 |
| --- a/homeop/fakehome/fakehome.go |
| +++ b/homeop/fakehome/fakehome.go |
| @@ -42,8 +42,10 @@ var registry = []string{"docs", "sheets", "slides", "calendar", "calls", "memori |
| type plan struct { |
| id, kind, label, name, owner string |
| - apps []string |
| - expires, window int64 |
| + // existing is an adoption plan's team SQID; empty for an ordinary one. |
| + existing string |
| + apps []string |
| + expires, window int64 |
| } |
| type stored struct { |
| @@ -121,6 +123,11 @@ type Home struct { |
| // Calls counts operations by action (committed or not). |
| Calls map[string]int |
| + // requests is the committed operations in order; committedApp is the |
| + // app the operation in flight touched, set by mutate. |
| + requests []string |
| + committedApp string |
| + |
| // RecordSigner, when set, signs provisioning records instead of the |
| // directory's provisioning key; RecordAudience, when set, is the |
| // audience records bind. Both make records Alta must refuse. |
| @@ -171,6 +178,25 @@ func (h *Home) AddPerson(address string) string { |
| return ref |
| } |
| +// AddEnvConsumer adds an entry to the credential role's immutable env |
| +// manifest (HOME_CONSUMERS), as an existing instance has. Adoption's |
| +// register verifies against it and inserts nothing. |
| +func (h *Home) AddEnvConsumer(id, origin string) { |
| + h.mu.Lock() |
| + defer h.mu.Unlock() |
| + h.env[id] = origin |
| +} |
| + |
| +// Requests is the committed operations in order, each as its action, with |
| +// ":<app>" for the verbs that touch one app, for example |
| +// "directory.activate-consumer:calendar". A refused operation, an |
| +// operation that did not commit and an exact replay add nothing. |
| +func (h *Home) Requests() []string { |
| + h.mu.Lock() |
| + defer h.mu.Unlock() |
| + return slices.Clone(h.requests) |
| +} |
| + |
| // Confirm is Paul on role's confirm page: it opens the pending plan's |
| // window. owner is the typed address (credential role, create-team). |
| func (h *Home) Confirm(r, owner string) error { |
| @@ -399,6 +425,21 @@ func (h *Home) submit(x *role, body []byte, now int64) int { |
| if !canonical(payload, &p) || p.Version != 1 || p.Purpose != "operator-plan" || p.Role != x.name || p.Origin != x.origin || p.Installation != x.installation || p.Registry != x.registry || p.Device != x.device || !homeop.CanonicalToken(p.PlanID) || p.Issued > now || now >= p.Expires || p.Expires-p.Issued > homeop.PlanLifetime { |
| return 403 |
| } |
| + // Home's Plan.valid: an adoption plan binds a team SQID, only on |
| + // create-team or add-apps, only under label oficina, only for the |
| + // canonical apps; and oficina is reserved against everything else. |
| + if p.ExistingTeam != "" { |
| + if !validSQID(p.ExistingTeam) || (p.Kind != homeop.KindCreateTeam && p.Kind != homeop.KindAddApps) || (x.name == homeop.Directory && p.Label != "oficina") { |
| + return 403 |
| + } |
| + for _, a := range p.Apps { |
| + if homeop.CanonicalOrigin(a) == "" { |
| + return 403 |
| + } |
| + } |
| + } else if x.name == homeop.Directory && p.Label == "oficina" && (p.Kind == homeop.KindCreateTeam || p.Kind == homeop.KindAddApps) { |
| + return 403 |
| + } |
| if p.Kind == homeop.KindInitialize { |
| if x.name != homeop.Directory || len(p.Apps) != 0 || p.Label != "" || p.DisplayName != "" || p.Owner != "" { |
| return 403 |
| @@ -432,7 +473,7 @@ func (h *Home) submit(x *role, body []byte, now int64) int { |
| if x.pending != nil || (x.open != nil && x.open.id == p.PlanID) { |
| return 409 |
| } |
| - x.pending = &plan{id: p.PlanID, kind: p.Kind, label: p.Label, name: p.DisplayName, owner: p.Owner, apps: p.Apps, expires: p.Expires} |
| + x.pending = &plan{id: p.PlanID, kind: p.Kind, label: p.Label, name: p.DisplayName, owner: p.Owner, existing: p.ExistingTeam, apps: p.Apps, expires: p.Expires} |
| return 200 |
| } |
| @@ -467,6 +508,27 @@ func (h *Home) inspect(x *role, body []byte, now int64) ([]byte, bool) { |
| // distinct token per id. |
| func sqid(id int64) string { return "t" + strings.Repeat("x", int(id%5)+2) + string(rune('a'+id%26)) } |
| +var sqidShape = regexp.MustCompile(`^tx{2,6}[a-z]$`) |
| + |
| +// validSQID is Home's validTeamSQID for this fake's sqids: the shape sqid |
| +// produces. Home's decodes to exactly one positive id and re-encodes. |
| +func validSQID(s string) bool { return sqidShape.MatchString(s) } |
| + |
| +// routeScope is Home's routeScope (existing.go): an ordinary window never |
| +// touches the oficina label or a canonical origin; an adoption window |
| +// touches only the exact canonical tuple of the plan's team. |
| +func routeScope(existing, label, team, app, consumer, origin string) bool { |
| + if existing == "" { |
| + return label != "oficina" && origin != homeop.CanonicalOrigin(app) |
| + } |
| + return validSQID(existing) && team == existing && canonicalBinding(label, app, consumer, origin) |
| +} |
| + |
| +// canonicalBinding is directorydata.CanonicalBinding. |
| +func canonicalBinding(label, app, consumer, origin string) bool { |
| + return label == "oficina" && consumer == app && homeop.CanonicalOrigin(app) != "" && origin == homeop.CanonicalOrigin(app) |
| +} |
| + |
| // ---- operations ---- |
| type wrapper struct { |
| @@ -510,6 +572,7 @@ func (h *Home) execute(x *role, body []byte, now int64) ([]byte, int, string) { |
| return nil, 403, a.Action |
| } |
| base := homeop.Result{Version: 1, OperationID: a.OperationID, Outcome: "committed"} |
| + h.committedApp = "" |
| res, ok := h.mutate(x, w0, a, w.Input, head, now, base) |
| if !ok { |
| return nil, 403, a.Action |
| @@ -517,6 +580,11 @@ func (h *Home) execute(x *role, body []byte, now int64) ([]byte, int, string) { |
| out, _ := homeop.Encode(res) |
| x.results[a.OperationID] = stored{action: a.Action, seq: a.Sequence, head: head, mac: mac, result: out} |
| x.seq, x.head = a.Sequence, head |
| + entry := a.Action |
| + if h.committedApp != "" { |
| + entry += ":" + h.committedApp |
| + } |
| + h.requests = append(h.requests, entry) |
| return out, 200, a.Action |
| } |
| @@ -559,6 +627,9 @@ func (h *Home) mutate(x *role, w *plan, a homeop.Authorization, input []byte, he |
| if !canonical(input, &in) || !base(in.InputBase, a) || !in.ExistingOnly || in.Address != w.owner || in.Directory != h.roles[homeop.Directory].origin { |
| return res, false |
| } |
| + if w.existing != "" && in.TeamSQID != w.existing { |
| + return res, false |
| + } |
| ref, ok := h.People[in.Address] |
| if !ok || in.TeamID <= 0 || in.TeamSQID != sqid(in.TeamID) { |
| return res, false |
| @@ -570,6 +641,11 @@ func (h *Home) mutate(x *role, w *plan, a homeop.Authorization, input []byte, he |
| if !canonical(input, &in) || !base(in.InputBase, a) || a.Initial || in.Label != w.label || in.Name != w.name || h.generation == nil || in.Generation != *h.generation { |
| return res, false |
| } |
| + // Home's seedTeamForWindow: oficina is seeded only by an adoption |
| + // window, and only at that window's SQID. |
| + if (in.Label == "oficina") != (w.existing != "") || (w.existing != "" && in.TeamSQID != w.existing) { |
| + return res, false |
| + } |
| receipt, ok := h.verifyReceipt(in.Receipt, now) |
| if !ok || receipt.TeamID != in.TeamID || receipt.TeamSQID != in.TeamSQID || in.TeamID != h.nextTeam || in.TeamSQID != sqid(h.nextTeam) { |
| return res, false |
| @@ -590,9 +666,13 @@ func (h *Home) mutate(x *role, w *plan, a homeop.Authorization, input []byte, he |
| return res, false |
| } |
| t, ok := h.fence(in.TeamSQID, w.label) |
| - if !ok || in.Audience != "https://"+t.label+"."+in.App+".oficina.works" { |
| + if !ok || !routeScope(w.existing, t.label, in.TeamSQID, in.App, in.Consumer, in.Audience) { |
| return res, false |
| } |
| + if w.existing == "" && in.Audience != "https://"+t.label+"."+in.App+".oficina.works" { |
| + return res, false |
| + } |
| + h.committedApp = in.App |
| for c, i := range h.instances { |
| if (i.team == t.id && i.app == in.App) || c == in.Consumer || i.origin == in.Audience { |
| return res, false |
| @@ -635,6 +715,28 @@ func (h *Home) mutate(x *role, w *plan, a homeop.Authorization, input []byte, he |
| if !slices.Contains(w.apps, b.App) { |
| return res, false |
| } |
| + h.committedApp = b.App |
| + if w.existing != "" { |
| + // Home's register under an adoption window: verify only. The |
| + // exact pair is already in the env manifest, no other env |
| + // entry has the origin, and the table has neither; nothing is |
| + // inserted, replaced or retired. |
| + if b.Team != w.existing || !canonicalBinding("oficina", b.App, b.Consumer, b.Audience) || h.env[b.Consumer] != b.Audience { |
| + return res, false |
| + } |
| + for id, origin := range h.env { |
| + if id != b.Consumer && origin == b.Audience { |
| + return res, false |
| + } |
| + } |
| + for id, c := range h.consumers { |
| + if id == b.Consumer || c.origin == b.Audience { |
| + return res, false |
| + } |
| + } |
| + res.Manifest = h.manifest() |
| + return res, true |
| + } |
| for id, origin := range h.env { |
| if id == b.Consumer || origin == b.Audience { |
| return res, false |
| @@ -657,6 +759,7 @@ func (h *Home) mutate(x *role, w *plan, a homeop.Authorization, input []byte, he |
| if !ok || c.state != "active" || !slices.Contains(w.apps, c.app) { |
| return res, false |
| } |
| + h.committedApp = c.app |
| c.state = "retired" |
| h.consumers[in.Consumer] = c |
| res.Manifest = h.manifest() |
| @@ -666,9 +769,10 @@ func (h *Home) mutate(x *role, w *plan, a homeop.Authorization, input []byte, he |
| if !canonical(input, &in) || !base(in.InputBase, a) || a.Initial || !slices.Contains(w.apps, in.App) { |
| return res, false |
| } |
| - if _, ok := h.fence(in.TeamSQID, w.label); !ok { |
| + if _, ok := h.fence(in.TeamSQID, w.label); !ok || !routeScope(w.existing, w.label, in.TeamSQID, in.App, in.Consumer, in.Audience) { |
| return res, false |
| } |
| + h.committedApp = in.App |
| i, ok := h.pendingBinding(in.Consumer, in.TeamSQID, in.App, in.Audience, in.Generation, in.RecordSequence, in.RecordDigest, in.Owner, in.Epoch) |
| if !ok || in.Issued <= 0 || in.Issued > now || in.Expires <= now || in.Expires-in.Issued > 600 { |
| return res, false |
| @@ -685,13 +789,20 @@ func (h *Home) mutate(x *role, w *plan, a homeop.Authorization, input []byte, he |
| return res, false |
| } |
| p := in.Evidence |
| + // Home's activateForWindow: the window, not the evidence, picks |
| + // the policy. |
| + policy := homeop.ActivationPolicy |
| + if w.existing != "" { |
| + policy = homeop.ExistingActivationPolicy |
| + } |
| u, err := url.Parse(p.Audience) |
| - if err != nil || !slices.Contains(w.apps, p.App) || p.Policy != homeop.ActivationPolicy || !observedVersion.MatchString(p.AppVersion) || !homeop.CanonicalToken(p.ArtifactDigest) || !homeop.CanonicalToken(p.EnvironmentBinding) || !homeop.CanonicalToken(p.ManifestDigest) || p.AliasHost != u.Host || p.Completed > now || now-p.Completed >= 300 { |
| + if err != nil || !slices.Contains(w.apps, p.App) || p.Policy != policy || !observedVersion.MatchString(p.AppVersion) || !homeop.CanonicalToken(p.ArtifactDigest) || !homeop.CanonicalToken(p.EnvironmentBinding) || !homeop.CanonicalToken(p.ManifestDigest) || p.AliasHost != u.Host || p.Completed > now || now-p.Completed >= 300 { |
| return res, false |
| } |
| - if _, ok := h.fence(p.TeamSQID, w.label); !ok { |
| + if _, ok := h.fence(p.TeamSQID, w.label); !ok || !routeScope(w.existing, w.label, p.TeamSQID, p.App, p.Consumer, p.Audience) { |
| return res, false |
| } |
| + h.committedApp = p.App |
| i, ok := h.pendingBinding(p.Consumer, p.TeamSQID, p.App, p.Audience, p.Generation, p.RecordSequence, p.RecordDigest, p.Owner, p.Epoch) |
| if !ok || i.attempt == nil || i.attempt.id != p.Attempt || i.attempt.expires <= now || p.Started < i.attempt.issued || p.Completed >= i.attempt.expires { |
| return res, false |
| @@ -709,6 +820,7 @@ func (h *Home) mutate(x *role, w *plan, a homeop.Authorization, input []byte, he |
| if !ok || !ok2 || i.team != t.id || i.app != in.App || i.state == "disabled" { |
| return res, false |
| } |
| + h.committedApp = in.App |
| i.state = "disabled" |
| res.Generation, res.TeamID, res.TeamSQID = in.Generation, t.id, t.sqid |
| return res, true |
diff --git a/homeop/fakehome/fakehome_test.go b/homeop/fakehome/fakehome_test.go| new file mode 100644 |
| index 0000000..6d44d38 |
| --- /dev/null |
| +++ b/homeop/fakehome/fakehome_test.go |
| @@ -0,0 +1,499 @@ |
| +package fakehome |
| + |
| +import ( |
| + "bytes" |
| + "io" |
| + "net/http" |
| + "net/http/httptest" |
| + "slices" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/alta/homeop" |
| + family "amadan.net/rastrillo/rastrillo/crypto" |
| +) |
| + |
| +const ( |
| + credOrigin = "https://id.oficina.works" |
| + dirOrigin = "https://oficina.works" |
| + ownerAddr = "paul@example.test" |
| +) |
| + |
| +var canonicalApps = []string{"docs", "sheets", "slides", "calendar", "calls", "memoria"} |
| + |
| +// driver is Alta's side of the two operator streams, as little of it as |
| +// these tests need: it signs, sends and tracks each role's sequence. |
| +type driver struct { |
| + t *testing.T |
| + h *Home |
| + key *family.Keypair |
| + pre string |
| + now time.Time |
| + srv map[string]*httptest.Server |
| + seq map[string]int64 |
| + head map[string]string |
| + gen string |
| +} |
| + |
| +func newDriver(t *testing.T) *driver { |
| + t.Helper() |
| + d := &driver{t: t, now: time.Unix(2_000_000_000, 0), srv: map[string]*httptest.Server{}, seq: map[string]int64{}, head: map[string]string{}} |
| + d.key, _ = family.Generate() |
| + d.pre = homeop.Token() |
| + d.h = New(d.key.SignPub(), d.pre, credOrigin, dirOrigin, func() time.Time { return d.now }) |
| + d.h.AddPerson(ownerAddr) |
| + for _, r := range []string{homeop.Credential, homeop.Directory} { |
| + d.srv[r] = httptest.NewServer(d.h.Handler(r)) |
| + t.Cleanup(d.srv[r].Close) |
| + } |
| + return d |
| +} |
| + |
| +func (d *driver) post(role, path string, body []byte) (int, []byte) { |
| + d.t.Helper() |
| + req, _ := http.NewRequest(http.MethodPost, d.srv[role].URL+path, bytes.NewReader(body)) |
| + req.Header.Set("Content-Type", "application/json") |
| + req.Header.Set("Authorization", "Bearer "+d.pre) |
| + resp, err := http.DefaultClient.Do(req) |
| + if err != nil { |
| + return 0, nil |
| + } |
| + defer resp.Body.Close() |
| + out, _ := io.ReadAll(resp.Body) |
| + return resp.StatusCode, out |
| +} |
| + |
| +func (d *driver) pins(role string) homeop.Authorization { |
| + p := d.h.Pins(role) |
| + origin := dirOrigin |
| + if role == homeop.Credential { |
| + origin = credOrigin |
| + } |
| + return homeop.Authorization{Role: role, Origin: origin, Installation: p.Installation, Registry: p.Registry, Device: p.Device} |
| +} |
| + |
| +// plan signs and submits a plan, returning the HTTP status. |
| +func (d *driver) plan(role string, p homeop.Plan) int { |
| + d.t.Helper() |
| + a := d.pins(role) |
| + p.Role, p.Origin, p.Installation, p.Registry, p.Device = role, a.Origin, a.Installation, a.Registry, a.Device |
| + p.PlanID, p.Issued, p.Expires = homeop.Token(), d.now.Unix()-homeop.Skew, d.now.Unix()-homeop.Skew+homeop.PlanLifetime |
| + raw, err := homeop.SignPlan(d.key, p) |
| + if err != nil { |
| + d.t.Fatal(err) |
| + } |
| + status, _ := d.post(role, "/operator/v1/plan", raw) |
| + return status |
| +} |
| + |
| +// sign builds the next request on role's stream without sending it. |
| +func (d *driver) sign(role, action string, input func(homeop.InputBase) any) homeop.Request { |
| + d.t.Helper() |
| + a := d.pins(role) |
| + a.Sequence, a.JournalSequence = d.seq[role]+1, d.seq[role]+1 |
| + a.Previous = d.head[role] |
| + a.OperationID, a.Action = homeop.Token(), action |
| + a.Issued, a.Expires = d.now.Unix()-homeop.Skew, d.now.Unix()-homeop.Skew+homeop.RequestLifetime |
| + req, err := homeop.SignRequest(d.key, a, input(homeop.InputBase{Version: 1, Operation: action, OperationID: a.OperationID})) |
| + if err != nil { |
| + d.t.Fatal(err) |
| + } |
| + return req |
| +} |
| + |
| +// send posts req; a committed operation advances the stream. |
| +func (d *driver) send(role string, req homeop.Request) (homeop.Result, bool) { |
| + d.t.Helper() |
| + status, body := d.post(role, "/operator/v1", req.Bytes) |
| + if status != 200 { |
| + return homeop.Result{}, false |
| + } |
| + var res homeop.Result |
| + if err := homeop.Decode(body, &res); err != nil { |
| + d.t.Fatal(err) |
| + } |
| + if req.Authorization.Sequence == d.seq[role]+1 { |
| + d.seq[role], d.head[role] = req.Authorization.Sequence, req.Head |
| + } |
| + return res, true |
| +} |
| + |
| +func (d *driver) op(role, action string, input func(homeop.InputBase) any) (homeop.Result, bool) { |
| + d.t.Helper() |
| + return d.send(role, d.sign(role, action, input)) |
| +} |
| + |
| +func (d *driver) must(role, action string, input func(homeop.InputBase) any) homeop.Result { |
| + d.t.Helper() |
| + res, ok := d.op(role, action, input) |
| + if !ok { |
| + d.t.Fatalf("%s refused", action) |
| + } |
| + return res |
| +} |
| + |
| +// proposed is the team id and sqid the directory proposes next. |
| +func (d *driver) proposed() (int64, string) { |
| + d.t.Helper() |
| + a := d.pins(homeop.Directory) |
| + raw, err := homeop.SignInspect(d.key, homeop.InspectChallenge{Role: homeop.Directory, Origin: dirOrigin, Installation: a.Installation, Registry: a.Registry, Device: a.Device, Challenge: homeop.Token(), Issued: d.now.Unix() - homeop.Skew, Expires: d.now.Unix() - homeop.Skew + homeop.RequestLifetime}) |
| + if err != nil { |
| + d.t.Fatal(err) |
| + } |
| + status, body := d.post(homeop.Directory, "/operator/v1", raw) |
| + var in homeop.Inspection |
| + if status != 200 || homeop.Decode(body, &in) != nil { |
| + d.t.Fatalf("inspect %d", status) |
| + } |
| + return in.TeamID, in.TeamSQID |
| +} |
| + |
| +func (d *driver) initialize() { |
| + d.t.Helper() |
| + if d.plan(homeop.Directory, homeop.Plan{Kind: homeop.KindInitialize}) != 200 { |
| + d.t.Fatal("initialize plan") |
| + } |
| + if err := d.h.Confirm(homeop.Directory, ""); err != nil { |
| + d.t.Fatal(err) |
| + } |
| + d.gen = homeop.Token() |
| + d.must(homeop.Directory, homeop.DirectoryInitialize, func(b homeop.InputBase) any { |
| + return homeop.InitializeInput{InputBase: b, Generation: d.gen, Baseline: homeop.Baseline} |
| + }) |
| + // Let initialize's window lapse, as it does between Alta's phases. |
| + d.now = d.now.Add((homeop.WindowLifetime + 1) * time.Second) |
| +} |
| + |
| +// openCreate submits and confirms the two create-team adoption plans. |
| +func (d *driver) openCreate(existing string) { |
| + d.t.Helper() |
| + if s := d.plan(homeop.Credential, homeop.Plan{Kind: homeop.KindCreateTeam, Apps: canonicalApps, Owner: ownerAddr, ExistingTeam: existing}); s != 200 { |
| + d.t.Fatalf("credential plan %d", s) |
| + } |
| + if s := d.plan(homeop.Directory, homeop.Plan{Kind: homeop.KindCreateTeam, Apps: canonicalApps, Label: "oficina", DisplayName: "Oficina", ExistingTeam: existing}); s != 200 { |
| + d.t.Fatalf("directory plan %d", s) |
| + } |
| + if err := d.h.Confirm(homeop.Credential, ownerAddr); err != nil { |
| + d.t.Fatal(err) |
| + } |
| + if err := d.h.Confirm(homeop.Directory, ""); err != nil { |
| + d.t.Fatal(err) |
| + } |
| +} |
| + |
| +func (d *driver) ownerSeed(id int64, sq, address string) (homeop.Result, bool) { |
| + return d.op(homeop.Credential, homeop.CredentialOwnerSeed, func(b homeop.InputBase) any { |
| + return homeop.OwnerInput{InputBase: b, Directory: dirOrigin, TeamID: id, TeamSQID: sq, Address: address, ExistingOnly: true} |
| + }) |
| +} |
| + |
| +func (d *driver) seed(id int64, sq, label string, receipt []byte) (homeop.Result, bool) { |
| + return d.op(homeop.Directory, homeop.DirectorySeedTeam, func(b homeop.InputBase) any { |
| + return homeop.SeedInput{InputBase: b, Generation: d.gen, TeamID: id, TeamSQID: sq, Label: label, Name: "Oficina", Receipt: receipt} |
| + }) |
| +} |
| + |
| +func (d *driver) provision(sq, app, consumer, audience string) (homeop.Result, bool) { |
| + return d.op(homeop.Directory, homeop.DirectoryProvision, func(b homeop.InputBase) any { |
| + return homeop.ProvisionInput{InputBase: b, Generation: d.gen, TeamSQID: sq, App: app, Consumer: consumer, Audience: audience} |
| + }) |
| +} |
| + |
| +func (d *driver) register(record []byte) (homeop.Result, bool) { |
| + return d.op(homeop.Credential, homeop.CredentialRegister, func(b homeop.InputBase) any { |
| + return homeop.RegisterInput{InputBase: b, Record: record} |
| + }) |
| +} |
| + |
| +// seedTeam runs owner-seed and seed-team at the proposed sqid. |
| +func (d *driver) seedTeam() (id int64, sq string) { |
| + d.t.Helper() |
| + id, sq = d.proposed() |
| + d.openCreate(sq) |
| + res := d.must(homeop.Credential, homeop.CredentialOwnerSeed, func(b homeop.InputBase) any { |
| + return homeop.OwnerInput{InputBase: b, Directory: dirOrigin, TeamID: id, TeamSQID: sq, Address: ownerAddr, ExistingOnly: true} |
| + }) |
| + d.must(homeop.Directory, homeop.DirectorySeedTeam, func(b homeop.InputBase) any { |
| + return homeop.SeedInput{InputBase: b, Generation: d.gen, TeamID: id, TeamSQID: sq, Label: "oficina", Name: "Oficina", Receipt: res.Receipt} |
| + }) |
| + return id, sq |
| +} |
| + |
| +func (d *driver) canonicalEnv() { |
| + for _, a := range canonicalApps { |
| + d.h.AddEnvConsumer(a, homeop.CanonicalOrigin(a)) |
| + } |
| +} |
| + |
| +func TestFakeHomeAdoptionScope(t *testing.T) { |
| + t.Run("plans", func(t *testing.T) { |
| + d := newDriver(t) |
| + d.initialize() |
| + _, sq := d.proposed() |
| + dir := func(p homeop.Plan) int { return d.plan(homeop.Directory, p) } |
| + cases := map[string]homeop.Plan{ |
| + "ordinary create-team under oficina": {Kind: homeop.KindCreateTeam, Apps: canonicalApps, Label: "oficina", DisplayName: "Oficina"}, |
| + "ordinary add-apps under oficina": {Kind: homeop.KindAddApps, Apps: []string{"docs"}, Label: "oficina"}, |
| + "existing team under another label": {Kind: homeop.KindCreateTeam, Apps: canonicalApps, Label: "acme", DisplayName: "Acme", ExistingTeam: sq}, |
| + "existing team on retire-apps": {Kind: homeop.KindRetireApps, Apps: []string{"docs"}, Label: "oficina", ExistingTeam: sq}, |
| + "existing team that is not a sqid": {Kind: homeop.KindCreateTeam, Apps: canonicalApps, Label: "oficina", DisplayName: "Oficina", ExistingTeam: "not a sqid"}, |
| + } |
| + for name, p := range cases { |
| + if s := dir(p); s != 403 { |
| + t.Errorf("%s: plan answered %d, want 403", name, s) |
| + } |
| + } |
| + if s := dir(homeop.Plan{Kind: homeop.KindCreateTeam, Apps: canonicalApps, Label: "oficina", DisplayName: "Oficina", ExistingTeam: sq}); s != 200 { |
| + t.Errorf("adoption create-team plan answered %d, want 200", s) |
| + } |
| + }) |
| + |
| + t.Run("seed only at the proposed sqid", func(t *testing.T) { |
| + d := newDriver(t) |
| + d.initialize() |
| + id, sq := d.proposed() |
| + other := sqid(id + 1) |
| + d.openCreate(other) // a plan for a sqid Home did not propose |
| + // The owner receipt binds the proposed sqid, the plan another. |
| + if _, ok := d.ownerSeed(id, sq, ownerAddr); ok { |
| + t.Fatal("owner-seed at a sqid other than the plan's was committed") |
| + } |
| + res, ok := d.ownerSeed(id+1, other, ownerAddr) |
| + if !ok { |
| + t.Fatal("owner-seed at the plan's sqid refused") |
| + } |
| + if _, ok := d.seed(id+1, other, "oficina", res.Receipt); ok { |
| + t.Fatal("seed-team committed at a sqid Home did not propose") |
| + } |
| + if d.h.TeamCount() != 0 { |
| + t.Fatal("a team exists") |
| + } |
| + }) |
| + |
| + t.Run("seed at the proposed sqid", func(t *testing.T) { |
| + d := newDriver(t) |
| + d.initialize() |
| + id, sq := d.seedTeam() |
| + if got, gotSQ, ok := d.h.Team("oficina"); !ok || got != id || gotSQ != sq { |
| + t.Fatalf("team %v %v %v", got, gotSQ, ok) |
| + } |
| + }) |
| + |
| + t.Run("seed refuses a label other than oficina", func(t *testing.T) { |
| + d := newDriver(t) |
| + d.initialize() |
| + id, sq := d.proposed() |
| + d.openCreate(sq) |
| + res, _ := d.ownerSeed(id, sq, ownerAddr) |
| + if _, ok := d.seed(id, sq, "acme", res.Receipt); ok { |
| + t.Fatal("seed-team committed another label in an adoption window") |
| + } |
| + }) |
| + |
| + t.Run("provision admits only the canonical tuple", func(t *testing.T) { |
| + d := newDriver(t) |
| + d.initialize() |
| + d.canonicalEnv() |
| + _, sq := d.seedTeam() |
| + for name, c := range map[string][3]string{ |
| + "ordinary consumer id": {"docs", "oficina-docs", "https://docs.oficina.works"}, |
| + "ordinary origin": {"docs", "docs", "https://oficina.docs.oficina.works"}, |
| + "another app's origin": {"docs", "docs", "https://sheets.oficina.works"}, |
| + "another app's id": {"docs", "sheets", "https://docs.oficina.works"}, |
| + "foreign origin": {"docs", "docs", "https://docs.example.test"}, |
| + } { |
| + if _, ok := d.provision(sq, c[0], c[1], c[2]); ok { |
| + t.Errorf("%s: provisioned", name) |
| + } |
| + } |
| + if _, ok := d.provision("txxxa", "docs", "docs", "https://docs.oficina.works"); ok { |
| + t.Error("provisioned under a sqid other than the plan's team") |
| + } |
| + if _, ok := d.provision(sq, "docs", "docs", "https://docs.oficina.works"); !ok { |
| + t.Fatal("canonical provision refused") |
| + } |
| + if d.h.InstanceState("docs") != "pending" { |
| + t.Fatalf("state %q", d.h.InstanceState("docs")) |
| + } |
| + }) |
| + |
| + t.Run("register verifies and inserts nothing", func(t *testing.T) { |
| + d := newDriver(t) |
| + d.initialize() |
| + d.canonicalEnv() |
| + _, sq := d.seedTeam() |
| + res, ok := d.provision(sq, "docs", "docs", "https://docs.oficina.works") |
| + if !ok { |
| + t.Fatal("provision refused") |
| + } |
| + before := d.h.ConsumerCount() |
| + got, ok := d.register(res.Record) |
| + if !ok { |
| + t.Fatal("register of the canonical record refused") |
| + } |
| + if d.h.ConsumerCount() != before || d.h.ConsumerState("docs") != "" { |
| + t.Fatalf("register inserted a consumer: %d -> %d", before, d.h.ConsumerCount()) |
| + } |
| + if want := d.h.manifest(); got.Manifest != want { |
| + t.Fatalf("manifest %q, want the existing union %q", got.Manifest, want) |
| + } |
| + }) |
| + |
| + t.Run("register needs the env manifest entry", func(t *testing.T) { |
| + d := newDriver(t) |
| + d.initialize() |
| + _, sq := d.seedTeam() // no canonical env entries |
| + res, ok := d.provision(sq, "docs", "docs", "https://docs.oficina.works") |
| + if !ok { |
| + t.Fatal("provision refused") |
| + } |
| + if _, ok := d.register(res.Record); ok { |
| + t.Fatal("register without an env manifest entry committed") |
| + } |
| + d.h.AddEnvConsumer("docs", "https://elsewhere.oficina.works") |
| + if _, ok := d.register(res.Record); ok { |
| + t.Fatal("register against an env entry with another origin committed") |
| + } |
| + }) |
| + |
| + t.Run("activation policy", func(t *testing.T) { |
| + d := newDriver(t) |
| + d.initialize() |
| + d.canonicalEnv() |
| + _, sq := d.seedTeam() |
| + res, _ := d.provision(sq, "docs", "docs", "https://docs.oficina.works") |
| + owner := d.h.People[ownerAddr] |
| + d.must(homeop.Directory, homeop.DirectoryVerify, func(b homeop.InputBase) any { |
| + return homeop.VerificationInput{InputBase: b, Consumer: "docs", TeamSQID: sq, App: "docs", Audience: "https://docs.oficina.works", Generation: d.gen, RecordSequence: 1, RecordDigest: homeop.Digest(res.Record), Epoch: res.Epoch, Owner: owner, Issued: d.now.Unix() - 60, Expires: d.now.Unix() + 300} |
| + }) |
| + // The attempt id is the verify operation's id: the last committed one. |
| + d.h.mu.Lock() |
| + attempt := d.h.instances["docs"].attempt.id |
| + d.h.mu.Unlock() |
| + activate := func(policy string) bool { |
| + _, ok := d.op(homeop.Directory, homeop.DirectoryActivate, func(b homeop.InputBase) any { |
| + return homeop.ActivationInput{InputBase: b, Evidence: homeop.ActivationEvidence{Version: 1, Policy: policy, Attempt: attempt, Consumer: "docs", TeamSQID: sq, App: "docs", Audience: "https://docs.oficina.works", Generation: d.gen, RecordSequence: 1, RecordDigest: homeop.Digest(res.Record), Epoch: res.Epoch, Owner: owner, AppVersion: "v1", ArtifactDigest: homeop.Token(), EnvironmentBinding: homeop.Token(), ManifestDigest: homeop.Token(), AliasHost: "docs.oficina.works", Started: d.now.Unix() - 50, Completed: d.now.Unix() - 5}} |
| + }) |
| + return ok |
| + } |
| + if activate(homeop.ActivationPolicy) { |
| + t.Fatal("activation under oficina/team-activation/v1 committed in an adoption window") |
| + } |
| + if d.h.InstanceState("docs") != "pending" { |
| + t.Fatal("refused activation changed state") |
| + } |
| + if !activate(homeop.ExistingActivationPolicy) { |
| + t.Fatal("activation under the existing-app policy refused") |
| + } |
| + if d.h.InstanceState("docs") != "live" { |
| + t.Fatalf("state %q", d.h.InstanceState("docs")) |
| + } |
| + }) |
| +} |
| + |
| +// The window picks the policy both ways: an ordinary window keeps |
| +// oficina/team-activation/v1 and refuses the existing-app policy. |
| +func TestFakeHomeOrdinaryActivationPolicy(t *testing.T) { |
| + d := newDriver(t) |
| + d.initialize() |
| + id, sq := d.proposed() |
| + if s := d.plan(homeop.Credential, homeop.Plan{Kind: homeop.KindCreateTeam, Apps: []string{"docs"}, Owner: ownerAddr}); s != 200 { |
| + t.Fatalf("credential plan %d", s) |
| + } |
| + if s := d.plan(homeop.Directory, homeop.Plan{Kind: homeop.KindCreateTeam, Apps: []string{"docs"}, Label: "acme", DisplayName: "Oficina"}); s != 200 { |
| + t.Fatalf("directory plan %d", s) |
| + } |
| + if err := d.h.Confirm(homeop.Credential, ownerAddr); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := d.h.Confirm(homeop.Directory, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + owned, ok := d.ownerSeed(id, sq, ownerAddr) |
| + if !ok { |
| + t.Fatal("owner-seed") |
| + } |
| + if _, ok := d.seed(id, sq, "oficina", owned.Receipt); ok { |
| + t.Fatal("an ordinary window seeded the oficina label") |
| + } |
| + if _, ok := d.seed(id, sq, "acme", owned.Receipt); !ok { |
| + t.Fatal("seed") |
| + } |
| + if _, ok := d.provision(sq, "docs", "docs", "https://docs.oficina.works"); ok { |
| + t.Fatal("an ordinary window provisioned a canonical tuple") |
| + } |
| + res, ok := d.provision(sq, "docs", "acme-docs", "https://acme.docs.oficina.works") |
| + if !ok { |
| + t.Fatal("ordinary provision refused") |
| + } |
| + owner := d.h.People[ownerAddr] |
| + d.must(homeop.Directory, homeop.DirectoryVerify, func(b homeop.InputBase) any { |
| + return homeop.VerificationInput{InputBase: b, Consumer: "acme-docs", TeamSQID: sq, App: "docs", Audience: "https://acme.docs.oficina.works", Generation: d.gen, RecordSequence: 1, RecordDigest: homeop.Digest(res.Record), Epoch: res.Epoch, Owner: owner, Issued: d.now.Unix() - 60, Expires: d.now.Unix() + 300} |
| + }) |
| + d.h.mu.Lock() |
| + attempt := d.h.instances["acme-docs"].attempt.id |
| + d.h.mu.Unlock() |
| + activate := func(policy string) bool { |
| + _, ok := d.op(homeop.Directory, homeop.DirectoryActivate, func(b homeop.InputBase) any { |
| + return homeop.ActivationInput{InputBase: b, Evidence: homeop.ActivationEvidence{Version: 1, Policy: policy, Attempt: attempt, Consumer: "acme-docs", TeamSQID: sq, App: "docs", Audience: "https://acme.docs.oficina.works", Generation: d.gen, RecordSequence: 1, RecordDigest: homeop.Digest(res.Record), Epoch: res.Epoch, Owner: owner, AppVersion: "v1", ArtifactDigest: homeop.Token(), EnvironmentBinding: homeop.Token(), ManifestDigest: homeop.Token(), AliasHost: "acme.docs.oficina.works", Started: d.now.Unix() - 50, Completed: d.now.Unix() - 5}} |
| + }) |
| + return ok |
| + } |
| + if activate(homeop.ExistingActivationPolicy) { |
| + t.Fatal("an ordinary window accepted oficina/existing-app-activation/v1") |
| + } |
| + if !activate(homeop.ActivationPolicy) { |
| + t.Fatal("an ordinary window refused oficina/team-activation/v1") |
| + } |
| +} |
| + |
| +func TestFakeHomeRequestsOrdered(t *testing.T) { |
| + d := newDriver(t) |
| + if got := d.h.Requests(); len(got) != 0 { |
| + t.Fatalf("fresh Home has requests %v", got) |
| + } |
| + d.initialize() |
| + d.canonicalEnv() |
| + _, sq := d.seedTeam() |
| + // A refused request is not a committed one. |
| + if _, ok := d.provision(sq, "docs", "oficina-docs", "https://docs.oficina.works"); ok { |
| + t.Fatal("non-canonical provision committed") |
| + } |
| + docs, ok := d.provision(sq, "docs", "docs", "https://docs.oficina.works") |
| + if !ok { |
| + t.Fatal("provision") |
| + } |
| + if _, ok := d.provision(sq, "calendar", "calendar", "https://calendar.oficina.works"); !ok { |
| + t.Fatal("provision") |
| + } |
| + if _, ok := d.register(docs.Record); !ok { |
| + t.Fatal("register") |
| + } |
| + // An exact replay returns the stored result and commits nothing new. |
| + replay := d.sign(homeop.Directory, homeop.DirectoryProvision, func(b homeop.InputBase) any { |
| + return homeop.ProvisionInput{InputBase: b, Generation: d.gen, TeamSQID: sq, App: "sheets", Consumer: "sheets", Audience: "https://sheets.oficina.works"} |
| + }) |
| + if _, ok := d.send(homeop.Directory, replay); !ok { |
| + t.Fatal("provision") |
| + } |
| + if _, ok := d.send(homeop.Directory, replay); !ok { |
| + t.Fatal("replay refused") |
| + } |
| + want := []string{ |
| + "directory.initialize", |
| + "credential.owner-seed", |
| + "directory.seed-team", |
| + "directory.provision-consumer:docs", |
| + "directory.provision-consumer:calendar", |
| + "credential.register-consumer:docs", |
| + "directory.provision-consumer:sheets", |
| + } |
| + got := d.h.Requests() |
| + if !slices.Equal(got, want) { |
| + t.Fatalf("requests\n got %v\nwant %v", got, want) |
| + } |
| + got[0] = "tampered" |
| + if d.h.Requests()[0] != "directory.initialize" { |
| + t.Fatal("Requests returned the Home's own slice") |
| + } |
| +} |
diff --git a/homeop/protocol.go b/homeop/protocol.go| index acc9f52..2972848 100644 |
| --- a/homeop/protocol.go |
| +++ b/homeop/protocol.go |
| @@ -60,6 +60,9 @@ const ( |
| Baseline = "operator-attests-never-provisioned" |
| // ActivationPolicy is ActivationEvidence.Policy. |
| ActivationPolicy = "oficina/team-activation/v1" |
| + // ExistingActivationPolicy is the policy an adoption window's |
| + // activation carries; Home picks the policy from the window. |
| + ExistingActivationPolicy = "oficina/existing-app-activation/v1" |
| // ManifestContext is the consumer manifest digest's domain string. |
| ManifestContext = "oficina/home/consumer-manifest/v1" |
| ) |
| @@ -143,8 +146,25 @@ type Plan struct { |
| Label string `json:"label,omitzero"` |
| DisplayName string `json:"display_name,omitzero"` |
| Owner string `json:"owner,omitzero"` |
| - Issued int64 `json:"issued_at"` |
| - Expires int64 `json:"expires_at"` |
| + // ExistingTeam is the team SQID an adoption plan binds, never the |
| + // dashboard label (internal/operator/plan.go). |
| + ExistingTeam string `json:"existing_team,omitzero"` |
| + Issued int64 `json:"issued_at"` |
| + Expires int64 `json:"expires_at"` |
| +} |
| + |
| +// CanonicalOrigin is Alta's one copy of Home's closed registry of the |
| +// existing suite instances (internal/home/directorydata/canonical.go): the |
| +// six apps' consumer id is the slug and the origin is |
| +// https://<app>.oficina.works. It is empty for any other app. It lives |
| +// here, not in provision, because fakehome (imported by provision's tests) |
| +// needs it too. homecompat pins it against Home's own. |
| +func CanonicalOrigin(app string) string { |
| + switch app { |
| + case "docs", "sheets", "slides", "memoria", "calendar", "calls": |
| + return "https://" + app + ".oficina.works" |
| + } |
| + return "" |
| } |
| // InspectChallenge is <role>.inspect's signed request (inspect.go). |
diff --git a/homeop/protocol_test.go b/homeop/protocol_test.go| index 3b5ee8d..54a4837 100644 |
| --- a/homeop/protocol_test.go |
| +++ b/homeop/protocol_test.go |
| @@ -82,3 +82,48 @@ func TestManifestDigestIsOrderIndependent(t *testing.T) { |
| t.Fatal(a, b) |
| } |
| } |
| + |
| +// Home's Plan puts existing_team after owner and before issued_at, and |
| +// omits it when empty (internal/operator/plan.go). Home re-encodes what it |
| +// decodes and compares bytes, so the position is part of the contract. |
| +func TestPlanExistingTeamEncodesLikeHome(t *testing.T) { |
| + k, _ := family.Generate() |
| + plan := Plan{Role: Directory, Origin: "https://oficina.works", Installation: Token(), Registry: Token(), Device: Token(), PlanID: Token(), Kind: KindCreateTeam, Apps: []string{"docs"}, Label: "oficina", DisplayName: "Oficina", ExistingTeam: "Uk", Issued: 1, Expires: 900} |
| + raw, err := SignPlan(k, plan) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + p, _ := EnvelopePayload(raw) |
| + if !strings.Contains(string(p), `"display_name":"Oficina","existing_team":"Uk","issued_at"`) { |
| + t.Fatalf("plan payload %s", p) |
| + } |
| + // The credential role's plan carries an owner instead: still after it. |
| + owned := Plan{Role: Credential, Origin: "https://id.oficina.works", Installation: Token(), Registry: Token(), Device: Token(), PlanID: Token(), Kind: KindCreateTeam, Apps: []string{"docs"}, Owner: "o@x.test", ExistingTeam: "Uk", Issued: 1, Expires: 900} |
| + raw, _ = SignPlan(k, owned) |
| + p, _ = EnvelopePayload(raw) |
| + if !strings.Contains(string(p), `"owner":"o@x.test","existing_team":"Uk","issued_at"`) { |
| + t.Fatalf("credential plan payload %s", p) |
| + } |
| + plan.ExistingTeam = "" |
| + raw, _ = SignPlan(k, plan) |
| + p, _ = EnvelopePayload(raw) |
| + if strings.Contains(string(p), "existing_team") { |
| + t.Fatalf("empty existing_team encoded: %s", p) |
| + } |
| +} |
| + |
| +func TestCanonicalOrigin(t *testing.T) { |
| + for _, app := range []string{"docs", "sheets", "slides", "memoria", "calendar", "calls"} { |
| + if got := CanonicalOrigin(app); got != "https://"+app+".oficina.works" { |
| + t.Errorf("%s: %q", app, got) |
| + } |
| + } |
| + for _, app := range []string{"", "alta", "fichas", "Docs", "docs.oficina.works"} { |
| + if got := CanonicalOrigin(app); got != "" { |
| + t.Errorf("%q: %q", app, got) |
| + } |
| + } |
| + if ExistingActivationPolicy != "oficina/existing-app-activation/v1" || ExistingActivationPolicy == ActivationPolicy { |
| + t.Fatal(ExistingActivationPolicy) |
| + } |
| +} |
diff --git a/provision/apps.go b/provision/apps.go| index 13a8292..7875982 100644 |
| --- a/provision/apps.go |
| +++ b/provision/apps.go |
| @@ -127,11 +127,31 @@ func SortApps(apps []string) []string { |
| func RouteHost(label, app, account string) string { |
| return label + "-" + app + "." + account + ".oncarlos.com" |
| } |
| -func PublicHost(label, app string) string { return label + "." + app + "." + PublicDomain } |
| + |
| +// PublicHost, PublicOrigin and ConsumerID name a team's public tuple. The |
| +// adoption label is the one exception to label.app: Home's canonical |
| +// tuple for the six existing instances is host <app>.oficina.works and |
| +// consumer <app> (homeop.CanonicalOrigin). Every other label is unchanged. |
| +func PublicHost(label, app string) string { |
| + if label == AdoptionLabel { |
| + return app + "." + PublicDomain |
| + } |
| + return label + "." + app + "." + PublicDomain |
| +} |
| func PublicOrigin(label, app string) string { |
| return "https://" + PublicHost(label, app) |
| } |
| -func ConsumerID(label, app string) string { return label + "-" + app } |
| +func ConsumerID(label, app string) string { |
| + if label == AdoptionLabel { |
| + return app |
| + } |
| + return label + "-" + app |
| +} |
| + |
| +// AdoptionLabel is the directory label of the existing suite's team. It is |
| +// reserved (ReservedLabels), so no ordinary run reaches the canonical |
| +// answers above. |
| +const AdoptionLabel = "oficina" |
| // Class is a recipe key's treatment (§5). |
| type Class string |
| @@ -428,6 +448,17 @@ func teamKeys(p string, in Inputs) []Key { |
| } |
| } |
| +// TeamKeyNames is the names teamKeys produces for app: the <P>_TEAM_ five |
| +// an adoption must never write. |
| +func TeamKeyNames(app App) []string { |
| + keys := teamKeys(app.Prefix, Inputs{}) |
| + names := make([]string, len(keys)) |
| + for i, k := range keys { |
| + names[i] = k.Name |
| + } |
| + return names |
| +} |
| + |
| // operatorKeys is <P>_TEAM_OPERATOR_KEYS_BASE64: the directory's |
| // provisioning key as a one-entry []roster.Key, JSON, standard base64. |
| func operatorKeys(public string) string { |
diff --git a/provision/apps_test.go b/provision/apps_test.go| index 7e2beb5..6928390 100644 |
| --- a/provision/apps_test.go |
| +++ b/provision/apps_test.go |
| @@ -2,7 +2,10 @@ package provision |
| import ( |
| "slices" |
| + "strings" |
| "testing" |
| + |
| + "amadan.net/oficina/alta/homeop" |
| ) |
| // The recipes against each app's own config readers. Calls follows |
| @@ -60,6 +63,56 @@ func TestRosterRecipes(t *testing.T) { |
| // Memoria in team mode: MEMORIA_TEAM must be the first label of |
| // MEMORIA_ORIGIN (team_siblings.go refuses boot otherwise), and AI stays |
| // off: no MEMORIA_AI, TensorX key, siblings or logged mail, ever. |
| +// The adoption label answers Home's canonical tuple, from Alta's own |
| +// helpers; every other label keeps the label.app shape. |
| +func TestCanonicalHelpersForOficina(t *testing.T) { |
| + if AdoptionLabel != "oficina" { |
| + t.Fatal(AdoptionLabel) |
| + } |
| + for _, app := range []string{"docs", "sheets", "slides", "calendar", "calls", "memoria"} { |
| + if got := PublicOrigin(AdoptionLabel, app); got != homeop.CanonicalOrigin(app) || got != "https://"+app+".oficina.works" { |
| + t.Errorf("%s origin %q", app, got) |
| + } |
| + if got := PublicHost(AdoptionLabel, app); got != app+".oficina.works" { |
| + t.Errorf("%s host %q", app, got) |
| + } |
| + if got := ConsumerID(AdoptionLabel, app); got != app { |
| + t.Errorf("%s consumer %q", app, got) |
| + } |
| + if got := PublicOrigin("acme", app); got != "https://acme."+app+".oficina.works" { |
| + t.Errorf("acme origin %q", got) |
| + } |
| + if got := PublicHost("acme", app); got != "acme."+app+".oficina.works" { |
| + t.Errorf("acme host %q", got) |
| + } |
| + if got := ConsumerID("acme", app); got != "acme-"+app { |
| + t.Errorf("acme consumer %q", got) |
| + } |
| + } |
| +} |
| + |
| +// TeamKeyNames is the recipe's <P>_TEAM_ five, by name. |
| +func TestTeamKeyNamesMatchesRecipe(t *testing.T) { |
| + in := Inputs{Label: "lagged", TeamSQID: "Uk", Record: []byte("{}"), Home: HomeConfig{Directory: "https://oficina.works", Provisioner: "AQ"}} |
| + for _, app := range Apps { |
| + want := TeamKeyNames(app) |
| + if len(want) != 5 { |
| + t.Fatalf("%s: %v", app.Slug, want) |
| + } |
| + var got []string |
| + for _, k := range Recipe(app, in) { |
| + if strings.HasPrefix(k.Name, app.Prefix+"_TEAM_") { |
| + got = append(got, k.Name) |
| + } |
| + } |
| + slices.Sort(got) |
| + slices.Sort(want) |
| + if !slices.Equal(got, want) { |
| + t.Errorf("%s: recipe %v, TeamKeyNames %v", app.Slug, got, want) |
| + } |
| + } |
| +} |
| + |
| func TestMemoriaTeamLabelAndAIOff(t *testing.T) { |
| app, _ := AppBySlug("memoria") |
| vals := map[string]string{} |