def test_sha(self, m): """ Test sha method """ registry = DockerRegistry(DOCKER_HUB_DOMAIN, token_url=DOCKER_HUB_TOKEN_REQUEST) image = DockerImage('library/monimage', registry, tag='tag') m.get(DOCKER_HUB_TOKEN_REQUEST.format(image=image), json=self.token_json) m.get(registry.get_manifest_url(image), json=self.manifest_json, headers={'Authorization': 'Bearer {token}'.format(token=self.token)}) self.assertEqual("58c0a48e3b6a2c9f3b1d8166e096789f20b769f538f4aecaa73d5eae15672b2b", image.sha) self.assertEqual("58c0a48e3b6a", image.short_sha)
def test_get_layers_docker_hub_v2(self, m): """ Test de la méthode get_layer """ registry = DockerRegistry(DOCKER_HUB_DOMAIN, token_url=DOCKER_HUB_TOKEN_REQUEST) image = DockerImage('library/monimage', registry, tag='tag') m.get(DOCKER_HUB_TOKEN_REQUEST.format(image=image), json=self.token_json) m.get(registry.get_manifest_url(image), json=self.manifestv2_json, headers={'Authorization': 'Bearer {token}'.format(token=self.token)}) layers = image.get_layers() self.assertEqual(layers, self.EXPECTED_LAYERS_V2)
def test_get_layers_artifactory(self, m): """ Test de la méthode get_layer """ artifactory_registry = 'registry.artifactory.net' token_url = "https://{registry.domain}/api/docker/{image.repository}/v2/token?service={registry.domain}" registry = DockerRegistry(artifactory_registry, token_url=token_url, protocol="http") image = DockerImage('monimage', registry) m.get(token_url.format(image=image, registry=registry), json=self.token_json) m.get(registry.get_manifest_url(image), json=self.manifest_json, headers={'Authorization': 'Bearer {token}'.format(token=self.token)}) layers = image.get_layers() self.assertEqual(layers, self.EXPECTED_LAYERS)
def test_get_token(self, m): """ Test de la méthode get_token """ domain_lambda = 'registery.host' registry = DockerRegistry(domain_lambda, token=self.token, token_type='Basic') image = DockerImage('monimage', registry) # Manifest m.register_uri('GET', registry.get_manifest_url(image), json=self.manifestv2_json, request_headers={'Authorization': 'Basic {token}'.format(token=self.token)}) layers = image.get_layers() self.assertTrue(m.called) self.assertEqual(layers, self.EXPECTED_LAYERS_V2)
def test_get_layers_other_registery_v2(self, m): """ Test de la méthode get_layer """ domain_lambda = 'registery.host' registry = DockerRegistry(domain_lambda, token_url="https://token_url") image = DockerImage('monimage', registry) # Token m.get("https://token_url", json=self.token_json) # Manifest m.get(registry.get_manifest_url(image), json=self.manifestv2_json, headers={'Authorization': 'Bearer {token}'.format(token=self.token)}) layers = image.get_layers() self.assertEqual(layers, self.EXPECTED_LAYERS_V2)
def test_manifest_http_error(self, m): """ Http Error en cas d'erreur d'accès à la registry """ domain_lambda = 'registery.host' registry = DockerRegistry(domain_lambda, token_url="https://token_url") image = DockerImage('monimage', registry) # Token m.get("https://token_url", json=self.token_json) # Manifest m.register_uri('GET', registry.get_manifest_url(image), json=self.manifest_json, headers={'Authorization': 'Beare {token}'.format(token=self.token)}, status_code=401) with self.assertRaises(RegistryAccessError): image.get_layers()