Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add anchors to name regex #1385

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/core/lib/core/schema/console_instance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ defmodule Core.Schema.ConsoleInstance do
|> cast(attrs, @valid)
|> cast_embed(:configuration, with: &configuration_changeset/2)
|> cast_embed(:instance_status, with: &status_changeset/2)
|> validate_required(@valid -- ~w(external_id postgres_id cluster_id)a)
|> validate_required(@valid -- ~w(external_id name postgres_id cluster_id)a)
|> foreign_key_constraint(:cluster_id)
|> foreign_key_constraint(:postgres_id)
|> foreign_key_constraint(:owner_id)
|> unique_constraint(:subdomain)
|> unique_constraint(:name)
|> validate_format(:name, ~r/[a-z][a-z0-9]{5,10}/, message: "must be an alphanumeric string between 5 and 11 characters")
|> validate_format(:name, ~r/^[a-z][a-z0-9-]{4,14}$/, message: "must be an alphanumeric string between 5 and 15 characters, hyphens allowed")
|> validate_region()
end

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

Expand Down
15 changes: 15 additions & 0 deletions apps/core/test/services/cloud_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ defmodule Core.Services.CloudTest do
assert_receive {:event, %PubSub.ConsoleInstanceCreated{item: ^instance}}
end

test "cannot create instances w/ capitalized names" do
account = insert(:account)
enterprise_plan(account)
user = admin_user(account)
insert(:repository, name: "console")

{:error, _} = Cloud.create_instance(%{
type: :dedicated,
name: "My-Cluster",
cloud: :aws,
region: "us-east-1",
size: :small
}, user)
end

test "nonenterprise plans cannot create a dedicated cloud console instance" do
account = insert(:account)
enable_features(account, [:cd])
Expand Down
Loading