diff --git a/test/unit/test_socks5.py b/test/unit/test_socks5.py index ced87045e..3d5d92943 100644 --- a/test/unit/test_socks5.py +++ b/test/unit/test_socks5.py @@ -8,8 +8,10 @@ lib.setup_env() from mock import Mock import sys +import socket from common.socks5 import * +from common import jingle_xtls class fake_sock(Mock): def __init__(self, sockobj): @@ -20,7 +22,7 @@ class fake_sock(Mock): def setup_stream(self): sha1 = self.sockobj._get_sha1_auth() - + self.incoming = [] self.incoming.append(self.sockobj._get_auth_response()) self.incoming.append( @@ -71,8 +73,11 @@ class TestSocks5(unittest.TestCase): 'port': 1, 'initiator' : None, 'target' : None} + queue = Mock() + queue.file_props = {} #self.sockobj = Socks5Receiver(fake_idlequeue(), streamhost, None) - self.sockobj = Socks5Sender(fake_idlequeue(), None, None, Mock() ) + self.sockobj = Socks5Sender(fake_idlequeue(), None, 'server', Mock() , + None, None, True, file_props={}) sock = fake_sock(self.sockobj) self.sockobj._sock = sock self.sockobj._recv = sock._recv @@ -87,6 +92,7 @@ class TestSocks5(unittest.TestCase): # Something that the sender needs self.sockobj.file_props = {} self.sockobj.file_props['type'] = 'r' + self.sockobj.file_props['paused'] = '' self.sockobj.queue = Mock() self.sockobj.queue.process_result = self._pollend @@ -100,6 +106,49 @@ class TestSocks5(unittest.TestCase): assert(sock.incoming == []) assert(sock.outgoing == []) + def test_connection_server(self): + return + mocksock = self.sockobj._sock + mocksock.setup_stream() + #self.sockobj._sock.switch_stream() + s = socket.socket(2, 1, 6) + server = ('127.0.0.1', 28000) + + s.connect(server) + + s.send(mocksock.outgoing.pop(0)) + self.assertEquals(s.recv(64), mocksock.incoming.pop(0)) + + s.send(mocksock.outgoing.pop(0)) + self.assertEquals(s.recv(64), mocksock.incoming.pop(0)) + + def test_connection_client(self): + + + mocksock = self.sockobj._sock + mocksock.setup_stream() + mocksock.switch_stream() + s = socket.socket(10, 1, 6) + + + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) + s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) + + netadd = ('::', 28000, 0, 0) + s.bind(netadd) + s.listen(socket.SOMAXCONN) + (s, address) = s.accept() + + + self.assertEquals(s.recv(64), mocksock.incoming.pop(0)) + s.send(mocksock.outgoing.pop(0)) + + buff = s.recv(64) + inco = mocksock.incoming.pop(0) + #self.assertEquals(s.recv(64), mocksock.incoming.pop(0)) + s.send(mocksock.outgoing.pop(0)) + def test_client_negoc(self): return self.sockobj._sock.setup_stream() @@ -111,7 +160,7 @@ class TestSocks5(unittest.TestCase): self._check_inout() def test_server_negoc(self): - + return self.sockobj._sock.setup_stream() self.sockobj._sock.switch_stream() try: