From 43dd23d7ccef049f98d9735c2348f3409714c12c Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Mon, 20 Nov 2023 01:59:26 +0100
Subject: [PATCH] Continued: - more blacklist checks - some formatting

---
 fba/helpers/cookies.py    | 6 +++---
 fba/helpers/dicts.py      | 1 +
 fba/helpers/processing.py | 8 ++++++++
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/fba/helpers/cookies.py b/fba/helpers/cookies.py
index ff2457a..d98df82 100644
--- a/fba/helpers/cookies.py
+++ b/fba/helpers/cookies.py
@@ -24,7 +24,7 @@ logger = logging.getLogger(__name__)
 # Cookies storage
 _cookies = {}
 
-def store (domain: str, cookies: dict):
+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):
@@ -44,7 +44,7 @@ def get_all(domain: str) -> dict:
     logger.debug("_cookies[%s]()=%d - EXIT!", domain, len(_cookies[domain]))
     return _cookies[domain]
 
-def has (domain: str) -> bool:
+def has(domain: str) -> bool:
     logger.debug("domain='%s' - CALLED!", domain)
     domain_helper.raise_on(domain)
 
@@ -53,7 +53,7 @@ def has (domain: str) -> bool:
     logger.debug("has_cookies='%s' - EXIT!", has_cookies)
     return has_cookies
 
-def clear (domain: str):
+def clear(domain: str):
     logger.debug("domain='%s' - CALLED!", domain)
     domain_helper.raise_on(domain)
 
diff --git a/fba/helpers/dicts.py b/fba/helpers/dicts.py
index 0d6b8be..cd9ccbd 100644
--- a/fba/helpers/dicts.py
+++ b/fba/helpers/dicts.py
@@ -32,6 +32,7 @@ def has_key(lists: list, key: str, value: any) -> bool:
     logger.debug("Checking lists()=%d ...", len(lists))
     for row in lists:
         logger.debug("row[%s]='%s", type(row), row)
+
         if not isinstance(row, dict):
             raise ValueError(f"row[]='{type(row)}' is not of type 'dict'")
         elif not key in row:
diff --git a/fba/helpers/processing.py b/fba/helpers/processing.py
index c79815c..00f6ae0 100644
--- a/fba/helpers/processing.py
+++ b/fba/helpers/processing.py
@@ -45,6 +45,10 @@ def instance(blocked: str, blocker: str, command: str) -> bool:
         raise ValueError(f"Parameter command[]='{type(command)}' is not of type 'str'")
     elif command == "":
         raise ValueError("Parameter 'command' is empty")
+    elif blacklist.is_blacklisted(blocked):
+        raise ValueError(f"blocked='{blocked}' is blacklisted but function was invoked")
+    elif blacklist.is_blacklisted(blocker):
+        raise ValueError(f"blocker='{blocker}' is blacklisted but function was invoked")
 
     logger.debug("blocked='%s' - BEFORE!", blocked)
     blocked = utils.deobfuscate(blocked, blocker)
@@ -89,6 +93,8 @@ def block(blocker: str, blocked: str, reason: str, block_level: str) -> bool:
         raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'")
     elif block_level == "":
         raise ValueError("Parameter block_level is empty")
+    elif blacklist.is_blacklisted(blocker):
+        raise ValueError(f"blocker='{blocker}' is blacklisted but function was invoked")
     elif blacklist.is_blacklisted(blocked):
         raise ValueError(f"blocked='{blocked}' is blacklisted but function was invoked")
 
@@ -116,6 +122,8 @@ def csv_block(blocker: str, url: str, command: str):
         raise ValueError(f"command[]='{command}' is not of type 'str'")
     elif command == "":
         raise ValueError("Parameter 'command' is empty")
+    elif blacklist.is_blacklisted(blocker):
+        raise ValueError(f"blocker='{blocker}' is blacklisted but function was invoked")
 
     logger.debug("Setting last_blocked for blocker='%s' ...", blocker)
     instances.set_last_blocked(blocker)
-- 
2.39.5