Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

Tests: test_sfp_cleanbrowsing: Add handleEvent tests (#1479)

bcolesa449c2a99cc6
diff --git a/modules/sfp_cleanbrowsing.py b/modules/sfp_cleanbrowsing.py
index fc096e4d..2d2d3def 100644
--- a/modules/sfp_cleanbrowsing.py
+++ b/modules/sfp_cleanbrowsing.py
@@ -2,7 +2,8 @@
# -------------------------------------------------------------------------------
# Name: sfp_cleanbrowsing
# Purpose: SpiderFoot plug-in for looking up whether hosts are blocked by
-# CleanBrowsing.org DNS (185.228.168.168 and 185.228.168.169)
+# CleanBrowsing.org DNS content family filters
+# (185.228.168.168 and 185.228.168.169).
#
# Author: Steve Micallef <[email protected]>
#
@@ -20,7 +21,7 @@ class sfp_cleanbrowsing(SpiderFootPlugin):
meta = {
'name': "CleanBrowsing.org",
- 'summary': "Check if a host would be blocked by CleanBrowsing.org DNS",
+ 'summary': "Check if a host would be blocked by CleanBrowsing.org DNS content filters.",
'flags': [],
'useCases': ["Investigate", "Passive"],
'categories': ["Reputation Systems"],
@@ -29,6 +30,7 @@ class sfp_cleanbrowsing(SpiderFootPlugin):
'model': "FREE_NOAUTH_UNLIMITED",
'references': [
"https://cleanbrowsing.org/guides/",
+ "https://cleanbrowsing.org/filters/",
"https://cleanbrowsing.org/how-it-works",
"https://cleanbrowsing.org/web-filtering-for-shools-and-cipa-compliance",
"https://cleanbrowsing.org/getting-started"
@@ -77,7 +79,12 @@ class sfp_cleanbrowsing(SpiderFootPlugin):
def queryAddr(self, qaddr):
res = dns.resolver.Resolver()
+ # Family Filter
res.nameservers = ["185.228.168.168", "185.228.168.169"]
+ # Adult Filter
+ # res.nameservers = ["185.228.168.10", "185.228.169.11"]
+ # Security Filter
+ # res.nameservers = ["185.228.168.9", "185.228.169.9"]
try:
addrs = res.resolve(qaddr)
@@ -92,11 +99,9 @@ class sfp_cleanbrowsing(SpiderFootPlugin):
def handleEvent(self, event):
eventName = event.eventType
- srcModuleName = event.module
eventData = event.data
- parentEvent = event
- self.debug(f"Received event, {eventName}, from {srcModuleName}")
+ self.debug(f"Received event, {eventName}, from {event.module}")
if eventData in self.results:
return
@@ -104,7 +109,7 @@ class sfp_cleanbrowsing(SpiderFootPlugin):
self.results[eventData] = True
# Check that it resolves first, as it becomes a valid
- # malicious host only if NOT resolved by CleanBrowsing.org.
+ # malicious host only if NOT resolved by CleanBrowsing DNS.
if not self.sf.resolveHost(eventData) and not self.sf.resolveHost6(eventData):
return
@@ -114,6 +119,8 @@ class sfp_cleanbrowsing(SpiderFootPlugin):
if found:
return
+ self.debug(f"{eventData} was blocked by CleanBrowsing DNS")
+
typ = "MALICIOUS_" + eventName
if eventName == "CO_HOSTED_SITE":
@@ -121,9 +128,9 @@ class sfp_cleanbrowsing(SpiderFootPlugin):
evt = SpiderFootEvent(
typ,
- f"Blocked by CleanBrowsing.org [{eventData}]",
+ f"Blocked by CleanBrowsing DNS [{eventData}]",
self.__name__,
- parentEvent
+ event
)
self.notifyListeners(evt)
diff --git a/test/unit/modules/test_sfp_cleanbrowsing.py b/test/unit/modules/test_sfp_cleanbrowsing.py
index 057b8692..cc353c3b 100644
--- a/test/unit/modules/test_sfp_cleanbrowsing.py
+++ b/test/unit/modules/test_sfp_cleanbrowsing.py
@@ -34,10 +34,7 @@ class TestModulecleanbrowsing(unittest.TestCase):
module = sfp_cleanbrowsing()
self.assertIsInstance(module.producedEvents(), list)
- def test_queryAddr_should_resolve_unblocked_host(self):
- """
- Test queryAddr(self, qaddr)
- """
+ def test_handleEvent_event_data_adult_internet_name_blocked_should_return_event(self):
sf = SpiderFoot(self.default_options)
module = sfp_cleanbrowsing()
@@ -48,13 +45,38 @@ class TestModulecleanbrowsing(unittest.TestCase):
target = SpiderFootTarget(target_value, target_type)
module.setTarget(target)
- resolved = module.queryAddr('cleanbrowsing.org')
- self.assertTrue(resolved)
+ def new_notifyListeners(self, event):
+ expected = 'MALICIOUS_INTERNET_NAME'
+ if str(event.eventType) != expected:
+ raise Exception(f"{event.eventType} != {expected}")
- def test_handleEvent(self):
- """
- Test handleEvent(self, event)
- """
+ expected = 'Blocked by CleanBrowsing DNS [pornhub.com]'
+ if str(event.data) != expected:
+ raise Exception(f"{event.data} != {expected}")
+
+ raise Exception("OK")
+
+ module.notifyListeners = new_notifyListeners.__get__(module, sfp_cleanbrowsing)
+
+ event_type = 'ROOT'
+ event_data = 'example data'
+ event_module = ''
+ source_event = ''
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+
+ event_type = 'INTERNET_NAME'
+ event_data = 'pornhub.com'
+ event_module = 'example module'
+ source_event = evt
+
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+
+ with self.assertRaises(Exception) as cm:
+ module.handleEvent(evt)
+
+ self.assertEqual("OK", str(cm.exception))
+
+ def test_handleEvent_event_data_safe_internet_name_not_blocked_should_not_return_event(self):
sf = SpiderFoot(self.default_options)
module = sfp_cleanbrowsing()
@@ -65,12 +87,23 @@ class TestModulecleanbrowsing(unittest.TestCase):
target = SpiderFootTarget(target_value, target_type)
module.setTarget(target)
+ def new_notifyListeners(self, event):
+ raise Exception(f"Raised event {event.eventType}: {event.data}")
+
+ module.notifyListeners = new_notifyListeners.__get__(module, sfp_cleanbrowsing)
+
event_type = 'ROOT'
- event_data = 'cleanbrowsing.org'
+ event_data = 'example data'
event_module = ''
source_event = ''
evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+ event_type = 'INTERNET_NAME'
+ event_data = 'spiderfoot.net'
+ event_module = 'example module'
+ source_event = evt
+
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
result = module.handleEvent(evt)
self.assertIsNone(result)