From dcb970b7839041a3a6174bf95a0cbb2ad2b5c5a7 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 22 Mar 2017 17:03:42 -0400 Subject: [PATCH] Add registry app repository failure test --- endpoints/api/repository.py | 9 ++++++++- test/registry_tests.py | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/endpoints/api/repository.py b/endpoints/api/repository.py index 939be4e68..98a056a4b 100644 --- a/endpoints/api/repository.py +++ b/endpoints/api/repository.py @@ -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() diff --git a/test/registry_tests.py b/test/registry_tests.py index a391535d2..2805b92e8 100644 --- a/test/registry_tests.py +++ b/test/registry_tests.py @@ -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.