def test_state(self): c = flow.ClientConnect(("a", 22)) assert flow.ClientConnect._from_state(c._get_state()) == c c2 = flow.ClientConnect(("a", 25)) assert not c == c2 c._load_state(c2._get_state()) assert c == c2 c3 = c.copy() assert c3 == c
def test_state(self): c = flow.ClientConnect(("a", 22)) assert flow.ClientConnect._from_state(c._get_state()) == c c2 = flow.ClientConnect(("a", 25)) assert not c == c2 c2.requestcount = 99 c._load_state(c2._get_state()) assert c.requestcount == 99 c3 = c.copy() assert c3 == c assert str(c)
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"
def test_flow(self): """ normal flow: connect -> request -> response """ bc = flow.ClientConnect(("address", 22)) c = flow.State() req = tutils.treq(bc) f = c.add_request(req) assert f assert c.flow_count() == 1 assert c._flow_map.get(req) assert c.active_flow_count() == 1 newreq = tutils.treq() assert c.add_request(newreq) assert c._flow_map.get(newreq) assert c.active_flow_count() == 2 resp = tutils.tresp(req) assert c.add_response(resp) assert c.flow_count() == 2 assert c._flow_map.get(resp.request) assert c.active_flow_count() == 1 unseen_resp = tutils.tresp() assert not c.add_response(unseen_resp) assert not c._flow_map.get(unseen_resp.request) assert c.active_flow_count() == 1 resp = tutils.tresp(newreq) assert c.add_response(resp) assert c.active_flow_count() == 0
def test_simple(self): h = flow.ODictCaseless() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") u = r.get_url() assert r.set_url(u) assert not r.set_url("") assert r.get_url() == u assert r._assemble() assert r.size() == len(r._assemble()) r2 = r.copy() assert r == r2 r.content = None assert r._assemble() assert r.size() == len(r._assemble()) r.close = True assert "connection: close" in r._assemble() assert r._assemble(True) r.content = flow.CONTENT_MISSING assert not r._assemble()
def treq(conn=None): if not conn: conn = flow.ClientConnect(("address", 22)) headers = flow.ODictCaseless() headers["header"] = ["qvalue"] return flow.Request(conn, (1, 1), "host", 80, "http", "GET", "/path", headers, "content")
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 req(self): conn = flow.ClientConnect(("one", 2222)) headers = flow.ODictCaseless() headers["header"] = ["qvalue"] req = flow.Request(conn, (1, 1), "host", 80, "http", "GET", "/path", headers, "content_request") return flow.Flow(req)
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_simple(self): h = flow.Headers() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) req = flow.Request(c, "host", 22, "https", "GET", "/", h, "content") resp = flow.Response(req, 200, "msg", h.copy(), "content") assert resp._assemble() resp2 = resp.copy() assert resp2 == resp
def test_get_url(self): h = flow.ODictCaseless() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") assert r.get_url() == "https://host:22/" assert r.get_url(hostheader=True) == "https://host:22/" r.headers["Host"] = ["foo.com"] assert r.get_url() == "https://host:22/" assert r.get_url(hostheader=True) == "https://foo.com:22/"
def test_simple(self): h = flow.Headers() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) r = flow.Request(c, "host", 22, "https", "GET", "/", h, "content") u = r.get_url() assert r.set_url(u) assert not r.set_url("") assert r.get_url() == u assert r._assemble() r2 = r.copy() assert r == r2
def test_getset_state(self): h = flow.ODictCaseless() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) req = flow.Request(c, "host", 22, "https", "GET", "/", h, "content") resp = flow.Response(req, 200, "msg", h.copy(), "content") state = resp._get_state() assert flow.Response._from_state(req, state) == resp resp2 = flow.Response(req, 220, "foo", h.copy(), "test") assert not resp == resp2 resp._load_state(resp2._get_state()) assert resp == resp2
def test_simple(self): h = flow.ODictCaseless() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) req = flow.Request(c, "host", 22, "https", "GET", "/", h, "content") resp = flow.Response(req, 200, "msg", h.copy(), "content") assert resp._assemble() resp2 = resp.copy() assert resp2 == resp resp.content = None assert resp._assemble() resp.request.client_conn.close = True assert "connection: close" in resp._assemble()
def test_simple(self): h = flow.ODictCaseless() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) req = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") resp = flow.Response(req, (1, 1), 200, "msg", h.copy(), "content", None) assert resp._assemble() assert resp.size() == len(resp._assemble()) resp2 = resp.copy() assert resp2 == resp resp.content = None assert resp._assemble() assert resp.size() == len(resp._assemble()) resp.content = flow.CONTENT_MISSING assert not resp._assemble()
def test_path_components(self): h = flow.ODictCaseless() c = flow.ClientConnect(("addr", 2222)) r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") assert r.get_path_components() == [] r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/foo/bar", h, "content") assert r.get_path_components() == ["foo", "bar"] q = flow.ODict() q["test"] = ["123"] r.set_query(q) assert r.get_path_components() == ["foo", "bar"] r.set_path_components([]) assert r.get_path_components() == [] r.set_path_components(["foo"]) assert r.get_path_components() == ["foo"] r.set_path_components(["/oo"]) assert r.get_path_components() == ["/oo"] assert "%2F" in r.path
def test_getset_state(self): h = flow.ODictCaseless() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) r = flow.Request(c, "host", 22, "https", "GET", "/", h, "content") state = r._get_state() assert flow.Request._from_state(state) == r r.client_conn = None state = r._get_state() assert flow.Request._from_state(state) == r r2 = flow.Request(c, "testing", 20, "http", "PUT", "/foo", h, "test") assert not r == r2 r._load_state(r2._get_state()) assert r == r2 r2.client_conn = None r._load_state(r2._get_state()) assert not r.client_conn
def test_get_cookies_none(self): h = flow.ODictCaseless() c = flow.ClientConnect(("addr", 2222)) r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") assert r.get_cookies() == None
def req(self): conn = flow.ClientConnect(("one", 2222)) headers = flow.Headers() headers["header"] = ["qvalue"] return flow.Request(conn, "host", 80, "http", "GET", "/path", headers, "content_request")