aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-11-04 09:17:56 +1300
committerAldo Cortesi <aldo@nullcube.com>2016-11-04 09:17:56 +1300
commit4f4db223fea191b75d97ae33580db62d5d472961 (patch)
treefc8060bb5e68964c6b14727d39f8a2c50c92de4b /test
parentdeb66d3cac6106081d7c2260bdfed944a107a081 (diff)
downloadmitmproxy-4f4db223fea191b75d97ae33580db62d5d472961.tar.gz
mitmproxy-4f4db223fea191b75d97ae33580db62d5d472961.tar.bz2
mitmproxy-4f4db223fea191b75d97ae33580db62d5d472961.zip
addons: convert last of the test suite to taddons
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_anticache.py3
-rw-r--r--test/mitmproxy/addons/test_anticomp.py3
-rw-r--r--test/mitmproxy/addons/test_replace.py4
-rw-r--r--test/mitmproxy/addons/test_stickycookie.py173
-rw-r--r--test/mitmproxy/addons/test_termlog.py3
5 files changed, 92 insertions, 94 deletions
diff --git a/test/mitmproxy/addons/test_anticache.py b/test/mitmproxy/addons/test_anticache.py
index 851be945..928f2180 100644
--- a/test/mitmproxy/addons/test_anticache.py
+++ b/test/mitmproxy/addons/test_anticache.py
@@ -1,11 +1,10 @@
from mitmproxy.test import tflow
-from .. import mastertest
from mitmproxy.addons import anticache
from mitmproxy.test import taddons
-class TestAntiCache(mastertest.MasterTest):
+class TestAntiCache:
def test_simple(self):
sa = anticache.AntiCache()
with taddons.context() as tctx:
diff --git a/test/mitmproxy/addons/test_anticomp.py b/test/mitmproxy/addons/test_anticomp.py
index eaf8fe53..2a6cf3ce 100644
--- a/test/mitmproxy/addons/test_anticomp.py
+++ b/test/mitmproxy/addons/test_anticomp.py
@@ -1,11 +1,10 @@
from mitmproxy.test import tflow
-from .. import mastertest
from mitmproxy.addons import anticomp
from mitmproxy.test import taddons
-class TestAntiComp(mastertest.MasterTest):
+class TestAntiComp:
def test_simple(self):
sa = anticomp.AntiComp()
with taddons.context() as tctx:
diff --git a/test/mitmproxy/addons/test_replace.py b/test/mitmproxy/addons/test_replace.py
index 94efe9c3..34fa5017 100644
--- a/test/mitmproxy/addons/test_replace.py
+++ b/test/mitmproxy/addons/test_replace.py
@@ -1,14 +1,14 @@
from mitmproxy.test import tflow
from mitmproxy.test import tutils
-from .. import mastertest, tservers
+from .. import tservers
from mitmproxy.addons import replace
from mitmproxy import master
from mitmproxy import options
from mitmproxy import proxy
-class TestReplace(mastertest.MasterTest):
+class TestReplace:
def test_configure(self):
r = replace.Replace()
updated = set(["replacements"])
diff --git a/test/mitmproxy/addons/test_stickycookie.py b/test/mitmproxy/addons/test_stickycookie.py
index 7f1e83eb..df5d0221 100644
--- a/test/mitmproxy/addons/test_stickycookie.py
+++ b/test/mitmproxy/addons/test_stickycookie.py
@@ -1,11 +1,9 @@
from mitmproxy.test import tflow
from mitmproxy.test import tutils
+from mitmproxy.test import taddons
-from .. import mastertest
from mitmproxy.addons import stickycookie
-from mitmproxy import master
from mitmproxy import options
-from mitmproxy import proxy
from mitmproxy.test import tutils as ntutils
@@ -14,14 +12,7 @@ def test_domain_match():
assert stickycookie.domain_match("google.com", ".google.com")
-class TestStickyCookie(mastertest.MasterTest):
- def mk(self):
- o = options.Options(stickycookie = ".*")
- m = master.Master(o, proxy.DummyServer())
- sc = stickycookie.StickyCookie()
- m.addons.add(sc)
- return m, sc
-
+class TestStickyCookie:
def test_config(self):
sc = stickycookie.StickyCookie()
o = options.Options(stickycookie = "~b")
@@ -31,103 +22,113 @@ class TestStickyCookie(mastertest.MasterTest):
)
def test_simple(self):
- m, sc = self.mk()
- m.addons.add(sc)
-
- f = tflow.tflow(resp=True)
- f.response.headers["set-cookie"] = "foo=bar"
- m.request(f)
+ sc = stickycookie.StickyCookie()
+ with taddons.context() as tctx:
+ tctx.configure(sc, stickycookie=".*")
+ f = tflow.tflow(resp=True)
+ f.response.headers["set-cookie"] = "foo=bar"
+ sc.request(f)
- f.reply.acked = False
- m.response(f)
+ f.reply.acked = False
+ sc.response(f)
- assert sc.jar
- assert "cookie" not in f.request.headers
+ assert sc.jar
+ assert "cookie" not in f.request.headers
- f = f.copy()
- f.reply.acked = False
- m.request(f)
- assert f.request.headers["cookie"] == "foo=bar"
+ f = f.copy()
+ f.reply.acked = False
+ sc.request(f)
+ assert f.request.headers["cookie"] == "foo=bar"
- def _response(self, m, sc, cookie, host):
+ def _response(self, sc, cookie, host):
f = tflow.tflow(req=ntutils.treq(host=host, port=80), resp=True)
f.response.headers["Set-Cookie"] = cookie
- m.response(f)
+ sc.response(f)
return f
def test_response(self):
- m, sc = self.mk()
+ sc = stickycookie.StickyCookie()
+ with taddons.context() as tctx:
+ tctx.configure(sc, stickycookie=".*")
- c = "SSID=mooo; domain=.google.com, FOO=bar; Domain=.google.com; Path=/; " \
- "Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; "
+ c = "SSID=mooo; domain=.google.com, FOO=bar; Domain=.google.com; Path=/; " \
+ "Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; "
- self._response(m, sc, c, "host")
- assert not sc.jar.keys()
+ self._response(sc, c, "host")
+ assert not sc.jar.keys()
- self._response(m, sc, c, "www.google.com")
- assert sc.jar.keys()
+ self._response(sc, c, "www.google.com")
+ assert sc.jar.keys()
- sc.jar.clear()
- self._response(
- m, sc, "SSID=mooo", "www.google.com"
- )
- assert list(sc.jar.keys())[0] == ('www.google.com', 80, '/')
+ sc.jar.clear()
+ self._response(sc, "SSID=mooo", "www.google.com")
+ assert list(sc.jar.keys())[0] == ('www.google.com', 80, '/')
def test_response_multiple(self):
- m, sc = self.mk()
-
- # Test setting of multiple cookies
- c1 = "somecookie=test; Path=/"
- c2 = "othercookie=helloworld; Path=/"
- f = self._response(m, sc, c1, "www.google.com")
- f.response.headers["Set-Cookie"] = c2
- m.response(f)
- googlekey = list(sc.jar.keys())[0]
- assert len(sc.jar[googlekey].keys()) == 2
+ sc = stickycookie.StickyCookie()
+ with taddons.context() as tctx:
+ tctx.configure(sc, stickycookie=".*")
+
+ # Test setting of multiple cookies
+ c1 = "somecookie=test; Path=/"
+ c2 = "othercookie=helloworld; Path=/"
+ f = self._response(sc, c1, "www.google.com")
+ f.response.headers["Set-Cookie"] = c2
+ sc.response(f)
+ googlekey = list(sc.jar.keys())[0]
+ assert len(sc.jar[googlekey].keys()) == 2
def test_response_weird(self):
- m, sc = self.mk()
-
- # Test setting of weird cookie keys
- f = tflow.tflow(req=ntutils.treq(host="www.google.com", port=80), resp=True)
- cs = [
- "foo/bar=hello",
- "foo:bar=world",
- "foo@bar=fizz",
- ]
- for c in cs:
- f.response.headers["Set-Cookie"] = c
- m.response(f)
- googlekey = list(sc.jar.keys())[0]
- assert len(sc.jar[googlekey].keys()) == len(cs)
+ sc = stickycookie.StickyCookie()
+ with taddons.context() as tctx:
+ tctx.configure(sc, stickycookie=".*")
+
+ # Test setting of weird cookie keys
+ f = tflow.tflow(req=ntutils.treq(host="www.google.com", port=80), resp=True)
+ cs = [
+ "foo/bar=hello",
+ "foo:bar=world",
+ "foo@bar=fizz",
+ ]
+ for c in cs:
+ f.response.headers["Set-Cookie"] = c
+ sc.response(f)
+ googlekey = list(sc.jar.keys())[0]
+ assert len(sc.jar[googlekey].keys()) == len(cs)
def test_response_overwrite(self):
- m, sc = self.mk()
-
- # Test overwriting of a cookie value
- c1 = "somecookie=helloworld; Path=/"
- c2 = "somecookie=newvalue; Path=/"
- f = self._response(m, sc, c1, "www.google.com")
- f.response.headers["Set-Cookie"] = c2
- m.response(f)
- googlekey = list(sc.jar.keys())[0]
- assert len(sc.jar[googlekey].keys()) == 1
- assert list(sc.jar[googlekey]["somecookie"].items())[0][1] == "newvalue"
+ sc = stickycookie.StickyCookie()
+ with taddons.context() as tctx:
+ tctx.configure(sc, stickycookie=".*")
+
+ # Test overwriting of a cookie value
+ c1 = "somecookie=helloworld; Path=/"
+ c2 = "somecookie=newvalue; Path=/"
+ f = self._response(sc, c1, "www.google.com")
+ f.response.headers["Set-Cookie"] = c2
+ sc.response(f)
+ googlekey = list(sc.jar.keys())[0]
+ assert len(sc.jar[googlekey].keys()) == 1
+ assert list(sc.jar[googlekey]["somecookie"].items())[0][1] == "newvalue"
def test_response_delete(self):
- m, sc = self.mk()
+ sc = stickycookie.StickyCookie()
+ with taddons.context() as tctx:
+ tctx.configure(sc, stickycookie=".*")
- # Test that a cookie is be deleted
- # by setting the expire time in the past
- f = self._response(m, sc, "duffer=zafar; Path=/", "www.google.com")
- f.response.headers["Set-Cookie"] = "duffer=; Expires=Thu, 01-Jan-1970 00:00:00 GMT"
- m.response(f)
- assert not sc.jar.keys()
+ # Test that a cookie is be deleted
+ # by setting the expire time in the past
+ f = self._response(sc, "duffer=zafar; Path=/", "www.google.com")
+ f.response.headers["Set-Cookie"] = "duffer=; Expires=Thu, 01-Jan-1970 00:00:00 GMT"
+ sc.response(f)
+ assert not sc.jar.keys()
def test_request(self):
- m, sc = self.mk()
+ sc = stickycookie.StickyCookie()
+ with taddons.context() as tctx:
+ tctx.configure(sc, stickycookie=".*")
- f = self._response(m, sc, "SSID=mooo", "www.google.com")
- assert "cookie" not in f.request.headers
- m.request(f)
- assert "cookie" in f.request.headers
+ f = self._response(sc, "SSID=mooo", "www.google.com")
+ assert "cookie" not in f.request.headers
+ sc.request(f)
+ assert "cookie" in f.request.headers
diff --git a/test/mitmproxy/addons/test_termlog.py b/test/mitmproxy/addons/test_termlog.py
index 1045ec29..880fcb51 100644
--- a/test/mitmproxy/addons/test_termlog.py
+++ b/test/mitmproxy/addons/test_termlog.py
@@ -1,4 +1,3 @@
-from .. import mastertest
import io
from mitmproxy.addons import termlog
@@ -6,7 +5,7 @@ from mitmproxy import log
from mitmproxy.tools import dump
-class TestTermLog(mastertest.MasterTest):
+class TestTermLog:
def test_simple(self):
t = termlog.TermLog()
sio = io.StringIO()