def to_image_name(context, param, value: str) -> ImageName: """Converts an docker image name to an ImageName.""" if isinstance(value, str): result = ImageName.parse(value) else: result = [ImageName.parse(v) for v in value] return result
def test_registry_get_config_digest(registry_v2_manifest: RegistryV2Manifest): """Test image configuration digest retrieval.""" formattedsha256 = FormattedSHA256( "8f1196ff19e7b5c5861de192ae77e8d7a692fcbca2dd3174d324980f72ab49bf") assert registry_v2_manifest.get_config_digest() == formattedsha256 assert (registry_v2_manifest.get_config_digest( ImageName.parse("ignored")) == formattedsha256)
def test_parse(): """Test initialization via parsed strings.""" (endpoint, image, tag) = ["address:port", "namespace/image", "tag"] image_name = ImageName.parse("{0}/{1}:{2}".format(endpoint, image, tag)) assert image_name.endpoint == endpoint assert image_name.image == image assert image_name.tag == tag
def test_repository_get_config_digest( devicemapper_repository_manifest: DeviceMapperRepositoryManifest, img_name: str, config_digest: str, ): image_name = ImageName.parse(img_name) assert (devicemapper_repository_manifest.get_config_digest(image_name) == config_digest)
def test_layer_exists(registry_v2_image_source: RegistryV2ImageSource, image: str): """Test layer existence.""" image_name = ImageName.parse(image) layer = registry_v2_image_source.get_manifest(image_name).get_layers()[-1] assert registry_v2_image_source.layer_exists(image_name, layer) assert not registry_v2_image_source.layer_exists(image_name, FormattedSHA256("0" * 64))
def test_get_iamge_config(registry_v2_image_source: RegistryV2ImageSource, image: str): """Test image configuration retrieval.""" image_name = ImageName.parse(image) config = registry_v2_image_source.get_image_config(image_name) assert config assert isinstance(config, ImageConfig)
def test_get_manifest(registry_v2_image_source: RegistryV2ImageSource, image: str): """Test manifest retrieval.""" image_name = ImageName.parse(image) manifest = registry_v2_image_source.get_manifest(image_name) assert manifest assert isinstance(manifest, RegistryV2Manifest)
def test_repository_get_config_digest( devicemapper_repository_manifest: DeviceMapperRepositoryManifest, img_name: str, config_digest: str, ): """Test image configuration digest retrieval.""" image_name = ImageName.parse(img_name) assert (devicemapper_repository_manifest.get_config_digest(image_name) == config_digest)
def test_registry_get_layers(registry_v2_manifest: RegistryV2Manifest): """Test manifest layer retrieval.""" layers = [ "sha256:6c8c72249e560701aa1da4cd40192274a8c0419ddb8e4a553aa02b5a1acdb863", "sha256:1403b179e2c9df4f57e9ea94e32882739c6b3d75ed756d4e67fcc424288c29cc", ] assert registry_v2_manifest.get_layers() == layers assert registry_v2_manifest.get_layers( ImageName.parse("ignored")) == layers
def test_get_image_layer_to_disk( registry_v2_image_source: RegistryV2ImageSource, image: str): """Test layer retrieval to disk.""" image_name = ImageName.parse(image) config_digest = registry_v2_image_source.get_manifest( image_name).get_config_digest() temp = tempfile.NamedTemporaryFile() result = registry_v2_image_source.get_image_layer_to_disk( image_name, config_digest, temp) assert result["digest"] == config_digest
def test_repository_override_config( devicemapper_repository_manifest: DeviceMapperRepositoryManifest, formattedsha256: FormattedSHA256, img_name: str, ): """Test overriding manifest values.""" image_name = ImageName.parse(img_name) devicemapper_repository_manifest.override_config(formattedsha256, image_name) assert (devicemapper_repository_manifest.get_config_digest(image_name) == formattedsha256)
def test_archive_get_layers(archive_manifest: ArchiveManifest): """Test manifest layer retrieval.""" sha256 = "a51f3f9281a1a3d89dce25fec8acffbe9f59ddb67d98e04245c4c886e32d3782" image_name = ImageName.parse(sha256) assert archive_manifest.get_layers(image_name) == [ "sha256:137120c8596a15ab42c39c0c5cf83ef864b6b65b5516887c895915e87292bd07", "sha256:755520f73bc74ae73b12f53229e401e8d4c584b74f5704d2d36ba7c45e2657cf", "sha256:13fb089903a5e0e9b00d78ba48496da528ce8d81e08a1042ebeced8c35d714cb", "sha256:f86d68f70ca006025a7f7013f69898f78d1d9272c4d3909e3ec4c7f9958da20e", "sha256:7b4a4edd704242cec1710679a088be8aabff25c3a79f4eecbe8d11d57c53a20b", "sha256:ef4724d42630f3022ef67c3f6749e85a13e81b8efcf98fbd517476499f10e5ab", ]
def test__get_request_headers( request, registry_v2_image_source: RegistryV2ImageSource, image: str, expected_credentials: str, ): """Test request headers retrieval.""" registry_v2_image_source.credentials_store = get_test_data_path( request, "credentials_store.json") image_name = ImageName.parse(image) headers = registry_v2_image_source._get_request_headers(image_name) assert headers assert expected_credentials in headers["Authorization"]
def test_unsign_image_same_image_source( registry_v2_image_source: RegistryV2ImageSource, image: str): """Test image unsigning.""" src_image_name = ImageName.parse(image) dest_image_name = copy.deepcopy(src_image_name) dest_image_name.tag = "{0}_unsigned".format(dest_image_name.tag) def assertions(result: dict): assert result image_config = result["image_config"] assert image_config assert "FAKE SIGNATURE" not in str(image_config) verify_image_data = result["verify_image_data"] assert verify_image_data assert image_config == verify_image_data["image_config"] manifest = verify_image_data["manifest"] assert manifest manifest_unsigned = result["manifest_unsigned"] assert manifest_unsigned assert manifest_unsigned.get_config_digest( ) == image_config.get_config_digest() assert len(manifest_unsigned.get_layers()) == len( image_config.get_image_layers()) # 1. Pre signature assertions( registry_v2_image_source.unsign_image(src_image_name, registry_v2_image_source, dest_image_name)) # Sign registry_v2_image_source.sign_image(FakeSigner(), src_image_name, registry_v2_image_source, dest_image_name) # 2. Post signature assertions( registry_v2_image_source.unsign_image(src_image_name, registry_v2_image_source, dest_image_name))
def test_verify_image_integrity( registry_v2_image_source: RegistryV2ImageSource, image: str): """Test image unsigning.""" image_name = ImageName.parse(image) def assertions(result: dict): assert result image_config = result["image_config"] assert image_config manifest = result["manifest"] assert manifest assert len(result["compressed_layer_files"]) == len( result["uncompressed_layer_files"]) # 1. Unsigned assertions(registry_v2_image_source.verify_image_integrity(image_name))
def image_name(url): return ImageName.parse(url)
def image_name(url: str) -> ImageName: """Provides ImageName instance for the fake URL.""" return ImageName.parse(url)
def test_archive__get_config(archive_manifest: ArchiveManifest, img_name: str, config_value: str): """Test configuration retrieval.""" image_name = ImageName.parse(img_name) assert archive_manifest.get_config(image_name)["Config"] == config_value
def test_archive_get_config_digest(archive_manifest: ArchiveManifest): """Test configuration digest retrieval.""" formattedsha256 = FormattedSHA256( "a51f3f9281a1a3d89dce25fec8acffbe9f59ddb67d98e04245c4c886e32d3782") image_name = ImageName.parse(formattedsha256.sha256) assert archive_manifest.get_config_digest(image_name) == formattedsha256