diff options
author | Ujjwal Verma <ujjwalverma1111@gmail.com> | 2017-07-14 20:08:01 +0530 |
---|---|---|
committer | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2017-07-15 10:01:14 +0200 |
commit | fdc64be04a00e04f7acd934e3decc3996c29c7f1 (patch) | |
tree | d7112b1377dafc4115af3e57ba6c605d212f4910 /test | |
parent | be9c5084c52c8d4e3fe09aa174864c30c530e8f7 (diff) | |
download | mitmproxy-fdc64be04a00e04f7acd934e3decc3996c29c7f1.tar.gz mitmproxy-fdc64be04a00e04f7acd934e3decc3996c29c7f1.tar.bz2 mitmproxy-fdc64be04a00e04f7acd934e3decc3996c29c7f1.zip |
Allow remote addon
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_allowremote.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/mitmproxy/addons/test_allowremote.py b/test/mitmproxy/addons/test_allowremote.py new file mode 100644 index 00000000..4e1752e3 --- /dev/null +++ b/test/mitmproxy/addons/test_allowremote.py @@ -0,0 +1,41 @@ +from unittest import mock +import pytest + +from mitmproxy.addons import allowremote +from mitmproxy.test import taddons + + +class TestAllowRemote: + @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), + + ]) + def test_allowremote(self, allow_remote, ip, should_be_killed): + ar = allowremote.AllowRemote() + with taddons.context() as tctx: + tctx.master.addons.register(ar) + tctx.options.allow_remote = allow_remote + + with mock.patch('mitmproxy.proxy.protocol.base.Layer') as layer: + layer.client_conn.address = (ip,) + ar.clientconnect(layer) + if should_be_killed: + assert tctx.master.has_log("Client connection was killed", "warn") + else: + assert tctx.master.logs == [] + + tctx.master.clear() + tctx.options.proxyauth = "any" + ar.clientconnect(layer) + assert tctx.master.logs == [] |