diff options
author | Deepesh Pathak <deepshpathak@gmail.com> | 2018-02-24 16:50:40 +0530 |
---|---|---|
committer | Deepesh Pathak <deepshpathak@gmail.com> | 2018-02-24 16:50:40 +0530 |
commit | 9fed4fa40aba7320b228d6f362c68caff8c893bd (patch) | |
tree | 52e655815b71de456ec93e93b71e4f59a90dfc59 /test/examples | |
parent | eee109117f956600261bc938be52040d1474a97f (diff) | |
download | mitmproxy-9fed4fa40aba7320b228d6f362c68caff8c893bd.tar.gz mitmproxy-9fed4fa40aba7320b228d6f362c68caff8c893bd.tar.bz2 mitmproxy-9fed4fa40aba7320b228d6f362c68caff8c893bd.zip |
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
Diffstat (limited to 'test/examples')
-rw-r--r-- | test/examples/test_xss_scanner.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/examples/test_xss_scanner.py b/test/examples/test_xss_scanner.py index 8cf06a2a..610bdd72 100644 --- a/test/examples/test_xss_scanner.py +++ b/test/examples/test_xss_scanner.py @@ -296,6 +296,14 @@ class TestXSSScanner(): assert xss_info == expected_xss_info 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 def logger(self): class Logger(): @@ -309,6 +317,7 @@ class TestXSSScanner(): def test_find_unclaimed_URLs(self, monkeypatch, logger): logger.args = [] 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>", "https://example.com") assert logger.args == [] |