add test for connection
This commit is contained in:
parent
d97a490901
commit
f4cc439a7e
|
@ -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):
|
||||
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue