Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_browser_xpath(target, html_text_conf):
html_text_conf['transform'].insert(0, {
'xpath': './/*[@class="footer"]',
})
ok, content = Checker(html_text_conf).check()
assert ok is True
assert content == 'Footer content'
def test_python_script_sample(python_script_conf):
ok, content = Checker(python_script_conf).check()
assert ok is True
assert content == "python"
def test_browser_css(target, html_text_conf):
html_text_conf['transform'].insert(0, {
'css': '.footer',
})
ok, content = Checker(html_text_conf).check()
assert ok is True
assert content == 'Footer content'
def test_valid_http_404(target, not_found_conf):
not_found_conf.update({
'valid_http': [404],
})
ok, content = Checker(not_found_conf).check()
assert ok is True
assert '404' in content
def test_tag_transformer(target, html_text_conf):
html_text_conf['transform'].insert(0, {
'tag': 'div',
})
ok, content = Checker(html_text_conf).check()
assert ok is True
assert content == 'Hello world!'
def test_fill_form_sample(target):
conf = {
'name': 'Test page',
'url': "http://{0}:{1}/form.html".format(*target),
'form': [
{'id': 'name', 'value': '{{ "name" | sort | join("") }}'},
{'css': '#pass', 'creds': 'pass'}
],
# 'scenario': 'import pdb; pdb.set_trace()',
'transform': [{'css': '.unclosed-tag > #params'}, 'text'],
# 'headless': False,
}
ok, content = Checker(conf).check()
assert ok is True
assert content == "\n".join([
"name = aemn",
"pass = password",
])
def test_simple_fetcher_with_pretty_json(target, json_conf):
ok, content = Checker(json_conf).check()
assert ok is True
assert content == (
'{\n'
' "first name": "Peter",\n'
selected_checks = [
conf
for conf in checks
if conf['name'] in names
]
selected_names = [conf['name'] for conf in selected_checks]
if len(selected_checks) < len(checks):
logger.info("Filtered list of checks to: %r",
", ".join(sorted(selected_names)))
checks = selected_checks
if len(selected_names) < len(names):
logger.error(
"Following check(s) were not found: %r",
", ".join(sorted(set(names).difference(selected_names)))
)
return [Checker(conf)
for conf in checks]
def execute_conf(conf):
logging.basicConfig(level=logging.WARNING)
logging.getLogger('').handlers[0].level = logging.WARNING
checks = SettingsParser().parse_checks(conf)
for check in checks:
Checker(check).check()
# Reset global state for testability:
self.signals.update({
'reload_conf_pending': False,
'interrupted': False,
'open_backdoor': False,
})
self.setup_logger(log_level)
self.connect_signals()
try:
while True:
if self.signals['interrupted']:
return 1
if self.signals['reload_conf_pending']:
settings().reread()
self.signals['reload_conf_pending'] = False
checkers = Checker.create_from_settings(
checks=settings().checks,
names=names
)
if checkers:
self.before_start(checkers)
self.execute_all(checkers)
if once:
return 0
else:
self.check_forever(checkers)
else:
logger.warning("No checks defined. Exiting")
return 1
finally:
cleanup_fetchers()
return 0