From 48213f9ff97f34db6e1d095e8a987bddb57381ff Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 2 Jun 2016 12:46:20 -0400 Subject: [PATCH] Reject manifest 2 earlier to make pushes faster --- endpoints/v2/manifest.py | 4 ++-- test/registry_tests.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/endpoints/v2/manifest.py b/endpoints/v2/manifest.py index b2e60d18d..45eae6207 100644 --- a/endpoints/v2/manifest.py +++ b/endpoints/v2/manifest.py @@ -299,11 +299,11 @@ def _reject_manifest2_schema2(func): @v2_bp.route(MANIFEST_TAGNAME_ROUTE, methods=['PUT']) +@_reject_manifest2_schema2 @parse_repository_name() @process_registry_jwt_auth(scopes=['pull', 'push']) @require_repo_write @anon_protect -@_reject_manifest2_schema2 def write_manifest_by_tagname(namespace_name, repo_name, manifest_ref): try: manifest = SignedManifest(request.data) @@ -317,11 +317,11 @@ def write_manifest_by_tagname(namespace_name, repo_name, manifest_ref): @v2_bp.route(MANIFEST_DIGEST_ROUTE, methods=['PUT']) +@_reject_manifest2_schema2 @parse_repository_name() @process_registry_jwt_auth(scopes=['pull', 'push']) @require_repo_write @anon_protect -@_reject_manifest2_schema2 def write_manifest_by_digest(namespace_name, repo_name, manifest_ref): try: manifest = SignedManifest(request.data) diff --git a/test/registry_tests.py b/test/registry_tests.py index 85e6b6aa8..1776cee81 100644 --- a/test/registry_tests.py +++ b/test/registry_tests.py @@ -1090,6 +1090,25 @@ class V1RegistryTests(V1RegistryPullMixin, V1RegistryPushMixin, RegistryTestsMix class V2RegistryTests(V2RegistryPullMixin, V2RegistryPushMixin, RegistryTestsMixin, RegistryTestCaseMixin, LiveServerTestCase): """ Tests for V2 registry. """ + def test_invalid_manifest_type(self): + namespace = 'devtable' + repository = 'somerepo' + tag_name = 'sometag' + + repo_name = _get_repo_name(namespace, repository) + + self.v2_ping() + self.do_auth('devtable', 'password', namespace, repository, scopes=['push', 'pull']) + + # Build a fake manifest. + builder = SignedManifestBuilder(namespace, repository, tag_name) + builder.add_layer('sha256:' + hashlib.sha256('invalid').hexdigest(), json.dumps({'id': 'foo'})) + manifest = builder.build(_JWK) + + self.conduct('PUT', '/v2/%s/manifests/%s' % (repo_name, tag_name), + data=manifest.bytes, expected_code=415, + headers={'Content-Type': 'application/vnd.docker.distribution.manifest.v2+json'}, + auth='jwt') def test_invalid_blob(self): namespace = 'devtable'