mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
tests: SOCKS BIND
The proxy accepts the connection expected and joins it with the client both ways, and refuses one from another address than the one asked for. socks_bind() and socks_bind_peer() in the harness make the request and read the second reply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fea5bae665
commit
fdebdb16dc
3 files changed
+75
-1
No files matched your search
@@ -1,5 +1,7 @@
|
||||
"""The SOCKS proxy, reaching the built-in server."""
|
||||
|
||||
import socket
|
||||
|
||||
|
||||
def run(t):
|
||||
srv = t.free_port()
|
||||
@@ -85,6 +87,39 @@ def run(t):
|
||||
t.eq(None, reply,
|
||||
"an allow by host name does not let datagrams to an address through")
|
||||
|
||||
# --- BIND: the proxy accepts a connection for the client --------------
|
||||
# The far side connects to where the first reply says, the second reply
|
||||
# names it, and the two are then joined both ways.
|
||||
ctrl, where = t.socks_bind(plain, "127.0.0.1")
|
||||
peer = None
|
||||
try:
|
||||
peer = socket.create_connection(where, t.timeout)
|
||||
peer.settimeout(t.timeout)
|
||||
t.ne(None, t.socks_bind_peer(ctrl), "BIND takes the connection expected")
|
||||
peer.sendall(b"from the far side")
|
||||
t.eq(b"from the far side", t._recvall(ctrl, 17),
|
||||
"what the far side sends reaches the client")
|
||||
ctrl.sendall(b"from the client")
|
||||
t.eq(b"from the client", t._recvall(peer, 15),
|
||||
"what the client sends reaches the far side")
|
||||
finally:
|
||||
ctrl.close()
|
||||
if peer:
|
||||
peer.close()
|
||||
|
||||
# A connection from elsewhere than the address given is not the one
|
||||
# waited for.
|
||||
ctrl, where = t.socks_bind(plain, "192.0.2.1")
|
||||
peer = None
|
||||
try:
|
||||
peer = socket.create_connection(where, t.timeout)
|
||||
t.eq(None, t.socks_bind_peer(ctrl),
|
||||
"BIND refuses a connection from another address")
|
||||
finally:
|
||||
ctrl.close()
|
||||
if peer:
|
||||
peer.close()
|
||||
|
||||
# --- authentication ----------------------------------------------------
|
||||
t.eq(200, t.socks_http(guarded, origin + "/echo",
|
||||
auth=("alice", "secret")).status,
|
||||
|
||||
Reference in new issue
Block a user