diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_flow.py | 5 | ||||
-rw-r--r-- | test/test_proxy.py | 2 | ||||
-rw-r--r-- | test/test_utils.py | 63 |
3 files changed, 62 insertions, 8 deletions
diff --git a/test/test_flow.py b/test/test_flow.py index 9629934f..b71ce6af 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -32,10 +32,15 @@ class uFlow(libpry.AutoTree): def test_backup(self): f = utils.tflow() + f.response = utils.tresp() + f.request = f.response.request + f.request.content = "foo" assert not f.modified() f.backup() + f.request.content = "bar" assert f.modified() f.revert() + assert f.request.content == "foo" def test_getset_state(self): f = utils.tflow() diff --git a/test/test_proxy.py b/test/test_proxy.py index 340b6697..e343e693 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -236,7 +236,7 @@ class uRequest(libpry.AutoTree): c = proxy.ClientConnection(("addr", 2222)) r = proxy.Request(c, "host", 22, "https", "GET", "/", h, "content") state = r.get_state() - assert proxy.Request.from_state(state) == r + assert proxy.Request.from_state(c, state) == r class uResponse(libpry.AutoTree): diff --git a/test/test_utils.py b/test/test_utils.py index 325664a4..5cf81e2e 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,4 +1,4 @@ -import textwrap, cStringIO, os, time +import textwrap, cStringIO, os, time, re import libpry from libmproxy import utils @@ -228,13 +228,62 @@ class umake_bogus_cert(libpry.AutoTree): assert "CERTIFICATE" in d -class uprettybody(libpry.AutoTree): +class upretty_xmlish(libpry.AutoTree): + def test_tagre(self): + def f(s): + return re.search(utils.TAG, s, re.VERBOSE|re.MULTILINE) + assert f(r"<body>") + assert f(r"<body/>") + assert f(r"< body/>") + assert f(r"< body/ >") + assert f(r"< body / >") + assert f(r"<foo a=b>") + assert f(r"<foo a='b'>") + assert f(r"<foo a='b\"'>") + assert f(r'<a b=(a.b) href="foo">') + assert f('<td width=25%>') + assert f('<form name="search" action="/search.php" method="get" accept-charset="utf-8" class="search">') + assert f('<img src="gif" width="125" height="16" alt="" />') + + def test_all(self): - s = "<html><p></p></html>" - assert utils.prettybody(s) + def isbalanced(ret): + # The last tag should have no indent + assert ret[-1].strip() == ret[-1] + + s = "<html><br><br></br><p>one</p></html>" + ret = utils.pretty_xmlish(s) + isbalanced(ret) + + s = r""" +<body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onload="document.f.q.focus();if(document.images)new Image().src='/images/srpr/nav_logo27.png'" ><textarea id=csi style=display:none></textarea></body> + """ + isbalanced(utils.pretty_xmlish(textwrap.dedent(s))) + + s = r""" + <a href="http://foo.com" target=""> + <img src="http://foo.gif" alt="bar" height="25" width="132"> + </a> + """ + isbalanced(utils.pretty_xmlish(textwrap.dedent(s))) + + s = r""" + <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" + \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> + <html></html> + """ + ret = utils.pretty_xmlish(textwrap.dedent(s)) + isbalanced(ret) + + s = "<html><br/><p>one</p></html>" + ret = utils.pretty_xmlish(s) + assert len(ret) == 6 + isbalanced(ret) + + s = "gobbledygook" + assert utils.pretty_xmlish(s) == ["gobbledygook"] + - s = "".join([chr(i) for i in range(256)]) - assert utils.prettybody(s) @@ -249,5 +298,5 @@ tests = [ uMultiDict(), uHeaders(), uData(), - uprettybody(), + upretty_xmlish(), ] |