Esempio n. 1
0
    def test_generate_proxy_config(self):
        """ Test generating proxy.yaml from Proxy objects.
        """
        p1 = Proxy(host='proxy1.example.com', port=8001)
        p2 = Proxy(host='proxy2.example.com', port=8002)
        proxy_yaml = proxy.generate_proxy_config(p1, p2)
        proxy.validate_proxy_config(proxy_yaml)
        d = yaml.load(proxy_yaml)

        self.assertEquals('proxy1.example.com', d['proxies'][0]['host'])
        self.assertEquals(8001, d['proxies'][0]['port'])
        self.assertEqual('https', d['proxies'][0]['protocol'])
        self.assertEqual('encryptor', d['proxies'][0]['usage'])

        self.assertEquals('proxy2.example.com', d['proxies'][1]['host'])
        self.assertEquals(8002, d['proxies'][1]['port'])
Esempio n. 2
0
    def test_generate_proxy_config(self):
        """ Test generating proxy.yaml from Proxy objects.
        """
        p1 = Proxy(host='proxy1.example.com', port=8001)
        p2 = Proxy(host='proxy2.example.com', port=8002)
        proxy_yaml = proxy.generate_proxy_config(p1, p2)
        proxy.validate_proxy_config(proxy_yaml)
        d = yaml.load(proxy_yaml)

        self.assertEquals('proxy1.example.com', d['proxies'][0]['host'])
        self.assertEquals(8001, d['proxies'][0]['port'])
        self.assertEqual('https', d['proxies'][0]['protocol'])
        self.assertEqual('encryptor', d['proxies'][0]['usage'])

        self.assertEquals('proxy2.example.com', d['proxies'][1]['host'])
        self.assertEquals(8002, d['proxies'][1]['port'])
Esempio n. 3
0
    def test_validate_proxy_config(self):
        """ Test that proxy.yaml validation fails unless we specify at least
        one complete proxy configuration.
        """
        d = {}
        with self.assertRaises(ValidationError):
            proxy.validate_proxy_config(yaml.dump(d))

        d['proxies'] = []
        with self.assertRaises(ValidationError):
            proxy.validate_proxy_config(yaml.dump(d))

        proxies = {}
        d['proxies'].append(proxies)
        with self.assertRaises(ValidationError):
            proxy.validate_proxy_config(yaml.dump(d))

        proxies['host'] = 'proxy.example.com'
        with self.assertRaises(ValidationError):
            proxy.validate_proxy_config(yaml.dump(d))

        proxies['port'] = 8001
        proxy.validate_proxy_config(yaml.dump(d))
Esempio n. 4
0
    def test_validate_proxy_config(self):
        """ Test that proxy.yaml validation fails unless we specify at least
        one complete proxy configuration.
        """
        d = {}
        with self.assertRaises(ValidationError):
            proxy.validate_proxy_config(yaml.dump(d))

        d['proxies'] = []
        with self.assertRaises(ValidationError):
            proxy.validate_proxy_config(yaml.dump(d))

        proxies = {}
        d['proxies'].append(proxies)
        with self.assertRaises(ValidationError):
            proxy.validate_proxy_config(yaml.dump(d))

        proxies['host'] = 'proxy.example.com'
        with self.assertRaises(ValidationError):
            proxy.validate_proxy_config(yaml.dump(d))

        proxies['port'] = 8001
        proxy.validate_proxy_config(yaml.dump(d))
Esempio n. 5
0
def get_proxy_config(values):
    """ Read proxy config specified by either the --proxy or
    --proxy-config-file option.

    :return the contents of the proxy.yaml file, or None if not specified
    :raise ValidationError if the file cannot be read or is malformed
    """
    proxy_config = None
    if values.proxy_config_file:
        path = values.proxy_config_file
        log.debug('Loading proxy config from %s', path)
        try:
            with open(path) as f:
                proxy_config = f.read()
        except IOError as e:
            log.debug('Unable to read %s: %s', path, e)
            raise ValidationError('Unable to read %s' % path)
        validate_proxy_config(proxy_config)
    elif values.proxies:
        proxies = _parse_proxies(*values.proxies)
        proxy_config = generate_proxy_config(*proxies)
        log.debug('Using proxy configuration:\n%s', proxy_config)

    return proxy_config
Esempio n. 6
0
def get_proxy_config(values):
    """ Read proxy config specified by either the --proxy or
    --proxy-config-file option.

    :return the contents of the proxy.yaml file, or None if not specified
    :raise ValidationError if the file cannot be read or is malformed
    """
    proxy_config = None
    if values.proxy_config_file:
        path = values.proxy_config_file
        log.debug('Loading proxy config from %s', path)
        try:
            with open(path) as f:
                proxy_config = f.read()
        except IOError as e:
            log.debug('Unable to read %s: %s', path, e)
            raise ValidationError('Unable to read %s' % path)
        validate_proxy_config(proxy_config)
    elif values.proxies:
        proxies = _parse_proxies(*values.proxies)
        proxy_config = generate_proxy_config(*proxies)
        log.debug('Using proxy configuration:\n%s', proxy_config)

    return proxy_config