From e46e064df3e00e5807001a785730b49997c94169 Mon Sep 17 00:00:00 2001 From: David Kremer Date: Wed, 15 Aug 2018 18:40:27 +0200 Subject: [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. --- examples/complex/xss_scanner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') 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"aoso[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)) -- cgit v1.2.3