diff options
author | Aldo Cortesi <aldo@corte.si> | 2013-01-28 13:28:49 -0800 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2013-01-28 13:28:49 -0800 |
commit | 6f157d936f89a50927849611bdff3f1e8e1bb43b (patch) | |
tree | 91c04333f033de24debb75dc01189aff9025593d /test/test_flow.py | |
parent | a74ca40660a0796fbcc5494bfab31e46c3cec4d6 (diff) | |
parent | 330fbfe8cc54449b3e7c0fe8305b13f29b47c15c (diff) | |
download | mitmproxy-6f157d936f89a50927849611bdff3f1e8e1bb43b.tar.gz mitmproxy-6f157d936f89a50927849611bdff3f1e8e1bb43b.tar.bz2 mitmproxy-6f157d936f89a50927849611bdff3f1e8e1bb43b.zip |
Merge pull request #99 from rouli/master
Adding helper functions to make HAR export easier
Diffstat (limited to 'test/test_flow.py')
-rw-r--r-- | test/test_flow.py | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/test/test_flow.py b/test/test_flow.py index 2af702ce..ed3a988f 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -892,6 +892,57 @@ class TestRequest: assert not r.headers["content-encoding"] assert r.content == "falafel" + def test_get_cookies_single(self): + h = flow.ODictCaseless() + h["Cookie"] = ["cookiename=cookievalue"] + c = flow.ClientConnect(("addr", 2222)) + r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") + result = r.get_cookies() + assert len(result)==1 + assert result['cookiename']==('cookievalue',{}) + + def test_get_cookies_double(self): + h = flow.ODictCaseless() + h["Cookie"] = ["cookiename=cookievalue;othercookiename=othercookievalue"] + c = flow.ClientConnect(("addr", 2222)) + r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") + result = r.get_cookies() + assert len(result)==2 + assert result['cookiename']==('cookievalue',{}) + assert result['othercookiename']==('othercookievalue',{}) + + def test_get_cookies_withequalsign(self): + h = flow.ODictCaseless() + h["Cookie"] = ["cookiename=coo=kievalue;othercookiename=othercookievalue"] + c = flow.ClientConnect(("addr", 2222)) + r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") + result = r.get_cookies() + assert len(result)==2 + assert result['cookiename']==('coo=kievalue',{}) + assert result['othercookiename']==('othercookievalue',{}) + + def test_get_header_size(self): + h = flow.ODictCaseless() + h["headername"] = ["headervalue"] + c = flow.ClientConnect(("addr", 2222)) + r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") + result = r.get_header_size() + assert result==43 + + def test_get_transmitted_size(self): + h = flow.ODictCaseless() + h["headername"] = ["headervalue"] + c = flow.ClientConnect(("addr", 2222)) + r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") + result = r.get_transmitted_size() + assert result==len("content") + + def test_get_content_type(self): + h = flow.ODictCaseless() + h["Content-Type"] = ["text/plain"] + c = flow.ClientConnect(("addr", 2222)) + r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") + assert r.get_content_type()=="text/plain" class TestResponse: def test_simple(self): @@ -989,6 +1040,68 @@ class TestResponse: assert not r.headers["content-encoding"] assert r.content == "falafel" + def test_get_header_size(self): + r = tutils.tresp() + result = r.get_header_size() + assert result==49 + + def test_get_transmitted_size(self): + r = tutils.tresp() + r.headers["content-encoding"] = ["identity"] + r.content = "falafel" + result = r.get_transmitted_size() + assert result==len("falafel") + + def test_get_cookies_simple(self): + h = flow.ODictCaseless() + h["Set-Cookie"] = ["cookiename=cookievalue"] + resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None) + result = resp.get_cookies() + assert len(result)==1 + assert "cookiename" in result + assert result["cookiename"] == ("cookievalue", {}) + + def test_get_cookies_with_parameters(self): + h = flow.ODictCaseless() + h["Set-Cookie"] = ["cookiename=cookievalue;domain=example.com;expires=Wed Oct 21 16:29:41 2015;path=/; HttpOnly"] + resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None) + result = resp.get_cookies() + assert len(result)==1 + assert "cookiename" in result + assert result["cookiename"][0] == "cookievalue" + assert len(result["cookiename"][1])==4 + assert result["cookiename"][1]["domain"]=="example.com" + assert result["cookiename"][1]["expires"]=="Wed Oct 21 16:29:41 2015" + assert result["cookiename"][1]["path"]=="/" + assert result["cookiename"][1]["httponly"]=="" + + def test_get_cookies_no_value(self): + h = flow.ODictCaseless() + h["Set-Cookie"] = ["cookiename=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/"] + resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None) + result = resp.get_cookies() + assert len(result)==1 + assert "cookiename" in result + assert result["cookiename"][0] == "" + assert len(result["cookiename"][1])==2 + + def test_get_cookies_twocookies(self): + h = flow.ODictCaseless() + h["Set-Cookie"] = ["cookiename=cookievalue","othercookie=othervalue"] + resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None) + result = resp.get_cookies() + assert len(result)==2 + assert "cookiename" in result + assert result["cookiename"] == ("cookievalue", {}) + assert "othercookie" in result + assert result["othercookie"] == ("othervalue", {}) + + def test_get_content_type(self): + h = flow.ODictCaseless() + h["Content-Type"] = ["text/plain"] + resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None) + assert resp.get_content_type()=="text/plain" + class TestError: def test_getset_state(self): |