Skip to content

Commit

Permalink
Refs #23910 - Port robottelo tests - docker-repository
Browse files Browse the repository at this point in the history
  • Loading branch information
ldjebran committed Jul 4, 2018
1 parent 514128c commit 03e2670
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 24 deletions.
51 changes: 47 additions & 4 deletions test/models/repository_base.rb
Expand Up @@ -41,10 +41,10 @@ def valid_http_credentials_list(escape = false)
{ login: 'admin', pass: 'changeme', quote: false },
{ login: '@dmin', pass: 'changeme', quote: true },
{ login: 'adm/n', pass: 'changeme', quote: false },
{ login: 'admin2', 'pass': 'ch@ngeme', quote: true },
{ login: 'admin3', 'pass': 'chan:eme', quote: false },
{ login: 'admin4', 'pass': 'chan/eme', quote: true },
{ login: 'admin5', 'pass': 'ch@n:eme', quote: true },
{ login: 'admin2', pass: 'ch@ngeme', quote: true },
{ login: 'admin3', pass: 'chan:eme', quote: false },
{ login: 'admin4', pass: 'chan/eme', quote: true },
{ login: 'admin5', pass: 'ch@n:eme', quote: true },
{ login: '0', pass: 'mypassword', quote: false },
{ login: '0123456789012345678901234567890123456789', pass: 'changeme', quote: false },
{ login: 'admin', pass: '', quote: false },
Expand Down Expand Up @@ -76,5 +76,48 @@ def invalid_http_credentials(escape = false)
end
credentials
end

def valid_docker_upstream_names
value_0 = RFauxFactory.gen_alphanumeric(rand(3..6)).downcase
value_1 = RFauxFactory.gen_alphanumeric(rand(3..6)).downcase
value_2 = RFauxFactory.gen_alphanumeric(rand(3..6)).downcase
value_3 = RFauxFactory.gen_alphanumeric(rand(3..6)).downcase
value_4 = RFauxFactory.gen_alphanumeric(1).downcase
[
# boundaries
RFauxFactory.gen_alphanumeric(1).downcase,
RFauxFactory.gen_alphanumeric(255).downcase,
"#{RFauxFactory.gen_alphanumeric(1).downcase}/#{RFauxFactory.gen_alphanumeric(1).downcase}",
"#{RFauxFactory.gen_alphanumeric(127).downcase}/#{RFauxFactory.gen_alphanumeric(127).downcase}",
'valid',
'thisisareallylongbutstillvalidnam',
# allowed non alphanumeric character
'abc/valid',
'soisthis/thisisareallylongbutstillvalidname',
'single/slash',
'multiple/slash/es',
'abc/def/valid',
"#{value_0}-#{value_1}_#{value_2}/#{value_2}-#{value_1}_#{value_0}.#{value_3}",
"#{value_4}-_-_/#{value_4}-_."
]
end

def invalid_docker_upstream_names
[
RFauxFactory.gen_alphanumeric(256).downcase,
"#{RFauxFactory.gen_alphanumeric(127).downcase}/#{RFauxFactory.gen_alphanumeric(128).downcase}",
"#{RFauxFactory.gen_alphanumeric(128).downcase}/#{RFauxFactory.gen_alphanumeric(127).downcase}",
'things with spaces',
# with upper case
'Ab', 'UPPERCASE', 'Uppercase', 'uppercasE', 'Upper/case', 'UPPER/case', 'upper/Case',
# not allowed non alphanumeric character
'$ymbols', '$tuff.th@t.m!ght.h@ve.w%!rd.r#g#x.m*anings()', '/startingslash', 'trailingslash/',
'abcd/.-_',
'abc1d+_ab1cd/ab1cd-abc1d_1abcd.1abcd',
'abc1d-ab1cd_ab1cd/ab1cd+ab1cd_abc1d.1abcd',
"#{RFauxFactory.gen_alphanumeric(1).downcase}-_-_/-_.",
"-_-_/#{RFauxFactory.gen_alphanumeric(1).downcase}-_."
]
end
end
end
78 changes: 58 additions & 20 deletions test/models/repository_test.rb
Expand Up @@ -426,33 +426,71 @@ def test_docker_repository_in_content_view
assert view_repo.valid?
end

def test_docker_repository_docker_upstream_name_format
test_attributes :pid => '3360aab2-74f3-4f6e-a083-46498ceacad2'
def test_create_docker_with_valid_name
@repo.unprotected = true
@repo.content_type = 'docker'
@repo.download_policy = nil
valid = %w( valid
abc/valid
thisisareallylongbutstillvalidname
soisthis/thisisareallylongbutstillvalidname
single/slash
multiple/slash/es abc/def/valid
)
valid << 'a' * 255
valid.each do |name|
@repo.docker_upstream_name = 'busybox'
valid_name_list.each do |name|
@repo.name = name
assert @repo.valid?, "Validation failed for create with valid name '#{name}' length: #{name.length}"
end
end

test_attributes :pid => '7967e6b5-c206-4ad0-bcf5-64a7ce85233b'
def test_update_docker_with_valid_name
@repo.unprotected = true
@repo.content_type = 'docker'
@repo.download_policy = nil
@repo.docker_upstream_name = 'busybox'
@repo.save!
valid_name_list.each do |name|
@repo.name = name
assert @repo.valid?, "Validation failed for update with valid name '#{name}' length: #{name.length}"
end
end

test_attributes :pid => '742a2118-0ab2-4e63-b978-88fe9f52c034'
def test_create_docker_with_valid_upstream_name
@repo.unprotected = true
@repo.content_type = 'docker'
@repo.download_policy = nil
valid_docker_upstream_names.each do |name|
@repo.docker_upstream_name = name
assert(@repo.valid?, "container image name is valid '#{name}'")
assert @repo.valid?, "Validation failed for create with valid upstream name '#{name}'"
end
invalid = %w( things\ with\ spaces
UPPERCASE Uppercase uppercasE Upper/case UPPER/case upper/Case
$ymbols $tuff.th@t.m!ght.h@ve.w%!rd.r#g#x.m*anings()
/startingslash trailingslash/
abcd/.-_
)
invalid << 'a' * 256
invalid.each do |name|
end

test_attributes :pid => '2c5abb4a-e50b-427a-81d2-57eaf8f57a0f'
def test_create_docker_with_invalid_upstream_name
@repo.unprotected = true
@repo.content_type = 'docker'
@repo.download_policy = nil
invalid_docker_upstream_names.each do |name|
@repo.docker_upstream_name = name
refute(@repo.valid?, "container image name is not valid '#{name}'")
refute @repo.valid?, "Validation failed for create with invalid upstream name '#{name}'"
assert @repo.errors.key?(:docker_upstream_name)
end
end

test_attributes :pid => '92df93cb-9de2-40fa-8451-b8c1ba8f45be'
def test_destroy_docker
repo = build(:katello_repository,
:environment => @library,
:product => katello_products(:empty_product),
:content_view_version => @library.default_content_view_version,
:download_policy => nil,
:content_type => 'docker',
:docker_upstream_name => 'busybox',
:unprotected => true,
:url => 'http://rplevka.fedorapeople.org/fakerepo01/'
)
repo.save!
assert_difference('Repository.count', -1) do
repo.delete
end
refute Repository.exists?(repo.id)
end

def test_docker_full_path
Expand Down

0 comments on commit 03e2670

Please sign in to comment.