diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-07-14 10:08:41 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-07-14 10:08:41 +1200 |
commit | a8a083a10d09509be8f39fb4463a857e0d3e2eeb (patch) | |
tree | 0abe75497598fb0bf724fbe12af50bde5381c618 /test | |
parent | 696789b8ec41c6189226896c93eb121014946eff (diff) | |
download | mitmproxy-a8a083a10d09509be8f39fb4463a857e0d3e2eeb.tar.gz mitmproxy-a8a083a10d09509be8f39fb4463a857e0d3e2eeb.tar.bz2 mitmproxy-a8a083a10d09509be8f39fb4463a857e0d3e2eeb.zip |
Move StickyAuth into addon
This is the first addon that handles an OptionsError, so this commit also demos
how this works in console. Handling of command-line erorrs is on its way.
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/builtins/test_stickyauth.py | 23 | ||||
-rw-r--r-- | test/mitmproxy/test_flow.py | 34 |
2 files changed, 23 insertions, 34 deletions
diff --git a/test/mitmproxy/builtins/test_stickyauth.py b/test/mitmproxy/builtins/test_stickyauth.py new file mode 100644 index 00000000..9233f435 --- /dev/null +++ b/test/mitmproxy/builtins/test_stickyauth.py @@ -0,0 +1,23 @@ +from .. import tutils, mastertest +from mitmproxy.builtins import stickyauth +from mitmproxy.flow import master +from mitmproxy.flow import state +from mitmproxy import options + + +class TestStickyAuth(mastertest.MasterTest): + def test_simple(self): + s = state.State() + m = master.FlowMaster(options.Options(stickyauth = ".*"), None, s) + sa = stickyauth.StickyAuth() + m.addons.add(sa) + + f = tutils.tflow(resp=True) + f.request.headers["authorization"] = "foo" + self.invoke(m, "request", f) + + assert "address" in sa.hosts + + f = tutils.tflow(resp=True) + self.invoke(m, "request", f) + assert f.request.headers["authorization"] == "foo" diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 6b270872..a6a3038c 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -120,20 +120,6 @@ class TestStickyCookieState: assert "cookie" in f.request.headers -class TestStickyAuthState: - - def test_response(self): - s = flow.StickyAuthState(filt.parse(".*")) - f = tutils.tflow(resp=True) - f.request.headers["authorization"] = "foo" - s.handle_request(f) - assert "address" in s.hosts - - f = tutils.tflow(resp=True) - s.handle_request(f) - assert f.request.headers["authorization"] == "foo" - - class TestClientPlaybackState: def test_tick(self): @@ -1004,26 +990,6 @@ class TestFlowMaster: fm.request(f) assert f.request.headers["cookie"] == "foo=bar" - def test_stickyauth(self): - s = flow.State() - fm = flow.FlowMaster(None, None, s) - assert "Invalid" in fm.set_stickyauth("~h") - fm.set_stickyauth(".*") - assert fm.stickyauth_state - fm.set_stickyauth(None) - assert not fm.stickyauth_state - - fm.set_stickyauth(".*") - f = tutils.tflow(resp=True) - f.request.headers["authorization"] = "foo" - fm.request(f) - - f = tutils.tflow(resp=True) - assert fm.stickyauth_state.hosts - assert "authorization" not in f.request.headers - fm.request(f) - assert f.request.headers["authorization"] == "foo" - def test_stream(self): with tutils.tmpdir() as tdir: p = os.path.join(tdir, "foo") |