Skip to content

Commit

Permalink
Fail if image name begins with component containing '.'
Browse files Browse the repository at this point in the history
Addresses part of OSBS-4908.

Signed-off-by: Tim Waugh <twaugh@redhat.com>
  • Loading branch information
twaugh committed Jan 9, 2018
1 parent 8a24dc0 commit d47ab87
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
21 changes: 21 additions & 0 deletions osbs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,27 @@ def _check_labels(self, repo_info):
if required_missing:
raise OsbsValidationException("required label missing from Dockerfile")

# Verify the name label meets requirements.
# It is made up of slash-separated name components.
#
# When pulling an image, the first component of the name
# pulled is interpreted as a registry name if it contains a
# '.' character, and otherwise the configured registries are
# queried in turn.
#
# Due to this, a name with '.' in its initial component will
# be awkward to pull from a registry because the registry name
# will have to be explicitly supplied, e.g. "docker pull
# foo.bar/baz" will fail because the "foo.bar" registry cannot
# be contacted.
#
# Avoid this awkwardness by forbidding '.' in the initial
# component of the image name.
name_components = req_labels[utils.Labels.LABEL_TYPE_NAME].split('/', 1)
if '.' in name_components[0]:
raise OsbsValidationException("initial image name component "
"must not contain '.'")

return req_labels, df_parser.baseimage

def _get_flatpak_labels(self, module):
Expand Down
44 changes: 44 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,50 @@ class MockParser(object):
TEST_GIT_BRANCH, TEST_USER,
TEST_COMPONENT, TEST_TARGET, TEST_ARCH)

# osbs is a fixture here
@pytest.mark.parametrize('name,should_succeed', [ # noqa:F811
('fedora-25.1/something', False),
('fedora-25-1/something', True),
])
def test_reject_invalid_name(self, osbs, name, should_succeed):
"""
tests invalid name label is rejected
"""

class MockParser(object):
labels = {
'name': name,
'com.redhat.component': TEST_COMPONENT,
'version': TEST_VERSION,
}
baseimage = 'fedora:25'
(flexmock(utils)
.should_receive('get_repo_info')
.with_args(TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH)
.and_return(self.mock_repo_info(MockParser())))
create_build_args = {
'git_uri': TEST_GIT_URI,
'git_ref': TEST_GIT_REF,
'git_branch': TEST_GIT_BRANCH,
'user': TEST_USER,
'component': TEST_COMPONENT,
'target': TEST_TARGET,
'architecture': TEST_ARCH,
}
if should_succeed:
osbs.create_prod_build(**create_build_args)
else:
with pytest.raises(OsbsValidationException):
osbs.create_prod_build(**create_build_args)

del create_build_args['architecture']
create_build_args['platforms'] = [TEST_ARCH]
if should_succeed:
osbs.create_orchestrator_build(**create_build_args)
else:
with pytest.raises(OsbsValidationException):
osbs.create_orchestrator_build(**create_build_args)

# osbs is a fixture here
@pytest.mark.parametrize('component_label_name', ['com.redhat.component', 'BZComponent']) # noqa
def test_component_is_changed_from_label(self, osbs, component_label_name):
Expand Down

0 comments on commit d47ab87

Please sign in to comment.