Commit 44f2c87d authored by Patrick Bajao's avatar Patrick Bajao

Add regex validation on alias name

parent ae7f16d8
......@@ -4,5 +4,11 @@ class ProjectAlias < ApplicationRecord
belongs_to :project
validates :project, presence: true
validates :name, presence: true, uniqueness: true
validates :name,
presence: true,
uniqueness: true,
format: {
with: ::Gitlab::PathRegex.project_path_format_regex,
message: ::Gitlab::PathRegex.project_path_format_message
}
end
......@@ -10,4 +10,7 @@ describe ProjectAlias do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_uniqueness_of(:name) }
it { is_expected.not_to allow_value('/foo').for(:name) }
it { is_expected.not_to allow_value('foo/foo').for(:name) }
it { is_expected.not_to allow_value('foo.git').for(:name) }
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment