Ejemplo n.º 1
0
    def test_remote_file_exists_with_custom_certs(self, mock_curl):
        def mock_perform():
            curlopts[pycurl.WRITEFUNCTION](b'Available')

        def mock_setopt(opt, value):
            curlopts[opt] = value

        curlopts = {}
        curl = mock_curl.return_value
        curl.getinfo.return_value = 200
        curl.perform.side_effect = mock_perform
        curl.setopt.side_effect = mock_setopt

        client_cert = os.path.join(self.workdir, 'my-client-cert.cert')
        with open(client_cert, 'w'):
            pass

        ca_cert = os.path.join(self.workdir, 'my-custom-cacert.cert')
        with open(ca_cert, 'w'):
            pass

        lc = CGILookasideCache('_',
                               '_',
                               '_',
                               client_cert=client_cert,
                               ca_cert=ca_cert)
        lc.remote_file_exists('pyrpkg', 'pyrpkg-0.tar.xz', 'thehash')
        self.assertEqual(curlopts[pycurl.SSLCERT], client_cert)
        self.assertEqual(curlopts[pycurl.CAINFO], ca_cert)
Ejemplo n.º 2
0
    def test_remote_file_exists_missing_custom_certs(self, mock_curl,
                                                     mock_logger):
        def mock_perform():
            curlopts[pycurl.WRITEFUNCTION](b'Available')

        def mock_setopt(opt, value):
            curlopts[opt] = value

        def mock_warn(msg, *args, **kwargs):
            warn_messages.append(msg)

        curlopts = {}
        curl = mock_curl.return_value
        curl.getinfo.return_value = 200
        curl.perform.side_effect = mock_perform
        curl.setopt.side_effect = mock_setopt

        warn_messages = []
        log = mock_logger.return_value
        log.warning.side_effect = mock_warn

        client_cert = os.path.join(self.workdir, 'my-client-cert.cert')
        ca_cert = os.path.join(self.workdir, 'my-custom-cacert.cert')

        lc = CGILookasideCache('_',
                               '_',
                               '_',
                               client_cert=client_cert,
                               ca_cert=ca_cert)
        lc.remote_file_exists('pyrpkg', 'pyrpkg-0.tar.xz', 'thehash')
        self.assertTrue(pycurl.SSLCERT not in curlopts)
        self.assertTrue(pycurl.CAINFO not in curlopts)
        self.assertEqual(len(warn_messages), 2)
        self.assertTrue('Missing certificate: ' in warn_messages[0])
        self.assertTrue('Missing certificate: ' in warn_messages[1])
Ejemplo n.º 3
0
    def test_remote_file_does_not_exist(self, mock_curl):
        def mock_perform():
            curlopts[pycurl.WRITEFUNCTION](b'Missing')

        def mock_setopt(opt, value):
            curlopts[opt] = value

        curlopts = {}
        curl = mock_curl.return_value
        curl.getinfo.return_value = 200
        curl.perform.side_effect = mock_perform
        curl.setopt.side_effect = mock_setopt

        lc = CGILookasideCache('_', '_', '_')
        exists = lc.remote_file_exists('pyrpkg', 'pyrpkg-0.tar.xz', 'thehash')
        self.assertFalse(exists)