From c726519e73761e5df3a20a1a92c1655497dd49c0 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 20 Mar 2011 17:31:54 +1300 Subject: 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. --- test/test_flow.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test') 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(), -- cgit v1.2.3