addons anticom, anticache: expand tests, new truss

This commit is contained in:
Aldo Cortesi 2016-11-01 17:38:45 +13:00
parent 1cc2195f45
commit 83fdd82a52
3 changed files with 26 additions and 27 deletions

View File

@ -2,24 +2,22 @@ from mitmproxy.test import tflow
from .. import mastertest
from mitmproxy.addons import anticache
from mitmproxy import master
from mitmproxy import options
from mitmproxy import proxy
from mitmproxy.test import taddons
class TestAntiCache(mastertest.MasterTest):
def test_simple(self):
o = options.Options(anticache = True)
m = master.Master(o, proxy.DummyServer())
sa = anticache.AntiCache()
m.addons.add(sa)
with taddons.context() as tctx:
f = tflow.tflow(resp=True)
f.request.headers["if-modified-since"] = "test"
f.request.headers["if-none-match"] = "test"
f = tflow.tflow(resp=True)
m.request(f)
sa.request(f)
assert "if-modified-since" in f.request.headers
assert "if-none-match" in f.request.headers
f = tflow.tflow(resp=True)
f.request.headers["if-modified-since"] = "test"
f.request.headers["if-none-match"] = "test"
m.request(f)
assert "if-modified-since" not in f.request.headers
assert "if-none-match" not in f.request.headers
tctx.configure(sa, anticache = True)
sa.request(f)
assert "if-modified-since" not in f.request.headers
assert "if-none-match" not in f.request.headers

View File

@ -2,23 +2,19 @@ from mitmproxy.test import tflow
from .. import mastertest
from mitmproxy.addons import anticomp
from mitmproxy import master
from mitmproxy import options
from mitmproxy import proxy
from mitmproxy.test import taddons
class TestAntiComp(mastertest.MasterTest):
def test_simple(self):
o = options.Options(anticomp = True)
m = master.Master(o, proxy.DummyServer())
sa = anticomp.AntiComp()
m.addons.add(sa)
with taddons.context() as tctx:
f = tflow.tflow(resp=True)
sa.request(f)
f = tflow.tflow(resp=True)
m.request(f)
tctx.configure(sa, anticomp=True)
f = tflow.tflow(resp=True)
f = tflow.tflow(resp=True)
f.request.headers["Accept-Encoding"] = "foobar"
m.request(f)
assert f.request.headers["Accept-Encoding"] == "identity"
f.request.headers["Accept-Encoding"] = "foobar"
sa.request(f)
assert f.request.headers["Accept-Encoding"] == "identity"

View File

@ -0,0 +1,5 @@
from mitmproxy import addons
def test_defaults():
assert addons.default_addons()