How to use the mitmproxy.test.tflow function in mitmproxy

To help you get started, we’ve selected a few mitmproxy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mitmproxy / mitmproxy / test / mitmproxy / test_connections.py View on Github external
def test_send(self):
        c = tflow.tserver_conn()
        c.send(b'foobar')
        c.send([b'foo', b'bar'])
        with pytest.raises(TypeError):
            c.send('string')
        with pytest.raises(TypeError):
            c.send(['string', 'not'])
        assert c.wfile.getvalue() == b'foobarfoobar'
github mitmproxy / mitmproxy / test / mitmproxy / tools / console / test_common.py View on Github external
def test_format_flow():
    f = tflow.tflow(resp=True)
    assert common.format_flow(f, True)
    assert common.format_flow(f, True, hostheader=True)
    assert common.format_flow(f, True, extended=True)
github mitmproxy / mitmproxy / test / mitmproxy / addons / test_readstdin.py View on Github external
def gen_data(corrupt=False):
    tf = io.BytesIO()
    w = mitmproxy.io.FlowWriter(tf)
    for i in range(3):
        f = tflow.tflow(resp=True)
        w.add(f)
    for i in range(3):
        f = tflow.tflow(err=True)
        w.add(f)
    f = tflow.ttcpflow()
    w.add(f)
    f = tflow.ttcpflow(err=True)
    w.add(f)
    if corrupt:
        tf.write(b"flibble")
    tf.seek(0)
    return tf
github mitmproxy / mitmproxy / test / mitmproxy / test_websocket.py View on Github external
def test_copy(self):
        f = tflow.twebsocketflow()
        f.get_state()
        f2 = f.copy()
        a = f.get_state()
        b = f2.get_state()
        del a["id"]
        del b["id"]
        assert a == b
        assert not f == f2
        assert f is not f2

        assert f.client_key == f2.client_key
        assert f.client_protocol == f2.client_protocol
        assert f.client_extensions == f2.client_extensions
        assert f.server_accept == f2.server_accept
        assert f.server_protocol == f2.server_protocol
        assert f.server_extensions == f2.server_extensions
github mitmproxy / mitmproxy / test / mitmproxy / test_flowfilter.py View on Github external
def test_or(self):
        f = self.flow()
        f.server_conn = tflow.tserver_conn()
        assert self.q("~b hello | ~b me", f)
        assert self.q("~src :22 | ~b me", f)
        assert not self.q("~src :99 | ~dst :99", f)
        assert self.q("(~src :22 | ~dst :22) | ~b me", f)
github mitmproxy / mitmproxy / test / mitmproxy / test_types.py View on Github external
def test_flows():
    with taddons.context() as tctx:
        tctx.master.addons.add(DummyConsole())
        b = mitmproxy.types._FlowsType()
        assert len(
            b.completion(tctx.master.commands, typing.Sequence[flow.Flow], "")
        ) == len(b.valid_prefixes)
        assert b.is_valid(tctx.master.commands, typing.Sequence[flow.Flow], [tflow.tflow()]) is True
        assert b.is_valid(tctx.master.commands, typing.Sequence[flow.Flow], "xx") is False
        assert b.is_valid(tctx.master.commands, typing.Sequence[flow.Flow], 0) is False
        assert len(b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "0")) == 0
        assert len(b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "1")) == 1
        assert len(b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "2")) == 2
        with pytest.raises(mitmproxy.exceptions.TypeError):
            b.parse(tctx.master.commands, typing.Sequence[flow.Flow], "err")
github mitmproxy / mitmproxy / test / mitmproxy / addons / test_cut.py View on Github external
def test_extract():
    tf = tflow.tflow(resp=True)
    tests = [
        ["request.method", "GET"],
        ["request.scheme", "http"],
        ["request.host", "address"],
        ["request.http_version", "HTTP/1.1"],
        ["request.port", "22"],
        ["request.path", "/path"],
        ["request.url", "http://address:22/path"],
        ["request.text", "content"],
        ["request.content", b"content"],
        ["request.raw_content", b"content"],
        ["request.timestamp_start", "946681200"],
        ["request.timestamp_end", "946681201"],
        ["request.header[header]", "qvalue"],

        ["response.status_code", "200"],
github mitmproxy / mitmproxy / test / mitmproxy / addons / test_replace.py View on Github external
def test_order(self):
        r = replace.Replace()
        with taddons.context(r) as tctx:
            tctx.configure(
                r,
                replacements=[
                    "/foo/bar",
                    "/bar/baz",
                    "/foo/oh noes!",
                    "/bar/oh noes!",
                ]
            )
            f = tflow.tflow()
            f.request.content = b"foo"
            r.request(f)
            assert f.request.content == b"baz"
github mitmproxy / mitmproxy / test / mitmproxy / addons / test_save.py View on Github external
def test_tcp(tmpdir):
    sa = save.Save()
    with taddons.context(sa) as tctx:
        p = str(tmpdir.join("foo"))
        tctx.configure(sa, save_stream_file=p)

        tt = tflow.ttcpflow()
        sa.tcp_start(tt)
        sa.tcp_end(tt)
        tctx.configure(sa, save_stream_file=None)
        assert rd(p)