示例#1
0
    def test_state(self):
        c = tclient_conn()
        assert Client.from_state(c.get_state()).get_state() == c.get_state()

        c2 = tclient_conn()
        assert c != c2

        c2.timestamp_start = 42
        c.set_state(c2.get_state())
        assert c.timestamp_start == 42

        c3 = c.copy()
        assert c3.get_state() != c.get_state()
        c.id = c3.id = "foo"
        assert c3.get_state() == c.get_state()
示例#2
0
    def test_state(self):
        c = tflow.tclient_conn()
        assert connections.ClientConnection.from_state(c.get_state()).get_state() == \
            c.get_state()

        c2 = tflow.tclient_conn()
        c2.address = (c2.address[0], 4242)
        assert not c == c2

        c2.timestamp_start = 42
        c.set_state(c2.get_state())
        assert c.timestamp_start == 42

        c3 = c.copy()
        assert c3.get_state() == c.get_state()
示例#3
0
    def test_state(self):
        c = tflow.tclient_conn()
        assert connections.ClientConnection.from_state(c.get_state()).get_state() == \
            c.get_state()

        c2 = tflow.tclient_conn()
        c2.address = (c2.address[0], 4242)
        assert not c == c2

        c2.timestamp_start = 42
        c.set_state(c2.get_state())
        assert c.timestamp_start == 42

        c3 = c.copy()
        assert c3.get_state() == c.get_state()
示例#4
0
 def test_eq(self):
     c = tflow.tclient_conn()
     c2 = c.copy()
     assert c == c
     assert c != c2
     assert c != 42
     assert hash(c) != hash(c2)
示例#5
0
    def test_playback(self):
        cp = clientplayback.ClientPlayback()
        with taddons.context() as tctx:
            assert cp.count() == 0
            f = tflow.tflow(resp=True)
            cp.start_replay([f])
            assert cp.count() == 1
            RP = "mitmproxy.proxy.protocol.http_replay.RequestReplayThread"
            with mock.patch(RP) as rp:
                assert not cp.current_thread
                cp.tick()
                assert rp.called
                assert cp.current_thread

            cp.flows = []
            cp.current_thread.is_alive.return_value = False
            assert cp.count() == 1
            cp.tick()
            assert cp.count() == 0
            assert tctx.master.has_event("update")
            assert tctx.master.has_event("processing_complete")

            cp.current_thread = MockThread()
            cp.tick()
            assert cp.current_thread is None

            cp.start_replay([f])
            cp.stop_replay()
            assert not cp.flows

            df = tflow.DummyFlow(tflow.tclient_conn(), tflow.tserver_conn(),
                                 True)
            with pytest.raises(exceptions.CommandError,
                               match="Can't replay live flow."):
                cp.start_replay([df])
 def test_eq(self):
     c = tflow.tclient_conn()
     c2 = c.copy()
     assert c == c
     assert c != c2
     assert c != 42
     assert hash(c) != hash(c2)
示例#7
0
 def test_tls_established_property(self):
     c = tflow.tclient_conn()
     c.tls_established = True
     assert c.tls_established
     assert c.tls_established
     c.tls_established = False
     assert not c.tls_established
     assert not c.tls_established
 def test_tls_established_property(self):
     c = tflow.tclient_conn()
     c.tls_established = True
     assert c.tls_established
     assert c.tls_established
     c.tls_established = False
     assert not c.tls_established
     assert not c.tls_established
示例#9
0
 def test_roundtrip_client(self):
     c = tflow.tclient_conn()
     del c.reply
     c.rfile = None
     c.wfile = None
     pc = protobuf._dump_http_client_conn(c)
     lc = protobuf._load_http_client_conn(pc)
     assert c.__dict__ == lc.__dict__
示例#10
0
 def test_roundtrip_client(self):
     c = tflow.tclient_conn()
     del c.reply
     c.rfile = None
     c.wfile = None
     pc = protobuf._dump_http_client_conn(c)
     lc = protobuf._load_http_client_conn(pc)
     assert c.__dict__ == lc.__dict__
示例#11
0
 def test_send(self):
     c = tflow.tclient_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'
示例#12
0
 def test_send(self):
     c = tflow.tclient_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'
示例#13
0
 def test_socks5(self):
     pa = proxyauth.ProxyAuth()
     with taddons.context(pa, loadcore=False) as ctx:
         ctx.configure(pa, proxyauth="foo:bar", mode="regular")
         data = modes.Socks5AuthData(tflow.tclient_conn(), "foo", "baz")
         pa.socks5_auth(data)
         assert not data.valid
         data.password = "******"
         pa.socks5_auth(data)
         assert data.valid
示例#14
0
    def test_repr(self):
        c = tflow.tclient_conn()
        assert 'address:22' in repr(c)
        assert 'ALPN' in repr(c)
        assert 'TLS' not in repr(c)

        c.alpn_proto_negotiated = None
        c.tls_established = True
        assert 'ALPN' not in repr(c)
        assert 'TLS' in repr(c)
示例#15
0
def test_context():
    with taddons.context() as tctx:
        c = context.Context(tflow.tclient_conn(), tctx.options)
        assert repr(c)
        c.layers.append(1)
        c2 = c.fork()
        c.layers.append(2)
        c2.layers.append(3)
        assert c.layers == [1, 2]
        assert c2.layers == [1, 3]
示例#16
0
    def test_repr(self):
        c = tflow.tclient_conn()
        assert '127.0.0.1:22' in repr(c)
        assert 'ALPN' in repr(c)
        assert 'TLS' not in repr(c)

        c.alpn_proto_negotiated = None
        c.tls_established = True
        assert 'ALPN' not in repr(c)
        assert 'TLS' in repr(c)
示例#17
0
def test_self_connect():
    server = tserver_conn()
    client = tclient_conn()
    server.address = ("localhost", 8080)
    ps = Proxyserver()
    with taddons.context(ps) as tctx:
        # not calling .running() here to avoid unnecessary socket
        ps.options = tctx.options
        ps.server_connect(server_hooks.ServerConnectionHookData(
            server, client))
        assert server.error == "Stopped mitmproxy from recursively connecting to itself."
示例#18
0
 def test_roundtrip_client_cert(self, tdata):
     c = tflow.tclient_conn()
     c.rfile = None
     c.wfile = None
     del c.reply
     with open(tdata.path("mitmproxy/net/data/clientcert/client.pem"), "rb") as f:
         d = f.read()
     c.clientcert = certs.Cert.from_pem(d)
     pc = protobuf._dump_http_client_conn(c)
     lc = protobuf._load_http_client_conn(pc)
     assert c.__dict__ == lc.__dict__
示例#19
0
def test_self_connect():
    server = tserver_conn()
    client = tclient_conn()
    server.address = ("localhost", 8080)
    ps = Proxyserver()
    with taddons.context(ps) as tctx:
        # not calling .running() here to avoid unnecessary socket
        ps.options = tctx.options
        ps.server_connect(
            server_hooks.ServerConnectionHookData(server, client)
        )
        assert "Request destination unknown" in server.error