当前位置: 首页>>代码示例>>Python>>正文


Python tutils.treq函数代码示例

本文整理汇总了Python中mitmproxy.test.tutils.treq函数的典型用法代码示例。如果您正苦于以下问题:Python treq函数的具体用法?Python treq怎么用?Python treq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了treq函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_assemble_request_line

def test_assemble_request_line():
    assert _assemble_request_line(treq().data) == b"GET /path HTTP/1.1"

    authority_request = treq(method=b"CONNECT", first_line_format="authority").data
    assert _assemble_request_line(authority_request) == b"CONNECT address:22 HTTP/1.1"

    absolute_request = treq(first_line_format="absolute").data
    assert _assemble_request_line(absolute_request) == b"GET http://address:22/path HTTP/1.1"

    with raises(RuntimeError):
        _assemble_request_line(treq(first_line_format="invalid_form").data)
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:11,代码来源:test_assemble.py

示例2: test_intercept

 def test_intercept(self):
     """regression test for https://github.com/mitmproxy/mitmproxy/issues/1605"""
     m = self.mkmaster(intercept="~b bar")
     f = tflow.tflow(req=tutils.treq(content=b"foo"))
     m.addons.handle_lifecycle("request", f)
     assert not m.view[0].intercepted
     f = tflow.tflow(req=tutils.treq(content=b"bar"))
     m.addons.handle_lifecycle("request", f)
     assert m.view[1].intercepted
     f = tflow.tflow(resp=tutils.tresp(content=b"bar"))
     m.addons.handle_lifecycle("request", f)
     assert m.view[2].intercepted
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:12,代码来源:test_master.py

示例3: test_assemble_request

def test_assemble_request():
    assert assemble_request(treq()) == (
        b"GET /path HTTP/1.1\r\n"
        b"header: qvalue\r\n"
        b"content-length: 7\r\n"
        b"host: address:22\r\n"
        b"\r\n"
        b"content"
    )

    with raises(exceptions.HttpException):
        assemble_request(treq(content=None))
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:12,代码来源:test_assemble.py

示例4: test_host

    def test_host(self):
        request = treq()
        assert request.host == request.data.host.decode("idna")

        # Test IDNA encoding
        # Set str, get raw bytes
        request.host = "ídna.example"
        assert request.data.host == b"xn--dna-qma.example"
        # Set raw bytes, get decoded
        request.data.host = b"xn--idn-gla.example"
        assert request.host == "idná.example"
        # Set bytes, get raw bytes
        request.host = b"xn--dn-qia9b.example"
        assert request.data.host == b"xn--dn-qia9b.example"
        # IDNA encoding is not bijective
        request.host = "fußball"
        assert request.host == "fussball"

        # Don't fail on garbage
        request.data.host = b"foo\xFF\x00bar"
        assert request.host.startswith("foo")
        assert request.host.endswith("bar")
        # foo.bar = foo.bar should not cause any side effects.
        d = request.host
        request.host = d
        assert request.data.host == b"foo\xFF\x00bar"
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:26,代码来源:test_request.py

示例5: test_response

 def test_response(self, get_request_invuln, logger):
     mocked_flow = tflow.tflow(
         req=tutils.treq(path=b"index.html?q=1"),
         resp=tutils.tresp(content=b'<html></html>')
     )
     xss.response(mocked_flow)
     assert logger.args == []
开发者ID:mitmproxy,项目名称:mitmproxy,代码行数:7,代码来源:test_xss_scanner.py

示例6: test_anticache

 def test_anticache(self):
     request = treq()
     request.headers["If-Modified-Since"] = "foo"
     request.headers["If-None-Match"] = "bar"
     request.anticache()
     assert "If-Modified-Since" not in request.headers
     assert "If-None-Match" not in request.headers
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:7,代码来源:test_request.py

示例7: cycle

 def cycle(self, master, content):
     f = tflow.tflow(req=tutils.treq(content=content))
     master.addons.handle_lifecycle("clientconnect", f.client_conn)
     for i in eventsequence.iterate(f):
         master.addons.handle_lifecycle(*i)
     master.addons.handle_lifecycle("clientdisconnect", f.client_conn)
     return f
开发者ID:davidpshaw,项目名称:mitmproxy,代码行数:7,代码来源:tservers.py

示例8: tflow

def tflow(client_conn=True, server_conn=True, req=True, resp=None, err=None):
    """
    @type client_conn: bool | None | mitmproxy.proxy.connection.ClientConnection
    @type server_conn: bool | None | mitmproxy.proxy.connection.ServerConnection
    @type req:         bool | None | mitmproxy.proxy.protocol.http.HTTPRequest
    @type resp:        bool | None | mitmproxy.proxy.protocol.http.HTTPResponse
    @type err:         bool | None | mitmproxy.proxy.protocol.primitives.Error
    @return:           mitmproxy.proxy.protocol.http.HTTPFlow
    """
    if client_conn is True:
        client_conn = tclient_conn()
    if server_conn is True:
        server_conn = tserver_conn()
    if req is True:
        req = tutils.treq()
    if resp is True:
        resp = tutils.tresp()
    if err is True:
        err = terr()

    if req:
        req = http.HTTPRequest.wrap(req)
    if resp:
        resp = http.HTTPResponse.wrap(resp)

    f = http.HTTPFlow(client_conn, server_conn)
    f.request = req
    f.response = resp
    f.error = err
    f.reply = controller.DummyReply()
    return f
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:31,代码来源:tflow.py

