Пример #1
0
    def test_negotiate_socks_err(self):
        waiter = asyncio.Future(loop=self.loop)
        proto = make_base(self.loop, waiter=waiter)
        proto.socks_request = fake_coroutine(aiosocks.SocksError('test'))

        self.loop.run_until_complete(proto.negotiate(None, None))
        self.assertIn('Can not connect to', str(waiter.exception()))
Пример #2
0
async def test_base_negotiate_socks_err(loop):
    waiter = asyncio.Future(loop=loop)
    proto = make_base(loop, waiter=waiter)
    proto.socks_request = make_mocked_coro(
        raise_exception=aiosocks.SocksError('test'))
    await proto.negotiate(None, None)

    with pytest.raises(aiosocks.SocksError) as ct:
        await waiter
    assert 'Can not connect to' in str(ct.value)
Пример #3
0
    def test_proxy_negotiate_fail(self, cr_conn_mock):
        loop_mock = mock.Mock()
        cr_conn_mock.side_effect = \
            fake_coroutine(aiosocks.SocksError()).side_effect

        req = ClientRequest('GET', 'http://python.org', loop=self.loop)
        connector = SocksConnector(aiosocks.Socks5Addr('127.0.0.1'),
                                   None, loop=loop_mock)

        loop_mock.getaddrinfo = fake_coroutine([mock.MagicMock()])

        with self.assertRaises(aiosocks.SocksError):
            self.loop.run_until_complete(connector.connect(req))
Пример #4
0
async def test_proxy_negotiate_fail(loop):
    loop_mock = mock.Mock()
    loop_mock.getaddrinfo = make_mocked_coro(
        [[0, 0, 0, 0, ['127.0.0.1', 1080]]])

    with mock.patch('aiosocks.connector.create_connection',
                    make_mocked_coro(raise_exception=aiosocks.SocksError())):
        req = ProxyClientRequest(
            'GET', URL('http://python.org'), loop=loop,
            proxy=URL('socks5://127.0.0.1'))
        connector = ProxyConnector(loop=loop_mock)

        with pytest.raises(aiosocks.SocksError):
            await connector.connect(req)
Пример #5
0
async def test_negotiate_fail():
    addr = aiosocks.Socks5Addr('localhost')
    auth = aiosocks.Socks5Auth('usr', 'pwd')
    dst = ('python.org', 80)

    loop_mock = mock.Mock()
    loop_mock.create_connection = make_mocked_coro((mock.Mock(), mock.Mock()))

    with mock.patch('aiosocks.asyncio.Future') as future_mock:
        future_mock.side_effect = make_mocked_coro(
            raise_exception=aiosocks.SocksError())

        with pytest.raises(aiosocks.SocksError):
            await aiosocks.create_connection(None,
                                             addr,
                                             auth,
                                             dst,
                                             loop=loop_mock)
Пример #6
0
    def test_negotiate_fail(self, future_mock):
        addr = aiosocks.Socks5Addr('localhost')
        auth = aiosocks.Socks5Auth('usr', 'pwd')
        dst = ('python.org', 80)

        loop_mock = mock.Mock()
        loop_mock.create_connection = fake_coroutine(
            (mock.Mock(), mock.Mock()))

        fut = fake_coroutine(aiosocks.SocksError())
        future_mock.side_effect = fut.side_effect

        with self.assertRaises(aiosocks.SocksError):
            conn = aiosocks.create_connection(None,
                                              addr,
                                              auth,
                                              dst,
                                              loop=loop_mock)
            self.loop.run_until_complete(conn)