def test_http2(self): c = pathoc.Pathoc( ("127.0.0.1", self.d.port), fp=None, ssl=True, use_http2=True, ) assert isinstance(c.protocol, http2.HTTP2Protocol) c = pathoc.Pathoc(("127.0.0.1", self.d.port), ) assert c.protocol == http1
def tval(self, requests, showreq=False, showresp=False, explain=False, showssl=False, hexdump=False, timeout=None, ignorecodes=(), ignoretimeout=None, showsummary=True): s = cStringIO.StringIO() c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl=self.ssl, showreq=showreq, showresp=showresp, explain=explain, hexdump=hexdump, ignorecodes=ignorecodes, ignoretimeout=ignoretimeout, showsummary=showsummary, fp=s) c.connect(showssl=showssl, fp=s) if timeout: c.settimeout(timeout) for i in requests: r = language.parse_requests(i)[0] if explain: r = r.freeze(language.Settings()) try: c.request(r) except (http.HttpError, tcp.NetLibError), v: pass
def test_http2_without_ssl(self): fp = cStringIO.StringIO() c = pathoc.Pathoc(("127.0.0.1", self.d.port), use_http2=True, ssl=False, fp=fp) tutils.raises(NotImplementedError, c.connect)
def tval(self, requests, showreq=False, showresp=False, explain=False, showssl=False, hexdump=False, timeout=None, ignorecodes=None, ignoretimeout=None): c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl=self.ssl) c.connect() if timeout: c.settimeout(timeout) s = cStringIO.StringIO() for i in requests: c.print_request(i, showreq=showreq, showresp=showresp, explain=explain, showssl=showssl, hexdump=hexdump, ignorecodes=ignorecodes, ignoretimeout=ignoretimeout, fp=s) return s.getvalue()
def test_wait_finish(self): c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None, ws_read_limit=1) c.connect() c.request("ws:/") c.request("wf:f'wf:x100'") [i for i in c.wait(timeout=0, finish=False)] [i for i in c.wait(timeout=0)]
def pathoc( self, specs, timeout=None, connect_to=None, ssl=None, ws_read_limit=None, use_http2=False, ): """ Returns a (messages, text log) tuple. """ if ssl is None: ssl = self.ssl logfp = cStringIO.StringIO() c = pathoc.Pathoc( ("localhost", self.d.port), ssl=ssl, ws_read_limit=ws_read_limit, timeout=timeout, fp=logfp, use_http2=use_http2, ) c.connect(connect_to) ret = [] for i in specs: resp = c.request(i) if resp: ret.append(resp) for frm in c.wait(): ret.append(frm) c.stop() return ret, logfp.getvalue()
def tval(self, requests, showreq=False, showresp=False, explain=False, showssl=False, hexdump=False, timeout=None, ignorecodes=(), ignoretimeout=None, showsummary=True): s = cStringIO.StringIO() c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl=self.ssl, showreq=showreq, showresp=showresp, explain=explain, hexdump=hexdump, ignorecodes=ignorecodes, ignoretimeout=ignoretimeout, showsummary=showsummary, fp=s) c.connect(showssl=showssl, fp=s) if timeout: c.settimeout(timeout) for i in requests: r = language.parse_pathoc(i).next() if explain: r = r.freeze(language.Settings()) try: c.request(r) except NetlibException: pass return s.getvalue()
def pathoc(self, spec, timeout=None, connect_to=None, ssl=None): if ssl is None: ssl = self.ssl c = pathoc.Pathoc(("localhost", self.d.port), ssl=ssl) c.connect(connect_to) if timeout: c.settimeout(timeout) return c.request(spec)
def pathoc(self, spec, timeout=None): c = pathoc.Pathoc("localhost", self.d.port) c.connect() if self.ssl: c.convert_to_ssl() if timeout: c.settimeout(timeout) return c.request(spec)
def test_sni(self): c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl=True, sni="foobar.com") c.connect() c.request("get:/p/200") r = c.request("get:/api/log") d = json.loads(r.content) assert d["log"][0]["request"]["sni"] == "foobar.com"
def pathoc(self, ssl, sni=None): """ Returns a connected Pathoc instance. """ p = pathoc.Pathoc( ("localhost", self.proxy.port), ssl=True, sni=sni, fp=None ) p.connect() return p
def test_connect_fail(self): to = ("foobar", 80) c = pathoc.Pathoc(("127.0.0.1", self.d.port)) c.rfile, c.wfile = cStringIO.StringIO(), cStringIO.StringIO() tutils.raises("connect failed", c.http_connect, to) c.rfile = cStringIO.StringIO("HTTP/1.1 500 OK\r\n") tutils.raises("connect failed", c.http_connect, to) c.rfile = cStringIO.StringIO("HTTP/1.1 200 OK\r\n") c.http_connect(to)
def test_request(self): c = pathoc.Pathoc( ("127.0.0.1", self.d.port), fp=None, ssl=True, use_http2=True, ) c.connect() resp = c.request("get:/p/200") assert resp.status_code == 200
def test_clientcert(self): c = pathoc.Pathoc( ("127.0.0.1", self.d.port), ssl=True, clientcert=tutils.test_data.path("data/clientcert/client.pem")) c.connect() c.request("get:/p/200") r = c.request("get:/api/log") d = json.loads(r.content) assert d["log"][0]["request"]["clientcert"]["keyinfo"]
def test_http2_alpn(self): c = pathoc.Pathoc( ("127.0.0.1", self.d.port), fp=None, ssl=True, use_http2=True, http2_skip_connection_preface=True, ) tmp_convert_to_ssl = c.convert_to_ssl c.convert_to_ssl = Mock() c.convert_to_ssl.side_effect = tmp_convert_to_ssl c.connect() _, kwargs = c.convert_to_ssl.call_args assert set(kwargs['alpn_protos']) == set([b'http/1.1', b'h2'])
def test_socks_connect(self): to = ("foobar", 80) c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None) c.rfile, c.wfile = tutils.treader(""), cStringIO.StringIO() tutils.raises(pathoc.PathocError, c.socks_connect, to) c.rfile = tutils.treader("\x05\xEE") tutils.raises("SOCKS without authentication", c.socks_connect, ("example.com", 0xDEAD)) c.rfile = tutils.treader("\x05\x00" + "\x05\xEE\x00\x03\x0bexample.com\xDE\xAD") tutils.raises("SOCKS server error", c.socks_connect, ("example.com", 0xDEAD)) c.rfile = tutils.treader("\x05\x00" + "\x05\x00\x00\x03\x0bexample.com\xDE\xAD") c.socks_connect(("example.com", 0xDEAD))
def test_info(self): c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl=self.ssl, fp=None) c.connect() resp = c.request("get:/api/info") assert tuple(json.loads(resp.content)["version"]) == version.IVERSION
def test_sslerr(self): p = pathoc.Pathoc("localhost", self.proxy.port) p.connect() assert p.request("get:/").status_code == 400
#!/usr/bin/env python from libpathod import pathoc p = pathoc.Pathoc(("google.com", 80)) p.connect() print p.request("get:/") print p.request("get:/foo")
def test_info(self): c = pathoc.Pathoc("127.0.0.1", self.d.port) c.connect() _, _, _, _, content = c.request("get:/api/info") assert tuple(json.loads(content)["version"]) == version.IVERSION
def test_websocket_shutdown(self): c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None) c.connect() c.request("ws:/") c.stop()
def test_sslerr(self): p = pathoc.Pathoc(("localhost", self.proxy.port), fp=None) p.connect() r = p.request("get:/") assert r.status_code == 502
def test_ssl_error(self): c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl=True, fp=None) tutils.raises("ssl handshake", c.connect)