示例9: test_read_chunked

def test_read_chunked():
    req = treq(content=None)
    req.headers["Transfer-Encoding"] = "chunked"

    data = b"1\r\na\r\n0\r\n"
    with raises(exceptions.HttpSyntaxException):
        b"".join(_read_chunked(BytesIO(data)))

    data = b"1\r\na\r\n0\r\n\r\n"
    assert b"".join(_read_chunked(BytesIO(data))) == b"a"

    data = b"\r\n\r\n1\r\na\r\n1\r\nb\r\n0\r\n\r\n"
    assert b"".join(_read_chunked(BytesIO(data))) == b"ab"

    data = b"\r\n"
    with raises("closed prematurely"):
        b"".join(_read_chunked(BytesIO(data)))

    data = b"1\r\nfoo"
    with raises("malformed chunked body"):
        b"".join(_read_chunked(BytesIO(data)))

    data = b"foo\r\nfoo"
    with raises(exceptions.HttpSyntaxException):
        b"".join(_read_chunked(BytesIO(data)))

    data = b"5\r\naaaaa\r\n0\r\n\r\n"
    with raises("too large"):
        b"".join(_read_chunked(BytesIO(data), limit=2))
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:29,代码来源:test_read.py

示例10: test_get_cookies_withequalsign

 def test_get_cookies_withequalsign(self):
     request = treq()
     request.headers = Headers(cookie="cookiename=coo=kievalue;othercookiename=othercookievalue")
     result = request.cookies
     assert len(result) == 2
     assert result['cookiename'] == 'coo=kievalue'
     assert result['othercookiename'] == 'othercookievalue'
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:7,代码来源:test_request.py

示例11: test_replay

    def test_replay(self):
        opts = options.Options()
        fm = master.Master(opts)
        f = tflow.tflow(resp=True)
        f.request.content = None
        with pytest.raises(ReplayException, match="missing"):
            fm.replay_request(f)

        f.request = None
        with pytest.raises(ReplayException, match="request"):
            fm.replay_request(f)

        f.intercepted = True
        with pytest.raises(ReplayException, match="intercepted"):
            fm.replay_request(f)

        f.live = True
        with pytest.raises(ReplayException, match="live"):
            fm.replay_request(f)

        req = tutils.treq(headers=net_http.Headers(((b":authority", b"foo"), (b"header", b"qvalue"), (b"content-length", b"7"))))
        f = tflow.tflow(req=req)
        f.request.http_version = "HTTP/2.0"
        with mock.patch('mitmproxy.proxy.protocol.http_replay.RequestReplayThread.run'):
            rt = fm.replay_request(f)
            assert rt.f.request.http_version == "HTTP/1.1"
            assert ":authority" not in rt.f.request.headers
开发者ID:mhils,项目名称:mitmproxy,代码行数:27,代码来源:test_flow.py

示例12: test_path

 def test_path(self):
     req = treq()
     _test_decoded_attr(req, "path")
     # path can also be None.
     req.path = None
     assert req.path is None
     assert req.data.path is None
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:7,代码来源:test_request.py

示例13: test_response

 def test_response(self, monkeypatch, logger):
     logger.args = []
     monkeypatch.setattr("mitmproxy.ctx.log", logger)
     monkeypatch.setattr(requests, 'get', self.mocked_requests_invuln)
     mocked_flow = tflow.tflow(req=tutils.treq(path=b"index.html?q=1"), resp=tutils.tresp(content=b'<html></html>'))
     xss.response(mocked_flow)
     assert logger.args == []
开发者ID:cortesi,项目名称:mitmproxy,代码行数:7,代码来源:test_xss_scanner.py

示例14: test_get_urlencoded_form

    def test_get_urlencoded_form(self):
        request = treq(content=b"foobar=baz")
        assert not request.urlencoded_form

        request.headers["Content-Type"] = "application/x-www-form-urlencoded"
        assert list(request.urlencoded_form.items()) == [("foobar", "baz")]
        request.raw_content = b"\xFF"
        assert len(request.urlencoded_form) == 0
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:8,代码来源:test_request.py

示例15: get_request

def get_request():
    return tflow.tflow(
        req=tutils.treq(
            method=b'GET',
            content=b'',
            path=b"/path?a=foo&a=bar&b=baz"
        )
    )
开发者ID:cortesi,项目名称:mitmproxy,代码行数:8,代码来源:test_export.py


注:本文中的mitmproxy.test.tutils.treq函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。