예제 #1
0
    def test_all(self):
        """Verify whether content served by pulp can be downloaded.

        The process of creating a Maven mirror is simple:

        1. Create a Maven Remote with a URL pointing to the root of a Maven repository.
        2. Create a distribution with the remote set HREF from 1.

        Do the following:

        1. Create a Maven Remote and a Distribution.
        2. Select a random content unit in the distribution. Download that
           content unit from Pulp, and verify that the content unit has the
           same checksum when fetched directly from Maven Central.

        This test targets the following issues:

        * `Pulp #2895 <https://pulp.plan.io/issues/2895>`_
        * `Pulp Smash #872 <https://github.com/PulpQE/pulp-smash/issues/872>`_
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo["_href"])

        body = gen_maven_remote()
        remote = client.post(MAVEN_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote["_href"])

        repo = client.get(repo["_href"])

        # Create a distribution.
        body = gen_distribution()
        body["remote"] = remote["_href"]
        response_dict = client.post(MAVEN_DISTRIBUTION_PATH, body)
        dist_task = client.get(response_dict["task"])
        distribution_href = dist_task["created_resources"][0]
        distribution = client.get(distribution_href)
        self.addCleanup(client.delete, distribution["_href"])

        # Pick a content unit, and download it from both Pulp Fixtures…
        unit_path = choice(get_maven_content_paths(repo))
        fixtures_hash = hashlib.sha256(
            utils.http_get(urljoin(MAVEN_FIXTURE_URL, unit_path))).hexdigest()

        # …and Pulp.
        client.response_handler = api.safe_handler

        unit_url = cfg.get_hosts("content")[0].roles["content"]["scheme"]
        unit_url += "://" + distribution["base_url"] + "/"
        unit_url = urljoin(unit_url, unit_path)

        pulp_hash = hashlib.sha256(client.get(unit_url).content).hexdigest()
        self.assertEqual(fixtures_hash, pulp_hash)

        # Check that Pulp created a MavenArtifact
        content_filter_url = MAVEN_CONTENT_PATH + "?filename=custommatcher-1.0-javadoc.jar.sha1"
        content_unit = client.get(content_filter_url)
        self.assertEqual(1, content_unit.json()["count"])
예제 #2
0
    def test_02_create_same_name(self):
        """Try to create a second remote with an identical name.

        See: `Pulp Smash #1055
        <https://github.com/PulpQE/pulp-smash/issues/1055>`_.
        """
        body = gen_maven_remote()
        body["name"] = self.remote["name"]
        with self.assertRaises(HTTPError):
            self.client.post(MAVEN_REMOTE_PATH, body)
예제 #3
0
    def test_all(self):
        """Verify whether is possible to create a remote without a URL.

        This test targets the following issues:

        * `Pulp #3395 <https://pulp.plan.io/issues/3395>`_
        * `Pulp Smash #984 <https://github.com/PulpQE/pulp-smash/issues/984>`_
        """
        body = gen_maven_remote()
        del body["url"]
        with self.assertRaises(HTTPError):
            api.Client(config.get_config()).post(MAVEN_REMOTE_PATH, body)
예제 #4
0
def _gen_verbose_remote():
    """Return a semi-random dict for use in defining a remote.

    For most tests, it's desirable to create remotes with as few attributes
    as possible, so that the tests can specifically target and attempt to break
    specific features. This module specifically targets remotes, so it makes
    sense to provide as many attributes as possible.

    Note that 'username' and 'password' are write-only attributes.
    """
    attrs = gen_maven_remote()
    attrs.update({"password": utils.uuid4(), "username": utils.uuid4()})
    return attrs
예제 #5
0
def _gen_verbose_remote():
    """Return a semi-random dict for use in defining a remote.

    For most tests, it's desirable to create remotes with as few attributes
    as possible, so that the tests can specifically target and attempt to break
    specific features. This module specifically targets remotes, so it makes
    sense to provide as many attributes as possible.

    Note that 'username' and 'password' are write-only attributes.
    """
    attrs = gen_maven_remote()
    attrs.update({
        'password': utils.uuid4(),
        'username': utils.uuid4(),
        'policy': choice(DOWNLOAD_POLICIES),
        'validate': choice((False, True)),
    })
    return attrs