console: point a bought domain at an app through the attach door
POST /a/{sqid}/apps/{app}/domains/point (form field "domain") and its CLI
API twin POST /api/cli/apps/{account}/{app}/domains/point. The browser
door is the attach door's gate in its order (accountApp, CSRF, owner)
plus domainBuyReady; the API door is service-closed and requires a
person, the app in the account, the owner and domainBuyReady. Both are
gated off on a host-claim console, as buying is.
pointBoughtDomain refuses a domain that is not one of the account's
registrations with the neutral 404 and one still being bought with a
409, writes the zone's canonical pointed set (the purchase engine's
apex and proof source, now shared as pointedManagedSet), then attaches
the apex and www with attachDomain, returning its first refusal as is.
No admission or retry logic of its own; a repeat completes a partial
attach. Copy is a draft.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 files changed,
+603
−13
docs/parity.md+3 −2internal/console/domainbuy.go+21 −9internal/console/domainbuy_copy.go+8 −0internal/console/domainpoint.go+147 −0internal/console/domainpoint_test.go+409 −0internal/console/linkedpolicy.go+2 −0internal/console/nobucket_posts_test.go+1 −0internal/console/routedecls.go+6 −0internal/console/svcroutes_test.go+5 −2parity/parity.tsv+1 −0
diff --git a/docs/parity.md b/docs/parity.md| index 1e117a830..90f838def 100644 |
| --- a/docs/parity.md |
| +++ b/docs/parity.md |
| @@ -14,8 +14,8 @@ CLI rows are checked against the command registry (`parity/cli.tsv`). |
| | partial | 9 | |
| | gap | 65 | |
| | cli-only | 17 | |
| -| console-only | 17 | |
| -| Total | 152 | |
| +| console-only | 18 | |
| +| Total | 153 | |
| ## account |
| @@ -106,6 +106,7 @@ CLI rows are checked against the command registry (`parity/cli.tsv`). |
| | domains-attach | both | `domains attach`<br>`domains detach` | `POST /a/{sqid}/apps/{app}/domains/attach`<br>`POST /a/{sqid}/apps/{app}/domains/detach` | | | |
| | domains-verify | partial | `domains verify` | `POST /a/{sqid}/apps/{app}/domains/attach` | | There is no Verify button; attaching again verifies. | |
| | domains-buy | both | `domains check`<br>`domains buy` | `GET /a/{sqid}/apps/{app}/domains/buy`<br>`POST /a/{sqid}/apps/{app}/domains/check`<br>`POST /a/{sqid}/apps/{app}/domains/buy`<br>`GET /a/{sqid}/apps/{app}/domains/purchases/{id}`<br>`GET /a/{sqid}/apps/{app}/domains/purchases/{id}/status` | | | |
| +| domains-point | console-only | | `POST /a/{sqid}/apps/{app}/domains/point` | | Pointing a bought domain at an app; the CLI verb comes later. | |
| | domains-paths | gap | `domains paths` | | [wp-settings](#wp-settings) | | |
| | domains-placements | gap | `domains placements` | | [wp-settings](#wp-settings) | | |
| | gate | both | `gate set`<br>`gate clear`<br>`gate list` | `POST /a/{sqid}/apps/{app}/gate`<br>`GET /a/{sqid}/apps/{app}/settings/{section}` | | | |
diff --git a/internal/console/domainbuy.go b/internal/console/domainbuy.go| index b0f517c8f..4f3489e62 100644 |
| --- a/internal/console/domainbuy.go |
| +++ b/internal/console/domainbuy.go |
| @@ -709,6 +709,25 @@ func (s *Server) purchaseManagedSet(ctx context.Context, p *DomainPurchase) (zon |
| if p.App == "" { |
| return zonehost.ManagedSet{}, nil |
| } |
| + sqid := "" |
| + if s.cfg.DomainProof { |
| + acct, err := s.store.AccountByID(p.AccountID) |
| + if err != nil { |
| + return zonehost.ManagedSet{}, err |
| + } |
| + if acct == nil { |
| + return zonehost.ManagedSet{}, sql.ErrNoRows |
| + } |
| + sqid = acct.Sqid |
| + } |
| + return s.pointedManagedSet(ctx, p.Domain, sqid) |
| +} |
| + |
| +// pointedManagedSet is the canonical pointed set for domain: the apex |
| +// targets (the steering source, or the edge addresses without one), www, |
| +// and, when DomainProof is on, the apex and www proofs for the account |
| +// sqid. Shared by the purchase engine and the point door (domainpoint.go). |
| +func (s *Server) pointedManagedSet(ctx context.Context, domain, sqid string) (zonehost.ManagedSet, error) { |
| source := s.cfg.DomainApex |
| if source == nil { |
| source = zonehost.StaticApex(s.dnsTargets(ctx).EdgeIPs) |
| @@ -719,19 +738,12 @@ func (s *Server) purchaseManagedSet(ctx context.Context, p *DomainPurchase) (zon |
| } |
| var proof func(host string) zonehost.TXT |
| if s.cfg.DomainProof { |
| - acct, err := s.store.AccountByID(p.AccountID) |
| - if err != nil { |
| - return zonehost.ManagedSet{}, err |
| - } |
| - if acct == nil { |
| - return zonehost.ManagedSet{}, sql.ErrNoRows |
| - } |
| proof = func(host string) zonehost.TXT { |
| - txt := s.domainChallenge(host, acct.Sqid) |
| + txt := s.domainChallenge(host, sqid) |
| return zonehost.TXT{Name: txt.Name, Value: txt.Value} |
| } |
| } |
| - return zonehost.ManagedFor(p.Domain, apex, proof), nil |
| + return zonehost.ManagedFor(domain, apex, proof), nil |
| } |
| // capturedPurchase finishes a paid purchase. With no app it is done. With |
diff --git a/internal/console/domainbuy_copy.go b/internal/console/domainbuy_copy.go| index fd295dcda..d0f4a84f7 100644 |
| --- a/internal/console/domainbuy_copy.go |
| +++ b/internal/console/domainbuy_copy.go |
| @@ -132,3 +132,11 @@ var accountDomainsCopy = struct{ Named, Count, Unreadable string }{ |
| func accountDomainsRefusal(domains []string) string { |
| return fmt.Sprintf(accountDomainsCopy.Named, strings.Join(domains, ", ")) |
| } |
| + |
| +// domainPointCopy is the point door's (Plan 2a Task 7). DRAFTS |
| +// (2026-11-19), awaiting the copy pass. Pointed takes {domain} and {app}. |
| +var domainPointCopy = struct{ Pointed, Buying, Unavailable string }{ |
| + Pointed: "{domain} now points at {app}.", |
| + Buying: "this domain is still being bought. point it once the purchase has finished", |
| + Unavailable: "could not point this domain right now. try again in a minute", |
| +} |
diff --git a/internal/console/domainpoint.go b/internal/console/domainpoint.go| new file mode 100644 |
| index 000000000..bc29a0b3c |
| --- /dev/null |
| +++ b/internal/console/domainpoint.go |
| @@ -0,0 +1,147 @@ |
| +// Pointing a bought domain at an app (domain registration Plan 2a, spec |
| +// §11): an app-scoped door beside the attach door (appdomains.go), with the |
| +// attach door's gate plus domainBuyReady. It writes the bought zone's |
| +// canonical pointed set and then attaches the apex and www with the same |
| +// attachDomain call the attach door makes. It adds no admission or retry |
| +// logic of its own: destination admission (linked, temporary, plan, claims |
| +// held by another app or account, pending proofs) is attachDomain's, and a |
| +// retry of the same call completes a partial or pending attach. |
| +// |
| +// Moving a domain between apps is Detach on its current app, then Point. |
| +package console |
| + |
| +import ( |
| + "context" |
| + "log" |
| + "net/http" |
| + "strings" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/zonehost" |
| +) |
| + |
| +// handleAppDomainPoint is POST /a/{sqid}/apps/{app}/domains/point, form |
| +// field "domain". The gate is handleAppDomainAttach's, in its order |
| +// (session and app via accountApp, CSRF, owner with the byte-identical |
| +// 404), then domainBuyReady: pointing is part of buying, which is off on a |
| +// host-claim console. |
| +func (s *Server) handleAppDomainPoint(w http.ResponseWriter, r *http.Request) { |
| + addr, raw, acct, role, app, ok := s.accountApp(w, r) |
| + if !ok { |
| + return |
| + } |
| + if !csrfFormOK(r, raw) { |
| + s.renderMessage(w, r, http.StatusForbidden, "Refused", "Cross-site request blocked.") |
| + return |
| + } |
| + if role != RoleOwner || !s.domainBuyReady() { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + domain := normalizePointDomain(r.FormValue("domain")) |
| + ctx, cancel := context.WithTimeout(r.Context(), 20*time.Second) |
| + defer cancel() |
| + if ref := s.pointBoughtDomain(ctx, acct, app, domain, addr); ref != nil { |
| + s.renderDoorRefusal(w, r, ref) |
| + return |
| + } |
| + s.setFlash(w, "ok", strings.NewReplacer("{domain}", domain, "{app}", app).Replace(domainPointCopy.Pointed)) |
| + http.Redirect(w, r, appSettingsURL(acct.Sqid, app, "domains"), http.StatusSeeOther) |
| +} |
| + |
| +// handleAPIDomainPoint is the CLI twin: POST |
| +// /api/cli/apps/{account}/{app}/domains/point {"domain"}. Unlike the attach |
| +// API it admits no service role (registered with the zero Set); the |
| +// handler requires a person, the app in this account (apiAccountApp, the |
| +// membership check domainsGate makes), the owner and domainBuyReady, then |
| +// the domains rate ceiling. |
| +func (s *Server) handleAPIDomainPoint(w http.ResponseWriter, r *http.Request) { |
| + if !s.apiPerson(w, r) { |
| + return |
| + } |
| + addr, acct, app, ok := s.apiAccountApp(w, r) |
| + if !ok { |
| + return |
| + } |
| + role, err := s.store.Role(acct.ID, addr) |
| + if err != nil || role != RoleOwner || !s.domainBuyReady() { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + p, _ := principalFrom(r.Context()) |
| + if !s.allowDomains(p, time.Now()) { |
| + jsonError(w, http.StatusTooManyRequests, domainBuyCopy["rate"]) |
| + return |
| + } |
| + var in struct { |
| + Domain string `json:"domain"` |
| + } |
| + if !readJSONStrictLimit(w, r, &in, 8<<10) { |
| + return |
| + } |
| + domain := normalizePointDomain(in.Domain) |
| + ctx, cancel := context.WithTimeout(r.Context(), 20*time.Second) |
| + defer cancel() |
| + if ref := s.pointBoughtDomain(ctx, acct, app, domain, auditActor(p, acct)); ref != nil { |
| + writeDoorRefusalJSON(w, r, ref) |
| + return |
| + } |
| + writeJSON(w, http.StatusOK, map[string]any{"domain": domain, "app": app}) |
| +} |
| + |
| +func normalizePointDomain(domain string) string { |
| + return strings.TrimSuffix(strings.ToLower(strings.TrimSpace(domain)), ".") |
| +} |
| + |
| +// pointBoughtDomain points acct's registered domain at app: |
| +// |
| +// 1. domain must be one of the account's registrations, else the neutral |
| +// not-found refusal, and must have no purchase still in flight. |
| +// Terminal purchase states never become live again and a registered |
| +// domain cannot be bought twice, so this needs no lock shared with the |
| +// purchase pass. |
| +// 2. The zone gets the canonical pointed set, so a repeat is a no-op. If |
| +// a later step refuses, the zone answers with the edge addresses for a |
| +// name no app claims, which serves nothing. |
| +// 3. The apex, then www, are attached with attachDomain, as the purchase |
| +// engine's captured step does. The first refusal is returned as the |
| +// attach door returns it. |
| +func (s *Server) pointBoughtDomain(ctx context.Context, acct *Account, app, domain, principal string) *doorRefusal { |
| + if domain == "" { |
| + return &doorRefusal{Status: http.StatusNotFound} |
| + } |
| + reg, err := s.store.DomainRegistrationFor(ctx, acct.ID, domain) |
| + if err != nil { |
| + log.Printf("console: point %s/%s %s: registration: %v", acct.Sqid, app, domain, err) |
| + return pointUnavailable() |
| + } |
| + if reg == nil { |
| + return &doorRefusal{Status: http.StatusNotFound} |
| + } |
| + live, err := s.ownLiveDomainPurchase(ctx, acct.ID, domain) |
| + if err != nil { |
| + log.Printf("console: point %s/%s %s: purchases: %v", acct.Sqid, app, domain, err) |
| + return pointUnavailable() |
| + } |
| + if live != nil { |
| + return &doorRefusal{Status: http.StatusConflict, Msg: domainPointCopy.Buying} |
| + } |
| + m, err := s.pointedManagedSet(ctx, domain, acct.Sqid) |
| + if err == nil { |
| + err = s.cfg.ZoneHost.SetManaged(ctx, zonehost.Zone{ID: reg.ZoneID, Domain: reg.Domain}, m) |
| + } |
| + if err != nil { |
| + log.Printf("console: point %s/%s %s: zone: %v", acct.Sqid, app, domain, err) |
| + return pointUnavailable() |
| + } |
| + for _, host := range []string{domain, "www." + domain} { |
| + if _, ref := s.attachDomain(ctx, acct, app, host, "", "", principal); ref != nil { |
| + return ref |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +func pointUnavailable() *doorRefusal { |
| + return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: domainPointCopy.Unavailable} |
| +} |
diff --git a/internal/console/domainpoint_test.go b/internal/console/domainpoint_test.go| new file mode 100644 |
| index 000000000..1b88244d9 |
| --- /dev/null |
| +++ b/internal/console/domainpoint_test.go |
| @@ -0,0 +1,409 @@ |
| +package console |
| + |
| +// Plan 2a Task 7: pointing a bought domain at an app. The door is the |
| +// attach door's gate plus domainBuyReady; it writes the zone's canonical |
| +// pointed set and then attaches the apex and www with attachDomain, so every |
| +// claim refusal, pending proof and retry is the attach door's. |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "io" |
| + "net/http" |
| + "net/url" |
| + "os" |
| + "reflect" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/domains" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/svcrole" |
| + "github.com/carlosframework/platform/internal/zonehost" |
| +) |
| + |
| +const pointOwnerDomain = "shop.com" |
| + |
| +func pointOwner(f *purchaseFixture) string { return "owner" + f.acct.Sqid + "@example.com" } |
| + |
| +// boughtUnpointed buys shop.com with no app: registered, zone unpointed, |
| +// no claims. |
| +func (f *purchaseFixture) boughtUnpointed(t *testing.T) *DomainPurchase { |
| + t.Helper() |
| + p := f.startWith(t, "", purchaseContactSelection{New: newContact()}) |
| + f.authorise(t, p) |
| + p = f.until(t, p.ID, PurchaseDone) |
| + f.assertUnpointed(t, p.Domain) |
| + f.assertNoClaims(t, p.Domain) |
| + return p |
| +} |
| + |
| +// ownerBrowser is the account owner signed in, with the session's CSRF token. |
| +func (f *purchaseFixture) ownerBrowser(t *testing.T) (*http.Client, string) { |
| + t.Helper() |
| + c := newBrowser(t) |
| + f.setUser(pointOwner(f)) |
| + signUp(t, f.consoleFixture, c, "point-owner") |
| + return c, sessionToken(t, f.consoleFixture, c) |
| +} |
| + |
| +func (f *purchaseFixture) appURL(app, path string) string { |
| + return f.ts.URL + "/a/" + f.acct.Sqid + "/apps/" + app + path |
| +} |
| + |
| +// wantPointed: the zone holds exactly the canonical pointed set. |
| +func (f *purchaseFixture) wantPointed(t *testing.T, domain string) { |
| + t.Helper() |
| + var proof func(string) zonehost.TXT |
| + if f.srv.cfg.DomainProof { |
| + proof = func(host string) zonehost.TXT { |
| + c := f.srv.domainChallenge(host, f.acct.Sqid) |
| + return zonehost.TXT{Name: c.Name, Value: c.Value} |
| + } |
| + } |
| + want := zonehost.ManagedFor(domain, []zonehost.ApexTarget{{IP: "192.0.2.10"}}, proof) |
| + if got := f.zone.Managed[domain]; !reflect.DeepEqual(got, want) { |
| + t.Fatalf("managed set:\n got %+v\nwant %+v", got, want) |
| + } |
| +} |
| + |
| +func (f *purchaseFixture) claim(t *testing.T, host string) domains.Claim { |
| + t.Helper() |
| + c, err := domains.GetClaim(context.Background(), f.rel, host) |
| + if err != nil { |
| + t.Fatalf("claim %s: %v", host, err) |
| + } |
| + return *c |
| +} |
| + |
| +func (f *purchaseFixture) wantClaimedBy(t *testing.T, domain, app string) { |
| + t.Helper() |
| + for _, host := range []string{domain, "www." + domain} { |
| + if c := f.claim(t, host); c.Account != f.acct.Sqid || c.App != app { |
| + t.Fatalf("claim %s: %+v, want %s/%s", host, c, f.acct.Sqid, app) |
| + } |
| + } |
| +} |
| + |
| +func setCalls(f *purchaseFixture, domain string) int { |
| + return purchaseCalls(f.zone.Calls, "set:"+domain) |
| +} |
| + |
| +func TestPointUnpointedDomainWritesApexAndAttaches(t *testing.T) { |
| + f := newPurchaseFixture(t) |
| + f.srv.cfg.DomainProof = true |
| + p := f.boughtUnpointed(t) |
| + c, csrf := f.ownerBrowser(t) |
| + before := setCalls(f, p.Domain) |
| + status, loc, body := postForm(t, c, f.appURL("kass", "/domains/point"), url.Values{"csrf": {csrf}, "domain": {" SHOP.com "}}) |
| + if status != http.StatusSeeOther || loc != appSettingsURL(f.acct.Sqid, "kass", "domains") { |
| + t.Fatalf("point = %d %q:\n%s", status, loc, body) |
| + } |
| + if n := setCalls(f, p.Domain) - before; n != 1 { |
| + t.Fatalf("SetManaged calls = %d, want 1", n) |
| + } |
| + f.wantPointed(t, p.Domain) |
| + f.wantClaimedBy(t, p.Domain, "kass") |
| + if c := f.claim(t, p.Domain); c.CreatedBy != pointOwner(f) { |
| + t.Fatalf("claim principal: %+v", c) |
| + } |
| + // A repeat is the same canonical set and a re-attach. |
| + if ref := f.srv.pointBoughtDomain(context.Background(), f.acct, "kass", p.Domain, pointOwner(f)); ref != nil { |
| + t.Fatalf("repeat: %+v", ref) |
| + } |
| + f.wantPointed(t, p.Domain) |
| + f.wantClaimedBy(t, p.Domain, "kass") |
| +} |
| + |
| +func TestPointOtherAppsClaimRefusedNothingDetached(t *testing.T) { |
| + f := newPurchaseFixture(t) |
| + p := f.boughtUnpointed(t) |
| + if _, err := f.st.CreateAppIn(f.acct.ID, "b", "buyer@example.test", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + putPurgeClaim(t, f.rel, f.acct.Sqid, "b", p.Domain, false) |
| + putPurgeClaim(t, f.rel, "zzz", "theirs", "www."+p.Domain, false) |
| + apex, www := f.claim(t, p.Domain), f.claim(t, "www."+p.Domain) |
| + |
| + ctx := context.Background() |
| + ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", p.Domain, pointOwner(f)) |
| + _, attachRef := f.srv.attachDomain(ctx, f.acct, "kass", p.Domain, "", "", pointOwner(f)) |
| + if ref == nil || attachRef == nil || *ref != *attachRef { |
| + t.Fatalf("point refusal %+v, attach door's %+v", ref, attachRef) |
| + } |
| + if got := f.claim(t, p.Domain); !reflect.DeepEqual(got, apex) { |
| + t.Fatalf("apex claim changed: %+v -> %+v", apex, got) |
| + } |
| + if got := f.claim(t, "www."+p.Domain); !reflect.DeepEqual(got, www) { |
| + t.Fatalf("www claim changed: %+v -> %+v", www, got) |
| + } |
| +} |
| + |
| +func TestPointRetryCompletesPartialAttach(t *testing.T) { |
| + f := newPurchaseFixture(t) |
| + p := f.boughtUnpointed(t) |
| + ctx := context.Background() |
| + putPurgeClaim(t, f.rel, "zzz", "theirs", "www."+p.Domain, false) |
| + |
| + before := setCalls(f, p.Domain) |
| + ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", p.Domain, pointOwner(f)) |
| + if ref == nil { |
| + t.Fatal("the www attach was refused, but the point succeeded") |
| + } |
| + if n := setCalls(f, p.Domain) - before; n != 1 { |
| + t.Fatalf("first call: SetManaged calls = %d, want 1", n) |
| + } |
| + f.wantPointed(t, p.Domain) |
| + apex := f.claim(t, p.Domain) |
| + if apex.App != "kass" { |
| + t.Fatalf("apex not attached by the first call: %+v", apex) |
| + } |
| + |
| + // The foreign holder lets go; the same call again completes the attach. |
| + if err := f.rel.Delete(ctx, domains.ClaimKey("www."+p.Domain)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", p.Domain, pointOwner(f)); ref != nil { |
| + t.Fatalf("retry: %+v", ref) |
| + } |
| + if n := setCalls(f, p.Domain) - before; n != 2 { |
| + t.Fatalf("after retry: SetManaged calls = %d, want 2", n) |
| + } |
| + f.wantPointed(t, p.Domain) |
| + f.wantClaimedBy(t, p.Domain, "kass") |
| + if got := f.claim(t, p.Domain); !reflect.DeepEqual(got, apex) { |
| + t.Fatalf("apex claim changed on retry: %+v -> %+v", apex, got) |
| + } |
| +} |
| + |
| +func TestPointRefusedWhilePurchaseLive(t *testing.T) { |
| + f := newPurchaseFixture(t) |
| + p := f.startWith(t, "", purchaseContactSelection{New: newContact()}) |
| + f.authorise(t, p) |
| + f.until(t, p.ID, PurchaseRegistered) |
| + if r, err := f.st.DomainRegistrationFor(context.Background(), f.acct.ID, p.Domain); err != nil || r == nil { |
| + t.Fatalf("registration while registered: %+v %v", r, err) |
| + } |
| + before := setCalls(f, p.Domain) |
| + ref := f.srv.pointBoughtDomain(context.Background(), f.acct, "kass", p.Domain, pointOwner(f)) |
| + if ref == nil || ref.Status != http.StatusConflict || ref.Msg != domainPointCopy.Buying { |
| + t.Fatalf("refusal: %+v", ref) |
| + } |
| + if setCalls(f, p.Domain) != before { |
| + t.Fatal("a refused point wrote the zone") |
| + } |
| + f.assertNoClaims(t, p.Domain) |
| +} |
| + |
| +func TestPointAfterPurgeSucceeds(t *testing.T) { |
| + f := newPurchaseFixture(t) |
| + ctx := context.Background() |
| + p := f.start(t) |
| + f.authorise(t, p) |
| + f.until(t, p.ID, PurchaseDone) |
| + f.wantClaimedBy(t, p.Domain, "kass") |
| + if _, err := f.st.CreateAppIn(f.acct.ID, "web", "buyer@example.test", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.srv.cfg.Registry = attachRegistry(t, |
| + registry.Route{Host: "app.example.test", Account: f.acct.Sqid, App: "kass", Kind: "static", Status: "ready", Channel: "canary/live"}, |
| + registry.Route{Host: "web.example.test", Account: f.acct.Sqid, App: "web", Kind: "static", Status: "ready", Channel: "canary/live"}) |
| + // kass is trashed long enough ago that the hourly sweep purges it, |
| + // releasing its claims (Task 6). |
| + old := time.Now().Add(-31 * 24 * time.Hour) |
| + if err := release.TrashApp(ctx, f.rel, f.acct.Sqid, "kass", pointOwner(f), old); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := f.st.TrashAppRow(f.acct.ID, "kass", old); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.srv.trashSweep(ctx, time.Now()) |
| + f.assertNoClaims(t, p.Domain) |
| + |
| + if ref := f.srv.pointBoughtDomain(ctx, f.acct, "web", p.Domain, pointOwner(f)); ref != nil { |
| + t.Fatalf("point after purge: %+v", ref) |
| + } |
| + f.wantPointed(t, p.Domain) |
| + f.wantClaimedBy(t, p.Domain, "web") |
| +} |
| + |
| +func TestPointNotOwnedDomainIsNeutralNotFound(t *testing.T) { |
| + f := newPurchaseFixture(t) |
| + other := planAccount(t, f.consoleFixture, 502) |
| + if _, err := f.st.db.Exec(`INSERT INTO domain_registrations (domain, account_id, registrar_id, zone_id, expires_at, created_at) VALUES ('other.com', ?, 'r', 'zone-x', 0, 0)`, other.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + ctx := context.Background() |
| + for _, domain := range []string{"other.com", "never.com", ""} { |
| + ref := f.srv.pointBoughtDomain(ctx, f.acct, "kass", domain, pointOwner(f)) |
| + if ref == nil || ref.Status != http.StatusNotFound { |
| + t.Fatalf("%q: %+v", domain, ref) |
| + } |
| + } |
| + c, csrf := f.ownerBrowser(t) |
| + var bodies []string |
| + for _, domain := range []string{"other.com", "never.com"} { |
| + status, _, body := postForm(t, c, f.appURL("kass", "/domains/point"), url.Values{"csrf": {csrf}, "domain": {domain}}) |
| + if status != http.StatusNotFound { |
| + t.Fatalf("%s: %d %s", domain, status, body) |
| + } |
| + bodies = append(bodies, body) |
| + } |
| + if bodies[0] != bodies[1] { |
| + t.Fatalf("another account's domain answers differently: %q vs %q", bodies[0], bodies[1]) |
| + } |
| + if len(f.zone.Calls) != 0 { |
| + t.Fatalf("zone calls: %v", f.zone.Calls) |
| + } |
| + for _, host := range []string{"other.com", "www.other.com"} { |
| + if _, err := domains.GetClaim(ctx, f.rel, host); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("%s claimed: %v", host, err) |
| + } |
| + } |
| +} |
| + |
| +// doorAnswer is one browser POST's whole answer. |
| +type doorAnswer struct { |
| + Status int |
| + Location, Body string |
| +} |
| + |
| +func rawPost(t *testing.T, c *http.Client, u string, form url.Values, bearer string) doorAnswer { |
| + t.Helper() |
| + req, err := http.NewRequest(http.MethodPost, u, strings.NewReader(form.Encode())) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| + if bearer != "" { |
| + req.Header.Set("Authorization", "Bearer "+bearer) |
| + } |
| + res, err := c.Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer res.Body.Close() |
| + b, _ := io.ReadAll(res.Body) |
| + return doorAnswer{res.StatusCode, res.Header.Get("Location"), string(b)} |
| +} |
| + |
| +// TestPointGateMatchesAttachDoor: every gate refusal of the point door is |
| +// the attach door's answer, byte for byte, and nothing is written. |
| +func TestPointGateMatchesAttachDoor(t *testing.T) { |
| + f := newPurchaseFixture(t) |
| + p := f.boughtUnpointed(t) |
| + if err := f.st.AddMember(f.acct.ID, "member@example.com", RoleMember, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := f.st.CreateLinkedApp(f.acct.ID, "blog", "link:0123456789ab", "0123456789ab", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + owner, csrf := f.ownerBrowser(t) |
| + member := newBrowser(t) |
| + f.setUser("member@example.com") |
| + signUp(t, f.consoleFixture, member, "point-member") |
| + memberCSRF := sessionToken(t, f.consoleFixture, member) |
| + service := serviceToken(t, f.st, f.acct.ID, "pub", "kass", svcrole.Publish) |
| + anon := newBrowser(t) |
| + |
| + both := func(t *testing.T, c *http.Client, app string, form url.Values, bearer string) doorAnswer { |
| + t.Helper() |
| + attachForm, pointForm := url.Values{}, url.Values{} |
| + for k, v := range form { |
| + attachForm[k], pointForm[k] = v, v |
| + } |
| + attachForm.Set("host", p.Domain) |
| + pointForm.Set("domain", p.Domain) |
| + a := rawPost(t, c, f.appURL(app, "/domains/attach"), attachForm, bearer) |
| + pt := rawPost(t, c, f.appURL(app, "/domains/point"), pointForm, bearer) |
| + if a != pt { |
| + t.Fatalf("attach answered %+v\npoint answered %+v", a, pt) |
| + } |
| + return pt |
| + } |
| + cases := []struct { |
| + name string |
| + c *http.Client |
| + app string |
| + form url.Values |
| + bearer string |
| + status int |
| + }{ |
| + {"member", member, "kass", url.Values{"csrf": {memberCSRF}}, "", http.StatusNotFound}, |
| + {"service token", anon, "kass", url.Values{}, service, 0}, |
| + {"missing app", owner, "nope", url.Values{"csrf": {csrf}}, "", http.StatusNotFound}, |
| + {"linked app", owner, "blog", url.Values{"csrf": {csrf}}, "", 0}, |
| + {"no csrf", owner, "kass", url.Values{}, "", http.StatusForbidden}, |
| + } |
| + for _, tc := range cases { |
| + t.Run(tc.name, func(t *testing.T) { |
| + got := both(t, tc.c, tc.app, tc.form, tc.bearer) |
| + if got.Status < 300 || (tc.status != 0 && got.Status != tc.status) { |
| + t.Fatalf("answer %+v, want status %d", got, tc.status) |
| + } |
| + }) |
| + } |
| + f.assertUnpointed(t, p.Domain) |
| + f.assertNoClaims(t, p.Domain) |
| + |
| + // Beyond the attach door's gate: not where buying is off. |
| + f.srv.cfg.DomainCatalog = nil |
| + got := rawPost(t, owner, f.appURL("kass", "/domains/point"), url.Values{"csrf": {csrf}, "domain": {p.Domain}}, "") |
| + if got.Status != http.StatusNotFound || got.Body != "404 page not found\n" { |
| + t.Fatalf("buying off: %+v", got) |
| + } |
| + f.assertUnpointed(t, p.Domain) |
| + f.assertNoClaims(t, p.Domain) |
| +} |
| + |
| +func TestPointAPIPersonOwnerOnly(t *testing.T) { |
| + f := newPurchaseFixture(t) |
| + p := f.boughtUnpointed(t) |
| + if err := f.st.AddMember(f.acct.ID, "member@example.com", RoleMember, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + path := "/api/cli/apps/" + f.acct.Sqid + "/kass/domains/point" |
| + body := `{"domain":"shop.com"}` |
| + refused := map[string]string{ |
| + "publish": serviceToken(t, f.st, f.acct.ID, "pub", "kass", svcrole.Publish), |
| + "instance": serviceToken(t, f.st, f.acct.ID, "inst", "kass", svcrole.Instance), |
| + "member": cliToken(t, f.consoleFixture, "member@example.com", "point-member"), |
| + } |
| + for name, tok := range refused { |
| + status, b := buyRequest(t, f, http.MethodPost, path, tok, body) |
| + want := http.StatusForbidden // the closed-door refusal |
| + if name == "member" { |
| + want = http.StatusNotFound |
| + } |
| + if status != want { |
| + t.Fatalf("%s: %d %s", name, status, b) |
| + } |
| + } |
| + f.assertUnpointed(t, p.Domain) |
| + f.assertNoClaims(t, p.Domain) |
| + |
| + owner := cliToken(t, f.consoleFixture, pointOwner(f), "point-owner") |
| + // Not where buying is off, and not for an app outside the account. |
| + catalog := f.srv.cfg.DomainCatalog |
| + f.srv.cfg.DomainCatalog = nil |
| + if status, b := buyRequest(t, f, http.MethodPost, path, owner, body); status != http.StatusNotFound { |
| + t.Fatalf("buying off: %d %s", status, b) |
| + } |
| + f.srv.cfg.DomainCatalog = catalog |
| + if status, b := buyRequest(t, f, http.MethodPost, "/api/cli/apps/"+f.acct.Sqid+"/nope/domains/point", owner, body); status != http.StatusNotFound { |
| + t.Fatalf("missing app: %d %s", status, b) |
| + } |
| + if status, b := buyRequest(t, f, http.MethodPost, path, owner, `{"domain":"never.com"}`); status != http.StatusNotFound { |
| + t.Fatalf("not this account's: %d %s", status, b) |
| + } |
| + f.assertNoClaims(t, p.Domain) |
| + |
| + status, b := buyRequest(t, f, http.MethodPost, path, owner, body) |
| + if status != http.StatusOK || !strings.Contains(b, `"domain":"shop.com"`) || !strings.Contains(b, `"app":"kass"`) { |
| + t.Fatalf("owner: %d %s", status, b) |
| + } |
| + f.wantPointed(t, p.Domain) |
| + f.wantClaimedBy(t, p.Domain, "kass") |
| +} |
diff --git a/internal/console/linkedpolicy.go b/internal/console/linkedpolicy.go| index 4cd6a71d3..1f1b191b2 100644 |
| --- a/internal/console/linkedpolicy.go |
| +++ b/internal/console/linkedpolicy.go |
| @@ -78,6 +78,7 @@ var linkedPolicies = map[string]linkedPolicy{ |
| "GET /a/{sqid}/apps/{app}/domains/purchases/{id}/status": linkedRefuseDomains, |
| "POST /a/{sqid}/apps/{app}/domains/attach": linkedRefuseDomains, |
| "POST /a/{sqid}/apps/{app}/domains/detach": linkedRefuseDomains, |
| + "POST /a/{sqid}/apps/{app}/domains/point": linkedRefuseDomains, |
| "GET /api/cli/apps/{account}/{app}/domains": linkedRefuseDomains, |
| "GET /api/cli/apps/{account}/{app}/domains/{host}": linkedRefuseDomains, |
| "GET /api/cli/apps/{account}/{app}/domains/{host}/placements": linkedRefuseDomains, |
| @@ -85,6 +86,7 @@ var linkedPolicies = map[string]linkedPolicy{ |
| "POST /api/cli/apps/{account}/{app}/domains": linkedRefuseDomains, |
| "DELETE /api/cli/apps/{account}/{app}/domains/{host}": linkedRefuseDomains, |
| "PUT /api/cli/apps/{account}/{app}/domains/{host}/paths": linkedRefuseDomains, |
| + "POST /api/cli/apps/{account}/{app}/domains/point": linkedRefuseDomains, |
| // The browser's app doors that act on what lives at home. |
| "GET /a/{sqid}/apps/{app}/source": linkedRefuse, |
diff --git a/internal/console/nobucket_posts_test.go b/internal/console/nobucket_posts_test.go| index be8b442fa..6ae998eac 100644 |
| --- a/internal/console/nobucket_posts_test.go |
| +++ b/internal/console/nobucket_posts_test.go |
| @@ -28,6 +28,7 @@ var noBucketPostAllowed = map[string]string{ |
| "POST /a/{sqid}/apps/{app}/domains/detach": "detachDomain and detachInstanceCatchall refuse without a bucket", |
| "POST /a/{sqid}/apps/{app}/domains/buy": "domainPurchaseReady needs Releases, so the door is 404", |
| "POST /a/{sqid}/apps/{app}/domains/check": "domainPurchaseReady needs Releases, so the door is 404", |
| + "POST /a/{sqid}/apps/{app}/domains/point": "domainPurchaseReady needs Releases, so the door is 404", |
| "POST /a/{sqid}/apps/{app}/restart": "handleBrowserRestart refuses before any restart without a bucket", |
| "POST /a/{sqid}/apps/{app}/instances/{host}/restart": "handleBrowserRestart refuses before any restart without a bucket", |
| "POST /a/{sqid}/apps/{app}/instances/{host}/retry": "own gate 404s without a bucket (handleInstanceRetry)", |
diff --git a/internal/console/routedecls.go b/internal/console/routedecls.go| index 045b2a1df..6214afb61 100644 |
| --- a/internal/console/routedecls.go |
| +++ b/internal/console/routedecls.go |
| @@ -333,6 +333,9 @@ var routeDecls = []routeDecl{ |
| // passkey step-up (spec §6) — detach's guard is the typed-host confirm. |
| {Pattern: "POST /a/{sqid}/apps/{app}/domains/attach", Handler: (*Server).handleAppDomainAttach}, |
| {Pattern: "POST /a/{sqid}/apps/{app}/domains/detach", Handler: (*Server).handleAppDomainDetach}, |
| + // Pointing a bought domain at an app (domainpoint.go): the attach door's |
| + // gate plus domainBuyReady, so not registered where buying is off. |
| + {Pattern: "POST /a/{sqid}/apps/{app}/domains/point", Gate: gateNoHostClaim, Handler: (*Server).handleAppDomainPoint}, |
| // Customer fleets (Task 9): the owner's own remote boxes and what's |
| // placed on them — member-readable, owner-gated for rotate/detach |
| @@ -833,6 +836,9 @@ var routeDecls = []routeDecl{ |
| {Pattern: "POST /api/cli/accounts/{account}/domains/check", Kind: kindCLI, Gate: gateNoHostClaim, Allow: svcrole.Set{}, Handler: (*Server).handleAPIDomainCheck}, |
| {Pattern: "POST /api/cli/accounts/{account}/domains/purchases", Kind: kindCLI, Gate: gateNoHostClaim, Allow: svcrole.Set{}, Handler: (*Server).handleAPIDomainPurchase}, |
| {Pattern: "GET /api/cli/accounts/{account}/domains/purchases/{id}", Kind: kindCLI, Gate: gateNoHostClaim, Allow: svcrole.Set{}, Handler: (*Server).handleAPIDomainPurchaseStatus}, |
| + // The point door's CLI twin (domainpoint.go): a person and the owner |
| + // only, unlike the attach API it sits beside, so no service role. |
| + {Pattern: "POST /api/cli/apps/{account}/{app}/domains/point", Kind: kindCLI, Gate: gateNoHostClaim, Allow: svcrole.Set{}, Handler: (*Server).handleAPIDomainPoint}, |
| {Pattern: "DELETE /api/cli/apps/{account}/{app}/domains/{host}", Kind: kindCLIScoped, Allow: svcrole.Allow(svcrole.Publish, svcrole.Instance), Target: scopeDomainHost, Handler: (*Server).handleAPIDomainDetach}, |
| // The prefix-map publish (path-based routing): replace the WHOLE map of |
| // leading path segments a claimed hostname splits its traffic by. The |
diff --git a/internal/console/svcroutes_test.go b/internal/console/svcroutes_test.go| index 3c21faf02..63f35f1c8 100644 |
| --- a/internal/console/svcroutes_test.go |
| +++ b/internal/console/svcroutes_test.go |
| @@ -239,6 +239,8 @@ var closedDoors = []string{ |
| "GET /api/cli/accounts/{account}/domains/purchases/{id}", |
| "POST /api/cli/accounts/{account}/domains/check", |
| "POST /api/cli/accounts/{account}/domains/purchases", |
| + // Pointing a bought domain is the owner's act, a person's (domainpoint.go). |
| + "POST /api/cli/apps/{account}/{app}/domains/point", |
| "GET /api/cli/accounts/{account}/plan", |
| "POST /api/cli/accounts/{account}/plan", |
| // An account's subdomain, and the inventory of labels no account |
| @@ -445,6 +447,7 @@ var domainBuyDoors = []string{ |
| "GET /api/cli/accounts/{account}/domains/purchases/{id}", |
| "POST /api/cli/accounts/{account}/domains/check", |
| "POST /api/cli/accounts/{account}/domains/purchases", |
| + "POST /api/cli/apps/{account}/{app}/domains/point", |
| } |
| // TestEveryCLIDoorNamesItsRoles is the default-deny guarantee for the |
| @@ -1769,8 +1772,8 @@ func TestEveryClosedDoorRefusesAServiceCredential(t *testing.T) { |
| } |
| seen++ |
| } |
| - if seen != len(closedDoors) || seen != 103 { |
| - t.Errorf("walked %d closed doors, want all %d (and 103 today: three domain purchase doors, two managed admission doors, the fleet show door, two managed configuration doors, three environment ownership doors, instance-token, three door-key doors, the routes door, the regional placements write, instances-manifest, the app update policy, sidecars-manifest, the route-channel move, three instance update settings doors, two db replica doors, the forwarded db read, seven fleets, the instance label door, the fleet secrets key door, the two person link doors (list and unlink), the six home link doors, four services, two email credentials, email pause, the build probe, the swap policy, the copy count, the interactive setting, the interactive session door, two app policy doors, two app region doors, the live tenancy read, the layout read, the activation-cancel door, eleven system doors, three deployment-wide antivirus, the PDF status door, three platform geoip doors, two pointer digest doors, the hostname history status, the channel resign, two release authorize doors, four store-entitlement doors, two account plan doors, two billing problem doors, the billing revenue and payments doors, the billing house door, three account subdomain doors, the subdomain inventory, and the claimed source door)", |
| + if seen != len(closedDoors) || seen != 104 { |
| + t.Errorf("walked %d closed doors, want all %d (and 104 today: three domain purchase doors, the domain point door, two managed admission doors, the fleet show door, two managed configuration doors, three environment ownership doors, instance-token, three door-key doors, the routes door, the regional placements write, instances-manifest, the app update policy, sidecars-manifest, the route-channel move, three instance update settings doors, two db replica doors, the forwarded db read, seven fleets, the instance label door, the fleet secrets key door, the two person link doors (list and unlink), the six home link doors, four services, two email credentials, email pause, the build probe, the swap policy, the copy count, the interactive setting, the interactive session door, two app policy doors, two app region doors, the live tenancy read, the layout read, the activation-cancel door, eleven system doors, three deployment-wide antivirus, the PDF status door, three platform geoip doors, two pointer digest doors, the hostname history status, the channel resign, two release authorize doors, four store-entitlement doors, two account plan doors, two billing problem doors, the billing revenue and payments doors, the billing house door, three account subdomain doors, the subdomain inventory, and the claimed source door)", |
| seen, len(closedDoors)) |
| } |
| } |
diff --git a/parity/parity.tsv b/parity/parity.tsv| index 7fcdde519..6366434ff 100644 |
| --- a/parity/parity.tsv |
| +++ b/parity/parity.tsv |
| @@ -85,6 +85,7 @@ domains-list domains both domains list GET /a/{sqid}/apps/{app}/settings/{sectio |
| domains-attach domains both domains attach ; domains detach POST /a/{sqid}/apps/{app}/domains/attach ; POST /a/{sqid}/apps/{app}/domains/detach |
| domains-verify domains partial domains verify POST /a/{sqid}/apps/{app}/domains/attach There is no Verify button; attaching again verifies. |
| domains-buy domains both domains check ; domains buy GET /a/{sqid}/apps/{app}/domains/buy ; POST /a/{sqid}/apps/{app}/domains/check ; POST /a/{sqid}/apps/{app}/domains/buy ; GET /a/{sqid}/apps/{app}/domains/purchases/{id} ; GET /a/{sqid}/apps/{app}/domains/purchases/{id}/status |
| +domains-point domains console-only POST /a/{sqid}/apps/{app}/domains/point Pointing a bought domain at an app; the CLI verb comes later. |
| domains-paths domains gap domains paths wp-settings |
| domains-placements domains gap domains placements wp-settings |
| gate domains both gate set ; gate clear ; gate list POST /a/{sqid}/apps/{app}/gate ; GET /a/{sqid}/apps/{app}/settings/{section} |