| index 7f3914d7e..1da50338c 100644 |
| --- a/internal/console/regionclaim_test.go |
| +++ b/internal/console/regionclaim_test.go |
| @@ -226,3 +226,42 @@ func TestClaimHeldApexWritesNothing(t *testing.T) { |
| t.Fatalf("a refused claim logged a region line: %s", logs.String()) |
| } |
| } |
| + |
| +// 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) { |
| + 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) |
| + } |
| + if e := errOf(res); e != "" { |
| + t.Errorf("switch off 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) |
| + } |
| + } |
| +} |
| + |
| +// 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) |
| + } |
| +} |