| index 7517afbd2..e87f5f430 100644 |
| --- a/cli_add_regional_test.go |
| +++ b/cli_add_regional_test.go |
| @@ -44,7 +44,11 @@ func TestAddRefusesARegionalHost(t *testing.T) { |
| run := func(extraEnv []string, host string) (string, error) { |
| t.Helper() |
| cmd := exec.Command(bin, "add", "-registry", regPath, "-app", "shop", host) |
| - cmd.Env = carlosTestEnv(t, extraEnv...) |
| + // carlosTestEnv inherits the operator's shell; clear every deployment |
| + // variable first so each case sees only what it sets (later entries win). |
| + cmd.Env = carlosTestEnv(t, append([]string{ |
| + "CARLOS_DEPLOYMENT_BUCKET=", "CARLOS_DEPLOYMENT_DIR=", "CARLOS_RELEASE_PUBKEY=", |
| + }, extraEnv...)...) |
| // pick() walks cwd ancestors for .carlos/config, so the subprocess must not run from the real checkout. |
| cmd.Dir = scratch |
| out, err := cmd.CombinedOutput() |
| @@ -68,7 +72,7 @@ func TestAddRefusesARegionalHost(t *testing.T) { |
| return got != nil |
| } |
| |
| - for _, h := range []string{claimed, "*." + claimed} { |
| + for _, h := range []string{claimed, "*." + claimed, claimed + ".", "*." + claimed + ".", "Shop.Example.COM.", "*.SHOP.example.com."} { |
| out, err := run(withStore, h) |
| if err == nil { |
| t.Fatalf("add %s under a regional claim: want non-zero exit, got 0\n%s", h, out) |
| @@ -82,6 +86,9 @@ func TestAddRefusesARegionalHost(t *testing.T) { |
| if has(h) { |
| t.Errorf("add %s: refused, yet the registry has a row", h) |
| } |
| + if has(strings.TrimSuffix(strings.ToLower(h), ".")) { |
| + t.Errorf("add %s: refused, yet the registry has its canonical row", h) |
| + } |
| } |
| |
| // Neighbours the claim does not hold: a sub-host (no wildcard claim of its |
| @@ -156,3 +163,55 @@ func TestAddRegionalCheckPassesAPlainClaim(t *testing.T) { |
| t.Errorf("addRegionalCheck with no store = refused %v, skipped %v, want skipped only", refused, skipped) |
| } |
| } |
| + |
| +// The claim key is the canonical host (NormalizeAliasHost: lower-cased, one |
| +// trailing dot dropped), the same identity the claim writer uses. A host that |
| +// does not normalize keeps the old lower-cased spelling, so it reads as |
| +// not-found exactly as before. |
| +func TestRegionalClaimHostIsCanonical(t *testing.T) { |
| + for in, want := range map[string]string{ |
| + "shop.example.com": "shop.example.com", |
| + "shop.example.com.": "shop.example.com", |
| + "Shop.Example.COM.": "shop.example.com", |
| + "*.shop.example.com": "shop.example.com", |
| + "*.shop.example.com.": "shop.example.com", |
| + "*.SHOP.example.com.": "shop.example.com", |
| + "localhost": "localhost", |
| + "localhost.": "localhost.", |
| + "*.localhost.": "localhost.", |
| + "bad_host.example.com.": "bad_host.example.com.", |
| + "shop.example.com..": "shop.example.com..", |
| + "*.": "", |
| + "": "", |
| + } { |
| + if got := regionalClaimHost(in); got != want { |
| + t.Errorf("regionalClaimHost(%q) = %q, want %q", in, got, want) |
| + } |
| + } |
| +} |
| + |
| +// The trailing-dot spellings of a regional claim's host are refused by the |
| +// check itself, not only through the binary. |
| +func TestAddRegionalCheckRefusesTrailingDot(t *testing.T) { |
| + store := release.NewDirStore(t.TempDir()) |
| + ctx := context.Background() |
| + if _, err := domains.SetClaimPlacements(ctx, store, domains.Claim{ |
| + Schema: 2, Host: "shop.example.com", Account: "bab", App: "shop", |
| + Route: "shop-ie.example.net", |
| + CreatedAt: "2026-10-29T00:00:00Z", CreatedBy: "owner@example.com", |
| + Placements: []domains.Placement{{Region: "", Host: "shop-ie.example.net"}, {Region: "uk", Host: "shop-uk.example.net"}}, |
| + }, nil, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, h := range []string{"shop.example.com.", "Shop.Example.COM.", "*.shop.example.com.", "*.SHOP.example.com."} { |
| + if refused, skipped := addRegionalCheck(ctx, store, h); !refused || skipped { |
| + t.Errorf("addRegionalCheck(%s) = refused %v, skipped %v, want refused only", h, refused, skipped) |
| + } |
| + } |
| + // A host that does not normalize reads as not-found, as before. |
| + for _, h := range []string{"localhost.", "bad_host.example.com."} { |
| + if refused, skipped := addRegionalCheck(ctx, store, h); refused || skipped { |
| + t.Errorf("addRegionalCheck(%s) = refused %v, skipped %v, want neither", h, refused, skipped) |
| + } |
| + } |
| +} |