Skip to content
Snippets Groups Projects
Commit 1a47986b authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Check registry repository name against regexp

This regexp is extracted from Docker Distribution 2.4.1 docs, contains
additional `/` element that can be a separator of components.
parent 01280a5a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -22,7 +22,9 @@ module ContainerRegistry
end
 
def valid?
@nodes.size > 1 && @nodes.size < Namespace::NUMBER_OF_ANCESTORS_ALLOWED
@path =~ Gitlab::Regex.container_repository_name_regex &&
@nodes.size > 1 &&
@nodes.size < Namespace::NUMBER_OF_ANCESTORS_ALLOWED
end
 
def components
Loading
Loading
Loading
Loading
@@ -121,6 +121,13 @@ module Gitlab
git_reference_regex
end
 
##
# Docker Distribution Registry 2.4.1 repository name rules
#
def container_repository_name_regex
@container_repository_regex ||= %r{\A[a-z0-9]+(?:[-._/][a-z0-9]+)*\Z}
end
def environment_name_regex
@environment_name_regex ||= /\A[a-zA-Z0-9_\\\/\${}. -]+\z/.freeze
end
Loading
Loading
Loading
Loading
@@ -36,25 +36,31 @@ describe ContainerRegistry::Path do
context 'when path has less than two components' do
let(:path) { 'something/' }
 
it 'is not valid' do
expect(subject).not_to be_valid
end
it { is_expected.not_to be_valid }
end
 
context 'when path has more than allowed number of components' do
let(:path) { 'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/r/s/t/u/w/y/z' }
 
it 'is not valid' do
expect(subject).not_to be_valid
end
it { is_expected.not_to be_valid }
end
context 'when path has invalid characters' do
let(:path) { 'some\path' }
it { is_expected.not_to be_valid }
end
 
context 'when path has two or more components' do
let(:path) { 'some/path' }
 
it 'is valid' do
expect(subject).to be_valid
end
it { is_expected.to be_valid }
end
context 'when path is related to multi-level image' do
let(:path) { 'some/path/my/image' }
it { is_expected.to be_valid }
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment