aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-03-20 17:31:54 +1300
committerAldo Cortesi <aldo@nullcube.com>2011-03-20 17:31:54 +1300
commitc726519e73761e5df3a20a1a92c1655497dd49c0 (patch)
tree4eaf05e205d9613de3aa499f8225e75d28f3d30f /test
parent4f877cde6a9a6b99c3bf452f2164ab09abc64d50 (diff)
downloadmitmproxy-c726519e73761e5df3a20a1a92c1655497dd49c0.tar.gz
mitmproxy-c726519e73761e5df3a20a1a92c1655497dd49c0.tar.bz2
mitmproxy-c726519e73761e5df3a20a1a92c1655497dd49c0.zip
Add a stickyauth option.
This allows us to replay an HTTP Authorization header, in the same way as we replay cookies using stickycookies. This lets us conveniently get at HTTP Basic Auth protected resources through the proxy, but is not enough to do the same for HTTP Digest auth. We'll put that on the todo list.
Diffstat (limited to 'test')
-rw-r--r--test/test_flow.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/test_flow.py b/test/test_flow.py
index 463375aa..a6489462 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -34,6 +34,19 @@ class uStickyCookieState(libpry.AutoTree):
assert "cookie" in f.request.headers
+class uStickyAuthState(libpry.AutoTree):
+ def test_handle_response(self):
+ s = flow.StickyAuthState(filt.parse(".*"))
+ f = tutils.tflow_full()
+ f.request.headers["authorization"] = ["foo"]
+ s.handle_request(f)
+ assert "host" in s.hosts
+
+ f = tutils.tflow_full()
+ s.handle_request(f)
+ assert f.request.headers["authorization"] == ["foo"]
+
+
class uClientPlaybackState(libpry.AutoTree):
def test_tick(self):
first = tutils.tflow()
@@ -62,6 +75,9 @@ class uClientPlaybackState(libpry.AutoTree):
fm.state.clear()
fm.tick(q)
+ fm.stop_client_playback()
+ assert not fm.client_playback
+
class uServerPlaybackState(libpry.AutoTree):
def test_hash(self):
@@ -441,6 +457,9 @@ class uFlowMaster(libpry.AutoTree):
fm.tick(q)
assert controller.exit
+ fm.stop_server_playback()
+ assert not fm.server_playback
+
def test_stickycookie(self):
s = flow.State()
fm = flow.FlowMaster(None, s)
@@ -460,9 +479,30 @@ class uFlowMaster(libpry.AutoTree):
fm.handle_request(tf.request)
assert tf.request.headers["cookie"] == ["foo=bar"]
+ def test_stickyauth(self):
+ s = flow.State()
+ fm = flow.FlowMaster(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(".*")
+ tf = tutils.tflow_full()
+ tf.request.headers["authorization"] = ["foo"]
+ fm.handle_request(tf.request)
+
+ f = tutils.tflow_full()
+ assert fm.stickyauth_state.hosts
+ assert not "authorization" in f.request.headers
+ fm.handle_request(f.request)
+ assert f.request.headers["authorization"] == ["foo"]
+
tests = [
uStickyCookieState(),
+ uStickyAuthState(),
uServerPlaybackState(),
uClientPlaybackState(),
uFlow(),