test/registry: add accept header test
This commit is contained in:
parent
b7573a8c88
commit
6d4300a92a
3 changed files with 28 additions and 1 deletions
|
@ -136,6 +136,7 @@ class V2Protocol(RegistryProtocol):
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'Authorization': 'Bearer ' + token,
|
'Authorization': 'Bearer ' + token,
|
||||||
|
'Accept': options.accept_mimetypes,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build fake manifests.
|
# Build fake manifests.
|
||||||
|
|
|
@ -64,6 +64,7 @@ class ProtocolOptions(object):
|
||||||
self.chunks_for_upload = None
|
self.chunks_for_upload = None
|
||||||
self.skip_head_checks = False
|
self.skip_head_checks = False
|
||||||
self.manifest_content_type = None
|
self.manifest_content_type = None
|
||||||
|
self.accept_mimetypes = '*/*'
|
||||||
self.mount_blobs = None
|
self.mount_blobs = None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ import binascii
|
||||||
import bencode
|
import bencode
|
||||||
import resumablehashlib
|
import resumablehashlib
|
||||||
|
|
||||||
|
from werkzeug.datastructures import Accept
|
||||||
|
|
||||||
from test.fixtures import *
|
from test.fixtures import *
|
||||||
from test.registry.liveserverfixture import *
|
from test.registry.liveserverfixture import *
|
||||||
from test.registry.fixtures import *
|
from test.registry.fixtures import *
|
||||||
|
@ -17,6 +19,7 @@ from test.registry.protocols import Failures, Image, layer_bytes_for_contents, P
|
||||||
|
|
||||||
from app import instance_keys
|
from app import instance_keys
|
||||||
from data.model.tag import list_repository_tags
|
from data.model.tag import list_repository_tags
|
||||||
|
from image.docker.schema1 import DOCKER_SCHEMA1_MANIFEST_CONTENT_TYPE
|
||||||
from util.security.registry_jwt import decode_bearer_header
|
from util.security.registry_jwt import decode_bearer_header
|
||||||
from util.timedeltastring import convert_to_timedelta
|
from util.timedeltastring import convert_to_timedelta
|
||||||
|
|
||||||
|
@ -341,7 +344,7 @@ def test_push_library_with_support_disabled(pusher, basic_images, liveserver_ses
|
||||||
should fail.
|
should fail.
|
||||||
"""
|
"""
|
||||||
credentials = ('devtable', 'password')
|
credentials = ('devtable', 'password')
|
||||||
|
|
||||||
with FeatureFlagValue('LIBRARY_SUPPORT', False, registry_server_executor.on(liveserver)):
|
with FeatureFlagValue('LIBRARY_SUPPORT', False, registry_server_executor.on(liveserver)):
|
||||||
# Attempt to push a new repository.
|
# Attempt to push a new repository.
|
||||||
pusher.push(liveserver_session, '', 'newrepo', 'latest', basic_images,
|
pusher.push(liveserver_session, '', 'newrepo', 'latest', basic_images,
|
||||||
|
@ -543,6 +546,28 @@ def test_unsupported_manifest_content_type(content_type, manifest_protocol, basi
|
||||||
expected_failure=Failures.UNSUPPORTED_CONTENT_TYPE)
|
expected_failure=Failures.UNSUPPORTED_CONTENT_TYPE)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('accept_mimetypes', [
|
||||||
|
[('application/vnd.oci.image.manifest.v1+json', 1)],
|
||||||
|
[('application/vnd.docker.distribution.manifest.v2+json', 1),
|
||||||
|
('application/vnd.docker.distribution.manifest.list.v2+json', 1)],
|
||||||
|
[('application/vnd.foo.bar', 1)],
|
||||||
|
])
|
||||||
|
def test_unsupported_manifest_accept_headers(accept_mimetypes, manifest_protocol, basic_images,
|
||||||
|
liveserver_session, app_reloader):
|
||||||
|
""" Test: Attempt to push a manifest with an unsupported accept headers. """
|
||||||
|
credentials = ('devtable', 'password')
|
||||||
|
|
||||||
|
options = ProtocolOptions()
|
||||||
|
options.manifest_content_type = DOCKER_SCHEMA1_MANIFEST_CONTENT_TYPE
|
||||||
|
options.accept_mimetypes = str(Accept(accept_mimetypes))
|
||||||
|
|
||||||
|
# Attempt to push a new repository.
|
||||||
|
manifest_protocol.push(liveserver_session, 'devtable', 'newrepo', 'latest', basic_images,
|
||||||
|
credentials=credentials,
|
||||||
|
options=options,
|
||||||
|
expected_failure=Failures.UNSUPPORTED_CONTENT_TYPE)
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_blob_reference(manifest_protocol, basic_images, liveserver_session, app_reloader):
|
def test_invalid_blob_reference(manifest_protocol, basic_images, liveserver_session, app_reloader):
|
||||||
""" Test: Attempt to push a manifest with an invalid blob reference. """
|
""" Test: Attempt to push a manifest with an invalid blob reference. """
|
||||||
credentials = ('devtable', 'password')
|
credentials = ('devtable', 'password')
|
||||||
|
|
Reference in a new issue