예제 #1
0
    def test_raises_exception_when_invalid_socks_scheme(self, mock_socks):
        conf = namedtuple('ProxyConf', 'scheme username password hostport')
        self.config = {
            'http': conf(*_parse_proxy('socks6://socks_user:socks_pass@socks_host:3128')),
            'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
        }

        conn = ProxyAwareHTTPConnection(self.config, 'example.com')

        with self.assertRaises(TypeError):
            conn.connect()
예제 #2
0
    def test_connect_uses_remote_dns(self, mock_socks):
        conf = namedtuple('ProxyConf', 'scheme username password hostport')
        self.config = {
            'http':
            conf(*_parse_proxy(
                'socks5h://socks_user:socks_pass@socks_host:3128')),
            'no_proxy':
            'localhost,127.0.0.1,dev_server:8080'
        }
        mock_socks.PROXY_TYPE_SOCKS5 = socks.PROXY_TYPE_SOCKS5

        conn = ProxyAwareHTTPConnection(self.config, 'example.com')
        conn.connect()

        mock_socks.create_connection.assert_called_once_with(
            ('example.com', 80), socket._GLOBAL_DEFAULT_TIMEOUT, None,
            socks.PROXY_TYPE_SOCKS5, 'socks_host', 3128, True, 'socks_user',
            'socks_pass', ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1), ))
예제 #3
0
    def test_connect_does_not_use_socks_proxy(self, mock_socks):
        conn = ProxyAwareHTTPConnection(self.config, 'example.com')
        conn._create_connection = Mock()
        conn.connect()

        assert mock_socks._create_connection.call_count == 0