def test_browser_error(self, config): """ Browser.scan() exception test """ br = browser.__new__(browser) with self.assertRaises(BrowserError) as context: reader = Reader( browser_config={ 'list': config.scan, 'torlist': config.torlist, 'use_random': config.is_random_list, 'is_external_wordlist': config.is_external_wordlist, 'is_standalone_proxy': config.is_standalone_proxy, 'is_external_torlist': config.is_external_torlist, 'prefix': config.prefix }) result = {} result['total'] = helper.counter() result['items'] = helper.list() setattr(reader, '_Reader__config', self.__configuration) setattr(br, '_Browser__debug', Debug(config)) setattr(br, '_Browser__pool', self.__pool) setattr(br, '_Browser__config', config) setattr(br, '_Browser__reader', reader) setattr(br, '_Browser__response', Response(config=config, debug=Debug(config), tpl=Tpl)) setattr(br, '_Browser__result', result) br.scan() self.assertTrue(BrowserError == context.expected)
def test_http_scan(self, config): """ Browser.scan() http test """ br = browser.__new__(browser) reader = Reader( browser_config={ 'list': config.scan, 'torlist': config.torlist, 'use_random': config.is_random_list, 'is_external_wordlist': config.is_external_wordlist, 'is_standalone_proxy': config.is_standalone_proxy, 'is_external_torlist': config.is_external_torlist, 'prefix': config.prefix }) result = {} result['total'] = helper.counter() result['items'] = helper.list() setattr(reader, '_Reader__config', self.__configuration) setattr(br, '_Browser__debug', Debug(config)) setattr(br, '_Browser__pool', self.__pool) setattr(br, '_Browser__config', config) setattr(br, '_Browser__reader', reader) setattr(br, '_Browser__response', Response(config=config, debug=Debug(config), tpl=Tpl)) setattr(br, '_Browser__result', result) self.assertIs(br.scan(), None)
def setUp(self): with patch('sys.stdout', new=StringIO()): self.debug = Debug(self.CONFIG)
class TestBrowserDebug(unittest.TestCase): """TestBrowserDebug class""" CONFIG = Config({ 'debug' : 1, 'method' : 'HEAD', 'indexof' : None, 'random_agent': False, 'random_list' : True, 'threads' : 1 }) def setUp(self): with patch('sys.stdout', new=StringIO()): self.debug = Debug(self.CONFIG) def tearDown(self): StringIO().flush() logger = Logger.log() for handler in logger.handlers: logger.removeHandler(handler) del self.debug def test_level(self): """ Debug.level test """ self.assertIs(type(self.debug.level), int) self.assertTrue(0 < self.debug.level) @data('success', 'file', 'indexof', 'bad','forbidden', 'redirect', 'certificat', 'auth') def test_debug_request_uri(self, status): """ Debug.debug_request_uri() test """ setattr(self.debug, '_Reader__cfg.DEFAULT_SCAN', 'directories') if 'forbidden' in status: setattr(self.debug, '_Reader__cfg.scan', 'directories') else: setattr(self.debug, '_Reader__cfg.scan', 'subdomains') with patch('sys.stdout', new=StringIO()): self.assertTrue(self.debug.debug_request_uri(status,'http://test.local/data/')) def test_debug_request(self): """ Debug.debug_request() test """ self.assertTrue(self.debug.debug_request({},'http://test.local/data/', 'HEAD')) def test_debug_response(self): """ Debug.debug_response() test """ self.assertTrue(self.debug.debug_response(response_header={})) def test_debug_list(self): """ Debug.debug_list() test """ self.assertTrue(self.debug.debug_list(1)) def test_debug_connection_pool(self): """ Debug.debug_connection_pool() test """ self.assertTrue(self.debug.debug_connection_pool('http_pool_start', '')) def test_debug_proxy_pool(self): """ Debug.debug_proxy_pool() test """ self.assertTrue(self.debug.debug_proxy_pool()) def test_debug_user_agents(self): """ Debug.debug_user_agents() test """ self.assertTrue(self.debug.debug_user_agents())