From 5aadf92767614b7bd8e2ef677085410ac359e5e8 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 25 Oct 2014 08:18:39 +1300 Subject: Nicer way to specify patterns read for file - just use a path --- test/test_pathoc.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'test/test_pathoc.py') diff --git a/test/test_pathoc.py b/test/test_pathoc.py index fe7adc4d..5172d85f 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -139,11 +139,6 @@ class TestDaemon(_TestDaemon): 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)) -- cgit v1.2.3 From 00d0ee5ad56d8243b1e9bfffec9a941e11359d2c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 25 Oct 2014 15:30:54 +1300 Subject: Parse patterns eagerly on instantiation --- test/test_pathoc.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'test/test_pathoc.py') diff --git a/test/test_pathoc.py b/test/test_pathoc.py index 5172d85f..88479b6c 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,9 +41,18 @@ 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: @@ -47,7 +60,7 @@ class _TestDaemon: s = cStringIO.StringIO() for i in requests: c.print_request( - i, + language.parse_request(i), showreq = showreq, showresp = showresp, explain = explain, @@ -125,17 +138,14 @@ 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'"]) @@ -152,6 +162,3 @@ class TestDaemon(_TestDaemon): "HTTP/1.1 200 OK\r\n" ) c.http_connect(to) - - - -- cgit v1.2.3 From 6d8431ab3e96568b3579a85e680371fd20c961aa Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 25 Oct 2014 16:20:23 +1300 Subject: Allow specification of multiple patterns from file and on command line --- test/test_pathoc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test_pathoc.py') diff --git a/test/test_pathoc.py b/test/test_pathoc.py index 88479b6c..2542b622 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -60,7 +60,7 @@ class _TestDaemon: s = cStringIO.StringIO() for i in requests: c.print_request( - language.parse_request(i), + language.parse_requests(i)[0], showreq = showreq, showresp = showresp, explain = explain, -- cgit v1.2.3 From fc1fc80469dca11ff0241c4b263e4b39e5506ddd Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 26 Oct 2014 10:50:32 +1300 Subject: Allow nesting of pathod response specs in pathoc specs This opens the door to really neat, repeatable, client-side driven fuzzing, especially of proxies. --- test/test_pathoc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/test_pathoc.py') diff --git a/test/test_pathoc.py b/test/test_pathoc.py index 2542b622..23b42994 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -59,8 +59,11 @@ class _TestDaemon: c.settimeout(timeout) s = cStringIO.StringIO() for i in requests: + r = language.parse_requests(i)[0] + if explain: + r = r.freeze({}) c.print_request( - language.parse_requests(i)[0], + r, showreq = showreq, showresp = showresp, explain = explain, -- cgit v1.2.3