aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_pathoc.py25
-rw-r--r--test/tutils.py8
2 files changed, 32 insertions, 1 deletions
diff --git a/test/test_pathoc.py b/test/test_pathoc.py
index 6b037bcc..fb8d348a 100644
--- a/test/test_pathoc.py
+++ b/test/test_pathoc.py
@@ -4,7 +4,7 @@ import re
import OpenSSL
from mock import Mock
-from netlib import tcp, http, http2
+from netlib import tcp, http, http2, socks
from libpathod import pathoc, test, version, pathod, language
import tutils
@@ -230,6 +230,29 @@ class TestDaemon(_TestDaemon):
)
c.http_connect(to)
+ def test_socks_connect(self):
+ to = ("foobar", 80)
+ c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
+ c.rfile, c.wfile = tutils.treader(""), cStringIO.StringIO()
+ tutils.raises(pathoc.PathocError, c.socks_connect, to)
+
+ c.rfile = tutils.treader(
+ "\x05\xEE"
+ )
+ tutils.raises("SOCKS without authentication", c.socks_connect, ("example.com", 0xDEAD))
+
+ c.rfile = tutils.treader(
+ "\x05\x00" +
+ "\x05\xEE\x00\x03\x0bexample.com\xDE\xAD"
+ )
+ tutils.raises("SOCKS server error", c.socks_connect, ("example.com", 0xDEAD))
+
+ c.rfile = tutils.treader(
+ "\x05\x00" +
+ "\x05\x00\x00\x03\x0bexample.com\xDE\xAD"
+ )
+ c.socks_connect(("example.com", 0xDEAD))
+
class TestDaemonHTTP2(_TestDaemon):
ssl = True
diff --git a/test/tutils.py b/test/tutils.py
index 9d9b687d..f7fcc312 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -5,8 +5,16 @@ import shutil
import cStringIO
from contextlib import contextmanager
from libpathod import utils, test, pathoc, pathod, language
+from netlib import tcp
import requests
+def treader(bytes):
+ """
+ Construct a tcp.Read object from bytes.
+ """
+ fp = cStringIO.StringIO(bytes)
+ return tcp.Reader(fp)
+
class DaemonTests(object):
noweb = False