Add a check to ensure repository names are valid according to an extended set of rules.
Fixes #534
This commit is contained in:
parent
ee836da1e3
commit
a283c8d8ec
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 = [{
|
||||
|
|
Reference in a new issue