Merge pull request #535 from coreos-inc/reponameregex
Add a check to ensure repository names are valid according to an exte…
This commit is contained in:
commit
6e94f63a51
5 changed files with 36 additions and 3 deletions
|
@ -170,7 +170,7 @@ class RegistryTestCase(LiveServerTestCase):
|
|||
self.assertEquals(result.text, '"Username or email already exists"')
|
||||
self.conduct('GET', '/v1/users/', auth=(username, password))
|
||||
|
||||
def do_push(self, namespace, repository, username, password, images):
|
||||
def do_push(self, namespace, repository, username, password, images, expected_code=201):
|
||||
auth = (username, password)
|
||||
|
||||
# Ping!
|
||||
|
@ -180,7 +180,10 @@ class RegistryTestCase(LiveServerTestCase):
|
|||
data = [{"id": image['id']} for image in images]
|
||||
self.conduct('PUT', '/v1/repositories/%s/%s' % (namespace, repository),
|
||||
data=json.dumps(data), auth=auth,
|
||||
expected_code=201)
|
||||
expected_code=expected_code)
|
||||
|
||||
if expected_code != 201:
|
||||
return
|
||||
|
||||
for image in images:
|
||||
# PUT /v1/images/{imageID}/json
|
||||
|
@ -230,6 +233,7 @@ class RegistryTestCase(LiveServerTestCase):
|
|||
# GET /v1/repositories/{namespace}/{repository}/
|
||||
self.conduct('GET', prefix + 'images', auth=auth, expected_code=expected_code)
|
||||
if expected_code != 200:
|
||||
# Push was expected to fail, so nothing more to do for the push.
|
||||
return
|
||||
|
||||
# GET /v1/repositories/{namespace}/{repository}/
|
||||
|
@ -254,6 +258,13 @@ class RegistryTestCase(LiveServerTestCase):
|
|||
|
||||
|
||||
class RegistryTests(RegistryTestCase):
|
||||
def test_push_reponame_with_slashes(self):
|
||||
# Attempt to add a repository name with slashes. This should fail as we do not support it.
|
||||
images = [{
|
||||
'id': 'onlyimagehere'
|
||||
}]
|
||||
self.do_push('public', 'newrepo/somesubrepo', 'public', 'password', images, expected_code=400)
|
||||
|
||||
def test_pull_publicrepo_anonymous(self):
|
||||
# Add a new repository under the public user, so we have a real repository to pull.
|
||||
images = [{
|
||||
|
|
|
@ -1272,6 +1272,17 @@ class TestDeleteOrganizationTeamMember(ApiTestCase):
|
|||
|
||||
|
||||
class TestCreateRepo(ApiTestCase):
|
||||
def test_invalidreponame(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
json = self.postJsonResponse(RepositoryList,
|
||||
data=dict(repository='some/repo',
|
||||
visibility='public',
|
||||
description=''),
|
||||
expected_code=400)
|
||||
|
||||
self.assertEquals('Invalid repository name', json['error_description'])
|
||||
|
||||
def test_duplicaterepo(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
|
|
Reference in a new issue