import random import string import pytest from Crypto.PublicKey import RSA from jwkest.jwk import RSAKey from test.registry.protocols import Image, layer_bytes_for_contents from test.registry.protocol_v1 import V1Protocol from test.registry.protocol_v2 import V2Protocol @pytest.fixture(scope="session") def basic_images(): """ Returns basic images for push and pull testing. """ # Note: order is from base layer down to leaf. parent_bytes = layer_bytes_for_contents('parent contents') image_bytes = layer_bytes_for_contents('some contents') return [ Image(id='parentid', bytes=parent_bytes, parent_id=None), Image(id='someid', bytes=image_bytes, parent_id='parentid'), ] @pytest.fixture(scope="session") def sized_images(): """ Returns basic images (with sizes) for push and pull testing. """ # Note: order is from base layer down to leaf. parent_bytes = layer_bytes_for_contents('parent contents', mode='') image_bytes = layer_bytes_for_contents('some contents', mode='') return [ Image(id='parentid', bytes=parent_bytes, parent_id=None, size=len(parent_bytes), config={'foo': 'bar'}), Image(id='someid', bytes=image_bytes, parent_id='parentid', size=len(image_bytes), config={'foo': 'childbar'}), ] @pytest.fixture(scope="session") def jwk(): return RSAKey(key=RSA.generate(2048)) @pytest.fixture(params=[V2Protocol]) def v2_protocol(request, jwk): return request.param(jwk) @pytest.fixture(params=[V1Protocol]) def v1_protocol(request, jwk): return request.param(jwk) @pytest.fixture(params=[V2Protocol]) def manifest_protocol(request, jwk): return request.param(jwk) @pytest.fixture(params=[V1Protocol, V2Protocol]) def loginer(request, jwk): return request.param(jwk) @pytest.fixture(params=[V1Protocol, V2Protocol]) def pusher(request, jwk): return request.param(jwk) @pytest.fixture(params=[V1Protocol, V2Protocol]) def puller(request, jwk): return request.param(jwk) @pytest.fixture(scope="session") def random_layer_data(): size = 4096 contents = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(size)) return layer_bytes_for_contents(contents)