Claims cleanup R5 task 2: delete CONSOLE_APP_REGIONS and the code only it reached
Every appRegionsOn() branch collapses to its off arm: a create stores the home as "default", the API doors ignore region and timezone and answer regions_available 1, the browser door neither validates nor refuses a region and audits "created app <name>", and the create-app page has no picker. Deleted with it: Config.AppRegions, appRegionsSwitch, the picker (regionpicker.go, its template block and recordingLocator), regionReq and the explicit-region validation, resolveNewAppRegion, the claimApp region parameter, and the strings only the switch-on arm showed (C1-C3, C5, C18, C18b, C19, C19b, C21, C24, O1). The guess door, POST .../apps/new/region, answered with the switch off and stays (moved to regionguess.go). A console started with CONSOLE_APP_REGIONS set ignores it and logs one startup line. The task 1 pins are unchanged and green.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 files changed,
+259
−940
approved_copy_test.go+18 −4approved_copy_zdd_test.go+3 −3cmd/console/main.go+10 −4cmd/console/region_test.go+21 −4internal/console/apicli.go+11 −39internal/console/apicli_test.go+1 −1internal/console/apitemporary.go+4 −9internal/console/apps_claim_test.go+4 −4internal/console/claimlogging_test.go+1 −1internal/console/consolemail_test.go+1 −1internal/console/geoipfollower_test.go+0 −14internal/console/regionclaim.go+1 −98internal/console/regionclaim_test.go+25 −163internal/console/regionconfig.go+3 −11internal/console/regionconfig_test.go+6 −26internal/console/regioncopy.go+7 −29internal/console/regioncopy_test.go+2 −23internal/console/regiondefault_test.go+0 −1internal/console/regionfill_test.go+1 −2internal/console/regionguess.go+30 −0internal/console/regionguess_test.go+68 −0internal/console/regionmsgs.go+0 −16internal/console/regionmsgs_test.go+10 −14internal/console/regionpicker.go+0 −133internal/console/regionpicker_test.go+0 −258internal/console/server.go+8 −25internal/console/templates/app_new.html+1 −29internal/console/tempnames_test.go+2 −2internal/console/tempregion_test.go+21 −26
diff --git a/approved_copy_test.go b/approved_copy_test.go| index e44fb2c6d..456250adb 100644 |
| --- a/approved_copy_test.go |
| +++ b/approved_copy_test.go |
| @@ -48,6 +48,16 @@ var approvedCopyIDs = []string{ |
| // the file's string literals instead of its raw bytes. |
| var approvedCopyFragments = map[string]bool{"U1": true, "U2": true, "U3": true} |
| +// retiredCopyIDs are record entries whose code was deleted with the |
| +// nearest-region switch (claims cleanup R5): the picker, its refusal and |
| +// audit line, the new-app region refusals and the switch's startup line. |
| +// The record keeps them as history; the check requires them GONE from the |
| +// file the record names, so a string cannot be moved and still pass. |
| +var retiredCopyIDs = map[string]bool{ |
| + "C1": true, "C2": true, "C3": true, "C5": true, "C21": true, "C24": true, |
| + "C18": true, "C18b": true, "C19": true, "C19b": true, "O1": true, |
| +} |
| + |
| // shortCopyBytes is the length under which a text is a word or a flag name. |
| // A short text could appear by accident (the word "Region" in a comment), so |
| // in a Go file it must be the whole decoded value of a string literal. |
| @@ -62,13 +72,13 @@ func TestApprovedCopyIsApplied(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - checkApprovedCopy(t, raw, ".", approvedCopyIDs, approvedCopyFragments) |
| + checkApprovedCopy(t, raw, ".", approvedCopyIDs, approvedCopyFragments, retiredCopyIDs) |
| } |
| // checkApprovedCopy checks a record against the files under root. ids is the |
| // pinned inventory the record must name; fragments are the entries that sit |
| -// inside a longer literal. |
| -func checkApprovedCopy(t *testing.T, raw []byte, root string, ids []string, fragments map[string]bool) { |
| +// inside a longer literal; retired are the entries whose code was deleted. |
| +func checkApprovedCopy(t *testing.T, raw []byte, root string, ids []string, fragments, retired map[string]bool) { |
| t.Helper() |
| var rec struct { |
| ApprovedBy string `json:"approved_by"` |
| @@ -117,7 +127,11 @@ func checkApprovedCopy(t *testing.T, raw []byte, root string, ids []string, frag |
| t.Errorf("%s: %v", e.ID, err) |
| continue |
| } |
| - if !copyAppliedWith(fragments, e.ID, e.File, e.Text, body) { |
| + applied := copyAppliedWith(fragments, e.ID, e.File, e.Text, body) |
| + switch { |
| + case retired[e.ID] && applied: |
| + t.Errorf("%s: retired, but %s still contains %q", e.ID, e.File, e.Text) |
| + case !retired[e.ID] && !applied: |
| t.Errorf("%s: %s does not contain the approved text %q", e.ID, e.File, e.Text) |
| } |
| } |
diff --git a/approved_copy_zdd_test.go b/approved_copy_zdd_test.go| index e0900c5cb..a35001772 100644 |
| --- a/approved_copy_zdd_test.go |
| +++ b/approved_copy_zdd_test.go |
| @@ -69,7 +69,7 @@ func TestZeroDowntimeCopyIsApplied(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - checkApprovedCopy(t, raw, ".", zddCopyIDs, zddCopyFragments) |
| + checkApprovedCopy(t, raw, ".", zddCopyIDs, zddCopyFragments, nil) |
| } |
| // zddReadinessCopyIDs is the flag-readiness copy inventory: the three |
| @@ -87,7 +87,7 @@ func TestZeroDowntimeReadinessCopyIsApplied(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - checkApprovedCopy(t, raw, ".", zddReadinessCopyIDs, nil) |
| + checkApprovedCopy(t, raw, ".", zddReadinessCopyIDs, nil, nil) |
| } |
| // zddReadiness2CopyIDs is the flag-readiness round 2 copy inventory: the |
| @@ -110,5 +110,5 @@ func TestZeroDowntimeReadiness2CopyIsApplied(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - checkApprovedCopy(t, raw, ".", zddReadiness2CopyIDs, nil) |
| + checkApprovedCopy(t, raw, ".", zddReadiness2CopyIDs, nil, nil) |
| } |
diff --git a/cmd/console/main.go b/cmd/console/main.go| index d2dc5336b..a9bb737ab 100644 |
| --- a/cmd/console/main.go |
| +++ b/cmd/console/main.go |
| @@ -399,6 +399,7 @@ func serve() { |
| // Before the server exists: every door that seals reads this switch. |
| appconfig.SetBoundSealing(secretsEnvelopeV2()) |
| geoReader := consoleGeoReader(strings.TrimSpace(os.Getenv("CONSOLE_GEOIP_DB"))) |
| + logRetiredAppRegions(os.Getenv) |
| cfg := console.Config{ |
| Origin: origin, |
| Keymail: envOr("CONSOLE_KEYMAIL", "https://keymail.dev"), |
| @@ -414,7 +415,6 @@ func serve() { |
| // The deployment's AWS account id, the trust anchor of the Phase 1 |
| // move door's box identity check (unset: no box verifies). |
| AWSAccount: strings.TrimSpace(os.Getenv("CARLOS_AWS_ACCOUNT")), |
| - AppRegions: appRegionsSwitch(os.Getenv("CONSOLE_APP_REGIONS")), |
| // GeoIP (geoip spec §11.3): the CONSOLE_GEOIP_DB override when set, |
| // otherwise the follower of this box's own edge mirror. |
| GeoIP: geoLocator(geoReader), |
| @@ -1489,9 +1489,15 @@ func envBytes(k string, def int64) int64 { |
| return n |
| } |
| -// appRegionsSwitch reads CONSOLE_APP_REGIONS: exactly "on" (any case, |
| -// trimmed) turns app regions on. |
| -func appRegionsSwitch(v string) bool { return strings.EqualFold(strings.TrimSpace(v), "on") } |
| +// logRetiredAppRegions says once, at startup, that CONSOLE_APP_REGIONS is |
| +// set but no longer read. The nearest-region switch was deleted while off |
| +// everywhere (claims cleanup R5): every new app is created in the home, as |
| +// it was with the switch off, whatever the variable says. |
| +func logRetiredAppRegions(getenv func(string) string) { |
| + if strings.TrimSpace(getenv("CONSOLE_APP_REGIONS")) != "" { |
| + log.Print("console: CONSOLE_APP_REGIONS is set but no longer read; new apps are created in the home region") |
| + } |
| +} |
| // openGeoIP opens the optional CONSOLE_GEOIP_DB. Unset, unopenable or not |
| // an mmdb means the IP step is off, logged once and never fatal. Returns an |
diff --git a/cmd/console/region_test.go b/cmd/console/region_test.go| index 59efe142f..2cc09aed3 100644 |
| --- a/cmd/console/region_test.go |
| +++ b/cmd/console/region_test.go |
| @@ -1,7 +1,9 @@ |
| package main |
| import ( |
| + "bytes" |
| "errors" |
| + "log" |
| "net" |
| "path/filepath" |
| "strings" |
| @@ -21,10 +23,25 @@ func TestOpenGeoIPIsOptionalAndNeverFatal(t *testing.T) { |
| } |
| } |
| -func TestAppRegionsSwitchParses(t *testing.T) { |
| - for v, want := range map[string]bool{"on": true, "ON": true, " on ": true, "": false, "off": false, "true": false} { |
| - if got := appRegionsSwitch(v); got != want { |
| - t.Errorf("appRegionsSwitch(%q) = %v, want %v", v, got, want) |
| +// Claims cleanup R5: a set CONSOLE_APP_REGIONS is ignored and named in one |
| +// startup line; unset or blank says nothing. |
| +func TestRetiredAppRegionsLogsOnceWhenSet(t *testing.T) { |
| + const line = "console: CONSOLE_APP_REGIONS is set but no longer read; new apps are created in the home region\n" |
| + for v, want := range map[string]string{"on": line, "ON": line, "off": line, "": "", " ": ""} { |
| + var buf bytes.Buffer |
| + prev, flags := log.Writer(), log.Flags() |
| + log.SetOutput(&buf) |
| + log.SetFlags(0) |
| + logRetiredAppRegions(func(k string) string { |
| + if k == "CONSOLE_APP_REGIONS" { |
| + return v |
| + } |
| + return "" |
| + }) |
| + log.SetOutput(prev) |
| + log.SetFlags(flags) |
| + if buf.String() != want { |
| + t.Errorf("CONSOLE_APP_REGIONS=%q logged %q, want %q", v, buf.String(), want) |
| } |
| } |
| } |
diff --git a/internal/console/apicli.go b/internal/console/apicli.go| index 71b461943..1cdfc57f6 100644 |
| --- a/internal/console/apicli.go |
| +++ b/internal/console/apicli.go |
| @@ -401,8 +401,11 @@ func (s *Server) handleAPICreateApp(w http.ResponseWriter, r *http.Request) { |
| Place string `json:"place"` |
| ControlPlane bool `json:"control_plane"` |
| BuildProbe string `json:"build_probe"` |
| - Region string `json:"region"` |
| - Timezone string `json:"timezone"` |
| + // Region and Timezone are accepted and ignored: the app is created |
| + // in the home whatever they say (the nearest-region switch that |
| + // read them was deleted while off). |
| + Region string `json:"region"` |
| + Timezone string `json:"timezone"` |
| } |
| if !readJSON(w, r, &req) { |
| return |
| @@ -449,11 +452,6 @@ func (s *Server) handleAPICreateApp(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| } |
| - rq, ref := s.newAppRegionReq(r, req.Region, req.Timezone) |
| - if ref != nil { |
| - jsonError(w, ref.Status, ref.Msg) |
| - return |
| - } |
| // ownerClaim: a PERSON who owns this account may adopt objects already |
| // under its own prefix (#79). A service principal never may — it holds no |
| // account role, and handing a CI credential the power to adopt release |
| @@ -469,7 +467,7 @@ func (s *Server) handleAPICreateApp(w http.ResponseWriter, r *http.Request) { |
| jsonError(w, http.StatusInternalServerError, "could not create the app — try again") |
| return |
| } |
| - outcome, placed, held := s.claimApp(r.Context(), acct, name, addr, place, ownerClaim, rq) |
| + outcome, placed, held := s.claimApp(r.Context(), acct, name, addr, place, ownerClaim) |
| switch outcome { |
| case claimInvalid: |
| jsonError(w, http.StatusBadRequest, |
| @@ -548,40 +546,14 @@ func (s *Server) echoCreatedRegion(ctx context.Context, acct *Account, name stri |
| if ferr == nil { |
| cands = s.regionCands(files) |
| } |
| - // regions_available is what THIS create could use, not what the |
| - // fleet has. With the switch off (or no named home) every create |
| - // lands on the home and --region is ignored (C13b), so there is |
| - // one; a CLI that prints C11 at two or more then never invites a |
| - // flag this console ignores. Fixed here rather than in the CLI so |
| - // older CLIs benefit (final review, C11 on a switch-off console). |
| - available := eligibleCount(cands) |
| - if !s.appRegionsOn() { |
| - available = 1 |
| - } |
| out["region"] = s.homeRegionOut(gotRegion) |
| out["region_name"] = s.placeOf(gotRegion, cands) |
| out["region_source"] = gotSource |
| - out["regions_available"] = available |
| -} |
| - |
| -// newAppRegionReq builds a create door's regionReq from its optional region |
| -// and timezone fields, validating an explicit region exactly as /new always |
| -// has. A non-nil refusal is the response; nothing was claimed. |
| -func (s *Server) newAppRegionReq(r *http.Request, region, timezone string) (regionReq, *doorRefusal) { |
| - // The region is resolved inside claimApp, once it knows the claim is not |
| - // an adoption. The timezone and the address only ever feed that guess. |
| - rq := regionReq{tz: timezone, ip: s.personIP(r)} |
| - // With the switch off an explicit region is neither validated nor |
| - // refused (spec §9.6): resolveNewAppRegion stores the home as "default", |
| - // and a refusal there would offer choices that would not be honoured. |
| - if strings.TrimSpace(region) != "" && s.appRegionsOn() { |
| - code, ref := s.validateExplicitRegion(r.Context(), region) |
| - if ref != nil { |
| - return regionReq{}, ref |
| - } |
| - rq.explicit, rq.hasExplicit = code, true |
| - } |
| - return rq, nil |
| + // regions_available is what THIS create could use, not what the |
| + // fleet has: every create lands on the home and --region is ignored |
| + // (C13b), so there is one, and a CLI that prints C11 at two or more |
| + // never invites a flag this console ignores. |
| + out["regions_available"] = 1 |
| } |
| // handleAPIApps answers `carlos apps`: every account the caller can see, and |
diff --git a/internal/console/apicli_test.go b/internal/console/apicli_test.go| index 969d668d3..c0cfac39c 100644 |
| --- a/internal/console/apicli_test.go |
| +++ b/internal/console/apicli_test.go |
| @@ -2616,7 +2616,7 @@ func TestClaimAppPlacementWriteFailureDoesNotUndoClaim(t *testing.T) { |
| } |
| acct := &Account{ID: OpsAccountID, Sqid: fx.sqid} |
| - outcome, placed, _ := fx.srv.claimApp(context.Background(), acct, "titogo", "paul@keymail.dev", "fleet/pi", false, regionReq{}) |
| + outcome, placed, _ := fx.srv.claimApp(context.Background(), acct, "titogo", "paul@keymail.dev", "fleet/pi", false) |
| if outcome != claimOK { |
| t.Fatalf("claimApp outcome = %v, want claimOK — the claim itself must still succeed", outcome) |
| } |
diff --git a/internal/console/apitemporary.go b/internal/console/apitemporary.go| index 23166278d..ceb14898b 100644 |
| --- a/internal/console/apitemporary.go |
| +++ b/internal/console/apitemporary.go |
| @@ -132,8 +132,9 @@ func (s *Server) handleAPICreateTemporaryApp(w http.ResponseWriter, r *http.Requ |
| var req struct { |
| Name string `json:"name"` |
| TTLSeconds int64 `json:"ttl_seconds"` |
| - Region string `json:"region"` |
| - Timezone string `json:"timezone"` |
| + // Accepted and ignored, as on /new (handleAPICreateApp). |
| + Region string `json:"region"` |
| + Timezone string `json:"timezone"` |
| } |
| if !readJSONStrictLimit(w, r, &req, 8<<10) { |
| return |
| @@ -154,12 +155,6 @@ func (s *Server) handleAPICreateTemporaryApp(w http.ResponseWriter, r *http.Requ |
| "this console has no deployment bucket, so it cannot create a temporary app") |
| return |
| } |
| - // The same optional region fields /new takes, read the same way. |
| - rq, ref := s.newAppRegionReq(r, req.Region, req.Timezone) |
| - if ref != nil { |
| - jsonError(w, ref.Status, ref.Msg) |
| - return |
| - } |
| defer s.lockAccount(acct.Sqid)() |
| if err := s.temporaryCapCheck(acct.ID); err != nil { |
| var capErr *temporaryCapError |
| @@ -194,7 +189,7 @@ func (s *Server) handleAPICreateTemporaryApp(w http.ResponseWriter, r *http.Requ |
| }) |
| return |
| } |
| - outcome, _, held := s.claimAppWith(r.Context(), acct, name, addr, "", false, rq, now.Add(ttl)) |
| + outcome, _, held := s.claimAppWith(r.Context(), acct, name, addr, "", false, now.Add(ttl)) |
| switch outcome { |
| case claimOK: |
| case claimInvalid: |
diff --git a/internal/console/apps_claim_test.go b/internal/console/apps_claim_test.go| index ec0b0c60d..aa958c0dd 100644 |
| --- a/internal/console/apps_claim_test.go |
| +++ b/internal/console/apps_claim_test.go |
| @@ -115,7 +115,7 @@ func TestOwnerClaimsAppWhoseObjectsExist(t *testing.T) { |
| fx := newConsoleFixture(t) |
| seedBucketApp(t, fx, "bab", "console") |
| acct := opsAccount(t, fx) |
| - outcome, _, _ := fx.srv.claimApp(context.Background(), acct, "console", "paul@keymail.dev", "", true, regionReq{}) |
| + outcome, _, _ := fx.srv.claimApp(context.Background(), acct, "console", "paul@keymail.dev", "", true) |
| if outcome != claimOK { |
| t.Fatalf("owner claim over existing objects = %v, want claimOK", outcome) |
| } |
| @@ -131,7 +131,7 @@ func TestNonOwnerStillRefusedOverExistingObjects(t *testing.T) { |
| fx := newConsoleFixture(t) |
| seedBucketApp(t, fx, "bab", "console") |
| acct := opsAccount(t, fx) |
| - outcome, _, _ := fx.srv.claimApp(context.Background(), acct, "console", "member@keymail.dev", "", false, regionReq{}) |
| + outcome, _, _ := fx.srv.claimApp(context.Background(), acct, "console", "member@keymail.dev", "", false) |
| if outcome != claimTaken { |
| t.Fatalf("non-owner claim over existing objects = %v, want claimTaken", outcome) |
| } |
| @@ -147,7 +147,7 @@ func TestLegacyPrefixStillBlocksAnOwner(t *testing.T) { |
| t.Fatal(err) |
| } |
| acct := opsAccount(t, fx) |
| - outcome, _, _ := fx.srv.claimApp(context.Background(), acct, "oldsite", "paul@keymail.dev", "", true, regionReq{}) |
| + outcome, _, _ := fx.srv.claimApp(context.Background(), acct, "oldsite", "paul@keymail.dev", "", true) |
| if outcome != claimTaken { |
| t.Fatalf("owner claim over a LEGACY prefix = %v, want claimTaken — those objects are owed a migrate", outcome) |
| } |
| @@ -162,7 +162,7 @@ func TestGrantStillBlocksAnOwner(t *testing.T) { |
| t.Fatal(err) |
| } |
| acct := opsAccount(t, fx) |
| - outcome, _, _ := fx.srv.claimApp(context.Background(), acct, "derp", "paul@keymail.dev", "", true, regionReq{}) |
| + outcome, _, _ := fx.srv.claimApp(context.Background(), acct, "derp", "paul@keymail.dev", "", true) |
| if outcome != claimTaken { |
| t.Fatalf("owner claim over a GRANTED name = %v, want claimTaken", outcome) |
| } |
diff --git a/internal/console/claimlogging_test.go b/internal/console/claimlogging_test.go| index 9812e7658..82703b6f0 100644 |
| --- a/internal/console/claimlogging_test.go |
| +++ b/internal/console/claimlogging_test.go |
| @@ -52,7 +52,7 @@ func TestClaimCheckFailureIsLogged(t *testing.T) { |
| acct := opsAccount(t, fx) |
| tc.breakStore(t, fx) |
| buf := captureLog(t) |
| - outcome, placed, held := fx.srv.claimApp(context.Background(), acct, "logged-site", "paul@keymail.dev", "", true, regionReq{}) |
| + outcome, placed, held := fx.srv.claimApp(context.Background(), acct, "logged-site", "paul@keymail.dev", "", true) |
| if outcome != claimCheckFailed || placed != "" || held != nil { |
| t.Fatalf("claimApp = %v, %q, %v; want claimCheckFailed", outcome, placed, held) |
| } |
diff --git a/internal/console/consolemail_test.go b/internal/console/consolemail_test.go| index b4d447d54..7cc5ad6d6 100644 |
| --- a/internal/console/consolemail_test.go |
| +++ b/internal/console/consolemail_test.go |
| @@ -242,7 +242,7 @@ func TestConsoleMailAppIsReservedInOps(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if got, _, _ := fx.srv.claimApp(context.Background(), ops, consoleMailApp, "paul@keymail.dev", "", true, regionReq{}); got != claimReserved { |
| + if got, _, _ := fx.srv.claimApp(context.Background(), ops, consoleMailApp, "paul@keymail.dev", "", true); got != claimReserved { |
| t.Fatalf("claimApp(bab, %q) = %v, want claimReserved", consoleMailApp, got) |
| } |
| } |
diff --git a/internal/console/geoipfollower_test.go b/internal/console/geoipfollower_test.go| index 68b139370..00a8b9205 100644 |
| --- a/internal/console/geoipfollower_test.go |
| +++ b/internal/console/geoipfollower_test.go |
| @@ -118,20 +118,6 @@ func TestFollowerExpiresTheLoadedReaderWhateverCurrentSays(t *testing.T) { |
| } |
| } |
| -// Code review R4-4: the guess's credit names the reader that answered. |
| -func TestRecordingLocatorNamesTheAnsweringReader(t *testing.T) { |
| - sw := geo.NewSwappable() |
| - rec := &recordingLocator{sw: sw} |
| - if _, ok := rec.Locate(net.ParseIP("81.2.69.142")); ok || rec.used { |
| - t.Fatal("an empty reader answered") |
| - } |
| - db, _ := geo.OpenMMDB("../geo/testdata/GeoIP2-City-Test.mmdb") |
| - sw.Swap(db) |
| - if _, ok := rec.Locate(net.ParseIP("81.2.69.142")); !ok || !rec.used || rec.source != "GeoIP2-City" { |
| - t.Fatalf("recorded = %+v", rec) |
| - } |
| -} |
| - |
| // TestRealDatabaseVerifiesInTheChild runs only with GEOIP_REAL_MMDB set: |
| // a real database must fit the verifier child's memory cap. |
| func TestRealDatabaseVerifiesInTheChild(t *testing.T) { |
diff --git a/internal/console/regionclaim.go b/internal/console/regionclaim.go| index 2bc8b4a98..00c22852e 100644 |
| --- a/internal/console/regionclaim.go |
| +++ b/internal/console/regionclaim.go |
| @@ -1,66 +1,20 @@ |
| package console |
| import ( |
| - "context" |
| "net" |
| "net/http" |
| - "sort" |
| - "strings" |
| "github.com/carlosframework/platform/internal/geo" |
| "github.com/carlosframework/platform/internal/provision" |
| ) |
| -// regionReq is what a create door hands claimApp: never a resolved region. |
| -// The guess is resolved INSIDE claimApp, after it knows whether this is an |
| -// adoption (spec §5.5). ip is request-local and only set for a person. The |
| -// timezone and the address go into the guess and nowhere else: never |
| -// logged, stored, audited or echoed (spec §6.5). |
| -type regionReq struct { |
| - explicit string // a person's choice, record vocabulary |
| - hasExplicit bool |
| - tz string |
| - ip net.IP // request-local, person requests only |
| -} |
| - |
| -// validateExplicitRegion checks a person's explicit region as the instance |
| -// door checks one (spec §8.1): ValidRegion; armed and hosting unless the |
| -// gate is dormant; not provably without the secrets key (R9). The home's |
| -// name normalizes to "". A refusal lists exactly the codes this same check |
| -// would accept now (codex plan-R4 2). |
| -func (s *Server) validateExplicitRegion(ctx context.Context, raw string) (string, *doorRefusal) { |
| - code := s.homeRegionIn(strings.TrimSpace(raw)) |
| - if code == "" { |
| - return "", nil |
| - } |
| - gate := s.readExplicitGate(ctx) |
| - switch gate.refusal(code) { |
| - case "": |
| - return code, nil |
| - case "unknown": |
| - return "", &doorRefusal{http.StatusBadRequest, msgRegionUnknown(code, s.explicitChoices(gate))} |
| - case "not-armed": |
| - return "", &doorRefusal{http.StatusBadRequest, msgRegionNotArmed(code, s.explicitChoices(gate))} |
| - } |
| - return "", &doorRefusal{http.StatusBadRequest, msgNoSecretsKey(code)} |
| -} |
| - |
| -// explicitGate is one read of what an explicit app region must pass. |
| +// explicitGate is what an explicit region must pass (regionchoices.go). |
| type explicitGate struct { |
| caps map[string]placementCapability |
| published bool |
| cands []regionCandidate // nil when the edges read failed: R9 cannot refuse |
| } |
| -func (s *Server) readExplicitGate(ctx context.Context) explicitGate { |
| - g := explicitGate{} |
| - g.caps, g.published = placements(ctx, s.cfg.Releases) |
| - if snap, err := s.liveEdges(ctx); err == nil { |
| - g.cands = s.regionCands(snap) |
| - } |
| - return g |
| -} |
| - |
| // refusal is "" when an explicit, record-vocabulary code passes, else |
| // which bar it fails: "unknown", "not-armed" or "no-key". |
| func (g explicitGate) refusal(code string) string { |
| @@ -78,57 +32,6 @@ func (g explicitGate) refusal(code string) string { |
| return "" |
| } |
| -// explicitChoices is the home's name plus every published code that |
| -// refusal passes, sorted: never a code this door would refuse. |
| -func (s *Server) explicitChoices(g explicitGate) []string { |
| - set := map[string]bool{} |
| - if s.cfg.HomeRegion != "" { |
| - set[s.cfg.HomeRegion] = true |
| - } |
| - for code := range g.caps { |
| - if c := s.homeRegionIn(code); c != "" && g.refusal(c) == "" { |
| - set[c] = true |
| - } |
| - } |
| - out := make([]string, 0, len(set)) |
| - for c := range set { |
| - out = append(out, c) |
| - } |
| - sort.Strings(out) |
| - return out |
| -} |
| - |
| -// resolveNewAppRegion is spec §5.5 and §5.6 for a NEW row. A guess must |
| -// pass the same predicate that builds the C18 and C19 lists |
| -// (explicitGate.refusal), so no door ever stores a region another door |
| -// would refuse to list. |
| -func (s *Server) resolveNewAppRegion(ctx context.Context, rq regionReq, adopting bool) (region, source string) { |
| - if !s.appRegionsOn() { |
| - return "", "default" |
| - } |
| - if rq.hasExplicit { |
| - // Defence in depth for a future door that forgets to validate: a |
| - // code that is not a region never reaches the row. "" is the home. |
| - if rq.explicit != "" && !provision.ValidRegion(rq.explicit) { |
| - return "", "default" |
| - } |
| - return rq.explicit, "chosen" |
| - } |
| - if adopting { |
| - return "", "default" |
| - } |
| - g := s.readExplicitGate(ctx) |
| - if g.cands == nil { |
| - return "", "default" |
| - } |
| - guess, ok := guessRegion(g.cands, func(code string) bool { return g.refusal(code) == "" }, |
| - guessInput{TZ: rq.tz, IP: rq.ip}, s.cfg.GeoIP) |
| - if !ok { |
| - return "", "default" |
| - } |
| - return guess.Code, guess.Source |
| -} |
| - |
| // placeOf names a record-vocabulary code: its AWS region's place, else the |
| // code under its name. |
| func (s *Server) placeOf(code string, cands []regionCandidate) string { |
diff --git a/internal/console/regionclaim_test.go b/internal/console/regionclaim_test.go| index c3a98b767..acba3b31a 100644 |
| --- a/internal/console/regionclaim_test.go |
| +++ b/internal/console/regionclaim_test.go |
| @@ -2,9 +2,6 @@ package console |
| import ( |
| "bytes" |
| - "context" |
| - "encoding/json" |
| - "fmt" |
| "net/http" |
| "strings" |
| "testing" |
| @@ -12,118 +9,27 @@ import ( |
| "github.com/carlosframework/platform/internal/geo" |
| "github.com/carlosframework/platform/internal/registry" |
| - "github.com/carlosframework/platform/internal/svcrole" |
| ) |
| func regionFixture(t *testing.T) (*consoleFixture, string) { |
| t.Helper() |
| fx := newConsoleFixture(t) |
| - fx.srv.cfg.AppRegions, fx.srv.cfg.HomeRegion, fx.srv.cfg.SecretsPub = true, "ie", testKeyPub |
| + fx.srv.cfg.HomeRegion, fx.srv.cfg.SecretsPub = "ie", testKeyPub |
| setEdges(t, fx, map[string]string{"ie-box": homeBox, "uk-box": ukEligible}) |
| return fx, cliToken(t, fx, "paul@keymail.dev", "code-region-claim") |
| } |
| func newAppURL(fx *consoleFixture) string { return fx.ts.URL + "/api/cli/apps/bab/new" } |
| -// postJSONFrom is postJSON with an X-Forwarded-For, which the console |
| -// trusts from the loopback edge (authcli.go clientIP). |
| -func postJSONFrom(t *testing.T, u string, body any, bearer, xff string) (int, map[string]any) { |
| - t.Helper() |
| - raw, _ := json.Marshal(body) |
| - req, err := http.NewRequest(http.MethodPost, u, bytes.NewReader(raw)) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - req.Header.Set("Content-Type", "application/json") |
| - req.Header.Set("Authorization", "Bearer "+bearer) |
| - req.Header.Set("X-Forwarded-For", xff) |
| - return doJSON(t, req) |
| -} |
| - |
| -func errOf(res map[string]any) string { s, _ := res["error"].(string); return s } |
| - |
| var ukPlace = geo.PlaceName("eu-west-2", "uk") |
| -func TestAPICreateAppResolvesRegion(t *testing.T) { |
| - fx, token := regionFixture(t) |
| - status, res := postJSON(t, newAppURL(fx), map[string]string{"name": "blog", "timezone": "Europe/London"}, token) |
| - if status != http.StatusOK || res["region"] != "uk" || res["region_source"] != "timezone" || |
| - res["region_name"] != ukPlace || res["regions_available"] != float64(2) { |
| - t.Fatalf("create = %d %v", status, res) |
| - } |
| - if r, src, _ := fx.st.AppRegion(OpsAccountID, "blog"); r != "uk" || src != "timezone" { |
| - t.Fatalf("stored %q %q", r, src) |
| - } |
| - // An old CLI's body, from loopback with no forwarded address. |
| - if _, res = postJSON(t, newAppURL(fx), map[string]string{"name": "old"}, token); res["region"] != "ie" || res["region_source"] != "default" { |
| - t.Fatalf("old body = %v", res) |
| - } |
| - // An explicit home name is a choice, stored as "". |
| - postJSON(t, newAppURL(fx), map[string]string{"name": "athome", "region": "ie"}, token) |
| - if r, src, _ := fx.st.AppRegion(OpsAccountID, "athome"); r != "" || src != "chosen" { |
| - t.Fatalf("explicit home = %q %q", r, src) |
| - } |
| -} |
| - |
| -// The old-body path through the real door: a person's forwarded address |
| -// is located; a service principal's never is (spec §6.2). |
| -func TestAPICreateAppLocatesOnlyAPerson(t *testing.T) { |
| - fx, token := regionFixture(t) |
| - fx.srv.cfg.GeoIP = fakeLocator{"81.2.69.142": {Lat: 51.5, Lon: -0.12}} |
| - if status, res := postJSONFrom(t, newAppURL(fx), map[string]string{"name": "person"}, token, "81.2.69.142"); status != http.StatusOK || |
| - res["region"] != "uk" || res["region_source"] != "ip" { |
| - t.Fatalf("person = %d %v", status, res) |
| - } |
| - svc := serviceToken(t, fx.st, OpsAccountID, "hub", "", svcrole.Publish) |
| - if status, res := postJSONFrom(t, newAppURL(fx), map[string]string{"name": "hubapp"}, svc, "81.2.69.142"); status != http.StatusOK || |
| - res["region"] != "ie" || res["region_source"] != "default" { |
| - t.Fatalf("service = %d %v, want no IP step", status, res) |
| - } |
| -} |
| - |
| -func TestAPICreateAppRefusesBadExplicitRegions(t *testing.T) { |
| +func TestAPICreateAppStoresTheHome(t *testing.T) { |
| fx, token := regionFixture(t) |
| - // nz cannot host; au's current-writer box lacks the key (R9). |
| - auNoKey := edgeJSON("au-box", "9.9.9.8", "ap-southeast-2", "au", edgeOpts{hib: bp(true), shared: bp(true), inbound: bp(true)}) |
| - setEdges(t, fx, map[string]string{"nz-box": nzNoHosting, "au-box": auNoKey}) |
| - // codex plan-R4 2: each list names exactly what this door would take. |
| - choices := []string{"ie", "uk"} |
| - cases := []struct{ name, region, want string }{ |
| - {"xa", "Bad/Code", msgRegionUnknown("Bad/Code", choices)}, |
| - {"xb", "nz", msgRegionNotArmed("nz", choices)}, |
| - {"xc", "au", msgNoSecretsKey("au")}, |
| - } |
| - for _, c := range cases { |
| - status, res := postJSON(t, newAppURL(fx), map[string]string{"name": c.name, "region": c.region}, token) |
| - if status != http.StatusBadRequest || errOf(res) != c.want { |
| - t.Errorf("region %q = %d %q, want 400 %q", c.region, status, errOf(res), c.want) |
| - } |
| - if has, _ := fx.st.HasAppIn(OpsAccountID, c.name); has { |
| - t.Errorf("a refused region still claimed %s", c.name) |
| - } |
| - } |
| - // Every advertised choice is accepted by the same door, same fixture. |
| - for i, code := range choices { |
| - name := fmt.Sprintf("alt%d", i) |
| - if status, res := postJSON(t, newAppURL(fx), map[string]string{"name": name, "region": code}, token); status != http.StatusOK { |
| - t.Errorf("advertised %q refused: %d %v", code, status, res) |
| - } |
| - } |
| - // R9: a region whose current-writer boxes lack the key. |
| - setEdges(t, fx, map[string]string{"uk-box": ukNoKey}) |
| - if status, res := postJSON(t, newAppURL(fx), map[string]string{"name": "xd", "region": "uk"}, token); status != http.StatusBadRequest || errOf(res) != msgNoSecretsKey("uk") { |
| - t.Fatalf("keyless uk = %d %v, want C31", status, res) |
| - } |
| -} |
| - |
| -func TestAPICreateAppSwitchOffStoresTheHome(t *testing.T) { |
| - fx, token := regionFixture(t) |
| - fx.srv.cfg.AppRegions = false |
| _, res := postJSON(t, newAppURL(fx), map[string]string{"name": "off", "region": "uk", "timezone": "Europe/London"}, token) |
| if r, src, _ := fx.st.AppRegion(OpsAccountID, "off"); r != "" || src != "default" || res["region"] != "ie" { |
| - t.Fatalf("switch off = %q %q %v", r, src, res) |
| + t.Fatalf("create = %q %q %v", r, src, res) |
| } |
| - fx.srv.cfg.AppRegions, fx.srv.cfg.HomeRegion = true, "" |
| + fx.srv.cfg.HomeRegion = "" |
| // PF9: the second half must not pass on a failed create. |
| if status, res := postJSON(t, newAppURL(fx), map[string]string{"name": "unnamed", "region": "uk"}, token); status != http.StatusOK { |
| t.Fatalf("unnamed-home create = %d %v", status, res) |
| @@ -133,39 +39,19 @@ func TestAPICreateAppSwitchOffStoresTheHome(t *testing.T) { |
| } |
| } |
| -func TestClaimAdoptionDiscardsTheGuess(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - acct := &Account{ID: OpsAccountID, Sqid: "bab"} |
| - seedBucketApp(t, fx, "bab", "oldsite") |
| - if out, _, _ := fx.srv.claimApp(context.Background(), acct, "oldsite", "paul@keymail.dev", "", true, regionReq{tz: "Europe/London"}); out != claimOK { |
| - t.Fatalf("adoption = %v", out) |
| - } |
| - if r, src, _ := fx.st.AppRegion(OpsAccountID, "oldsite"); r != "" || src != "default" { |
| - t.Fatalf("adoption with a guess = %q %q", r, src) |
| - } |
| - seedBucketApp(t, fx, "bab", "oldsite2") |
| - fx.srv.claimApp(context.Background(), acct, "oldsite2", "paul@keymail.dev", "", true, regionReq{explicit: "uk", hasExplicit: true}) |
| - if r, src, _ := fx.st.AppRegion(OpsAccountID, "oldsite2"); r != "uk" || src != "chosen" { |
| - t.Fatalf("adoption with an explicit choice = %q %q", r, src) |
| - } |
| -} |
| - |
| // codex plan-R6 1, spec §6.5: every successful creation logs exactly one |
| -// region line, naming what was stored, whatever the switch says: on, off, |
| -// and on with an unnamed home (which keeps assignment off). |
| -func TestClaimLogsOneRegionLineInEverySwitchState(t *testing.T) { |
| +// region line, naming what was stored, with the home named or not. |
| +func TestClaimLogsOneRegionLine(t *testing.T) { |
| for _, c := range []struct { |
| name, app, home string |
| - on bool |
| stored, source string |
| line string |
| }{ |
| - {"assignment on", "on1", "ie", true, "uk", "chosen", "console: app region bab/on1: uk (chosen)"}, |
| - {"assignment off", "off1", "ie", false, "", "default", "console: app region bab/off1: ie (default)"}, |
| - {"on, home unnamed", "unnamed1", "", true, "", "default", "console: app region bab/unnamed1: (default)"}, |
| + {"home named", "off1", "ie", "", "default", "console: app region bab/off1: ie (default)"}, |
| + {"home unnamed", "unnamed1", "", "", "default", "console: app region bab/unnamed1: (default)"}, |
| } { |
| fx, token := regionFixture(t) |
| - fx.srv.cfg.AppRegions, fx.srv.cfg.HomeRegion = c.on, c.home |
| + fx.srv.cfg.HomeRegion = c.home |
| var logs bytes.Buffer |
| restore := captureLogTo(&logs) |
| status, res := postJSON(t, newAppURL(fx), map[string]string{"name": c.app, "region": "uk"}, token) |
| @@ -227,62 +113,38 @@ func TestClaimHeldApexWritesNothing(t *testing.T) { |
| } |
| } |
| -// Controller ruling: with the switch off the API door neither validates nor |
| -// refuses an explicit region (spec §9.6, C13b is the CLI's word for it). It |
| -// stores the home as "default", with no bucket reads for a refusal. |
| -func TestAPICreateAppSwitchOffIgnoresAnExplicitRegion(t *testing.T) { |
| +// Controller ruling: the API door neither validates nor refuses an |
| +// explicit region (spec §9.6, C13b is the CLI's word for it). It stores the |
| +// home as "default", with no bucket reads for a refusal. |
| +func TestAPICreateAppIgnoresAnExplicitRegion(t *testing.T) { |
| fx, token := regionFixture(t) |
| - fx.srv.cfg.AppRegions = false |
| for _, region := range []string{"nz", "Bad/Code"} { |
| name := "off" + strings.ToLower(strings.ReplaceAll(region, "/", "")) |
| status, res := postJSON(t, newAppURL(fx), map[string]string{"name": name, "region": region}, token) |
| if status != http.StatusOK || res["region"] != "ie" || res["region_source"] != "default" { |
| - t.Fatalf("switch off, region %q = %d %v, want 200 home/default", region, status, res) |
| + t.Fatalf("region %q = %d %v, want 200 home/default", region, status, res) |
| } |
| - if e := errOf(res); e != "" { |
| - t.Errorf("switch off refused: %q", e) |
| + if e, _ := res["error"].(string); e != "" { |
| + t.Errorf("refused: %q", e) |
| } |
| if r, src, _ := fx.st.AppRegion(OpsAccountID, name); r != "" || src != "default" { |
| - t.Fatalf("switch off, region %q stored %q %q", region, r, src) |
| + t.Fatalf("region %q stored %q %q", region, r, src) |
| } |
| } |
| } |
| -// Final review, C11 on a switch-off console: regions_available is what the |
| -// create could actually use. With the switch off every create lands on the |
| -// home and --region is ignored (C13b), so the answer is 1, and a CLI, old |
| -// or new, that prints C11 at two or more never invites a flag this console |
| -// ignores. The same fleet with the switch on still answers 2. |
| -func TestAPICreateAppSwitchOffReportsOneRegionAvailable(t *testing.T) { |
| +// Final review, C11: regions_available is what the create could actually |
| +// use. Every create lands on the home and --region is ignored (C13b), so |
| +// the answer is 1 on a fleet of two eligible regions, named home or not, |
| +// and a CLI that prints C11 at two or more never invites a flag this |
| +// console ignores. |
| +func TestAPICreateAppReportsOneRegionAvailable(t *testing.T) { |
| fx, token := regionFixture(t) |
| - if status, res := postJSON(t, newAppURL(fx), map[string]string{"name": "on"}, token); status != http.StatusOK || res["regions_available"] != 2.0 { |
| - t.Fatalf("switch on = %d %v, want regions_available 2", status, res) |
| - } |
| - fx.srv.cfg.AppRegions = false |
| if status, res := postJSON(t, newAppURL(fx), map[string]string{"name": "off"}, token); status != http.StatusOK || res["regions_available"] != 1.0 { |
| - t.Fatalf("switch off = %d %v, want regions_available 1", status, res) |
| + t.Fatalf("named home = %d %v, want regions_available 1", status, res) |
| } |
| - // An unnamed home is the switch off too (appRegionsOn). |
| - fx.srv.cfg.AppRegions, fx.srv.cfg.HomeRegion = true, "" |
| + fx.srv.cfg.HomeRegion = "" |
| if status, res := postJSON(t, newAppURL(fx), map[string]string{"name": "unnamed"}, token); status != http.StatusOK || res["regions_available"] != 1.0 { |
| t.Fatalf("unnamed home = %d %v, want regions_available 1", status, res) |
| } |
| } |
| - |
| -// Defence in depth for future doors: an explicit code that is not a valid |
| -// region never reaches the row. |
| -func TestResolveNewAppRegionRejectsAGarbageExplicitCode(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - for _, bad := range []string{"Bad/Code", "../x", "UK", "a b"} { |
| - if r, src := fx.srv.resolveNewAppRegion(context.Background(), regionReq{explicit: bad, hasExplicit: true}, false); r != "" || src != "default" { |
| - t.Errorf("explicit %q resolved to %q %q, want the home as default", bad, r, src) |
| - } |
| - } |
| - // Valid choices still stand: a coded region, and the home's "". |
| - if r, src := fx.srv.resolveNewAppRegion(context.Background(), regionReq{explicit: "uk", hasExplicit: true}, false); r != "uk" || src != "chosen" { |
| - t.Errorf("explicit uk = %q %q", r, src) |
| - } |
| - if r, src := fx.srv.resolveNewAppRegion(context.Background(), regionReq{explicit: "", hasExplicit: true}, false); r != "" || src != "chosen" { |
| - t.Errorf("explicit home = %q %q", r, src) |
| - } |
| -} |
diff --git a/internal/console/regionconfig.go b/internal/console/regionconfig.go| index 90be4c12c..a6a2a9320 100644 |
| --- a/internal/console/regionconfig.go |
| +++ b/internal/console/regionconfig.go |
| @@ -6,11 +6,6 @@ import ( |
| "github.com/carlosframework/platform/internal/appconfig" |
| ) |
| -// appRegionsOn is spec §5.6: the switch AND a named home. |
| -func (s *Server) appRegionsOn() bool { |
| - return s.cfg.AppRegions && s.cfg.HomeRegion != "" |
| -} |
| - |
| // expectedSecretsFP is the fingerprint a box must publish to receive |
| // placed instances (spec R9): the console's own CARLOS_SECRETS_PUBKEY, |
| // the key the CLI seals config to. "" means the console cannot judge, and |
| @@ -35,13 +30,10 @@ func (s *Server) appRegion(accountID int64, app string) (string, string, error) |
| return s.store.AppRegion(accountID, app) |
| } |
| -// logRegionConfig names, once at startup, each configuration that leaves |
| -// part of the feature off. The secrets-key line does not depend on the |
| -// switch: the guess endpoint answers with the switch off too (R9). |
| +// logRegionConfig names, once at startup, a configuration that leaves |
| +// part of region placement off: the instance doors and the guess endpoint |
| +// read the secrets key (R9). |
| func logRegionConfig(cfg Config) { |
| - if cfg.AppRegions && cfg.HomeRegion == "" { |
| - log.Print("console: CONSOLE_APP_REGIONS=on but CONSOLE_HOME_REGION is unset, so app regions stay off until the home is named") |
| - } |
| if cfg.SecretsPub == "" { |
| log.Print("console: CARLOS_SECRETS_PUBKEY is unset, so no region outside the home can be chosen automatically") |
| } |
diff --git a/internal/console/regionconfig_test.go b/internal/console/regionconfig_test.go| index 9d4a714b7..f29a2289b 100644 |
| --- a/internal/console/regionconfig_test.go |
| +++ b/internal/console/regionconfig_test.go |
| @@ -22,20 +22,6 @@ func mustTestSecretsKey() (pubB64, fp string) { |
| return base64.StdEncoding.EncodeToString(priv.PublicKey().Bytes()), appconfig.KeyFingerprint(priv.PublicKey()) |
| } |
| -func TestAppRegionsOnNeedsANamedHome(t *testing.T) { |
| - fx := newConsoleFixture(t) |
| - for _, c := range []struct { |
| - on bool |
| - home string |
| - want bool |
| - }{{false, "ie", false}, {true, "", false}, {true, "ie", true}} { |
| - fx.srv.cfg.AppRegions, fx.srv.cfg.HomeRegion = c.on, c.home |
| - if got := fx.srv.appRegionsOn(); got != c.want { |
| - t.Errorf("AppRegions=%v HomeRegion=%q: appRegionsOn = %v, want %v", c.on, c.home, got, c.want) |
| - } |
| - } |
| -} |
| - |
| func TestExpectedSecretsFP(t *testing.T) { |
| fx := newConsoleFixture(t) |
| pub, fp := mustTestSecretsKey() |
| @@ -71,22 +57,16 @@ func TestLogRegionConfig(t *testing.T) { |
| prev := log.Writer() |
| log.SetOutput(&buf) |
| defer log.SetOutput(prev) |
| - logRegionConfig(Config{AppRegions: true}) |
| - out := buf.String() |
| - if !strings.Contains(out, "CONSOLE_APP_REGIONS=on but CONSOLE_HOME_REGION is unset, so app regions stay off until the home is named") || |
| - !strings.Contains(out, "CARLOS_SECRETS_PUBKEY is unset, so no region outside the home can be chosen automatically") { |
| - t.Fatalf("missing startup lines: %s", out) |
| - } |
| - // Switch off: the guess endpoint still answers, so a missing secrets |
| - // key is still worth saying (codex plan-R2 8); an unnamed home is not. |
| - buf.Reset() |
| logRegionConfig(Config{}) |
| - if out := buf.String(); !strings.Contains(out, "CARLOS_SECRETS_PUBKEY is unset") || strings.Contains(out, "CONSOLE_HOME_REGION") { |
| - t.Fatalf("switch off logged %q, want only the secrets-key line", out) |
| + // The guess endpoint and the instance doors read the key, so a missing |
| + // one is worth saying (codex plan-R2 8); an unnamed home is not. |
| + if out := buf.String(); !strings.Contains(out, "CARLOS_SECRETS_PUBKEY is unset, so no region outside the home can be chosen automatically") || |
| + strings.Contains(out, "CONSOLE_HOME_REGION") || strings.Contains(out, "CONSOLE_APP_REGIONS") { |
| + t.Fatalf("logged %q, want only the secrets-key line", out) |
| } |
| buf.Reset() |
| pub, _ := mustTestSecretsKey() |
| - logRegionConfig(Config{AppRegions: true, HomeRegion: "ie", SecretsPub: pub}) |
| + logRegionConfig(Config{HomeRegion: "ie", SecretsPub: pub}) |
| if buf.Len() != 0 { |
| t.Fatalf("a complete configuration logged: %s", buf.String()) |
| } |
diff --git a/internal/console/regioncopy.go b/internal/console/regioncopy.go| index 942db6d2e..2d819f06e 100644 |
| --- a/internal/console/regioncopy.go |
| +++ b/internal/console/regioncopy.go |
| @@ -1,36 +1,14 @@ |
| package console |
| -// attributionURL is where C24's credit must link. DB-IP's licence requires |
| -// the credit to link there, so the console page renders Attribution as an |
| -// <a href> to this URL (Paul's ruling, 2026-10-03). |
| -const attributionURL = "https://db-ip.com" |
| - |
| -// regionCopy is every console-page string the nearest-region feature |
| -// shows (spec §19), as approved in the nearest-region copy record. Verbs |
| -// are %s in the order each comment names. Change none of them without a |
| -// new copy review. |
| +// regionCopy is every console-page string the region feature shows (spec |
| +// §19), as approved in the nearest-region copy record. Verbs are %s in the |
| +// order each comment names. Change none of them without a new copy review. |
| type regionCopyStrings struct { |
| - PickerLabel string // C1 |
| - PickerHelp string // C2 |
| - AutoOption string // C3: place |
| - Unavailable string // C5 |
| - StartsIn string // C7: place |
| - CantStart string // C8: place |
| - AuditCreated string // C21: app name, place |
| - Attribution string // C24, rendered as a link to AttributionURL |
| - AttributionURL string // C24's link target |
| + StartsIn string // C7: place |
| + CantStart string // C8: place |
| } |
| var regionCopy = regionCopyStrings{ |
| - PickerLabel: "Region", |
| - PickerHelp: "Where this app's instances run. We picked the region nearest to you. Choose another if most of your users are somewhere else.", |
| - AutoOption: "%s (nearest to you)", |
| - Unavailable: "That region can't take new apps right now. Choose another.", |
| - StartsIn: "New instances start in %s, this app's region.", |
| - CantStart: "New instances can't start in %s, this app's region, right now. Pass a region to place one elsewhere.", |
| - AuditCreated: "created app %s in %s", |
| - Attribution: "IP Geolocation by DB-IP", |
| - AttributionURL: attributionURL, |
| + StartsIn: "New instances start in %s, this app's region.", |
| + CantStart: "New instances can't start in %s, this app's region, right now. Pass a region to place one elsewhere.", |
| } |
| - |
| -func (p page) RegionCopy() regionCopyStrings { return regionCopy } |
diff --git a/internal/console/regioncopy_test.go b/internal/console/regioncopy_test.go| index f2db026b5..d1e2a82be 100644 |
| --- a/internal/console/regioncopy_test.go |
| +++ b/internal/console/regioncopy_test.go |
| @@ -19,10 +19,8 @@ func TestRegionCopyHasNoEmDashesAndRendersItsVerbs(t *testing.T) { |
| } |
| } |
| for _, s := range []string{ |
| - fmt.Sprintf(regionCopy.AutoOption, "P"), |
| fmt.Sprintf(regionCopy.StartsIn, "P"), |
| fmt.Sprintf(regionCopy.CantStart, "P"), |
| - fmt.Sprintf(regionCopy.AuditCreated, "blog", "P"), |
| } { |
| if strings.Contains(s, "%!") { |
| t.Errorf("bad verb: %q", s) |
| @@ -42,7 +40,6 @@ func TestRegionCopyMatchesTheApprovedRecord(t *testing.T) { |
| Entries []struct { |
| ID string `json:"id"` |
| Text string `json:"text"` |
| - Link string `json:"link"` |
| } `json:"entries"` |
| } |
| if err := json.Unmarshal(raw, &rec); err != nil { |
| @@ -53,20 +50,12 @@ func TestRegionCopyMatchesTheApprovedRecord(t *testing.T) { |
| t.Fatal(err) |
| } |
| byID := map[string]string{} |
| - links := map[string]string{} |
| for _, e := range rec.Entries { |
| byID[e.ID] = e.Text |
| - links[e.ID] = e.Link |
| } |
| for id, got := range map[string]string{ |
| - "C1": regionCopy.PickerLabel, |
| - "C2": regionCopy.PickerHelp, |
| - "C3": regionCopy.AutoOption, |
| - "C5": regionCopy.Unavailable, |
| - "C7": regionCopy.StartsIn, |
| - "C8": regionCopy.CantStart, |
| - "C21": regionCopy.AuditCreated, |
| - "C24": regionCopy.Attribution, |
| + "C7": regionCopy.StartsIn, |
| + "C8": regionCopy.CantStart, |
| } { |
| want, ok := byID[id] |
| if !ok { |
| @@ -80,14 +69,4 @@ func TestRegionCopyMatchesTheApprovedRecord(t *testing.T) { |
| t.Errorf("%s: regioncopy.go has no literal %s", id, strconv.Quote(want)) |
| } |
| } |
| - // C24 is DB-IP's required credit; the licence wants it linked. |
| - if links["C24"] == "" { |
| - t.Fatal("C24: the record carries no link") |
| - } |
| - if regionCopy.AttributionURL != links["C24"] || attributionURL != links["C24"] { |
| - t.Errorf("attribution URL = %q / %q, record has %q", regionCopy.AttributionURL, attributionURL, links["C24"]) |
| - } |
| - if regionCopy.Attribution != "IP Geolocation by DB-IP" { |
| - t.Errorf("Attribution = %q", regionCopy.Attribution) |
| - } |
| } |
diff --git a/internal/console/regiondefault_test.go b/internal/console/regiondefault_test.go| index 3b327a150..f43b9cb01 100644 |
| --- a/internal/console/regiondefault_test.go |
| +++ b/internal/console/regiondefault_test.go |
| @@ -363,7 +363,6 @@ func TestInstancesTabRegionLines(t *testing.T) { |
| anyLine := func(body string) bool { return strings.Contains(body, `id="app-region-line"`) } |
| fx, _, _ := fillFixture(t, "uk") |
| - fx.srv.cfg.AppRegions = true |
| body := page(fx) |
| if !strings.Contains(body, starts) { |
| t.Fatal("no C7 line for an available region") |
diff --git a/internal/console/regionfill_test.go b/internal/console/regionfill_test.go| index d61013170..d28920968 100644 |
| --- a/internal/console/regionfill_test.go |
| +++ b/internal/console/regionfill_test.go |
| @@ -293,8 +293,7 @@ func TestExplicitCreateWithTheEdgesListingDownIsNotRefused(t *testing.T) { |
| } |
| func TestFillRunsWithTheSwitchOff(t *testing.T) { |
| - fx, token, u := fillFixture(t, "uk") |
| - fx.srv.cfg.AppRegions = false |
| + _, token, u := fillFixture(t, "uk") |
| if rec := mustCreate(t, u, token, `{"host":"a.go.tito.io"}`); rec.Region != "uk" { |
| t.Fatalf("switch off = %+v, want the stored uk", rec) |
| } |
diff --git a/internal/console/regionguess.go b/internal/console/regionguess.go| index 1b2dc03b6..709c747d6 100644 |
| --- a/internal/console/regionguess.go |
| +++ b/internal/console/regionguess.go |
| @@ -1,7 +1,9 @@ |
| package console |
| import ( |
| + "crypto/subtle" |
| "net" |
| + "net/http" |
| "github.com/carlosframework/platform/internal/geo" |
| ) |
| @@ -52,3 +54,31 @@ func guessRegion(cands []regionCandidate, allows func(code string) bool, in gues |
| } |
| return guessResult{}, false |
| } |
| + |
| +// handleNewAppRegion is the region guess (spec §9.5): POST with csrf and |
| +// tz, session-gated, writing nothing. It was the create-app picker's |
| +// script's; the picker went with the nearest-region switch, and the door |
| +// answers as it did with the switch off. The hints are read from the body, |
| +// used for this one guess and neither logged nor echoed (spec §6.5). |
| +func (s *Server) handleNewAppRegion(w http.ResponseWriter, r *http.Request) { |
| + _, raw, _, _, ok := s.account(w, r) |
| + if !ok { |
| + return |
| + } |
| + if subtle.ConstantTimeCompare([]byte(r.FormValue("csrf")), []byte(raw)) != 1 { |
| + jsonError(w, http.StatusForbidden, "Cross-site request blocked.") |
| + return |
| + } |
| + files, err := s.liveEdges(r.Context()) |
| + cands := homeOnlyCandidates() |
| + if err == nil { |
| + cands = s.regionCands(files) |
| + } |
| + g, ok := guessRegion(cands, func(string) bool { return true }, guessInput{TZ: r.FormValue("tz"), IP: s.personIP(r)}, s.cfg.GeoIP) |
| + if !ok { |
| + g = guessResult{"", "default"} |
| + } |
| + writeJSON(w, http.StatusOK, map[string]string{ |
| + "code": s.homeRegionOut(g.Code), "name": s.placeOf(g.Code, cands), "source": g.Source, |
| + }) |
| +} |
diff --git a/internal/console/regionguess_test.go b/internal/console/regionguess_test.go| index 9408728ea..375101fe4 100644 |
| --- a/internal/console/regionguess_test.go |
| +++ b/internal/console/regionguess_test.go |
| @@ -2,8 +2,13 @@ package console |
| import ( |
| "bytes" |
| + "encoding/json" |
| + "log" |
| "math/rand/v2" |
| "net" |
| + "net/http" |
| + "net/url" |
| + "os" |
| "strings" |
| "testing" |
| @@ -168,3 +173,66 @@ func TestRegionCandidatesHomeWithNoPointLogsNoO7(t *testing.T) { |
| t.Fatalf("log = %q, want the coded region only", buf.String()) |
| } |
| } |
| + |
| +// The guess door (moved with handleNewAppRegion from regionpicker_test.go). |
| +func TestNewAppRegionRouteNeedsSessionAndCSRF(t *testing.T) { |
| + fx, _ := regionFixture(t) |
| + c, csrf := signInAs(t, fx, "paul@keymail.dev", "code-route") |
| + status, _, body := postForm(t, c, fx.u("/apps/new/region"), url.Values{"csrf": {csrf}, "tz": {"Europe/London"}}) |
| + var res map[string]string |
| + if err := json.Unmarshal([]byte(body), &res); err != nil { |
| + t.Fatalf("guess route body %q: %v", body, err) |
| + } |
| + if status != http.StatusOK || res["code"] != "uk" || res["source"] != "timezone" || res["name"] != ukPlace { |
| + t.Fatalf("guess route = %d %v", status, res) |
| + } |
| + if status, _, _ := postForm(t, c, fx.u("/apps/new/region"), url.Values{"csrf": {"wrong"}, "tz": {"Europe/London"}}); status != http.StatusForbidden { |
| + t.Fatalf("bad csrf = %d, want 403", status) |
| + } |
| + if status, _, _ := postForm(t, newBrowser(t), fx.u("/apps/new/region"), url.Values{"tz": {"Europe/London"}}); status == http.StatusOK { |
| + t.Fatal("no session got a guess") |
| + } |
| +} |
| + |
| +// §6.5: the timezone and the address are never echoed, stored or logged. |
| +// PF9: assert the route answers 2xx before any negative check. |
| +func TestRegionGuessHintsNeverLeak(t *testing.T) { |
| + fx, _ := regionFixture(t) |
| + fx.srv.cfg.GeoIP = fakeLocator{"81.2.69.142": geo.Point{Lat: 51.5, Lon: -0.12}} |
| + var logged bytes.Buffer |
| + log.SetOutput(&logged) |
| + t.Cleanup(func() { log.SetOutput(os.Stderr) }) |
| + c, csrf := signInAs(t, fx, "paul@keymail.dev", "code-leak") |
| + |
| + const tz, ip = "Europe/London", "81.2.69.142" |
| + req, err := http.NewRequest(http.MethodPost, fx.u("/apps/new/region"), strings.NewReader(url.Values{"csrf": {csrf}, "tz": {tz}}.Encode())) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| + req.Header.Set("X-Forwarded-For", ip) |
| + res, err := c.Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var buf bytes.Buffer |
| + buf.ReadFrom(res.Body) |
| + res.Body.Close() |
| + if res.StatusCode < 200 || res.StatusCode > 299 { |
| + t.Fatalf("guess route = %d %s", res.StatusCode, buf.String()) |
| + } |
| + if strings.Contains(buf.String(), tz) || strings.Contains(buf.String(), ip) { |
| + t.Fatalf("guess answer echoes a hint: %s", buf.String()) |
| + } |
| + if strings.Contains(logged.String(), tz) || strings.Contains(logged.String(), ip) { |
| + t.Fatalf("a hint was logged: %s", logged.String()) |
| + } |
| + // The form page carries no hint. |
| + status, _, body := get(t, c, fx.u("/apps/new")) |
| + if status != http.StatusOK { |
| + t.Fatalf("form = %d", status) |
| + } |
| + if strings.Contains(body, tz) || strings.Contains(body, ip) { |
| + t.Fatal("form page echoes a hint") |
| + } |
| +} |
diff --git a/internal/console/regionmsgs.go b/internal/console/regionmsgs.go| index 9b3504436..b22d64199 100644 |
| --- a/internal/console/regionmsgs.go |
| +++ b/internal/console/regionmsgs.go |
| @@ -52,22 +52,6 @@ func msgAppRegionNotAllowed(code string, allowed []string) string { |
| code, strings.Join(allowed, ", ")) |
| } |
| -// msgRegionUnknown is C18, or C18b when choices is empty. |
| -func msgRegionUnknown(code string, choices []string) string { |
| - if len(choices) == 0 { |
| - return fmt.Sprintf("region %s is not one this platform runs in. Run the command without --region.", code) |
| - } |
| - return fmt.Sprintf("region %s is not one this platform runs in. Choose from: %s.", code, strings.Join(choices, ", ")) |
| -} |
| - |
| -// msgRegionNotArmed is C19, or C19b when choices is empty. |
| -func msgRegionNotArmed(code string, choices []string) string { |
| - if len(choices) == 0 { |
| - return fmt.Sprintf("region %s can't take new apps right now. Run the command without --region.", code) |
| - } |
| - return fmt.Sprintf("region %s can't take new apps right now. Choose from: %s.", code, strings.Join(choices, ", ")) |
| -} |
| - |
| // msgAppRegionUnreadable is C20. |
| const msgAppRegionUnreadable = "could not read this app's region. Try again." |
diff --git a/internal/console/regionmsgs_test.go b/internal/console/regionmsgs_test.go| index 0d0709866..c51687ca9 100644 |
| --- a/internal/console/regionmsgs_test.go |
| +++ b/internal/console/regionmsgs_test.go |
| @@ -13,19 +13,15 @@ func TestRegionMessagesRender(t *testing.T) { |
| all := []string{ |
| msgAppRegionUnavailable("uk", "absent", []string{"ie", "au"}), |
| msgAppRegionNotAllowed("uk", []string{"ie"}), |
| - msgRegionUnknown("zz", []string{"ie", "uk"}), |
| - msgRegionNotArmed("uk", []string{"ie"}), |
| msgAppRegionUnreadable, |
| msgReplicaOverlap("uk"), |
| msgPolicyUnreadable, |
| msgAppRegionUnconfirmed("uk"), |
| msgPlacementDiscrepancy("a.go.tito.io", "blog", "uk"), |
| msgNoSecretsKey("uk"), |
| - // codex plan-R4 2: the empty-list variants, C16b to C19b. |
| + // codex plan-R4 2: the empty-list variants, C16b and C17b. |
| msgAppRegionUnavailable("uk", "absent", nil), |
| msgAppRegionNotAllowed("uk", nil), |
| - msgRegionUnknown("zz", nil), |
| - msgRegionNotArmed("uk", nil), |
| } |
| for _, s := range all { |
| if s == "" || strings.Contains(s, "—") || strings.Contains(s, "%!") { |
| @@ -35,7 +31,7 @@ func TestRegionMessagesRender(t *testing.T) { |
| if !strings.Contains(all[0], reasonText("absent")) || !strings.Contains(all[0], "ie, au") { |
| t.Errorf("C16 = %q, want the readable reason and the list", all[0]) |
| } |
| - for _, s := range all[len(all)-4:] { |
| + for _, s := range all[len(all)-2:] { |
| if strings.Contains(s, ": .") || strings.Contains(s, ": ,") { |
| t.Errorf("an empty list rendered as a list: %q", s) |
| } |
| @@ -73,11 +69,14 @@ func TestRegionMessagesMatchTheApprovedRecord(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| + // The new-app region refusals went with the nearest-region switch |
| + // (claims cleanup R5); the record still lists them. |
| + retired := map[string]bool{"C18": true, "C18b": true, "C19": true, "C19b": true} |
| byID := map[string]string{} |
| mapped := 0 |
| for _, e := range rec.Entries { |
| byID[e.ID] = e.Text |
| - if e.File != "internal/console/regionmsgs.go" { |
| + if e.File != "internal/console/regionmsgs.go" || retired[e.ID] { |
| continue |
| } |
| mapped++ |
| @@ -85,9 +84,10 @@ func TestRegionMessagesMatchTheApprovedRecord(t *testing.T) { |
| t.Errorf("%s: regionmsgs.go has no literal %s", e.ID, strconv.Quote(e.Text)) |
| } |
| } |
| - // The record maps 4 reasons, C16 to C20, C16b to C19b, C26 to C29 and C31. |
| - if mapped != 18 { |
| - t.Errorf("the record maps %d entries to regionmsgs.go, want 18", mapped) |
| + // The record maps 4 reasons, C16, C17, C20, C16b, C17b, C26 to C29 and |
| + // C31 to the file still. |
| + if mapped != 14 { |
| + t.Errorf("the record maps %d entries to regionmsgs.go, want 14", mapped) |
| } |
| list := []string{"ie", "au"} |
| cases := []struct { |
| @@ -99,12 +99,8 @@ func TestRegionMessagesMatchTheApprovedRecord(t *testing.T) { |
| {"R-not-eligible", reasonText("not-eligible"), byID["R-not-eligible"]}, |
| {"C16", msgAppRegionUnavailable("uk", "absent", list), fmt.Sprintf(byID["C16"], "uk", reasonText("absent"), "ie, au")}, |
| {"C17", msgAppRegionNotAllowed("uk", list), fmt.Sprintf(byID["C17"], "uk", "ie, au")}, |
| - {"C18", msgRegionUnknown("zz", list), fmt.Sprintf(byID["C18"], "zz", "ie, au")}, |
| - {"C19", msgRegionNotArmed("uk", list), fmt.Sprintf(byID["C19"], "uk", "ie, au")}, |
| {"C16b", msgAppRegionUnavailable("uk", "absent", nil), fmt.Sprintf(byID["C16b"], "uk", reasonText("absent"))}, |
| {"C17b", msgAppRegionNotAllowed("uk", nil), fmt.Sprintf(byID["C17b"], "uk")}, |
| - {"C18b", msgRegionUnknown("zz", nil), fmt.Sprintf(byID["C18b"], "zz")}, |
| - {"C19b", msgRegionNotArmed("uk", nil), fmt.Sprintf(byID["C19b"], "uk")}, |
| {"C20", msgAppRegionUnreadable, byID["C20"]}, |
| {"C26", msgReplicaOverlap("uk"), fmt.Sprintf(byID["C26"], "uk", "uk")}, |
| {"C27", msgPolicyUnreadable, byID["C27"]}, |
diff --git a/internal/console/regionpicker.go b/internal/console/regionpicker.go| deleted file mode 100644 |
| index 599347e40..000000000 |
| --- a/internal/console/regionpicker.go |
| +++ /dev/null |
| @@ -1,133 +0,0 @@ |
| -package console |
| - |
| -import ( |
| - "context" |
| - "crypto/subtle" |
| - "fmt" |
| - "github.com/carlosframework/platform/internal/geo" |
| - "github.com/carlosframework/platform/internal/geoip" |
| - "net" |
| - "net/http" |
| - "strings" |
| -) |
| - |
| -// autoRegion is the picker's "let the server guess" value. "@" is outside |
| -// the placement-code grammar, so no real region collides with it (codex |
| -// R2-3). |
| -const autoRegion = "@auto" |
| - |
| -type regionOption struct{ Value, Label string } |
| - |
| -type regionPickerView struct { |
| - Auto string // the @auto option's label (C3) |
| - Options []regionOption |
| - Attribution bool // C24, when the IP step is configured |
| - // AttributionText and AttributionURL are the credit the loaded |
| - // database requires (geoip spec §13): DB-IP's is C24, GeoLite2's is |
| - // MaxMind's. |
| - AttributionText, AttributionURL string |
| -} |
| - |
| -// newAppPicker builds the picker, or nil: switch off, an edges read |
| -// failure, or fewer than two eligible regions (§10). The server's own |
| -// guess is IP, then home; the page script relabels @auto with the |
| -// browser's timezone guess. |
| -func (s *Server) newAppPicker(ctx context.Context, ip net.IP) *regionPickerView { |
| - if !s.appRegionsOn() { |
| - return nil |
| - } |
| - files, err := s.liveEdges(ctx) |
| - if err != nil { |
| - return nil |
| - } |
| - cands := s.regionCands(files) |
| - if eligibleCount(cands) < 2 { |
| - return nil |
| - } |
| - var loc geo.Locator = s.cfg.GeoIP |
| - var rec *recordingLocator |
| - if s.cfg.GeoIPReader != nil { |
| - rec = &recordingLocator{sw: s.cfg.GeoIPReader} |
| - loc = rec |
| - } |
| - g, _ := guessRegion(cands, func(string) bool { return true }, guessInput{IP: ip}, loc) |
| - v := ®ionPickerView{Auto: fmt.Sprintf(regionCopy.AutoOption, s.placeOf(g.Code, cands))} |
| - switch { |
| - case rec != nil: |
| - // The credit names the database that made THIS guess, read under |
| - // the same lock as the lookup (code review R4-4); a guess that used |
| - // no GeoIP data owes no credit. |
| - if a, ok := geoip.AttributionFor(rec.source); ok && rec.used { |
| - v.Attribution, v.AttributionText, v.AttributionURL = true, a.Text, a.URL |
| - } |
| - case s.cfg.GeoIP != nil: |
| - // A bare Locator (tests, older wiring): the IP step is DB-IP's. |
| - v.Attribution, v.AttributionText, v.AttributionURL = true, regionCopy.Attribution, regionCopy.AttributionURL |
| - } |
| - for _, c := range cands { |
| - if c.Eligible { |
| - v.Options = append(v.Options, regionOption{Value: s.homeRegionOut(c.Code), Label: s.placeOf(c.Code, cands)}) |
| - } |
| - } |
| - return v |
| -} |
| - |
| -// pickedRegion turns the form's region field into a regionReq. ok=false |
| -// means the submitted code is not an acceptable region NOW (C5). It is the |
| -// API door's check (validateExplicitRegion), because claimApp does not |
| -// re-validate an explicit region; with the switch off an explicit region is |
| -// neither validated nor refused (spec §9.6, as apicli.go does). |
| -func (s *Server) pickedRegion(ctx context.Context, r *http.Request) (regionReq, bool) { |
| - rq := regionReq{tz: r.FormValue("tz"), ip: s.personIP(r)} |
| - v := strings.TrimSpace(r.FormValue("region")) |
| - if v == "" || v == autoRegion || !s.appRegionsOn() { |
| - return rq, true |
| - } |
| - code, ref := s.validateExplicitRegion(ctx, v) |
| - if ref != nil { |
| - return rq, false |
| - } |
| - rq.explicit, rq.hasExplicit = code, true |
| - return rq, true |
| -} |
| - |
| -// handleNewAppRegion is the page script's guess (spec §9.5): POST with csrf |
| -// and tz, session-gated, writing nothing. The hints are read from the body, |
| -// used for this one guess and neither logged nor echoed (spec §6.5). |
| -func (s *Server) handleNewAppRegion(w http.ResponseWriter, r *http.Request) { |
| - _, raw, _, _, ok := s.account(w, r) |
| - if !ok { |
| - return |
| - } |
| - if subtle.ConstantTimeCompare([]byte(r.FormValue("csrf")), []byte(raw)) != 1 { |
| - jsonError(w, http.StatusForbidden, "Cross-site request blocked.") |
| - return |
| - } |
| - files, err := s.liveEdges(r.Context()) |
| - cands := homeOnlyCandidates() |
| - if err == nil { |
| - cands = s.regionCands(files) |
| - } |
| - g, ok := guessRegion(cands, func(string) bool { return true }, guessInput{TZ: r.FormValue("tz"), IP: s.personIP(r)}, s.cfg.GeoIP) |
| - if !ok { |
| - g = guessResult{"", "default"} |
| - } |
| - writeJSON(w, http.StatusOK, map[string]string{ |
| - "code": s.homeRegionOut(g.Code), "name": s.placeOf(g.Code, cands), "source": g.Source, |
| - }) |
| -} |
| - |
| -// recordingLocator remembers which database answered the guess's lookup. |
| -type recordingLocator struct { |
| - sw *geo.Swappable |
| - source string |
| - used bool |
| -} |
| - |
| -func (r *recordingLocator) Locate(ip net.IP) (geo.Point, bool) { |
| - p, ok, src := r.sw.LocateFrom(ip) |
| - if ok { |
| - r.source, r.used = src, true |
| - } |
| - return p, ok |
| -} |
diff --git a/internal/console/regionpicker_test.go b/internal/console/regionpicker_test.go| deleted file mode 100644 |
| index 2a36efc90..000000000 |
| --- a/internal/console/regionpicker_test.go |
| +++ /dev/null |
| @@ -1,258 +0,0 @@ |
| -package console |
| - |
| -import ( |
| - "bytes" |
| - "encoding/json" |
| - "html" |
| - "log" |
| - "net/http" |
| - "net/url" |
| - "os" |
| - "regexp" |
| - "strings" |
| - "testing" |
| - |
| - "github.com/carlosframework/platform/internal/geo" |
| -) |
| - |
| -func has(body, plain string) bool { return strings.Contains(body, html.EscapeString(plain)) } |
| - |
| -// newAppFormGolden is the base tree's own rendering of the create-app form |
| -// (the branch base, switch off), with the session's CSRF value blanked. |
| -const newAppFormGolden = `<form class="signin" method="post" action="/a/bab/apps/new"> |
| - <input type="hidden" name="csrf" value="CSRF"> |
| - <label class="visually-hidden" for="app-name">App name</label> |
| - <input id="app-name" type="text" name="name" placeholder="my-app" autofocus |
| - required pattern="[A-Za-z][A-Za-z0-9-]{0,31}" maxlength="32"> |
| - <button type="submit">Create app</button> |
| -</form>` |
| - |
| -// newAppForm is the rendered <form>…</form>, CSRF value blanked. |
| -func newAppForm(t *testing.T, body string) string { |
| - t.Helper() |
| - i := strings.Index(body, `<form class="signin"`) |
| - if i < 0 { |
| - t.Fatalf("no create-app form in %s", body) |
| - } |
| - j := strings.Index(body[i:], "</form>") + i + len("</form>") |
| - return regexp.MustCompile(`name="csrf" value="[^"]*"`).ReplaceAllString(body[i:j], `name="csrf" value="CSRF"`) |
| -} |
| - |
| -// codex plan-R4 3, spec §10 and §16: whenever there is no picker, the form |
| -// is today's form byte for byte: with the switch off, and with the switch |
| -// on but only one eligible region. |
| -func TestNewAppPageWithoutPickerIsUnchanged(t *testing.T) { |
| - off := newConsoleFixture(t) |
| - one, _ := regionFixture(t) |
| - setEdges(t, one, map[string]string{"uk-box": ukNoKey}) // the home alone is eligible |
| - for name, fx := range map[string]*consoleFixture{"switch off": off, "one eligible region": one} { |
| - _, _, body := get(t, signInPaul(t, fx), fx.u("/apps/new")) |
| - if got := newAppForm(t, body); got != newAppFormGolden { |
| - t.Errorf("%s: form =\n%q\nwant\n%q", name, got, newAppFormGolden) |
| - } |
| - } |
| -} |
| - |
| -func TestNewAppPickerAndAutoChoice(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - c, csrf := signInAs(t, fx, "paul@keymail.dev", "code-picker") |
| - _, _, body := get(t, c, fx.u("/apps/new")) |
| - for _, want := range []string{`name="region"`, `value="@auto"`, `value="uk"`, `value="ie"`} { |
| - if !strings.Contains(body, want) { |
| - t.Fatalf("picker missing %q", want) |
| - } |
| - } |
| - if !has(body, ukPlace) || !has(body, regionCopy.PickerLabel) || !has(body, regionCopy.PickerHelp) { |
| - t.Fatal("picker missing its copy") |
| - } |
| - if status, _, _ := postForm(t, c, fx.u("/apps/new"), url.Values{"csrf": {csrf}, "name": {"auto1"}, "region": {"@auto"}, "tz": {"Europe/London"}}); status != http.StatusSeeOther { |
| - t.Fatalf("@auto post = %d", status) |
| - } |
| - if r, src, _ := fx.st.AppRegion(OpsAccountID, "auto1"); r != "uk" || src != "timezone" { |
| - t.Fatalf("@auto = %q %q", r, src) |
| - } |
| - postForm(t, c, fx.u("/apps/new"), url.Values{"csrf": {csrf}, "name": {"chose"}, "region": {"ie"}, "tz": {"Europe/London"}}) |
| - if r, src, _ := fx.st.AppRegion(OpsAccountID, "chose"); r != "" || src != "chosen" { |
| - t.Fatalf("explicit ie = %q %q", r, src) |
| - } |
| -} |
| - |
| -// codex R2-3: a home NAMED "auto" is a region, not the sentinel. |
| -func TestRegionNamedAutoIsNotTheSentinel(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - fx.srv.cfg.HomeRegion = "auto" |
| - c, csrf := signInAs(t, fx, "paul@keymail.dev", "code-auto-name") |
| - postForm(t, c, fx.u("/apps/new"), url.Values{"csrf": {csrf}, "name": {"homeauto"}, "region": {"auto"}}) |
| - if r, src, _ := fx.st.AppRegion(OpsAccountID, "homeauto"); r != "" || src != "chosen" { |
| - t.Fatalf("explicit home named auto = %q %q", r, src) |
| - } |
| -} |
| - |
| -// Review Focus 3: uk's box loses the secrets key between render and POST. |
| -func TestNewAppPostWithANoLongerEligibleRegion(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - c, csrf := signInAs(t, fx, "paul@keymail.dev", "code-stale") |
| - if _, _, body := get(t, c, fx.u("/apps/new")); !strings.Contains(body, `value="uk"`) { |
| - t.Fatal("precondition: uk offered") |
| - } |
| - setEdges(t, fx, map[string]string{"uk-box": ukNoKey}) |
| - status, loc, _ := postForm(t, c, fx.u("/apps/new"), url.Values{"csrf": {csrf}, "name": {"stale"}, "region": {"uk"}}) |
| - if status != http.StatusSeeOther || loc != fx.path("/apps/new") { |
| - t.Fatalf("stale region = %d %q, want back to the form", status, loc) |
| - } |
| - if _, _, body := get(t, c, fx.u("/apps/new")); !has(body, regionCopy.Unavailable) { |
| - t.Fatal("no C5 flash") |
| - } |
| - if exists, _ := fx.st.HasAppIn(OpsAccountID, "stale"); exists { |
| - t.Fatal("a refused region still created the app") |
| - } |
| -} |
| - |
| -func TestNewAppRegionRouteNeedsSessionAndCSRF(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - c, csrf := signInAs(t, fx, "paul@keymail.dev", "code-route") |
| - status, _, body := postForm(t, c, fx.u("/apps/new/region"), url.Values{"csrf": {csrf}, "tz": {"Europe/London"}}) |
| - var res map[string]string |
| - if err := json.Unmarshal([]byte(body), &res); err != nil { |
| - t.Fatalf("guess route body %q: %v", body, err) |
| - } |
| - if status != http.StatusOK || res["code"] != "uk" || res["source"] != "timezone" || res["name"] != ukPlace { |
| - t.Fatalf("guess route = %d %v", status, res) |
| - } |
| - if status, _, _ := postForm(t, c, fx.u("/apps/new/region"), url.Values{"csrf": {"wrong"}, "tz": {"Europe/London"}}); status != http.StatusForbidden { |
| - t.Fatalf("bad csrf = %d, want 403", status) |
| - } |
| - if status, _, _ := postForm(t, newBrowser(t), fx.u("/apps/new/region"), url.Values{"tz": {"Europe/London"}}); status == http.StatusOK { |
| - t.Fatal("no session got a guess") |
| - } |
| -} |
| - |
| -// §9.6 as 69a84224 made it: with the switch off the browser door neither |
| -// validates nor refuses an explicit region (resolveNewAppRegion stores the |
| -// home as "default"), exactly as the API door does. |
| -func TestNewAppExplicitRegionSkippedWithSwitchOff(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - fx.srv.cfg.AppRegions = false |
| - c, csrf := signInAs(t, fx, "paul@keymail.dev", "code-off") |
| - for _, region := range []string{"uk", "mars"} { |
| - name := "off-" + region |
| - status, loc, _ := postForm(t, c, fx.u("/apps/new"), url.Values{"csrf": {csrf}, "name": {name}, "region": {region}}) |
| - if status != http.StatusSeeOther || loc == fx.path("/apps/new") { |
| - t.Fatalf("switch off, region %q: %d %q, want the app created", region, status, loc) |
| - } |
| - if r, src, _ := fx.st.AppRegion(OpsAccountID, name); r != "" || src != "default" { |
| - t.Fatalf("switch off, region %q stored %q %q, want \"\" default", region, r, src) |
| - } |
| - } |
| -} |
| - |
| -// With the switch on, a code that is not a region at all is refused with |
| -// C5 too, and nothing is created. |
| -func TestNewAppUnknownRegionIsRefused(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - c, csrf := signInAs(t, fx, "paul@keymail.dev", "code-unknown") |
| - status, loc, _ := postForm(t, c, fx.u("/apps/new"), url.Values{"csrf": {csrf}, "name": {"nowhere"}, "region": {"mars!"}}) |
| - if status != http.StatusSeeOther || loc != fx.path("/apps/new") { |
| - t.Fatalf("unknown region = %d %q", status, loc) |
| - } |
| - if _, _, body := get(t, c, fx.u("/apps/new")); !has(body, regionCopy.Unavailable) { |
| - t.Fatal("no C5 flash") |
| - } |
| - if exists, _ := fx.st.HasAppIn(OpsAccountID, "nowhere"); exists { |
| - t.Fatal("an unknown region still created the app") |
| - } |
| -} |
| - |
| -// The picker's preselected option is "@auto", never a region code, so an |
| -// untouched form is not an explicit choice (adoption must never move). |
| -func TestNewAppPickerPreselectsAuto(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - status, _, body := get(t, signInPaul(t, fx), fx.u("/apps/new")) |
| - if status != http.StatusOK { |
| - t.Fatalf("form = %d", status) |
| - } |
| - if !strings.Contains(body, `<option value="@auto" selected>`) { |
| - t.Fatalf("@auto is not the preselected option: %s", body) |
| - } |
| - if n := strings.Count(body, " selected>"); n != 1 { |
| - t.Fatalf("%d selected options, want exactly 1", n) |
| - } |
| - if !strings.Contains(body, `id="app-region"`) || !strings.Contains(body, `name="tz"`) { |
| - t.Fatal("picker has no region select or tz hint") |
| - } |
| - // The hints travel in POST bodies, never in a URL. |
| - if !strings.Contains(body, `method: "POST"`) { |
| - t.Fatal("the guess script does not POST") |
| - } |
| - if strings.Contains(body, "?tz=") || strings.Contains(body, "&tz=") { |
| - t.Fatal("tz in a URL") |
| - } |
| -} |
| - |
| -// C24 (Paul's ruling for DB-IP's licence): a link to db-ip.com carrying the |
| -// approved text, shown only when GeoIP is configured. |
| -func TestNewAppAttributionOnlyWithGeoIP(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - c := signInPaul(t, fx) |
| - status, _, body := get(t, c, fx.u("/apps/new")) |
| - if status != http.StatusOK || !strings.Contains(body, `id="app-region"`) { |
| - t.Fatalf("precondition: picker page = %d", status) |
| - } |
| - if strings.Contains(body, "db-ip.com") || has(body, regionCopy.Attribution) { |
| - t.Fatal("attribution shown with no GeoIP") |
| - } |
| - fx.srv.cfg.GeoIP = fakeLocator{"81.2.69.142": geo.Point{Lat: 51.5, Lon: -0.12}} |
| - _, _, body = get(t, c, fx.u("/apps/new")) |
| - want := `<a href="https://db-ip.com">` + html.EscapeString("IP Geolocation by DB-IP") + `</a>` |
| - if !strings.Contains(body, want) { |
| - t.Fatalf("attribution link %q not in page", want) |
| - } |
| -} |
| - |
| -// §6.5: the timezone and the address are never echoed, stored or logged. |
| -// PF9: assert the route answers 2xx before any negative check, and key the |
| -// page checks on an element id. |
| -func TestRegionGuessHintsNeverLeak(t *testing.T) { |
| - fx, _ := regionFixture(t) |
| - fx.srv.cfg.GeoIP = fakeLocator{"81.2.69.142": geo.Point{Lat: 51.5, Lon: -0.12}} |
| - var logged bytes.Buffer |
| - log.SetOutput(&logged) |
| - t.Cleanup(func() { log.SetOutput(os.Stderr) }) |
| - c, csrf := signInAs(t, fx, "paul@keymail.dev", "code-leak") |
| - |
| - const tz, ip = "Europe/London", "81.2.69.142" |
| - req, err := http.NewRequest(http.MethodPost, fx.u("/apps/new/region"), strings.NewReader(url.Values{"csrf": {csrf}, "tz": {tz}}.Encode())) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| - req.Header.Set("X-Forwarded-For", ip) |
| - res, err := c.Do(req) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - var buf bytes.Buffer |
| - buf.ReadFrom(res.Body) |
| - res.Body.Close() |
| - if res.StatusCode < 200 || res.StatusCode > 299 { |
| - t.Fatalf("guess route = %d %s", res.StatusCode, buf.String()) |
| - } |
| - if strings.Contains(buf.String(), tz) || strings.Contains(buf.String(), ip) { |
| - t.Fatalf("guess answer echoes a hint: %s", buf.String()) |
| - } |
| - if strings.Contains(logged.String(), tz) || strings.Contains(logged.String(), ip) { |
| - t.Fatalf("a hint was logged: %s", logged.String()) |
| - } |
| - // The form page carries no hint, and the tz field starts empty (the |
| - // script fills it in the browser). |
| - status, _, body := get(t, c, fx.u("/apps/new")) |
| - if status != http.StatusOK { |
| - t.Fatalf("form = %d", status) |
| - } |
| - if !strings.Contains(body, `id="app-region"`) || !strings.Contains(body, `<input type="hidden" name="tz" value="">`) { |
| - t.Fatal("picker page without its empty tz field") |
| - } |
| - if strings.Contains(body, tz) || strings.Contains(body, ip) { |
| - t.Fatal("form page echoes a hint") |
| - } |
| -} |
diff --git a/internal/console/server.go b/internal/console/server.go| index f977c3f05..a3a449fe1 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -534,9 +534,6 @@ type Config struct { |
| // and nothing about placement changes when it is set. "" is legal: the |
| // regions endpoint then reports no home row and an empty default. |
| HomeRegion string |
| - // AppRegions is CONSOLE_APP_REGIONS=on (nearest-region spec §5.6). Off |
| - // never stops the create door's fill for rows already holding a region. |
| - AppRegions bool |
| // GeoIP is the optional CONSOLE_GEOIP_DB locator; nil = IP step off. |
| GeoIP geo.Locator |
| // GeoIPReader is the same reader as GeoIP when it is a Swappable (the |
| @@ -1867,8 +1864,6 @@ func normalizeHost(host string) string { |
| // page is the one bag every template reads from; unused fields are ignored. |
| type page struct { |
| - RegionPicker *regionPickerView // new-app page: nil = no picker |
| - |
| AccountStore *accountStoreView |
| StoreQueue *storeQueueView |
| StorePending *int |
| @@ -4251,8 +4246,8 @@ func reservedAppName(acct *Account, name string) bool { |
| // claimApp is the permanent claim every existing door makes: claimAppWith |
| // with a zero expiresAt. |
| -func (s *Server) claimApp(ctx context.Context, acct *Account, name, addr, placement string, ownerClaim bool, rq regionReq) (outcome claimOutcome, placed string, held *apexHold) { |
| - return s.claimAppWith(ctx, acct, name, addr, placement, ownerClaim, rq, time.Time{}) |
| +func (s *Server) claimApp(ctx context.Context, acct *Account, name, addr, placement string, ownerClaim bool) (outcome claimOutcome, placed string, held *apexHold) { |
| + return s.claimAppWith(ctx, acct, name, addr, placement, ownerClaim, time.Time{}) |
| } |
| // claimAppWith claims an app name for acct — once, ever. A name is refused when |
| @@ -4309,7 +4304,7 @@ func (s *Server) claimApp(ctx context.Context, acct *Account, name, addr, placem |
| // other name, runs with ownerClaim false whatever the caller's role (spec |
| // §3, so any object under the prefix refuses), and inserts the row with its |
| // expiry in the same statement that claims the name. |
| -func (s *Server) claimAppWith(ctx context.Context, acct *Account, name, addr, placement string, ownerClaim bool, rq regionReq, expiresAt time.Time) (outcome claimOutcome, placed string, held *apexHold) { |
| +func (s *Server) claimAppWith(ctx context.Context, acct *Account, name, addr, placement string, ownerClaim bool, expiresAt time.Time) (outcome claimOutcome, placed string, held *apexHold) { |
| if !release.ValidApp(name) { |
| return claimInvalid, "", nil |
| } |
| @@ -4413,7 +4408,9 @@ func (s *Server) claimAppWith(ctx context.Context, acct *Account, name, addr, pl |
| } |
| return claimTaken, "", nil |
| } |
| - region, source := s.resolveNewAppRegion(ctx, rq, adoptingExistingApp) |
| + // A new row is the home's: region "" from "default". No create door |
| + // chooses another (the nearest-region switch was deleted while off). |
| + region, source := "", "default" |
| if s.beforeClaimInsert != nil { |
| s.beforeClaimInsert() |
| } |
| @@ -4469,7 +4466,6 @@ func (s *Server) handleNewAppForm(w http.ResponseWriter, r *http.Request) { |
| p := s.accountPage(w, r, addr, raw, acct, role) |
| p.Title = "Create an app" |
| p.ActiveNav = "apps" |
| - p.RegionPicker = s.newAppPicker(r.Context(), s.personIP(r)) |
| s.render(w, http.StatusOK, "app_new", p) |
| } |
| @@ -4499,13 +4495,6 @@ func (s *Server) handleNewApp(w http.ResponseWriter, r *http.Request) { |
| http.Redirect(w, r, formPage, http.StatusSeeOther) |
| } |
| name := normalizeAppName(r.FormValue("name")) |
| - // The region is resolved inside claimApp, once it knows the claim is not |
| - // an adoption; the timezone and the address only ever feed that guess. |
| - rq, regionOK := s.pickedRegion(r.Context(), r) |
| - if !regionOK { |
| - fail(regionCopy.Unavailable) |
| - return |
| - } |
| // The browser door never places at create time, so the second return |
| // (what actually stuck) is always "" here and there is nothing to echo |
| // it to — this form has no placement concept at all. |
| @@ -4520,7 +4509,7 @@ func (s *Server) handleNewApp(w http.ResponseWriter, r *http.Request) { |
| fail("Could not create the app. Please try again.") |
| return |
| } |
| - outcome, _, held := s.claimApp(r.Context(), acct, name, addr, "", role == RoleOwner, rq) |
| + outcome, _, held := s.claimApp(r.Context(), acct, name, addr, "", role == RoleOwner) |
| switch outcome { |
| case claimInvalid: |
| fail("Invalid app name — lowercase letters, digits, and dashes, starting with a letter.") |
| @@ -4539,13 +4528,7 @@ func (s *Server) handleNewApp(w http.ResponseWriter, r *http.Request) { |
| case claimCreateFailed: |
| fail("Could not create the app. Please try again.") |
| case claimOK: |
| - detail := "created app " + name |
| - if s.appRegionsOn() { |
| - region, _, _ := s.store.AppRegion(acct.ID, name) |
| - files, _ := s.liveEdges(r.Context()) |
| - detail = fmt.Sprintf(regionCopy.AuditCreated, name, s.placeOf(region, s.regionCands(files))) |
| - } |
| - s.audit(acct, name, addr, "create", detail) |
| + s.audit(acct, name, addr, "create", "created app "+name) |
| s.setFlash(w, "ok", "Created app "+name+" — it's yours.") |
| http.Redirect(w, r, home+"apps/"+url.PathEscape(name), http.StatusSeeOther) |
| } |
diff --git a/internal/console/templates/app_new.html b/internal/console/templates/app_new.html| index efd6e13b1..02d232e8d 100644 |
| --- a/internal/console/templates/app_new.html |
| +++ b/internal/console/templates/app_new.html |
| @@ -10,35 +10,7 @@ |
| <input type="hidden" name="csrf" value="{{.CSRF}}"> |
| <label class="visually-hidden" for="app-name">App name</label> |
| <input id="app-name" type="text" name="name" placeholder="my-app" autofocus |
| - required pattern="[A-Za-z][A-Za-z0-9-]{0,31}" maxlength="32">{{with .RegionPicker}} |
| - <label for="app-region">{{$.RegionCopy.PickerLabel}}</label> |
| - <select id="app-region" name="region"> |
| - <option value="@auto" selected>{{.Auto}}</option> |
| - {{range .Options}}<option value="{{.Value}}">{{.Label}}</option>{{end}} |
| - </select> |
| - <input type="hidden" name="tz" value=""> |
| - <p class="small">{{$.RegionCopy.PickerHelp}}</p> |
| - {{if .Attribution}}<p class="small"><a href="{{.AttributionURL}}">{{.AttributionText}}</a></p>{{end}} |
| - <script> |
| - // Enhancement only: with JS off the server's IP-or-home guess stands. |
| - // Fills the tz hint and relabels ONLY the @auto option; its value stays |
| - // "@auto" so the server still knows the person did not choose. |
| - (function () { |
| - var f = document.currentScript.closest("form"), sel = f.elements.region, tz = ""; |
| - var label = {{printf $.RegionCopy.AutoOption "%PLACE%"}}; |
| - try { tz = Intl.DateTimeFormat().resolvedOptions().timeZone || ""; } catch (e) {} |
| - f.elements.tz.value = tz; |
| - if (!tz) return; |
| - var body = new URLSearchParams({ csrf: f.elements.csrf.value, tz: tz }); |
| - fetch("{{$.Base}}/apps/new/region", { method: "POST", body: body, credentials: "same-origin" }) |
| - .then(function (r) { return r.ok ? r.json() : null; }) |
| - .then(function (g) { |
| - if (!g || sel.value !== "@auto") return; |
| - sel.options[0].text = label.replace("%PLACE%", g.name); |
| - }) |
| - .catch(function () {}); |
| - })(); |
| - </script>{{end}} |
| + required pattern="[A-Za-z][A-Za-z0-9-]{0,31}" maxlength="32"> |
| <button type="submit">Create app</button> |
| </form> |
| <p class="small">Names are lowercase letters, digits, and dashes, starting with a letter — unique within this account, not across the platform.</p> |
diff --git a/internal/console/tempnames_test.go b/internal/console/tempnames_test.go| index 72185a2fd..628ac375f 100644 |
| --- a/internal/console/tempnames_test.go |
| +++ b/internal/console/tempnames_test.go |
| @@ -16,11 +16,11 @@ import ( |
| func TestPermanentClaimsRefuseTheTmpNamespace(t *testing.T) { |
| fx := newConsoleFixture(t) |
| acct := opsAccount(t, fx) |
| - if got, _, _ := fx.srv.claimApp(context.Background(), acct, "tmp-docs", "paul@keymail.dev", "", true, regionReq{}); got != claimTemporaryReserved { |
| + if got, _, _ := fx.srv.claimApp(context.Background(), acct, "tmp-docs", "paul@keymail.dev", "", true); got != claimTemporaryReserved { |
| t.Fatalf("claimApp(tmp-docs) = %v, want claimTemporaryReserved", got) |
| } |
| // And a temporary claim refuses anything outside it. |
| - if got, _, _ := fx.srv.claimAppWith(context.Background(), acct, "docs", "paul@keymail.dev", "", false, regionReq{}, time.Now().Add(time.Hour)); got != claimInvalid { |
| + if got, _, _ := fx.srv.claimAppWith(context.Background(), acct, "docs", "paul@keymail.dev", "", false, time.Now().Add(time.Hour)); got != claimInvalid { |
| t.Fatalf("temporary claimAppWith(docs) = %v, want claimInvalid", got) |
| } |
diff --git a/internal/console/tempregion_test.go b/internal/console/tempregion_test.go| index 07a93d59a..9f70175de 100644 |
| --- a/internal/console/tempregion_test.go |
| +++ b/internal/console/tempregion_test.go |
| @@ -5,32 +5,31 @@ import ( |
| "testing" |
| ) |
| -// /new-temporary takes /new's optional region fields, resolved the same way |
| -// and stored in the same insert as the expiry. |
| +// /new-temporary takes /new's optional region fields and, like /new, |
| +// ignores them: the home is stored in the same insert as the expiry. |
| func newTemporaryURL(fx *consoleFixture) string { |
| return fx.ts.URL + "/api/cli/apps/" + fx.sqid + "/new-temporary" |
| } |
| -func TestTemporaryCreateResolvesRegion(t *testing.T) { |
| +func TestTemporaryCreateStoresTheHome(t *testing.T) { |
| fx, token := regionFixture(t) |
| fx.srv.cfg.TemporaryApps = true |
| - status, res := postJSON(t, newTemporaryURL(fx), map[string]any{"name": "tmp-tz", "timezone": "Europe/London"}, token) |
| - if status != http.StatusOK || res["region"] != "uk" || res["region_source"] != "timezone" || |
| - res["region_name"] != ukPlace || res["regions_available"] != float64(2) { |
| - t.Fatalf("timezone create = %d %v", status, res) |
| - } |
| - if r, src, _ := fx.st.AppRegion(OpsAccountID, "tmp-tz"); r != "uk" || src != "timezone" { |
| - t.Fatalf("stored %q %q", r, src) |
| - } |
| - if l := lifeOf(t, fx, "tmp-tz"); l == nil || !l.Temporary() { |
| - t.Fatalf("row = %+v, want a temporary row", l) |
| - } |
| - status, res = postJSON(t, newTemporaryURL(fx), map[string]any{"name": "tmp-chosen", "region": "uk"}, token) |
| - if status != http.StatusOK || res["region"] != "uk" || res["region_source"] != "chosen" { |
| - t.Fatalf("--region create = %d %v", status, res) |
| - } |
| - if r, src, _ := fx.st.AppRegion(OpsAccountID, "tmp-chosen"); r != "uk" || src != "chosen" { |
| - t.Fatalf("stored %q %q", r, src) |
| + for _, body := range []map[string]any{ |
| + {"name": "tmp-tz", "timezone": "Europe/London"}, |
| + {"name": "tmp-chosen", "region": "uk"}, |
| + {"name": "tmp-bad", "region": "Bad/Code"}, |
| + } { |
| + name := body["name"].(string) |
| + status, res := postJSON(t, newTemporaryURL(fx), body, token) |
| + if status != http.StatusOK || res["region"] != "ie" || res["region_source"] != "default" || res["regions_available"] != float64(1) { |
| + t.Fatalf("%s: create = %d %v", name, status, res) |
| + } |
| + if r, src, _ := fx.st.AppRegion(OpsAccountID, name); r != "" || src != "default" { |
| + t.Fatalf("%s: stored %q %q", name, r, src) |
| + } |
| + if l := lifeOf(t, fx, name); l == nil || !l.Temporary() { |
| + t.Fatalf("%s: row = %+v, want a temporary row", name, l) |
| + } |
| } |
| } |
| @@ -46,13 +45,9 @@ func TestTemporaryCreateWithoutRegionGetsTheDefault(t *testing.T) { |
| } |
| } |
| -func TestTemporaryCreateRefusesABadRegionAndUnknownFields(t *testing.T) { |
| +func TestTemporaryCreateRefusesItsUnknownFields(t *testing.T) { |
| fx, token := regionFixture(t) |
| fx.srv.cfg.TemporaryApps = true |
| - status, res := postJSON(t, newTemporaryURL(fx), map[string]any{"name": "tmp-bad", "region": "Bad/Code"}, token) |
| - if status != http.StatusBadRequest || errOf(res) != msgRegionUnknown("Bad/Code", []string{"ie", "uk"}) { |
| - t.Fatalf("bad region = %d %v, want /new's refusal", status, res) |
| - } |
| for _, extra := range []string{"place", "control_plane", "build_probe", "regions"} { |
| name := "tmp-x" + extra[:2] |
| status, _ := postJSON(t, newTemporaryURL(fx), map[string]any{"name": name, extra: "fleet/pi"}, token) |
| @@ -60,7 +55,7 @@ func TestTemporaryCreateRefusesABadRegionAndUnknownFields(t *testing.T) { |
| t.Errorf("%s = %d, want 400", extra, status) |
| } |
| } |
| - for _, name := range []string{"tmp-bad", "tmp-xpl", "tmp-xco", "tmp-xbu", "tmp-xre"} { |
| + for _, name := range []string{"tmp-xpl", "tmp-xco", "tmp-xbu", "tmp-xre"} { |
| if has, _ := fx.st.HasAppIn(OpsAccountID, name); has { |
| t.Errorf("a refused create still claimed %s", name) |
| } |