def test_includes_strict_rules(): rules = HttpRules("include strict") assert len(rules) == 2 assert len(rules.remove) == 1 assert len(rules.replace) == 1 rules = HttpRules("include strict\n") assert len(rules) == 2 rules = HttpRules("include strict\nsample 50") assert len(rules) == 3 assert len(rules.sample) == 1 rules = HttpRules("include strict\ninclude strict\n") assert len(rules) == 4 rules = HttpRules("include strict\nsample 50\ninclude strict\n") assert len(rules) == 5 assert HttpRules.default_rules() == HttpRules.strict_rules() try: HttpRules.set_default_rules("include strict") rules = HttpRules("") assert len(rules) == 2 assert len(rules.remove) == 1 assert len(rules.replace) == 1 finally: HttpRules.set_default_rules(HttpRules.strict_rules())
def test_includes_standard_rules(): rules = HttpRules("include standard") assert len(rules) == 3 assert len(rules.remove) == 1 assert len(rules.replace) == 2 rules = HttpRules("include standard\n") assert len(rules) == 3 rules = HttpRules("include standard\nsample 50") assert len(rules) == 4 assert len(rules.sample) == 1 rules = HttpRules("include standard\ninclude standard\n") assert len(rules) == 6 rules = HttpRules("include standard\nsample 50\ninclude standard\n") assert len(rules) == 7 assert HttpRules.default_rules() == HttpRules.strict_rules() try: HttpRules.set_default_rules("include standard") rules = HttpRules("") assert len(rules) == 3 assert len(rules.remove) == 1 assert len(rules.replace) == 2 finally: HttpRules.set_default_rules(HttpRules.strict_rules())
def test_includes_debug_rules(): rules = HttpRules("include debug") assert len(rules) == 2 assert rules.allow_http_url is True assert len(rules.copy_session_field) == 1 rules = HttpRules("include debug\n") assert len(rules) == 2 rules = HttpRules("include debug\nsample 50") assert len(rules) == 3 assert len(rules.sample) == 1 rules = HttpRules("include debug\ninclude debug\n") assert len(rules) == 4 rules = HttpRules("include debug\nsample 50\ninclude debug\n") assert len(rules) == 5 assert HttpRules.default_rules() == HttpRules.strict_rules() try: HttpRules.set_default_rules("include debug") rules = HttpRules("") assert len(rules) == 2 assert rules.allow_http_url is True assert len(rules.copy_session_field) == 1 finally: HttpRules.set_default_rules(HttpRules.strict_rules())
def test_overrides_default_rules(): assert HttpRules.default_rules() == HttpRules.strict_rules() try: logger = HttpLogger(url="https://mysite.com") assert logger.rules.text == HttpRules.strict_rules() logger = HttpLogger(url="https://mysite.com", rules="# 123") assert logger.rules.text == "# 123" HttpRules.set_default_rules("") logger = HttpLogger(url="https://mysite.com") assert logger.rules.text == "" logger = HttpLogger(url="https://mysite.com", rules=" ") assert logger.rules.text == "" logger = HttpLogger(url="https://mysite.com", rules=" sample 42") assert logger.rules.text == " sample 42" HttpRules.set_default_rules("skip_compression") logger = HttpLogger(url="https://mysite.com") assert logger.rules.text == "skip_compression" logger = HttpLogger(url="https://mysite.com", rules="include default\nskip_submission\n") assert logger.rules.text == "skip_compression\nskip_submission\n" HttpRules.set_default_rules("sample 42\n") logger = HttpLogger(url="https://mysite.com") assert logger.rules.text == "sample 42\n" logger = HttpLogger(url="https://mysite.com", rules=" ") assert logger.rules.text == "sample 42\n" logger = HttpLogger(url="https://mysite.com", rules="include default\nskip_submission\n") assert logger.rules.text == "sample 42\n\nskip_submission\n" HttpRules.set_default_rules("include debug") logger = HttpLogger(url="https://mysite.com", rules=HttpRules.strict_rules()) assert logger.rules.text == HttpRules.strict_rules() finally: HttpRules.set_default_rules(HttpRules.strict_rules())
def test_changes_default_rules(): assert HttpRules.default_rules() == HttpRules.strict_rules() try: HttpRules.set_default_rules("") assert HttpRules.default_rules() == "" assert len(HttpRules(HttpRules.default_rules())) == 0 HttpRules.set_default_rules(" include default") assert HttpRules.default_rules() == "" HttpRules.set_default_rules("include default\n") assert HttpRules.default_rules() == "" HttpRules.set_default_rules(" include default\ninclude default\n") assert len(HttpRules(HttpRules.default_rules())) == 0 HttpRules.set_default_rules( " include default\ninclude default\nsample 42") rules = HttpRules(HttpRules.default_rules()) assert len(rules) == 1 assert len(rules.sample) == 1 finally: HttpRules.set_default_rules(HttpRules.strict_rules())
def test_changes_default_rules(): assert HttpRules.default_rules() == HttpRules.strict_rules() try: HttpRules.set_default_rules('') assert HttpRules.default_rules() == '' assert len(HttpRules(HttpRules.default_rules())) == 0 HttpRules.set_default_rules(' include default') assert HttpRules.default_rules() == '' HttpRules.set_default_rules('include default\n') assert HttpRules.default_rules() == '' HttpRules.set_default_rules(' include default\ninclude default\n') assert len(HttpRules(HttpRules.default_rules())) == 0 HttpRules.set_default_rules( ' include default\ninclude default\nsample 42') rules = HttpRules(HttpRules.default_rules()) assert len(rules) == 1 assert len(rules.sample) == 1 finally: HttpRules.set_default_rules(HttpRules.strict_rules())