def test_defaultFactory(self): proxy = FakeEndpoint() endpoint = client.SOCKS4ClientEndpoint('127.0.0.1', 0, proxy) endpoint.connect(None) # PY3KPORT: Py2-3 compatible port using six self.assertEqual( proxy.transport.value(), six.ensure_binary('\x04\x01\x00\x00\x7f\x00\x00\x01\x00'))
def test_differentUser(self): proxy = FakeEndpoint() endpoint = client.SOCKS4ClientEndpoint('127.0.0.1', 0, proxy, 'spam') endpoint.connect(None) # Py3k fixes # PY3KPORT: Py2-3 compatible port using six self.assertEqual( proxy.transport.value(), six.ensure_binary('\x04\x01\x00\x00\x7f\x00\x00\x01spam\x00'))
def test_hostname(self): proxy = FakeEndpoint() endpoint = client.SOCKS4ClientEndpoint('spam.com', 0, proxy) endpoint.connect(None) # PY3KPORT: Py2-3 compatible port using six self.assertEqual( proxy.transport.value(), six.ensure_binary( '\x04\x01\x00\x00\x00\x00\x00\x01\x00spam.com\x00'))
def test_dataSentByPeer(self): wrappedFac = FakeFactory() proxy = FakeEndpoint() endpoint = client.SOCKS4ClientEndpoint('', 0, proxy) endpoint.connect(wrappedFac) proxy.proto.dataReceived('\x00\x5a\x00\x00\x00\x00\x00\x00') proxy.proto.transport.clear() wrappedFac.proto.transport.write('xxxxx') self.assertEqual(proxy.proto.transport.value(), 'xxxxx')
def test_buildingWrappedFactory(self): wrappedFac = FakeFactory() proxy = FakeEndpoint() endpoint = client.SOCKS4ClientEndpoint('', 0, proxy) d = endpoint.connect(wrappedFac) proxy.proto.dataReceived('\x00\x5a\x00\x00\x00\x00\x00\x00xxxxx') d.addCallback(self.assertEqual, wrappedFac.proto) self.assertEqual(wrappedFac.proto.data, 'xxxxx') return d
def test_dataSentByPeer(self): wrappedFac = FakeFactory() proxy = FakeEndpoint() endpoint = client.SOCKS4ClientEndpoint('', 0, proxy) endpoint.connect(wrappedFac) proxy.proto.dataReceived('\x00\x5a\x00\x00\x00\x00\x00\x00') proxy.proto.transport.clear() # PY3KPORT: Py2-3 compatible port using six wrappedFac.proto.transport.write(six.b('xxxxx')) self.assertEqual(proxy.proto.transport.value(), six.b('xxxxx'))
def test_buildingWrappedFactory(self): wrappedFac = FakeFactory() proxy = FakeEndpoint() endpoint = client.SOCKS4ClientEndpoint('', 0, proxy) d = endpoint.connect(wrappedFac) proxy.proto.dataReceived('\x00\x5a\x00\x00\x00\x00\x00\x00xxxxx') d.addCallback(self.assertEqual, wrappedFac.proto) # PY3KPORT: Py2-3 compatible port using six self.assertEqual(wrappedFac.proto.data, six.b('xxxxx')) return d
def test_clientConnectionFailed(self): proxy = FakeEndpoint(failure=connectionRefusedFailure) endpoint = client.SOCKS4ClientEndpoint('', 0, proxy) d = endpoint.connect(None) return self.assertFailure(d, ConnectionRefusedError)
def test_differentUser(self): proxy = FakeEndpoint() endpoint = client.SOCKS4ClientEndpoint('127.0.0.1', 0, proxy, 'spam') endpoint.connect(None) self.assertEqual(proxy.transport.value(), '\x04\x01\x00\x00\x7f\x00\x00\x01spam\x00')
def test_hostname(self): proxy = FakeEndpoint() endpoint = client.SOCKS4ClientEndpoint('spam.com', 0, proxy) endpoint.connect(None) self.assertEqual(proxy.transport.value(), '\x04\x01\x00\x00\x00\x00\x00\x01\x00spam.com\x00')
def test_defaultFactory(self): proxy = FakeEndpoint() endpoint = client.SOCKS4ClientEndpoint('127.0.0.1', 0, proxy) endpoint.connect(None) self.assertEqual(proxy.transport.value(), '\x04\x01\x00\x00\x7f\x00\x00\x01\x00')