mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-05 13:37:45 +03:00
fix: socks5 udp domain handling bug & add test case for it
This commit is contained in:
parent
fefabaf739
commit
b27628607a
2 changed files with 31 additions and 8 deletions
|
@ -6,33 +6,51 @@ ADDR = "127.0.0.1"
|
|||
PORT = 11080
|
||||
|
||||
|
||||
def test_tcp(size, count, it):
|
||||
def test_tcp(size, count, it, domain=False):
|
||||
for i in range(it):
|
||||
s = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.set_proxy(socks.SOCKS5, ADDR, PORT)
|
||||
|
||||
s.connect(("test_tcp", 12345))
|
||||
if domain:
|
||||
s.connect(("test.tcp.com", 12345))
|
||||
else:
|
||||
s.connect(("1.2.3.4", 12345))
|
||||
|
||||
for j in range(count):
|
||||
payload = os.urandom(size)
|
||||
s.send(payload)
|
||||
rsp = s.recv(size)
|
||||
assert rsp == payload
|
||||
|
||||
s.close()
|
||||
|
||||
|
||||
def test_udp(size, count, it):
|
||||
def test_udp(size, count, it, domain=False):
|
||||
for i in range(it):
|
||||
s = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.set_proxy(socks.SOCKS5, ADDR, PORT)
|
||||
|
||||
for j in range(count):
|
||||
payload = os.urandom(size)
|
||||
s.sendto(payload, ("test_udp", 12345))
|
||||
|
||||
if domain:
|
||||
s.sendto(payload, ("test.udp.com", 12345))
|
||||
else:
|
||||
s.sendto(payload, ("1.2.3.4", 12345))
|
||||
|
||||
rsp, addr = s.recvfrom(size)
|
||||
assert rsp == payload and addr == (b"test_udp", 12345)
|
||||
assert rsp == payload
|
||||
|
||||
if domain:
|
||||
assert addr == (b"test.udp.com", 12345)
|
||||
else:
|
||||
assert addr == ("1.2.3.4", 12345)
|
||||
|
||||
s.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_tcp(1024, 1024, 10)
|
||||
test_udp(1024, 1024, 10)
|
||||
test_tcp(1024, 1024, 10, domain=False)
|
||||
test_tcp(1024, 1024, 10, domain=True)
|
||||
test_udp(1024, 1024, 10, domain=False)
|
||||
test_udp(1024, 1024, 10, domain=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue