carlos / platform Public

tests: owner gates meet main's new tests; fixture mints leave no owner

Two tests merged from main drive the CLI detach and trash doors with a
member's token; both doors are owner-only on this branch (H4-M2, H4-M7),
so the tests make that member an owner. serviceToken, teamToken and the
backups mint helper now add their minter as an owner only for the mint
and delete that row by hand after it, so the plan-notice tests count
the owners they made and nothing else.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c3ae49c2dd0bb35799ac6d7f50ebe14591b8f27d parent 072b98f
5 files changed, +32 −9
  • internal/console/apibackups_test.go +1 −1
  • internal/console/apiservices_test.go +1 −1
  • internal/console/seedholdreview_test.go +2 −0
  • internal/console/seedslice3review_test.go +2 −0
  • internal/console/svcfixture_test.go +26 −7
diff --git a/internal/console/apibackups_test.go b/internal/console/apibackups_test.go
index 189d72971..81b4643d7 100644
--- a/internal/console/apibackups_test.go
+++ b/internal/console/apibackups_test.go
@@ -159,7 +159,7 @@ func backupsToken(t *testing.T, st *Store, accountID int64, name, app string, ro
default:
return serviceToken(t, st, accountID, name, app, role)
}
- mustMintingOwner(t, st, accountID, "paul@example.test")
+ defer mintAsOwner(t, st, accountID, "paul@example.test")()
tok, err := st.NewServicePrincipalScoped(accountID, name, app, role, rungs, commands, "paul@example.test", time.Now())
if err != nil {
t.Fatalf("mint %s %q: %v", role, name, err)
diff --git a/internal/console/apiservices_test.go b/internal/console/apiservices_test.go
index e7918c151..9896ac361 100644
--- a/internal/console/apiservices_test.go
+++ b/internal/console/apiservices_test.go
@@ -836,7 +836,7 @@ func TestServiceCredentialCannotBeAccountScoped(t *testing.T) {
}
// Bound to an app, it mints (as an owner: H4-M1 review round 2).
- mustMintingOwner(t, fx.st, OpsAccountID, "op@keymail.dev")
+ defer mintAsOwner(t, fx.st, OpsAccountID, "op@keymail.dev")()
if _, err := fx.st.NewServicePrincipal(OpsAccountID, "svc-app", "kass", svcrole.Service, "op@keymail.dev", now); err != nil {
t.Fatalf("app-scoped Service credential: %v", err)
}
diff --git a/internal/console/seedholdreview_test.go b/internal/console/seedholdreview_test.go
index 3b2a06445..3e2115a99 100644
--- a/internal/console/seedholdreview_test.go
+++ b/internal/console/seedholdreview_test.go
@@ -78,6 +78,8 @@ func TestDomainDetachRefusesHeldFleetFileSeed(t *testing.T) {
mode := map[bool]string{false: "lifetimes off", true: "lifetimes on"}[on]
t.Run(mode+", the CLI door", func(t *testing.T) {
fx, member, _ := holdWorld(t, on)
+ // Detach is the owner's at the CLI door too (security hunt H4-M7).
+ makeOwner(t, fx, "alice@keymail.dev")
code, _, out := rawReq(t, http.MethodDelete, domainsURL(fx, "bab", "titogo")+"/"+holdHost, member, "")
if code != http.StatusConflict || errorOf(t, out) != held {
t.Fatalf("detach = %d %s, want 409 %q", code, out, held)
diff --git a/internal/console/seedslice3review_test.go b/internal/console/seedslice3review_test.go
index b48bd5e26..3629ccbb1 100644
--- a/internal/console/seedslice3review_test.go
+++ b/internal/console/seedslice3review_test.go
@@ -23,6 +23,8 @@ import (
// box's rollback and the finish, lets the trash through.
func TestTrashAppRefusesHeldFleetFileSeed(t *testing.T) {
f := newFleetFileFixture(t)
+ // Trash is the owner's at the CLI door too (security hunt H4-M2).
+ makeOwner(t, f.fx, "alice@keymail.dev")
ctx := context.Background()
id := f.fleetSeedRecord(t, fileHost, seeds.StateAborted, "", "", time.Now())
trash := func() (int, string) {
diff --git a/internal/console/svcfixture_test.go b/internal/console/svcfixture_test.go
index 89b014096..7630c36e4 100644
--- a/internal/console/svcfixture_test.go
+++ b/internal/console/svcfixture_test.go
@@ -19,7 +19,7 @@ func serviceToken(t *testing.T, st *Store, accountID int64, name, app string, ro
// scope is "alta", which teamToken takes a caller's choice of.
return teamToken(t, st, accountID, name, app, "alta")
}
- mustMintingOwner(t, st, accountID, "paul@example.test")
+ defer mintAsOwner(t, st, accountID, "paul@example.test")()
raw, err := st.NewServicePrincipal(accountID, name, app, role, "paul@example.test", time.Now())
if err != nil {
t.Fatalf("NewServicePrincipal(%q): %v", name, err)
@@ -31,7 +31,7 @@ func serviceToken(t *testing.T, st *Store, accountID int64, name, app string, ro
// its bearer: serviceToken for the one role that takes a scope.
func teamToken(t *testing.T, st *Store, accountID int64, name, app, scope string) string {
t.Helper()
- mustMintingOwner(t, st, accountID, "paul@example.test")
+ defer mintAsOwner(t, st, accountID, "paul@example.test")()
raw, err := st.NewServicePrincipalWithScopeContext(context.Background(), accountID, name, app, svcrole.Team, nil, nil, scope, "paul@example.test", time.Now())
if err != nil {
t.Fatalf("NewServicePrincipalWithScope(%q): %v", name, err)
@@ -50,17 +50,36 @@ func ownerMintsServices(t *testing.T, fx *consoleFixture) {
}
// mustMintingOwner makes address an owner of accountID when it holds no
-// membership there: a service credential mint re-reads its minter's role
-// and refuses anyone but an owner (security hunt H4-M1, review round 2).
-// A member is left a member, so a test that mints as one meets the refusal.
-func mustMintingOwner(t *testing.T, s *Store, accountID int64, address string) {
+// membership there, and reports whether it did: a service credential mint
+// re-reads its minter's role and refuses anyone but an owner (security
+// hunt H4-M1, review round 2). A member is left a member, so a test that
+// mints as one meets the refusal.
+func mustMintingOwner(t *testing.T, s *Store, accountID int64, address string) bool {
t.Helper()
if role, err := s.Role(accountID, address); err != nil {
t.Fatal(err)
} else if role != "" {
- return
+ return false
}
if err := s.AddMember(accountID, address, RoleOwner, time.Now()); err != nil {
t.Fatal(err)
}
+ return true
+}
+
+// mintAsOwner is mustMintingOwner for one mint: the returned func, run
+// after the mint, deletes the membership row it added (by hand, so nothing
+// is revoked), leaving the world's members as the test made them. A test
+// that drives an owner gate with the credential makes its minter an owner
+// itself (ownerMintsServices).
+func mintAsOwner(t *testing.T, s *Store, accountID int64, address string) func() {
+ t.Helper()
+ if !mustMintingOwner(t, s, accountID, address) {
+ return func() {}
+ }
+ return func() {
+ if _, err := s.db.Exec(`DELETE FROM memberships WHERE account_id = ? AND address = ?`, accountID, address); err != nil {
+ t.Fatal(err)
+ }
+ }
}