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

Refs #23910 - Port robottelo tests - docker-repository #7499

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -441,33 +441,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 => '742a2118-0ab2-4e63-b978-88fe9f52c034'
def test_create_docker_with_valid_upstream_name
@repo.unprotected = true
@repo.content_type = 'docker'
jturel marked this conversation as resolved.
Show resolved Hide resolved
@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 => '4e2fb78d-0b6a-4455-8869-8eaf9d4a61b0'
def test_update_docker_with_valid_upstream_name
@repo.unprotected = true
@repo.content_type = 'docker'
@repo.download_policy = nil
@repo.docker_upstream_name = 'busybox'
@repo.save!
valid_docker_upstream_names.each do |name|
@repo.docker_upstream_name = name
assert @repo.valid?, "Validation failed for update with valid upstream name '#{name}'"
end
end

test_attributes :pid => '92df93cb-9de2-40fa-8451-b8c1ba8f45be'
def test_destroy_docker
repo = build(:katello_repository,
jturel marked this conversation as resolved.
Show resolved Hide resolved
: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
jturel marked this conversation as resolved.
Show resolved Hide resolved
repo.delete
end
refute Repository.exists?(repo.id)
end

def test_docker_full_path
Expand Down