Skip to content

Commit d6939fe

Browse files
Add anchors to name regex (#1385)
1 parent 20083a1 commit d6939fe

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

apps/core/lib/core/schema/console_instance.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ defmodule Core.Schema.ConsoleInstance do
113113
|> cast(attrs, @valid)
114114
|> cast_embed(:configuration, with: &configuration_changeset/2)
115115
|> cast_embed(:instance_status, with: &status_changeset/2)
116-
|> validate_required(@valid -- ~w(external_id postgres_id cluster_id)a)
116+
|> validate_required(@valid -- ~w(external_id name postgres_id cluster_id)a)
117117
|> foreign_key_constraint(:cluster_id)
118118
|> foreign_key_constraint(:postgres_id)
119119
|> foreign_key_constraint(:owner_id)
120120
|> unique_constraint(:subdomain)
121121
|> unique_constraint(:name)
122-
|> validate_format(:name, ~r/[a-z][a-z0-9]{5,10}/, message: "must be an alphanumeric string between 5 and 11 characters")
122+
|> validate_format(:name, ~r/^[a-z][a-z0-9-]{4,14}$/, message: "must be an alphanumeric string between 5 and 15 characters, hyphens allowed")
123123
|> validate_region()
124124
end
125125

@@ -133,7 +133,7 @@ defmodule Core.Schema.ConsoleInstance do
133133
|> foreign_key_constraint(:owner_id)
134134
|> unique_constraint(:subdomain)
135135
|> unique_constraint(:name)
136-
|> validate_format(:name, ~r/[a-z][a-z0-9]{5,10}/, message: "must be an alphanumeric string between 5 and 11 characters")
136+
|> validate_format(:name, ~r/^[a-z][a-z0-9-]{4,14}$/, message: "must be an alphanumeric string between 5 and 15 characters, hyphens allowed")
137137
|> validate_region()
138138
end
139139

apps/core/test/services/cloud_test.exs

+15
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ defmodule Core.Services.CloudTest do
7171
assert_receive {:event, %PubSub.ConsoleInstanceCreated{item: ^instance}}
7272
end
7373

74+
test "cannot create instances w/ capitalized names" do
75+
account = insert(:account)
76+
enterprise_plan(account)
77+
user = admin_user(account)
78+
insert(:repository, name: "console")
79+
80+
{:error, _} = Cloud.create_instance(%{
81+
type: :dedicated,
82+
name: "My-Cluster",
83+
cloud: :aws,
84+
region: "us-east-1",
85+
size: :small
86+
}, user)
87+
end
88+
7489
test "nonenterprise plans cannot create a dedicated cloud console instance" do
7590
account = insert(:account)
7691
enable_features(account, [:cd])

0 commit comments

Comments
 (0)