diff options
author | David Kremer <courrier@david-kremer.fr> | 2018-08-15 18:40:27 +0200 |
---|---|---|
committer | David Kremer <courrier@david-kremer.fr> | 2018-08-15 19:47:55 +0200 |
commit | e46e064df3e00e5807001a785730b49997c94169 (patch) | |
tree | f5d3b983c81226b5a09170c260a3df3b68e64879 | |
parent | a945b0cf1111d81e1adc2aa0239dee9389ca5711 (diff) | |
download | mitmproxy-e46e064df3e00e5807001a785730b49997c94169.tar.gz mitmproxy-e46e064df3e00e5807001a785730b49997c94169.tar.bz2 mitmproxy-e46e064df3e00e5807001a785730b49997c94169.zip |
[examples/xss_scanner] replace relative import
test_xss_scanner.py was utterly failing because of a trouble (bug?)
with the `monkeypatch` fixture failing to replace `gethostbyname`
with the correct mock function.
Indeed, when stepping through the code, the `gethostbyname` presumably
mocked was reported as a builtin python function. The problem could
then come from the fact that it is hard to monkeypatch builtin function
in python.
Using absolute imports seems to resolve the problem.
-rwxr-xr-x | examples/complex/xss_scanner.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/complex/xss_scanner.py b/examples/complex/xss_scanner.py index 55fc2fe7..cdaaf478 100755 --- a/examples/complex/xss_scanner.py +++ b/examples/complex/xss_scanner.py @@ -37,9 +37,9 @@ Line: 1029zxcs'd"ao<ac>so[sb]po(pc)se;sl/bsl\eq=3847asd from html.parser import HTMLParser from typing import Dict, Union, Tuple, Optional, List, NamedTuple -from socket import gaierror, gethostbyname from urllib.parse import urlparse import re +import socket import requests @@ -109,8 +109,8 @@ def find_unclaimed_URLs(body: str, requestUrl: bytes) -> None: url_parser = urlparse(url) domain = url_parser.netloc try: - gethostbyname(domain) - except gaierror: + socket.gethostbyname(domain) + except socket.gaierror: ctx.log.error("XSS found in %s due to unclaimed URL \"%s\"." % (requestUrl, url)) |