aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-04-14 11:58:10 +1200
committerAldo Cortesi <aldo@nullcube.com>2015-04-14 11:58:10 +1200
commitbea0bd236a60e3e6c80027448e51b7802394304a (patch)
tree1cc160e19eb1834703798503f1818e4278bce1b2 /test
parentf37efecd0a22313eacad33251512ef371557fde7 (diff)
downloadmitmproxy-bea0bd236a60e3e6c80027448e51b7802394304a.tar.gz
mitmproxy-bea0bd236a60e3e6c80027448e51b7802394304a.tar.bz2
mitmproxy-bea0bd236a60e3e6c80027448e51b7802394304a.zip
Housekeeping and cleanups
- No output to stdout on load in examples - they muck up the test suite. - Use the odict module directly, rather than aliasing it. The small convenience this gives to scripters is not worth it. - Move the cookie tests from the flow test module to the protocol_http test module.
Diffstat (limited to 'test')
-rw-r--r--test/test_console_contentview.py20
-rw-r--r--test/test_filt.py6
-rw-r--r--test/test_flow.py66
-rw-r--r--test/test_protocol_http.py41
-rw-r--r--test/test_utils.py3
-rw-r--r--test/tutils.py6
6 files changed, 74 insertions, 68 deletions
diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py
index 44378cf7..83dbbb8f 100644
--- a/test/test_console_contentview.py
+++ b/test/test_console_contentview.py
@@ -2,8 +2,9 @@ import os
from nose.plugins.skip import SkipTest
if os.name == "nt":
raise SkipTest("Skipped on Windows.")
-
import sys
+
+from netlib import odict
import libmproxy.console.contentview as cv
from libmproxy import utils, flow, encoding
import tutils
@@ -30,14 +31,14 @@ class TestContentView:
def test_view_auto(self):
v = cv.ViewAuto()
f = v(
- flow.ODictCaseless(),
+ odict.ODictCaseless(),
"foo",
1000
)
assert f[0] == "Raw"
f = v(
- flow.ODictCaseless(
+ odict.ODictCaseless(
[["content-type", "text/html"]],
),
"<html></html>",
@@ -46,7 +47,7 @@ class TestContentView:
assert f[0] == "HTML"
f = v(
- flow.ODictCaseless(
+ odict.ODictCaseless(
[["content-type", "text/flibble"]],
),
"foo",
@@ -55,7 +56,7 @@ class TestContentView:
assert f[0] == "Raw"
f = v(
- flow.ODictCaseless(
+ odict.ODictCaseless(
[["content-type", "text/flibble"]],
),
"<xml></xml>",
@@ -166,20 +167,20 @@ Content-Disposition: form-data; name="submit-name"
Larry
--AaB03x
""".strip()
- h = flow.ODictCaseless(
+ h = odict.ODictCaseless(
[("Content-Type", "multipart/form-data; boundary=AaB03x")]
)
assert view(h, v, 1000)
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
assert not view(h, v, 1000)
- h = flow.ODictCaseless(
+ h = odict.ODictCaseless(
[("Content-Type", "multipart/form-data")]
)
assert not view(h, v, 1000)
- h = flow.ODictCaseless(
+ h = odict.ODictCaseless(
[("Content-Type", "unparseable")]
)
assert not view(h, v, 1000)
@@ -281,4 +282,3 @@ if cv.ViewProtobuf.is_available():
def test_get_by_shortcut():
assert cv.get_by_shortcut("h")
-
diff --git a/test/test_filt.py b/test/test_filt.py
index 279f550f..97b8e73c 100644
--- a/test/test_filt.py
+++ b/test/test_filt.py
@@ -1,4 +1,5 @@
import cStringIO
+from netlib import odict
from libmproxy import filt, flow
from libmproxy.protocol import http
from libmproxy.protocol.primitives import Error
@@ -74,7 +75,7 @@ class TestParsing:
class TestMatching:
def req(self):
- headers = flow.ODictCaseless()
+ headers = odict.ODictCaseless()
headers["header"] = ["qvalue"]
req = http.HTTPRequest(
"absolute",
@@ -96,7 +97,7 @@ class TestMatching:
def resp(self):
f = self.req()
- headers = flow.ODictCaseless()
+ headers = odict.ODictCaseless()
headers["header_response"] = ["svalue"]
f.response = http.HTTPResponse((1, 1), 200, "OK", headers, "content_response", None, None)
@@ -253,4 +254,3 @@ class TestMatching:
assert self.q("! ~c 201", s)
assert self.q("!~c 201 !~c 202", s)
assert not self.q("!~c 201 !~c 200", s)
-
diff --git a/test/test_flow.py b/test/test_flow.py
index b0b0ee5c..760f7d5b 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -2,6 +2,7 @@ import Queue, time, os.path
from cStringIO import StringIO
import email.utils
import mock
+from netlib import odict
from libmproxy import filt, protocol, controller, utils, tnetstring, flow
from libmproxy.protocol.primitives import Error, Flow
from libmproxy.protocol.http import decoded, CONTENT_MISSING
@@ -931,7 +932,7 @@ class TestRequest:
assert r.get_path_components() == []
r.path = "/foo/bar"
assert r.get_path_components() == ["foo", "bar"]
- q = flow.ODict()
+ q = odict.ODict()
q["test"] = ["123"]
r.set_query(q)
assert r.get_path_components() == ["foo", "bar"]
@@ -945,12 +946,12 @@ class TestRequest:
assert "%2F" in r.path
def test_getset_form_urlencoded(self):
- d = flow.ODict([("one", "two"), ("three", "four")])
+ d = odict.ODict([("one", "two"), ("three", "four")])
r = tutils.treq(content=utils.urlencode(d.lst))
r.headers["content-type"] = [protocol.http.HDR_FORM_URLENCODED]
assert r.get_form_urlencoded() == d
- d = flow.ODict([("x", "y")])
+ d = odict.ODict([("x", "y")])
r.set_form_urlencoded(d)
assert r.get_form_urlencoded() == d
@@ -958,7 +959,7 @@ class TestRequest:
assert not r.get_form_urlencoded()
def test_getset_query(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
r = tutils.treq()
r.path = "/foo?x=y&a=b"
@@ -975,14 +976,14 @@ class TestRequest:
r.path = "/foo?x=y&a=b"
assert r.get_query()
- r.set_query(flow.ODict([]))
+ r.set_query(odict.ODict([]))
assert not r.get_query()
- qv = flow.ODict([("a", "b"), ("c", "d")])
+ qv = odict.ODict([("a", "b"), ("c", "d")])
r.set_query(qv)
assert r.get_query() == qv
def test_anticache(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
r = tutils.treq()
r.headers = h
h["if-modified-since"] = ["test"]
@@ -1046,43 +1047,8 @@ class TestRequest:
r.encode("gzip")
assert r.get_decoded_content() == "falafel"
- def test_get_cookies_none(self):
- h = flow.ODictCaseless()
- r = tutils.treq()
- r.headers = h
- assert r.get_cookies() is None
-
- def test_get_cookies_single(self):
- h = flow.ODictCaseless()
- h["Cookie"] = ["cookiename=cookievalue"]
- r = tutils.treq()
- r.headers = h
- result = r.get_cookies()
- assert len(result)==1
- assert result['cookiename']==('cookievalue',{})
-
- def test_get_cookies_double(self):
- h = flow.ODictCaseless()
- h["Cookie"] = ["cookiename=cookievalue;othercookiename=othercookievalue"]
- r = tutils.treq()
- r.headers = h
- result = r.get_cookies()
- assert len(result)==2
- assert result['cookiename']==('cookievalue',{})
- assert result['othercookiename']==('othercookievalue',{})
-
- def test_get_cookies_withequalsign(self):
- h = flow.ODictCaseless()
- h["Cookie"] = ["cookiename=coo=kievalue;othercookiename=othercookievalue"]
- r = tutils.treq()
- r.headers = h
- result = r.get_cookies()
- assert len(result)==2
- assert result['cookiename']==('coo=kievalue',{})
- assert result['othercookiename']==('othercookievalue',{})
-
def test_header_size(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
h["headername"] = ["headervalue"]
r = tutils.treq()
r.headers = h
@@ -1090,7 +1056,7 @@ class TestRequest:
assert len(raw) == 62
def test_get_content_type(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
h["Content-Type"] = ["text/plain"]
resp = tutils.tresp()
resp.headers = h
@@ -1183,13 +1149,13 @@ class TestResponse:
assert result==44
def test_get_cookies_none(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
resp = tutils.tresp()
resp.headers = h
assert not resp.get_cookies()
def test_get_cookies_simple(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
h["Set-Cookie"] = ["cookiename=cookievalue"]
resp = tutils.tresp()
resp.headers = h
@@ -1199,7 +1165,7 @@ class TestResponse:
assert result["cookiename"] == ("cookievalue", {})
def test_get_cookies_with_parameters(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
h["Set-Cookie"] = ["cookiename=cookievalue;domain=example.com;expires=Wed Oct 21 16:29:41 2015;path=/; HttpOnly"]
resp = tutils.tresp()
resp.headers = h
@@ -1214,7 +1180,7 @@ class TestResponse:
assert result["cookiename"][1]["httponly"]==""
def test_get_cookies_no_value(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
h["Set-Cookie"] = ["cookiename=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/"]
resp = tutils.tresp()
resp.headers = h
@@ -1225,7 +1191,7 @@ class TestResponse:
assert len(result["cookiename"][1])==2
def test_get_cookies_twocookies(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
h["Set-Cookie"] = ["cookiename=cookievalue","othercookie=othervalue"]
resp = tutils.tresp()
resp.headers = h
@@ -1237,7 +1203,7 @@ class TestResponse:
assert result["othercookie"] == ("othervalue", {})
def test_get_content_type(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
h["Content-Type"] = ["text/plain"]
resp = tutils.tresp()
resp.headers = h
diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py
index 23c3f469..08ed114c 100644
--- a/test/test_protocol_http.py
+++ b/test/test_protocol_http.py
@@ -1,6 +1,10 @@
+from cStringIO import StringIO
+
from mock import MagicMock
+
from libmproxy.protocol.http import *
-from cStringIO import StringIO
+from netlib import odict
+
import tutils, tservers
@@ -131,6 +135,41 @@ class TestHTTPRequest:
assert r.get_form_multipart.called
+ def test_get_cookies_none(self):
+ h = odict.ODictCaseless()
+ r = tutils.treq()
+ r.headers = h
+ assert r.get_cookies() is None
+
+ def test_get_cookies_single(self):
+ h = odict.ODictCaseless()
+ h["Cookie"] = ["cookiename=cookievalue"]
+ r = tutils.treq()
+ r.headers = h
+ result = r.get_cookies()
+ assert len(result)==1
+ assert result['cookiename']==('cookievalue',{})
+
+ def test_get_cookies_double(self):
+ h = odict.ODictCaseless()
+ h["Cookie"] = ["cookiename=cookievalue;othercookiename=othercookievalue"]
+ r = tutils.treq()
+ r.headers = h
+ result = r.get_cookies()
+ assert len(result)==2
+ assert result['cookiename']==('cookievalue',{})
+ assert result['othercookiename']==('othercookievalue',{})
+
+ def test_get_cookies_withequalsign(self):
+ h = odict.ODictCaseless()
+ h["Cookie"] = ["cookiename=coo=kievalue;othercookiename=othercookievalue"]
+ r = tutils.treq()
+ r.headers = h
+ result = r.get_cookies()
+ assert len(result)==2
+ assert result['cookiename']==('coo=kievalue',{})
+ assert result['othercookiename']==('othercookievalue',{})
+
diff --git a/test/test_utils.py b/test/test_utils.py
index 35ba0c9d..ea38b9a3 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -1,5 +1,6 @@
import json
from libmproxy import utils, flow
+from netlib import odict
import tutils
utils.CERT_SLEEP_TIME = 0
@@ -54,7 +55,7 @@ def test_urldecode():
def test_multipartdecode():
boundary = 'somefancyboundary'
- headers = flow.ODict([('content-type', ('multipart/form-data; boundary=%s' % boundary))])
+ headers = odict.ODict([('content-type', ('multipart/form-data; boundary=%s' % boundary))])
content = "--{0}\n" \
"Content-Disposition: form-data; name=\"field1\"\n\n" \
"value1\n" \
diff --git a/test/tutils.py b/test/tutils.py
index e7720d33..499efc6e 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -9,7 +9,7 @@ import mock_urwid
from libmproxy.console.flowview import FlowView
from libmproxy.console import ConsoleState
from libmproxy.protocol.primitives import Error
-from netlib import certutils
+from netlib import certutils, odict
from nose.plugins.skip import SkipTest
from mock import Mock
from time import time
@@ -81,7 +81,7 @@ def treq(content="content", scheme="http", host="address", port=22):
"""
@return: libmproxy.protocol.http.HTTPRequest
"""
- headers = flow.ODictCaseless()
+ headers = odict.ODictCaseless()
headers["header"] = ["qvalue"]
req = http.HTTPRequest("relative", "GET", scheme, host, port, "/path", (1, 1), headers, content,
None, None, None)
@@ -104,7 +104,7 @@ def tresp(content="message"):
@return: libmproxy.protocol.http.HTTPResponse
"""
- headers = flow.ODictCaseless()
+ headers = odict.ODictCaseless()
headers["header_response"] = ["svalue"]
resp = http.HTTPResponse((1, 1), 200, "OK", headers, content, time(), time())