aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_pathoc.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-11-11 12:29:34 +0100
committerMaximilian Hils <git@maximilianhils.com>2014-11-11 12:29:34 +0100
commit8635e00175117d8574b4bea5edc1c43528ddf3e9 (patch)
tree1be23a6349a8fb81a89f8417b0b9d236d1829639 /test/test_pathoc.py
parentb917b61e6aead4f353ef15838315ecc0df721e29 (diff)
parent27c7e9e9345bbc458e7efc4093c2074e19011d12 (diff)
downloadmitmproxy-8635e00175117d8574b4bea5edc1c43528ddf3e9.tar.gz
mitmproxy-8635e00175117d8574b4bea5edc1c43528ddf3e9.tar.bz2
mitmproxy-8635e00175117d8574b4bea5edc1c43528ddf3e9.zip
Merge remote-tracking branch 'origin/master'
Conflicts: setup.py
Diffstat (limited to 'test/test_pathoc.py')
-rw-r--r--test/test_pathoc.py45
1 files changed, 25 insertions, 20 deletions
diff --git a/test/test_pathoc.py b/test/test_pathoc.py
index fe7adc4d..23b42994 100644
--- a/test/test_pathoc.py
+++ b/test/test_pathoc.py
@@ -1,6 +1,8 @@
import json
import cStringIO
-from libpathod import pathoc, test, version, pathod
+import re
+
+from libpathod import pathoc, test, version, pathod, language
import tutils
@@ -18,7 +20,9 @@ class _TestDaemon:
ssl=self.ssl,
ssloptions=self.ssloptions,
staticdir=tutils.test_data.path("data"),
- anchors=[("/anchor/.*", "202")]
+ anchors=[
+ (re.compile("/anchor/.*"), language.parse_response("202"))
+ ]
)
@classmethod
@@ -37,17 +41,29 @@ class _TestDaemon:
r = c.request("get:/api/info")
assert tuple(json.loads(r.content)["version"]) == version.IVERSION
- def tval(self, requests, showreq=False, showresp=False, explain=False,
- showssl=False, hexdump=False, timeout=None, ignorecodes=None,
- ignoretimeout=None):
+ def tval(
+ self,
+ requests,
+ showreq=False,
+ showresp=False,
+ explain=False,
+ showssl=False,
+ hexdump=False,
+ timeout=None,
+ ignorecodes=None,
+ ignoretimeout=None
+ ):
c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl=self.ssl)
c.connect()
if timeout:
c.settimeout(timeout)
s = cStringIO.StringIO()
for i in requests:
+ r = language.parse_requests(i)[0]
+ if explain:
+ r = r.freeze({})
c.print_request(
- i,
+ r,
showreq = showreq,
showresp = showresp,
explain = explain,
@@ -125,25 +141,17 @@ class TestDaemon(_TestDaemon):
assert "HTTP/" in v
def test_explain(self):
- reqs = [ "get:/p/200:b@100" ]
- assert not "b@100" in self.tval(reqs, explain=True)
+ reqs = ["get:/p/200:b@100"]
+ assert "b@100" not in self.tval(reqs, explain=True)
def test_showreq(self):
- reqs = [ "get:/api/info:p0,0", "get:/api/info:p0,0" ]
+ reqs = ["get:/api/info:p0,0", "get:/api/info:p0,0"]
assert self.tval(reqs, showreq=True).count("unprintables escaped") == 2
assert self.tval(reqs, showreq=True, hexdump=True).count("hex dump") == 2
- def test_parse_err(self):
- assert "Error parsing" in self.tval(["foo"])
-
def test_conn_err(self):
assert "Invalid server response" in self.tval(["get:'/p/200:d2'"])
- def test_fileread(self):
- d = tutils.test_data.path("data/request")
- assert "foo" in self.tval(["+%s"%d], showreq=True)
- assert "File" in self.tval(["+/nonexistent"])
-
def test_connect_fail(self):
to = ("foobar", 80)
c = pathoc.Pathoc(("127.0.0.1", self.d.port))
@@ -157,6 +165,3 @@ class TestDaemon(_TestDaemon):
"HTTP/1.1 200 OK\r\n"
)
c.http_connect(to)
-
-
-