diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-13 12:54:02 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-13 12:54:02 +0300 |
commit | b5b6c7b17527cc2360066557207af935bec2168f (patch) | |
tree | 5d1eb736f0d9a892f73dfff7f0739d75e7359079 | |
parent | 259108ada340a0f1d49e2d80d1c433a377983e1c (diff) |
Sanitize container repository path in model class
-rw-r--r-- | app/models/container_repository.rb | 3 | ||||
-rw-r--r-- | lib/container_registry/path.rb | 4 | ||||
-rw-r--r-- | spec/models/container_repository_spec.rb | 14 |
3 files changed, 16 insertions, 5 deletions
diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index 82f4182d59a..d0c94d3b694 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -20,7 +20,8 @@ class ContainerRepository < ActiveRecord::Base end def path - @path ||= [project.full_path, name].select(&:present?).join('/') + @path ||= [project.full_path, name] + .select(&:present?).join('/').downcase end def location diff --git a/lib/container_registry/path.rb b/lib/container_registry/path.rb index 30828bb6565..4a585996aa5 100644 --- a/lib/container_registry/path.rb +++ b/lib/container_registry/path.rb @@ -15,7 +15,7 @@ module ContainerRegistry LEVELS_SUPPORTED = 3 def initialize(path) - @path = path.downcase + @path = path.to_s.downcase end def valid? @@ -25,7 +25,7 @@ module ContainerRegistry end def components - @components ||= @path.to_s.split('/') + @components ||= @path.split('/') end def nodes diff --git a/spec/models/container_repository_spec.rb b/spec/models/container_repository_spec.rb index 6d6c9f2adfc..eff41d85972 100644 --- a/spec/models/container_repository_spec.rb +++ b/spec/models/container_repository_spec.rb @@ -34,8 +34,18 @@ describe ContainerRepository do end describe '#path' do - it 'returns a full path to the repository' do - expect(repository.path).to eq('group/test/my_image') + context 'when project path does not contain uppercase letters' do + it 'returns a full path to the repository' do + expect(repository.path).to eq('group/test/my_image') + end + end + + context 'when path contains uppercase letters' do + let(:project) { create(:project, path: 'MY_PROJECT', group: group) } + + it 'returns a full path without capital letters' do + expect(repository.path).to eq('group/my_project/my_image') + end end end |