Add registry app repository failure test
This commit is contained in:
parent
ca7a0f14d8
commit
dcb970b783
2 changed files with 33 additions and 1 deletions
|
@ -77,6 +77,11 @@ class RepositoryList(ApiResource):
|
|||
'type': 'string',
|
||||
'description': 'Markdown encoded description for the repository',
|
||||
},
|
||||
'kind': {
|
||||
'type': 'string',
|
||||
'description': 'The kind of repository',
|
||||
'enum': ['image', 'application'],
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -111,7 +116,9 @@ class RepositoryList(ApiResource):
|
|||
if not REPOSITORY_NAME_REGEX.match(repository_name):
|
||||
raise InvalidRequest('Invalid repository name')
|
||||
|
||||
repo = model.repository.create_repository(namespace_name, repository_name, owner, visibility)
|
||||
kind = req.get('kind', 'image')
|
||||
repo = model.repository.create_repository(namespace_name, repository_name, owner, visibility,
|
||||
repo_kind=kind)
|
||||
repo.description = req['description']
|
||||
repo.save()
|
||||
|
||||
|
|
|
@ -168,6 +168,7 @@ class FailureCodes:
|
|||
INVALID_REGISTRY = ('invalidregistry', 404, 404)
|
||||
DOES_NOT_EXIST = ('doesnotexist', 404, 404)
|
||||
INVALID_REQUEST = ('invalidrequest', 400, 400)
|
||||
APP_REPOSITORY = ('apprepository', 405, 405)
|
||||
|
||||
def _get_expected_code(expected_failure, version, success_status_code):
|
||||
""" Returns the HTTP status code for the expected failure under the specified protocol version
|
||||
|
@ -545,6 +546,8 @@ class V2RegistryPushMixin(V2RegistryMixin):
|
|||
expected_auth_code = 200
|
||||
if expect_failure == FailureCodes.INVALID_REGISTRY:
|
||||
expected_auth_code = 400
|
||||
elif expect_failure == FailureCodes.APP_REPOSITORY:
|
||||
expected_auth_code = 405
|
||||
|
||||
self.do_auth(username, password, namespace, repository, scopes=scopes or ['push', 'pull'],
|
||||
expected_code=expected_auth_code)
|
||||
|
@ -685,6 +688,8 @@ class V2RegistryPullMixin(V2RegistryMixin):
|
|||
expected_auth_code = 200
|
||||
if expect_failure == FailureCodes.UNAUTHENTICATED:
|
||||
expected_auth_code = 401
|
||||
elif expect_failure == FailureCodes.APP_REPOSITORY:
|
||||
expected_auth_code = 405
|
||||
|
||||
self.do_auth(username, password, namespace, repository, scopes=['pull'],
|
||||
expected_code=expected_auth_code)
|
||||
|
@ -765,6 +770,26 @@ class V2RegistryLoginMixin(object):
|
|||
|
||||
|
||||
class RegistryTestsMixin(object):
|
||||
def test_application_repo(self):
|
||||
# Create an application repository via the API.
|
||||
self.conduct_api_login('devtable', 'password')
|
||||
data = {
|
||||
'repository': 'someapprepo',
|
||||
'visibility': 'private',
|
||||
'kind': 'application',
|
||||
'description': 'test app repo',
|
||||
}
|
||||
self.conduct('POST', '/api/v1/repository', json_data=data, expected_code=201)
|
||||
|
||||
# Try to push to the repo, which should fail with a 405.
|
||||
self.do_push('devtable', 'someapprepo', 'devtable', 'password',
|
||||
expect_failure=FailureCodes.APP_REPOSITORY)
|
||||
|
||||
# Try to pull from the repo, which should fail with a 405.
|
||||
self.do_pull('devtable', 'someapprepo', 'devtable', 'password',
|
||||
expect_failure=FailureCodes.APP_REPOSITORY)
|
||||
|
||||
|
||||
def test_middle_layer_different_sha(self):
|
||||
if self.push_version == 'v1':
|
||||
# No SHAs to munge in V1.
|
||||
|
|
Reference in a new issue