From 298ef21501d4cc23ab00704847c6de3173b6fcbc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 5 Dec 2023 02:38:15 +0100 Subject: [PATCH] Continued: - more checks against blacklist --- fba/helpers/blocklists.py | 4 ++++ fba/helpers/cookies.py | 15 ++++++++++++++- fba/models/blocks.py | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/fba/helpers/blocklists.py b/fba/helpers/blocklists.py index 03af850..0538cff 100644 --- a/fba/helpers/blocklists.py +++ b/fba/helpers/blocklists.py @@ -16,6 +16,7 @@ import logging +from fba.helpers import blacklist from fba.helpers import domain as domain_helper logging.basicConfig(level=logging.INFO) @@ -104,6 +105,9 @@ def has(domain: str) -> bool: logger.debug("domain='%s' - CALLED!") domain_helper.raise_on(domain) + if blacklist.is_blacklisted(domain): + raise ValueError(f"domain='{domain}' is blacklisted but function was invoked") + # Default is not found found = False for row in oliphant_blocklists + csv_files: diff --git a/fba/helpers/cookies.py b/fba/helpers/cookies.py index d98df82..15f4fc7 100644 --- a/fba/helpers/cookies.py +++ b/fba/helpers/cookies.py @@ -16,6 +16,7 @@ import logging +from fba.helpers import blacklist from fba.helpers import domain as domain_helper logging.basicConfig(level=logging.INFO) @@ -27,7 +28,10 @@ _cookies = {} def store(domain: str, cookies: dict): logger.debug("domain='%s',cookies()=%d - CALLED!", domain, len(cookies)) domain_helper.raise_on(domain) - if not isinstance(cookies, dict): + + if blacklist.is_blacklisted(domain): + raise ValueError(f"domain='{domain}' is blacklisted but function was invoked") + elif not isinstance(cookies, dict): raise ValueError(f"Parameter cookies[]='{type(cookies)}' is not of type 'dict'") _cookies[domain] = cookies @@ -38,6 +42,9 @@ def get_all(domain: str) -> dict: logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) + if blacklist.is_blacklisted(domain): + raise ValueError(f"domain='{domain}' is blacklisted but function was invoked") + if domain not in _cookies: return dict() @@ -48,6 +55,9 @@ def has(domain: str) -> bool: logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) + if blacklist.is_blacklisted(domain): + raise ValueError(f"domain='{domain}' is blacklisted but function was invoked") + has_cookies = domain in _cookies logger.debug("has_cookies='%s' - EXIT!", has_cookies) @@ -57,6 +67,9 @@ def clear(domain: str): logger.debug("domain='%s' - CALLED!", domain) domain_helper.raise_on(domain) + if blacklist.is_blacklisted(domain): + raise ValueError(f"domain='{domain}' is blacklisted but function was invoked") + if has(domain): logger.debug("Removing cookies for domain='%s' ...", domain) del _cookies[domain] diff --git a/fba/models/blocks.py b/fba/models/blocks.py index 70e6eb3..904286d 100644 --- a/fba/models/blocks.py +++ b/fba/models/blocks.py @@ -40,6 +40,10 @@ def update_reason(reason: str, blocker: str, blocked: str, block_level: str): raise ValueError("Parameter 'block_level' is empty") elif block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]: raise ValueError(f"block_level='{block_level}' is not wanted.") + elif blacklist.is_blacklisted(blocker): + raise Exception(f"blocker='{blocker}' is blacklisted but function invoked") + elif blacklist.is_blacklisted(blocked): + raise Exception(f"blocked='{blocked}' is blacklisted but function invoked") elif not is_instance_blocked(blocker, blocked, block_level): raise Exception(f"blocker='{blocker}',blocked='{blocked}',block_level='{block_level}' is not registered but function is invoked") -- 2.39.5