witness: a platform deploys a customer's static site end to end
TestE2EPlatformCustomerStaticSite drives slice 1 through production wiring: a real console.Server over a DirStore with the example plan catalog, real device-flow logins, and the verbs in-process. An operator grants an account; its owner mints a platform credential; that credential creates two customers and mints a publish credential for each. The first deploys a static site that serves through a real edge, with the record read back from the store. "site" is then created in the second customer through its own credential, both credentials read their own site, and only then are cross-account reads and well-formed ships refused with the stdlib 404 in both directions, release lists unchanged. After the revoke all three credentials answer 401 and the site still serves.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+408
−0
platform_e2e_test.go+408 −0
CI failed — run details
diff --git a/platform_e2e_test.go b/platform_e2e_test.go| new file mode 100644 |
| index 000000000..e845ac49a |
| --- /dev/null |
| +++ b/platform_e2e_test.go |
| @@ -0,0 +1,408 @@ |
| +package main |
| + |
| +// The acceptance witness for platform accounts slice 1 (spec |
| +// docs/superpowers/specs/2026-11-19-platform-accounts-design.md): an |
| +// operator grants an account platform status, the platform's credential |
| +// creates two customer accounts and mints a short-lived credential for each, |
| +// one of those credentials deploys a static site that serves, each credential |
| +// is refused on the other customer's account, and both platform and customer |
| +// credentials are refused once the grant is revoked, while the site keeps |
| +// serving. |
| +// |
| +// Built the way TestE2EStaticDeployMintsPlatformHost (deploy_e2e_test.go) is: |
| +// a REAL console.Server over a DirStore and a real SQLite console database, |
| +// real device-flow logins, the verbs driven in-process through their real |
| +// entry points (so the watch can be pointed at a loopback edge through the |
| +// watchOrigin seam), and useTempCredentials keeping the operator's own |
| +// login, config, console and bucket out of reach. Every console record read |
| +// here is one the console wrote; the edge registry row stands in for the |
| +// box's reconcile pass, exactly as in the sibling. |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "fmt" |
| + "mime/multipart" |
| + "net/http" |
| + "net/http/httptest" |
| + "os" |
| + "path/filepath" |
| + "slices" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/console" |
| + "github.com/carlosframework/platform/internal/edge" |
| + "github.com/carlosframework/platform/internal/plans" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +func TestE2EPlatformCustomerStaticSite(t *testing.T) { |
| + // The catalog path is relative to the package directory, so it is read |
| + // before useTempCredentials moves the working directory to scratch space. |
| + catalog, err := plans.LoadCatalog(filepath.Join("internal", "plans", "testdata", "example-catalog.json")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + useTempCredentials(t) |
| + clearDeploymentEnv(t) |
| + checkNoRegistry := requireNoRegistryTouch(t) |
| + |
| + const ( |
| + operator = "ops@example.com" |
| + owner = "owner@example.com" |
| + app = "site" |
| + ) |
| + // A new app's pipeline is the default one, and a first deploy promotes |
| + // to its entry. |
| + entry := release.DefaultPipelineChannels()[0].Name |
| + ctx := context.Background() |
| + |
| + tmp := t.TempDir() |
| + relStore := release.NewDirStore(filepath.Join(tmp, "store")) |
| + seed, pubB64, err := release.GenerateKey() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + priv, err := release.ParseSigningKey(seed, "e2e") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + pub, err := release.ParsePublicKey(pubB64, "e2e") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + cst, err := console.Open(filepath.Join(tmp, "console.db")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { cst.Close() }) |
| + |
| + var srv *console.Server |
| + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + srv.ServeHTTP(w, r) |
| + })) |
| + t.Cleanup(ts.Close) |
| + srv, err = console.NewServer(console.Config{ |
| + Origin: ts.URL, |
| + Keymail: "http://keymail.invalid", |
| + Registry: filepath.Join(tmp, "registry.db"), |
| + Releases: relStore, |
| + ReleasePub: pub, |
| + Key: priv, |
| + AppScheme: "http", |
| + AppsDomain: "oncarlos.test", |
| + PlanCatalog: catalog, |
| + }, cst) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + // 1. The operator: a fleet operator, logged in through the device flow. |
| + // Their session is built here rather than saved to the credentials |
| + // file, so the file holds the owner alone and the verbs that read it |
| + // cannot pick the wrong person. |
| + if err := cst.SetOperator(operator, true); err != nil { |
| + t.Fatal(err) |
| + } |
| + opsToken, _ := e2eDeviceLogin(t, ts.URL, cst, operator, "e2e@ops") |
| + opsSess := &apiSession{c: newConsoleClient(ts.URL, opsToken), console: ts.URL, address: operator} |
| + |
| + // 2. The owner logs in, and creates the account that becomes the |
| + // platform through the console's CLI create door (what `carlos accounts |
| + // create` calls when this terminal is logged in). |
| + ownerToken, ownerExpires := e2eDeviceLogin(t, ts.URL, cst, owner, "e2e@owner") |
| + credFile, err := loadCredentials() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + credFile.put(credential{Console: ts.URL, Address: owner, Token: ownerToken, ExpiresAt: ownerExpires}) |
| + if err := credFile.save(); err != nil { |
| + t.Fatal(err) |
| + } |
| + var created struct { |
| + Sqid string `json:"sqid"` |
| + Owner string `json:"owner"` |
| + } |
| + if _, err := newConsoleClient(ts.URL, ownerToken).do(ctx, http.MethodPost, "/auth/cli/accounts", |
| + map[string]string{"name": "platform"}, &created); err != nil { |
| + t.Fatalf("create the platform account: %v", err) |
| + } |
| + p := created.Sqid |
| + if p == "" || created.Owner != owner { |
| + t.Fatalf("account create = %+v, want a sqid owned by %s", created, owner) |
| + } |
| + |
| + // 3. The operator grants it. |
| + var out strings.Builder |
| + if err := runAccountsPlatformWithSession(ctx, opsSess, []string{"--account", p, "--grant", "--max-customers", "5", |
| + "--plans", "free,personal", "--default-plan", "free", "--reason", "witness"}, &out); err != nil { |
| + t.Fatalf("accounts platform --grant: %v", err) |
| + } |
| + if want := fmt.Sprintf(cliPlatformCopyGranted, p) + "\n"; !strings.HasPrefix(out.String(), want) { |
| + t.Fatalf("grant output:\n%s\nwant it to start %q", out.String(), want) |
| + } |
| + |
| + // 4. The owner mints the platform credential: carlos services create |
| + // --role platform, the credential the platform's own server holds. |
| + buf := captureStdout(t) |
| + runServicesCreate([]string{"--account", p, "--role", "platform", "--json", "cms"}) |
| + var svc serviceCreatedJSON |
| + if err := json.Unmarshal(buf.Bytes(), &svc); err != nil { |
| + t.Fatalf("services create --json: %v\n%s", err, buf.String()) |
| + } |
| + if svc.Secret == "" || svc.Role != "platform" || svc.Account != p || svc.App != "" { |
| + t.Fatalf("services create = %+v, want an account-wide platform credential on %s", svc, p) |
| + } |
| + platformToken := svc.Secret |
| + |
| + // 5. As the platform's server: CARLOS_SERVICE_TOKEN and CARLOS_CONSOLE, |
| + // no login. Two customers. |
| + t.Setenv("CARLOS_CONSOLE", ts.URL) |
| + t.Setenv("CARLOS_SERVICE_TOKEN", platformToken) |
| + createCustomer := func(name, ref string) string { |
| + t.Helper() |
| + buf.Reset() |
| + if err := runPlatformCustomersCreate([]string{"--platform", p, "--name", name, "--ref", ref, "--json"}); err != nil { |
| + t.Fatalf("platform customers create %s: %v", name, err) |
| + } |
| + var res platformCreateReply |
| + if err := json.Unmarshal(buf.Bytes(), &res); err != nil { |
| + t.Fatalf("platform customers create --json: %v\n%s", err, buf.String()) |
| + } |
| + c := res.Customer |
| + if !res.Created || c.Account == "" || c.Account == p || c.Name != name || c.Ref != ref || c.Plan != "free" { |
| + t.Fatalf("customer create = %+v, want a new account %s (ref %s) on the default plan free", res, name, ref) |
| + } |
| + return c.Account |
| + } |
| + c1 := createCustomer("shop", "4812") |
| + c2 := createCustomer("bakery", "4813") |
| + if c1 == c2 { |
| + t.Fatalf("both customers are account %s", c1) |
| + } |
| + |
| + // 6. One per-customer credential each: Publish on the customer's |
| + // account, an hour by default. |
| + mint := func(customer string) string { |
| + t.Helper() |
| + buf.Reset() |
| + before := time.Now() |
| + if err := runPlatformCredentialsMint([]string{"--platform", p, "--customer", customer, "--json"}); err != nil { |
| + t.Fatalf("platform credentials mint %s: %v", customer, err) |
| + } |
| + after := time.Now() |
| + var res platformCredentialReply |
| + if err := json.Unmarshal(buf.Bytes(), &res); err != nil { |
| + t.Fatalf("platform credentials mint --json: %v\n%s", err, buf.String()) |
| + } |
| + if res.Token == "" || res.Account != customer || res.Role != "publish" || res.App != "" { |
| + t.Fatalf("mint = %+v, want an account-wide publish credential on %s", res, customer) |
| + } |
| + if !res.ExpiresAt.After(before) || res.ExpiresAt.After(after.Add(time.Hour)) { |
| + t.Fatalf("mint expires_at %s, want within the hour after %s", res.ExpiresAt, before) |
| + } |
| + return res.Token |
| + } |
| + t1 := mint(c1) |
| + t2 := mint(c2) |
| + if t1 == t2 || t1 == platformToken || t2 == platformToken { |
| + t.Fatal("a minted credential repeats another's token") |
| + } |
| + |
| + // The edge, and its row for c1's site: the reconcile pass's job on a |
| + // box, on the loopback host the watch dials. |
| + wantHost := app + "." + c1 + ".oncarlos.test" |
| + edgeReg, err := registry.Open(filepath.Join(tmp, "edge-registry.db")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { edgeReg.Close() }) |
| + ed, err := edge.New(edgeReg, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + ed.EnableStatic(relStore, pub, filepath.Join(tmp, "edge-cache")) |
| + ed.SetStaticRecheck(0) |
| + edgeSrv := httptest.NewServer(ed) |
| + t.Cleanup(edgeSrv.Close) |
| + if err := edgeReg.Upsert(registry.Route{ |
| + Host: "127.0.0.1", Kind: "static", Account: c1, App: app, Channel: entry, Status: "ready", |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := ed.Reload(); err != nil { |
| + t.Fatal(err) |
| + } |
| + origOrigin := watchOrigin |
| + watchOrigin = func(h string) string { |
| + if h != wantHost { |
| + t.Errorf("watch dialled %q, want the MINTED host %q", h, wantHost) |
| + } |
| + return edgeSrv.URL |
| + } |
| + t.Cleanup(func() { watchOrigin = origOrigin }) |
| + |
| + siteDir := filepath.Join(tmp, "site") |
| + if err := os.MkdirAll(siteDir, 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(filepath.Join(siteDir, "index.html"), []byte("hello"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + // 7. The customer's credential deploys the site: the app is created, |
| + // its host minted through the platform-host door, shipped, promoted |
| + // and watched until it serves. |
| + t.Setenv("CARLOS_SERVICE_TOKEN", t1) |
| + buf.Reset() |
| + runDeploy([]string{"-app", app, "-account", c1, "-kind", "static", "-version", "sha0001", |
| + "-channel", entry, "-timeout", "30s", siteDir}) |
| + deployed := buf.String() |
| + for _, wantLine := range []string{ |
| + "minted " + wantHost, |
| + "promoted " + app + " sha0001 -> " + entry, |
| + "live https://" + wantHost, |
| + } { |
| + if !strings.Contains(deployed, wantLine) { |
| + t.Fatalf("deploy stdout missing %q:\n%s", wantLine, deployed) |
| + } |
| + } |
| + rec, err := provision.GetRecord(ctx, relStore, c1, app, wantHost) |
| + if err != nil { |
| + t.Fatalf("record after the deploy: %v", err) |
| + } |
| + if rec.Kind != "static" || rec.Channel != entry { |
| + t.Fatalf("record Kind %q Channel %q, want static on %s", rec.Kind, rec.Channel, entry) |
| + } |
| + assertServes(t, edgeSrv.URL, "hello", "sha0001") |
| + |
| + // 8. (Astra r1-5) "site" in BOTH accounts, each made through its own |
| + // customer's credential, and each credential working in its own |
| + // account, so a 404 below is isolation and not a missing app. |
| + t.Setenv("CARLOS_SERVICE_TOKEN", t2) |
| + buf.Reset() |
| + runAppsCreate([]string{"--account", c2, "--app", app}) |
| + if want := "created app " + app + " in account " + c2; !strings.Contains(buf.String(), want) { |
| + t.Fatalf("apps create stdout missing %q:\n%s", want, buf.String()) |
| + } |
| + sess1 := platformE2ESession(ts.URL, t1) |
| + sess2 := platformE2ESession(ts.URL, t2) |
| + channelsPath := func(account string) string { return apiPath(apiAcct{Seg: account}, app, "/channels") } |
| + platformE2EStatus(t, sess2, channelsPath(c2), http.StatusOK, "T2 reads its own site's channels") |
| + platformE2EStatus(t, sess1, channelsPath(c1), http.StatusOK, "T1 reads its own site's channels") |
| + before1 := platformE2EReleases(t, sess1, c1) |
| + before2 := platformE2EReleases(t, sess2, c2) |
| + if !slices.Equal(before1, []string{"sha0001"}) || len(before2) != 0 { |
| + t.Fatalf("releases before: %s %v, %s %v; want sha0001 and none", c1, before1, c2, before2) |
| + } |
| + |
| + // 9. Only now, across accounts, a read and a ship in both directions: |
| + // the stdlib 404, and the other account's releases unchanged. |
| + platformE2EStatus(t, sess1, channelsPath(c2), http.StatusNotFound, "T1 reads c2's site") |
| + platformE2EStatus(t, sess2, channelsPath(c1), http.StatusNotFound, "T2 reads c1's site") |
| + platformE2EShipRefused(t, sess1, c2, siteDir, "sha0666", "T1 ships to c2's site") |
| + platformE2EShipRefused(t, sess2, c1, siteDir, "sha0667", "T2 ships to c1's site") |
| + if got := platformE2EReleases(t, sess2, c2); !slices.Equal(got, before2) { |
| + t.Fatalf("c2 releases after T1's refused ship = %v, want %v", got, before2) |
| + } |
| + if got := platformE2EReleases(t, sess1, c1); !slices.Equal(got, before1) { |
| + t.Fatalf("c1 releases after T2's refused ship = %v, want %v", got, before1) |
| + } |
| + |
| + // 10. The operator revokes. The platform credential and both customer |
| + // credentials stop working on their next request. |
| + out.Reset() |
| + if err := runAccountsPlatformWithSession(ctx, opsSess, []string{"--account", p, "--revoke", "--reason", "witness"}, &out); err != nil { |
| + t.Fatalf("accounts platform --revoke: %v", err) |
| + } |
| + if want := fmt.Sprintf(cliPlatformCopyRevoked, p, 3) + "\n"; out.String() != want { |
| + t.Fatalf("revoke output %q, want %q (the platform credential and two customer credentials)", out.String(), want) |
| + } |
| + platformE2EStatus(t, sess1, channelsPath(c1), http.StatusUnauthorized, "T1 after the revoke") |
| + platformE2EStatus(t, sess2, channelsPath(c2), http.StatusUnauthorized, "T2 after the revoke") |
| + platformE2EStatus(t, platformE2ESession(ts.URL, platformToken), platformCustomersPath(p), http.StatusUnauthorized, |
| + "the platform credential after the revoke") |
| + |
| + // 11. Revoking stops credentials, not sites. |
| + assertServes(t, edgeSrv.URL, "hello", "sha0001") |
| + |
| + checkNoRegistry() |
| +} |
| + |
| +// platformE2ESession is the session resolveMode builds from |
| +// CARLOS_SERVICE_TOKEN, for one credential. |
| +func platformE2ESession(consoleURL, token string) *apiSession { |
| + return &apiSession{c: newConsoleClient(consoleURL, token), console: consoleURL, address: serviceSessionLabel} |
| +} |
| + |
| +// platformE2EStatus GETs path with sess's credential and wants status; a |
| +// 404 must be the stdlib's, the byte-identical answer for an account the |
| +// caller cannot see. |
| +func platformE2EStatus(t *testing.T, sess *apiSession, path string, want int, what string) { |
| + t.Helper() |
| + status, body, err := sess.getJSON(context.Background(), path) |
| + if err != nil { |
| + t.Fatalf("%s: GET %s: %v", what, path, err) |
| + } |
| + if status != want { |
| + t.Fatalf("%s: GET %s = %d %s, want %d", what, path, status, body, want) |
| + } |
| + if want == http.StatusNotFound && string(body) != "404 page not found\n" { |
| + t.Fatalf("%s: GET %s 404 body %q, want the stdlib 404", what, path, body) |
| + } |
| +} |
| + |
| +// platformE2EReleases is the versions in account's site, read with sess. |
| +func platformE2EReleases(t *testing.T, sess *apiSession, account string) []string { |
| + t.Helper() |
| + rels, err := sess.releases(context.Background(), apiAcct{Seg: account}, "site") |
| + if err != nil { |
| + t.Fatalf("releases in %s: %v", account, err) |
| + } |
| + var out []string |
| + for _, r := range rels { |
| + out = append(out, r.Version) |
| + } |
| + return out |
| +} |
| + |
| +// platformE2EShipRefused POSTs a well-formed static ship of siteDir (the |
| +// meta part, then site.tar.gz, as apiSession.ship sends it) to account's |
| +// site with sess's credential, and wants the stdlib 404. |
| +func platformE2EShipRefused(t *testing.T, sess *apiSession, account, siteDir, version, what string) { |
| + t.Helper() |
| + tarball, err := edge.PackDir(siteDir) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + path := apiPath(apiAcct{Seg: account}, "site", "/releases") |
| + status, body, err := sess.c.doMultipart(context.Background(), path, func(mw *multipart.Writer) error { |
| + meta, err := json.Marshal(map[string]string{"version": version, "kind": "static"}) |
| + if err != nil { |
| + return err |
| + } |
| + part, err := mw.CreateFormField("meta") |
| + if err != nil { |
| + return err |
| + } |
| + if _, err := part.Write(meta); err != nil { |
| + return err |
| + } |
| + file, err := mw.CreateFormFile("site.tar.gz", "site.tar.gz") |
| + if err != nil { |
| + return err |
| + } |
| + _, err = file.Write(tarball) |
| + return err |
| + }) |
| + if err != nil { |
| + t.Fatalf("%s: POST %s: %v", what, path, err) |
| + } |
| + if status != http.StatusNotFound || string(body) != "404 page not found\n" { |
| + t.Fatalf("%s: POST %s = %d %q, want the stdlib 404", what, path, status, body) |
| + } |
| +} |