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()
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()
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()
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)
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)
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
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__
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__
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'
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'
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
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)
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]
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)
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."
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__
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