def test_ssl_validation_true(self):
        """
        Assert that Curl is configured to do SSL validation when ssl_validation is explicitly set to True.
        """
        config = DownloaderConfig(ssl_validation=True)
        curl_downloader = HTTPSCurlDownloader(config)
        easy_handle = mock.Mock()

        curl_downloader._add_ssl_configuration(easy_handle)

        self.assertEqual(easy_handle.setopt.call_count, 2)
        easy_handle.setopt.assert_any_call(pycurl.SSL_VERIFYPEER, 1)
        easy_handle.setopt.assert_any_call(pycurl.SSL_VERIFYHOST, 2)
    def test_ssl_validation_unset(self):
        """
        Assert that Curl is configured to do SSL validation by default when ssl_validation is unset.
        """
        config = DownloaderConfig()
        curl_downloader = HTTPSCurlDownloader(config)
        easy_handle = mock.Mock()

        curl_downloader._add_ssl_configuration(easy_handle)

        self.assertEqual(easy_handle.setopt.call_count, 2)
        easy_handle.setopt.assert_any_call(pycurl.SSL_VERIFYPEER, 1)
        easy_handle.setopt.assert_any_call(pycurl.SSL_VERIFYHOST, 2)
    def test_defaults(self):
        """
        Assert that the default configuration options are handed to the pycurl easy_handle.
        """
        config = DownloaderConfig('https')
        curl_downloader = HTTPSCurlDownloader(config)
        easy_handle = mock.MagicMock()

        curl_downloader._add_connection_configuration(easy_handle)

        # There are currently 6 settings that this method should set. If this assertion fails due to changes you
        # intentionally made to _add_connection_configuration, please update this count, and please also update
        # the setting assertions below it so that they are complete.
        self.assertEqual(easy_handle.setopt.call_count, 6)
        easy_handle.setopt.assert_any_call(pycurl.FOLLOWLOCATION, DEFAULT_FOLLOW_LOCATION)
        easy_handle.setopt.assert_any_call(pycurl.MAXREDIRS, DEFAULT_MAX_REDIRECTS)
        easy_handle.setopt.assert_any_call(pycurl.CONNECTTIMEOUT, DEFAULT_CONNECT_TIMEOUT)
        easy_handle.setopt.assert_any_call(pycurl.LOW_SPEED_LIMIT, DEFAULT_LOW_SPEED_LIMIT)
        easy_handle.setopt.assert_any_call(pycurl.LOW_SPEED_TIME, DEFAULT_LOW_SPEED_TIME)
        easy_handle.setopt.assert_any_call(pycurl.NOPROGRESS, DEFAULT_NO_PROGRESS)
Beispiel #4
0
 def _downloader(self, config):
     """
     Get a configured downloader.
     The integration between the importer configuration and the
     download package happens here.  The https downloader may be
     used for both http and https so always chosen for simplicity.
     :param config: The importer configuration.
     :param config: pulp.plugins.config.PluginCallConfiguration
     :return: A configured downloader
     :rtype: nectar.downloaders.base.Downloader
     """
     ssl = config.get(constants.SSL_KEYWORD, {})
     conf = DownloaderConfig(max_concurrent=MAX_CONCURRENCY,
                             ssl_ca_cert_path=self._safe_str(
                                 ssl.get(constants.CA_CERT_KEYWORD)),
                             ssl_client_cert_path=self._safe_str(
                                 ssl.get(constants.CLIENT_CERT_KEYWORD)),
                             ssl_validation=False)
     downloader = HTTPSCurlDownloader(conf)
     return downloader