From 54e2daa21e2c56c7c1469ce4239f9a4ff7815bc4 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sat, 5 May 2018 13:56:41 +0200 Subject: fix #3024 --- test/mitmproxy/addons/test_allowremote.py | 48 ++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/addons/test_allowremote.py b/test/mitmproxy/addons/test_allowremote.py index 0bdc5495..c8e3eb9e 100644 --- a/test/mitmproxy/addons/test_allowremote.py +++ b/test/mitmproxy/addons/test_allowremote.py @@ -5,27 +5,49 @@ from mitmproxy.addons import allowremote, proxyauth from mitmproxy.test import taddons -@pytest.mark.parametrize("allow_remote, ip, should_be_killed", [ - (True, "192.168.1.3", False), - (True, "122.176.243.101", False), - (False, "192.168.1.3", False), - (False, "122.176.243.101", True), - (True, "::ffff:1:2", False), - (True, "fe80::", False), - (True, "2001:4860:4860::8888", False), - (False, "::ffff:1:2", False), - (False, "fe80::", False), - (False, "2001:4860:4860::8888", True), +@pytest.mark.parametrize("allow_remote, should_be_killed, address", [ + (True, False, ("10.0.0.1",)), + (True, False, ("172.20.0.1",)), + (True, False, ("192.168.1.1",)), + (True, False, ("1.1.1.1",)), + (True, False, ("8.8.8.8",)), + (True, False, ("216.58.207.174",)), + (True, False, ("::ffff:1.1.1.1",)), + (True, False, ("::ffff:8.8.8.8",)), + (True, False, ("::ffff:216.58.207.174",)), + (True, False, ("::ffff:10.0.0.1",)), + (True, False, ("::ffff:172.20.0.1",)), + (True, False, ("::ffff:192.168.1.1",)), + (True, False, ("fe80::",)), + (True, False, ("2001:4860:4860::8888",)), + (False, False, ("10.0.0.1",)), + (False, False, ("172.20.0.1",)), + (False, False, ("192.168.1.1",)), + (False, True, ("1.1.1.1",)), + (False, True, ("8.8.8.8",)), + (False, True, ("216.58.207.174",)), + (False, True, ("::ffff:1.1.1.1",)), + (False, True, ("::ffff:8.8.8.8",)), + (False, True, ("::ffff:216.58.207.174",)), + (False, False, ("::ffff:10.0.0.1",)), + (False, False, ("::ffff:172.20.0.1",)), + (False, False, ("::ffff:192.168.1.1",)), + (False, False, ("fe80::",)), + (False, True, ("2001:4860:4860::8888",)), ]) @pytest.mark.asyncio -async def test_allowremote(allow_remote, ip, should_be_killed): +async def test_allowremote(allow_remote, should_be_killed, address): + if allow_remote: + # prevent faulty tests + assert not should_be_killed + ar = allowremote.AllowRemote() up = proxyauth.ProxyAuth() with taddons.context(ar, up) as tctx: tctx.options.allow_remote = allow_remote with mock.patch('mitmproxy.proxy.protocol.base.Layer') as layer: - layer.client_conn.address = (ip, 12345) + layer.client_conn.address = address ar.clientconnect(layer) if should_be_killed: -- cgit v1.2.3