mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Update test_allowremote.py
This commit is contained in:
parent
fdc64be04a
commit
74708d546b
@ -5,37 +5,34 @@ from mitmproxy.addons import allowremote
|
|||||||
from mitmproxy.test import taddons
|
from mitmproxy.test import taddons
|
||||||
|
|
||||||
|
|
||||||
class TestAllowRemote:
|
@pytest.mark.parametrize("allow_remote, ip, should_be_killed", [
|
||||||
@pytest.mark.parametrize("allow_remote, ip, should_be_killed",
|
|
||||||
[
|
|
||||||
(True, "192.168.1.3", False),
|
(True, "192.168.1.3", False),
|
||||||
(True, "122.176.243.101", False),
|
(True, "122.176.243.101", False),
|
||||||
(False, "192.168.1.3", False),
|
(False, "192.168.1.3", False),
|
||||||
(False, "122.176.243.101", True),
|
(False, "122.176.243.101", True),
|
||||||
|
|
||||||
(True, "::ffff:1:2", False),
|
(True, "::ffff:1:2", False),
|
||||||
(True, "fe80::", False),
|
(True, "fe80::", False),
|
||||||
(True, "2001:4860:4860::8888", False),
|
(True, "2001:4860:4860::8888", False),
|
||||||
(False, "::ffff:1:2", False),
|
(False, "::ffff:1:2", False),
|
||||||
(False, "fe80::", False),
|
(False, "fe80::", False),
|
||||||
(False, "2001:4860:4860::8888", True),
|
(False, "2001:4860:4860::8888", True),
|
||||||
|
|
||||||
])
|
])
|
||||||
def test_allowremote(self, allow_remote, ip, should_be_killed):
|
def test_allowremote(allow_remote, ip, should_be_killed):
|
||||||
ar = allowremote.AllowRemote()
|
ar = allowremote.AllowRemote()
|
||||||
with taddons.context() as tctx:
|
with taddons.context() as tctx:
|
||||||
tctx.master.addons.register(ar)
|
tctx.master.addons.register(ar)
|
||||||
tctx.options.allow_remote = allow_remote
|
tctx.options.allow_remote = allow_remote
|
||||||
|
|
||||||
with mock.patch('mitmproxy.proxy.protocol.base.Layer') as layer:
|
with mock.patch('mitmproxy.proxy.protocol.base.Layer') as layer:
|
||||||
layer.client_conn.address = (ip,)
|
layer.client_conn.address = (ip, 12345)
|
||||||
|
|
||||||
ar.clientconnect(layer)
|
ar.clientconnect(layer)
|
||||||
if should_be_killed:
|
if should_be_killed:
|
||||||
assert tctx.master.has_log("Client connection was killed", "warn")
|
assert tctx.master.has_log("Client connection was killed", "warn")
|
||||||
else:
|
else:
|
||||||
assert tctx.master.logs == []
|
assert tctx.master.logs == []
|
||||||
|
|
||||||
tctx.master.clear()
|
tctx.master.clear()
|
||||||
|
|
||||||
tctx.options.proxyauth = "any"
|
tctx.options.proxyauth = "any"
|
||||||
ar.clientconnect(layer)
|
ar.clientconnect(layer)
|
||||||
assert tctx.master.logs == []
|
assert tctx.master.logs == []
|
||||||
|
Loading…
Reference in New Issue
Block a user