mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-31 23:38:46 +00:00
Fix test fails in test_xss_scanner when running tox without internet connections.
- Add mock implementation for gethostbyname in test_xss_scanner. - Fix failed tests when running tox without internet connection. - Fixes #2867
This commit is contained in:
parent
eee109117f
commit
9fed4fa40a
@ -296,6 +296,14 @@ class TestXSSScanner():
|
|||||||
assert xss_info == expected_xss_info
|
assert xss_info == expected_xss_info
|
||||||
assert sqli_info is None
|
assert sqli_info is None
|
||||||
|
|
||||||
|
def mocked_socket_gethostbyname(domain):
|
||||||
|
claimed_domains = ["google.com"]
|
||||||
|
if domain not in claimed_domains:
|
||||||
|
from socket import gaierror
|
||||||
|
raise gaierror("[Errno -2] Name or service not known")
|
||||||
|
else:
|
||||||
|
return '216.58.221.46'
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def logger(self):
|
def logger(self):
|
||||||
class Logger():
|
class Logger():
|
||||||
@ -309,6 +317,7 @@ class TestXSSScanner():
|
|||||||
def test_find_unclaimed_URLs(self, monkeypatch, logger):
|
def test_find_unclaimed_URLs(self, monkeypatch, logger):
|
||||||
logger.args = []
|
logger.args = []
|
||||||
monkeypatch.setattr("mitmproxy.ctx.log", logger)
|
monkeypatch.setattr("mitmproxy.ctx.log", logger)
|
||||||
|
monkeypatch.setattr("socket.gethostbyname", self.mocked_socket_gethostbyname)
|
||||||
xss.find_unclaimed_URLs("<html><script src=\"http://google.com\"></script></html>",
|
xss.find_unclaimed_URLs("<html><script src=\"http://google.com\"></script></html>",
|
||||||
"https://example.com")
|
"https://example.com")
|
||||||
assert logger.args == []
|
assert logger.args == []
|
||||||
|
Loading…
Reference in New Issue
Block a user