aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/data/1.css1
-rw-r--r--test/test_console_contentview.py25
-rw-r--r--test/test_controller.py2
-rw-r--r--test/test_dump.py2
-rw-r--r--test/test_flow.py21
-rw-r--r--test/test_proxy.py20
-rw-r--r--test/tservers.py4
7 files changed, 51 insertions, 24 deletions
diff --git a/test/data/1.css b/test/data/1.css
new file mode 100644
index 00000000..33387ca7
--- /dev/null
+++ b/test/data/1.css
@@ -0,0 +1 @@
+body,html{height:100%}body{font-family:'Open Sans',sans-serif;font-size:1.5em;padding-top:80px}
diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py
index ef44f834..b982aff3 100644
--- a/test/test_console_contentview.py
+++ b/test/test_console_contentview.py
@@ -13,6 +13,11 @@ try:
except ImportError:
pyamf = None
+try:
+ import cssutils
+except:
+ cssutils = None
+
class TestContentView:
def test_trailer(self):
@@ -112,6 +117,26 @@ class TestContentView:
assert v([], "[1, 2, 3", 100)
assert v([], "function(a){[1, 2, 3]}", 100)
+ def test_view_css(self):
+ v = cv.ViewCSS()
+
+ with open('./test/data/1.css', 'r') as fp:
+ fixture_1 = fp.read()
+
+ result = v([], 'a', 100)
+
+ if cssutils:
+ assert len(result[1]) == 0
+ else:
+ assert len(result[1]) == 1
+
+ result = v([], fixture_1, 100)
+
+ if cssutils:
+ assert len(result[1]) > 1
+ else:
+ assert len(result[1]) == 1
+
def test_view_hex(self):
v = cv.ViewHex()
assert v([], "foo", 1000)
diff --git a/test/test_controller.py b/test/test_controller.py
index f6d6b5eb..e71a148e 100644
--- a/test/test_controller.py
+++ b/test/test_controller.py
@@ -6,7 +6,7 @@ class TestMaster:
def test_default_handler(self):
m = controller.Master(None)
msg = mock.MagicMock()
- m.handle(msg)
+ m.handle("type", msg)
assert msg.reply.call_count == 1
diff --git a/test/test_dump.py b/test/test_dump.py
index 3d375f16..9874b650 100644
--- a/test/test_dump.py
+++ b/test/test_dump.py
@@ -114,7 +114,7 @@ class TestDumpMaster:
o = dump.Options(app=True)
s = mock.MagicMock()
m = dump.DumpMaster(s, o, None)
- assert s.apps.add.call_count == 1
+ assert len(m.apps.apps) == 1
def test_replacements(self):
o = dump.Options(replacements=[(".*", "content", "foo")])
diff --git a/test/test_flow.py b/test/test_flow.py
index c614960b..bf6a7a42 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -5,6 +5,27 @@ from libmproxy import filt, flow, controller, utils, tnetstring, proxy
import tutils
+def test_app_registry():
+ ar = flow.AppRegistry()
+ ar.add("foo", "domain", 80)
+
+ r = tutils.treq()
+ r.host = "domain"
+ r.port = 80
+ assert ar.get(r)
+
+ r.port = 81
+ assert not ar.get(r)
+
+ r = tutils.treq()
+ r.host = "domain2"
+ r.port = 80
+ assert not ar.get(r)
+ r.headers["host"] = ["domain"]
+ assert ar.get(r)
+
+
+
class TestStickyCookieState:
def _response(self, cookie, host):
s = flow.StickyCookieState(filt.parse(".*"))
diff --git a/test/test_proxy.py b/test/test_proxy.py
index dfccaaf7..371e5ef7 100644
--- a/test/test_proxy.py
+++ b/test/test_proxy.py
@@ -11,26 +11,6 @@ def test_proxy_error():
assert str(p)
-def test_app_registry():
- ar = proxy.AppRegistry()
- ar.add("foo", "domain", 80)
-
- r = tutils.treq()
- r.host = "domain"
- r.port = 80
- assert ar.get(r)
-
- r.port = 81
- assert not ar.get(r)
-
- r = tutils.treq()
- r.host = "domain2"
- r.port = 80
- assert not ar.get(r)
- r.headers["host"] = ["domain"]
- assert ar.get(r)
-
-
class TestServerConnection:
def setUp(self):
self.d = test.Daemon()
diff --git a/test/tservers.py b/test/tservers.py
index f886d42d..ac95b168 100644
--- a/test/tservers.py
+++ b/test/tservers.py
@@ -23,10 +23,10 @@ def errapp(environ, start_response):
class TestMaster(flow.FlowMaster):
def __init__(self, testq, config):
s = proxy.ProxyServer(config, 0)
- s.apps.add(testapp, "testapp", 80)
- s.apps.add(errapp, "errapp", 80)
state = flow.State()
flow.FlowMaster.__init__(self, s, state)
+ self.apps.add(testapp, "testapp", 80)
+ self.apps.add(errapp, "errapp", 80)
self.testq = testq
self.clear_log()
self.start_app(APP_HOST, APP_PORT, False)