def test_generate_negative(): # unknown args key with pytest.raises(UnknownKeyException): config.generate({'key_does_not_exist': "value"}, {}) # unknown ini key with pytest.raises(UnknownKeyException): config.generate({}, {'key_does_not_exist': "value"})
def test_generate_default(): # no args or ini test = config.generate({}, {}) assert test == config.defaults # args None test = config.generate({'agent': None, 'timeout': None}, {}) assert test == config.defaults # ini None test = config.generate({}, {'processes': None, 'threads': None}) assert test == config.defaults # other keys test = config.generate({'config': "config.ini", 'quiet': False, 'debug': True}, {}) assert test == config.defaults
def main(args): """ Gets configurations from command line and AVA configuration file. Optionally, prints available modules and sets logging level. Auditors and checks are comma-separated strings. Cookies, headers, and parameters are lists of key/value delimited strings. Entry point for other scripts. :param args: list of system arguments :return: integer for success or failure """ # get system args reader = ArgumentReader(args) sys_args = reader.parse() # list modules if sys_args['list']: _print_modules() return 0 if sys_args['show_examples']: _print_examples() return 0 try: # check required vectors argument _check_vectors(sys_args['hars']) except MissingComponentException as e: logger.error("%s. Quitting.", e) return 2 # set logging if sys_args['debug'] or sys_args['quiet']: _set_logging(sys_args) try: # parse optional yaml args yaml_args = _parse_yaml( sys_args['config']) if sys_args['config'] else {} except (MissingComponentException, InvalidFormatException, UnknownKeyException) as e: logger.error("%s. Quitting.", e) return 2 try: # generate configs from sys and yaml args configs = config.generate(sys_args, yaml_args) except (InvalidValueException, UnknownKeyException) as e: logger.error("%s. Quitting.", e) return 2 try: # run scanner _run_scanner(configs) except (InvalidFormatException, MissingComponentException) as e: logger.error("%s. Quitting.", e) return 2 # exit return 0
def test_generate_positive(): users = { 'auditors': ["parameter", "cookie"], 'actives': ["xss", "open_redirect"], 'blinds': {'xss': "http://localhost/"}, 'passives': ["pii"], 'set_payloads': {'xss.value.tag': "value"}, 'add_payloads': {'xss.blind.direct': "value"}, 'report': "report.json", 'cookies': {'key': "value"}, 'headers': {'key': "value"}, 'parameters': {'key': "value"}, 'excludes': ["/admin"], 'skips': ["token"], 'ignores': ["*****@*****.**"], 'domain': "example.com", 'agent': "Mozilla/5.0", 'timeout': 5, 'proxy': "127.0.0.1:8080", 'processes': 4, 'threads': 4, 'value': "test", 'follow': True, 'reduce': True, 'url': "127.0.0.1", 'summary': True, 'hars': ["vectors.har"] } converted = { 'auditors': ["parameter", "cookie"], 'actives': ["xss", "open_redirect"], 'blinds': {'xss': "http://localhost/"}, 'passives': ["pii"], 'set_payloads': {'xss.value.tag': "value"}, 'add_payloads': {'xss.blind.direct': "value"}, 'report': "report.json", 'cookies': {'key': "value"}, 'headers': {'key': "value"}, 'parameters': {'key': "value"}, 'excludes': ["/admin"], 'skips': ["token"], 'ignores': ["*****@*****.**"], 'domain': "example.com", 'agent': "Mozilla/5.0", 'timeout': 5, 'proxy': "127.0.0.1:8080", 'processes': 4, 'threads': 4, 'value': "test", 'follow': True, 'reduce': True, 'url': "127.0.0.1", 'summary': True, 'hars': ["vectors.har"] } # split args = {key: value for key, value in users.items() if key in ['auditors', 'actives', 'proxy', 'summary']} yamls = {key: value for key, value in users.items() if key not in args} # args generated = copy(config.defaults) generated.update({key: value for key, value in converted.items() if key in args}) test = config.generate(args, {}) assert test == generated # yaml generated = copy(config.defaults) generated.update({key: value for key, value in converted.items() if key in yamls}) test = config.generate({}, yamls) assert test == generated # args and ini test = config.generate(args, yamls) assert test == converted