Update registry tests
This commit is contained in:
parent
e6c2ddfa93
commit
45db1d27e7
3 changed files with 47 additions and 12 deletions
|
@ -21,6 +21,7 @@ class V2ProtocolSteps(Enum):
|
|||
BLOB_HEAD_CHECK = 'blob-head-check'
|
||||
GET_MANIFEST = 'get-manifest'
|
||||
PUT_MANIFEST = 'put-manifest'
|
||||
PUT_MANIFEST_LIST = 'put-manifest-list'
|
||||
MOUNT_BLOB = 'mount-blob'
|
||||
CATALOG = 'catalog'
|
||||
LIST_TAGS = 'list-tags'
|
||||
|
@ -60,6 +61,9 @@ class V2Protocol(RegistryProtocol):
|
|||
Failures.INVALID_BLOB: 400,
|
||||
Failures.UNSUPPORTED_CONTENT_TYPE: 415,
|
||||
},
|
||||
V2ProtocolSteps.PUT_MANIFEST_LIST: {
|
||||
Failures.INVALID_MANIFEST: 400,
|
||||
}
|
||||
}
|
||||
|
||||
def __init__(self, jwk, schema2=False):
|
||||
|
@ -164,7 +168,7 @@ class V2Protocol(RegistryProtocol):
|
|||
assert manifest.digest == manifestlist.digest
|
||||
|
||||
|
||||
def push_list(self, session, namespace, repo_name, tag_names, manifestlist, blobs,
|
||||
def push_list(self, session, namespace, repo_name, tag_names, manifestlist, manifests, blobs,
|
||||
credentials=None, expected_failure=None, options=None):
|
||||
options = options or ProtocolOptions()
|
||||
scopes = options.scopes or ['repository:%s:push,pull' % self.repo_name(namespace, repo_name)]
|
||||
|
@ -190,6 +194,17 @@ class V2Protocol(RegistryProtocol):
|
|||
expected_failure):
|
||||
return
|
||||
|
||||
# Push the individual manifests.
|
||||
for manifest in manifests:
|
||||
manifest_headers = {'Content-Type': manifest.media_type}
|
||||
manifest_headers.update(headers)
|
||||
|
||||
self.conduct(session, 'PUT',
|
||||
'/v2/%s/manifests/%s' % (self.repo_name(namespace, repo_name), manifest.digest),
|
||||
data=manifest.bytes,
|
||||
expected_status=(202, expected_failure, V2ProtocolSteps.PUT_MANIFEST),
|
||||
headers=manifest_headers)
|
||||
|
||||
# Push the manifest list.
|
||||
for tag_name in tag_names:
|
||||
manifest_headers = {'Content-Type': manifestlist.media_type}
|
||||
|
@ -201,7 +216,7 @@ class V2Protocol(RegistryProtocol):
|
|||
self.conduct(session, 'PUT',
|
||||
'/v2/%s/manifests/%s' % (self.repo_name(namespace, repo_name), tag_name),
|
||||
data=manifestlist.bytes,
|
||||
expected_status=(202, expected_failure, V2ProtocolSteps.PUT_MANIFEST),
|
||||
expected_status=(202, expected_failure, V2ProtocolSteps.PUT_MANIFEST_LIST),
|
||||
headers=manifest_headers)
|
||||
|
||||
return PushResult(manifests=None, headers=headers)
|
||||
|
|
|
@ -53,6 +53,7 @@ class Failures(Enum):
|
|||
DISALLOWED_LIBRARY_NAMESPACE = 'disallowed-library-namespace'
|
||||
MISSING_TAG = 'missing-tag'
|
||||
INVALID_TAG = 'invalid-tag'
|
||||
INVALID_MANIFEST = 'invalid-manifest'
|
||||
INVALID_IMAGES = 'invalid-images'
|
||||
UNSUPPORTED_CONTENT_TYPE = 'unsupported-content-type'
|
||||
INVALID_BLOB = 'invalid-blob'
|
||||
|
|
|
@ -1390,17 +1390,14 @@ def test_push_pull_manifest_list_back_compat(v22_protocol, legacy_puller, basic_
|
|||
|
||||
second_manifest = v22_protocol.build_schema2(different_images, blobs, options)
|
||||
|
||||
# Add the manifests themselves to the blobs map.
|
||||
blobs[str(first_manifest.digest)] = first_manifest.bytes
|
||||
blobs[str(second_manifest.digest)] = second_manifest.bytes
|
||||
|
||||
# Create and push the manifest list.
|
||||
builder = DockerSchema2ManifestListBuilder()
|
||||
builder.add_manifest(first_manifest, 'amd64' if is_amd else 'something', 'linux')
|
||||
builder.add_manifest(second_manifest, 'arm', 'linux')
|
||||
manifestlist = builder.build()
|
||||
|
||||
v22_protocol.push_list(liveserver_session, 'devtable', 'newrepo', 'latest', manifestlist, blobs,
|
||||
v22_protocol.push_list(liveserver_session, 'devtable', 'newrepo', 'latest', manifestlist,
|
||||
[first_manifest, second_manifest], blobs,
|
||||
credentials=credentials, options=options)
|
||||
|
||||
# Pull the tag and ensure we (don't) get back the basic images, since they are(n't) part of the
|
||||
|
@ -1435,17 +1432,14 @@ def test_push_pull_manifest_list(v22_protocol, basic_images, different_images, l
|
|||
|
||||
second_manifest = v22_protocol.build_schema2(different_images, blobs, options)
|
||||
|
||||
# Add the manifests themselves to the blobs map.
|
||||
blobs[str(first_manifest.digest)] = first_manifest.bytes
|
||||
blobs[str(second_manifest.digest)] = second_manifest.bytes
|
||||
|
||||
# Create and push the manifest list.
|
||||
builder = DockerSchema2ManifestListBuilder()
|
||||
builder.add_manifest(first_manifest, 'amd64', 'linux')
|
||||
builder.add_manifest(second_manifest, 'arm', 'linux')
|
||||
manifestlist = builder.build()
|
||||
|
||||
v22_protocol.push_list(liveserver_session, 'devtable', 'newrepo', 'latest', manifestlist, blobs,
|
||||
v22_protocol.push_list(liveserver_session, 'devtable', 'newrepo', 'latest', manifestlist,
|
||||
[first_manifest, second_manifest], blobs,
|
||||
credentials=credentials, options=options)
|
||||
|
||||
# Pull and verify the manifest list.
|
||||
|
@ -1474,3 +1468,28 @@ def test_push_pull_manifest_remote_layers(v22_protocol, legacy_puller, liveserve
|
|||
# Ensure that the image cannot be pulled by a legacy protocol.
|
||||
legacy_puller.pull(liveserver_session, 'devtable', 'newrepo', 'latest', remote_images,
|
||||
credentials=credentials, expected_failure=Failures.UNKNOWN_TAG)
|
||||
|
||||
|
||||
def test_push_pull_manifest_list_missing_manifest(v22_protocol, basic_images, liveserver_session,
|
||||
app_reloader, data_model):
|
||||
""" Test: Attempt to push a new tag with a manifest list containing an invalid manifest.
|
||||
"""
|
||||
if data_model != 'oci_model':
|
||||
return
|
||||
|
||||
credentials = ('devtable', 'password')
|
||||
options = ProtocolOptions()
|
||||
|
||||
# Build the manifests that will go in the list.
|
||||
blobs = {}
|
||||
manifest = v22_protocol.build_schema2(basic_images, blobs, options)
|
||||
|
||||
# Create and push the manifest list, but without the manifest itself.
|
||||
builder = DockerSchema2ManifestListBuilder()
|
||||
builder.add_manifest(manifest, 'amd64', 'linux')
|
||||
manifestlist = builder.build()
|
||||
|
||||
v22_protocol.push_list(liveserver_session, 'devtable', 'newrepo', 'latest', manifestlist,
|
||||
[], blobs,
|
||||
credentials=credentials, options=options,
|
||||
expected_failure=Failures.INVALID_MANIFEST)
|
||||
|
|
Reference in a new issue