Ejemplo n.º 1
0
    def test_compute_simple(self):
        out = checksums.compute_simple(None, '')
        self.assertTrue(out.startswith('sha256:'))
        nl = '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b'
        self.assertTrue(out.endswith(nl))

        out = checksums.compute_simple(None, 'test')
        h = 'f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2'
        self.assertTrue(out.endswith(h))
Ejemplo n.º 2
0
    def test_compute_simple(self):
        out = checksums.compute_simple(None, '')
        self.assertTrue(out.startswith('sha256:'))
        nl = '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b'
        self.assertTrue(out.endswith(nl))

        out = checksums.compute_simple(None, 'test')
        h = 'f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2'
        self.assertTrue(out.endswith(h))
Ejemplo n.º 3
0
    def docker_pull(self, namespace, repos):
        # Test pull
        # Docker -> Index

        resp = requests.get('{0}/v1/repositories/{1}/{2}/images'.format(
            self.index_endpoint, namespace, repos),)
        self.assertEqual(resp.status_code, 200)

        resp = requests.get('{0}/v1/repositories/{1}/{2}/images'.format(
            self.index_endpoint, namespace, repos),
            auth=tuple(self.user_credentials),
            headers={'X-Docker-Token': 'true'})
        self.assertEqual(resp.status_code, 200)
        self.token = resp.headers.get('x-docker-token')
        # Here we should use the 'X-Endpoints' returned in a real environment
        # Docker -> Registry
        resp = requests.get('{0}/v1/repositories/{1}/{2}/tags/latest'.format(
                            self.registry_endpoint, namespace, repos),
                            headers={'Authorization': 'Token ' + self.token})
        self.assertEqual(resp.status_code, 200, resp.text)

        resp = requests.get('{0}/v1/repositories/{1}/{2}/tags/latest'.format(
                            self.registry_endpoint, namespace, repos),
                            )
        self.assertEqual(resp.status_code, 200, resp.text)

        # Docker -> Registry
        # Note(dmp): unicode patch XXX not applied assume requests does the job
        image_id = json.loads(resp.text)
        resp = requests.get('{0}/v1/images/{1}/ancestry'.format(
            self.registry_endpoint, image_id),
        )
        self.assertEqual(resp.status_code, 200, resp.text)
        # Note(dmp): unicode patch XXX not applied assume requests does the job
        ancestry = json.loads(resp.text)
        # We got the ancestry, let's fetch all the images there
        for image_id in ancestry:
            json_data, checksum, blob = self.fetch_image(image_id)
            # check queried checksum and local computed checksum from the image
            # are the same
            tmpfile = StringIO()
            tmpfile.write(blob)
            tmpfile.seek(0)
            computed_checksum = checksums.compute_simple(tmpfile, json_data)
            tmpfile.close()
            self.assertEqual(checksum, computed_checksum)
        # Remove the repository
        resp = requests.delete('{0}/v1/repositories/{1}/{2}/images'.format(
            self.registry_endpoint, namespace, repos), )
        self.assertEqual(resp.status_code, 204, resp.text)
        # Remove image_id, then parent_id
        store = storage.load()
        try:
            store.remove(os.path.join(store.images, self.image_id))
        except Exception:
            pass
        try:
            store.remove(os.path.join(store.images, self.parent_id))
        except Exception:
            pass