コード例 #1
0
        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
コード例 #2
0
 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
コード例 #3
0
 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)
コード例 #4
0
ファイル: test_pathoc.py プロジェクト: spsforks/pathod
 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()
コード例 #5
0
 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)]
コード例 #6
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()
コード例 #7
0
 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()
コード例 #8
0
 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)
コード例 #9
0
ファイル: tutils.py プロジェクト: emidln/pathod
 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)
コード例 #10
0
 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"
コード例 #11
0
ファイル: test_server.py プロジェクト: mackjoner/mitmproxy
 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
コード例 #12
0
 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)
コード例 #13
0
 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
コード例 #14
0
 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"]
コード例 #15
0
        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'])
コード例 #16
0
    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))
コード例 #17
0
 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
コード例 #18
0
ファイル: test_server.py プロジェクト: tusharbabbar/mitmproxy
 def test_sslerr(self):
     p = pathoc.Pathoc("localhost", self.proxy.port)
     p.connect()
     assert p.request("get:/").status_code == 400
コード例 #19
0
#!/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")
コード例 #20
0
ファイル: test_pathoc.py プロジェクト: emidln/pathod
 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
コード例 #21
0
 def test_websocket_shutdown(self):
     c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
     c.connect()
     c.request("ws:/")
     c.stop()
コード例 #22
0
ファイル: test_server.py プロジェクト: mackjoner/mitmproxy
 def test_sslerr(self):
     p = pathoc.Pathoc(("localhost", self.proxy.port), fp=None)
     p.connect()
     r = p.request("get:/")
     assert r.status_code == 502
コード例 #23
0
 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)