From 69262282fe4cd754f3fae5ad0202fbb321102b40 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 15 Feb 2016 10:57:20 -0500 Subject: [PATCH] Make sure to encode all V1 metadata strings Fixes #1239 --- endpoints/v2/manifest.py | 3 ++- test/registry_tests.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/endpoints/v2/manifest.py b/endpoints/v2/manifest.py index df116a87d..8840972d1 100644 --- a/endpoints/v2/manifest.py +++ b/endpoints/v2/manifest.py @@ -408,7 +408,8 @@ def _write_manifest(namespace, repo_name, manifest): images_map[v1_mdata.docker_id].storage.content_checksum != digest_str) or has_rewritten_ids): - working_docker_id = hashlib.sha256(mdata.v1_metadata_str + '@' + digest_str).hexdigest() + v1_metadata_str = mdata.v1_metadata_str.encode('utf-8') + working_docker_id = hashlib.sha256(v1_metadata_str + '@' + digest_str).hexdigest() logger.debug('Rewriting docker_id %s/%s %s -> %s', namespace, repo_name, v1_mdata.docker_id, working_docker_id) has_rewritten_ids = True diff --git a/test/registry_tests.py b/test/registry_tests.py index d2507405a..f9cec9e2e 100644 --- a/test/registry_tests.py +++ b/test/registry_tests.py @@ -749,6 +749,38 @@ class RegistryTestsMixin(object): # Pull the repository. self.do_pull('public', 'newrepo', 'public', 'password', images=images, munge_shas=True) + + def test_push_same_ids_different_sha_with_unicode(self): + if self.push_version == 'v1': + # No SHAs to munge in V1. + return + + images = [ + { + 'id': 'latestid', + 'contents': 'The latest image', + 'unicode': u'the Pawe\xc5\x82 Kami\xc5\x84ski image', + 'parent': 'baseid', + }, + { + 'id': 'baseid', + 'contents': 'The base image', + } + ] + + # Push a new repository. + self.do_push('public', 'newrepo', 'public', 'password', images=images) + + # Pull the repository. + self.do_pull('public', 'newrepo', 'public', 'password', images=images) + + # Push a the repository again, but with different SHAs. + self.do_push('public', 'newrepo', 'public', 'password', images=images, munge_shas=True) + + # Pull the repository. + self.do_pull('public', 'newrepo', 'public', 'password', images=images, munge_shas=True) + + def test_push_pull_logging(self): # Push a new repository. self.do_push('public', 'newrepo', 'public', 'password')