Skip to content

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

test_sfp_countryname: Add handleEvent test for PHONE_NUMBER event (#1603)

bcoles9b14235fc963
diff --git a/test/unit/modules/test_sfp_countryname.py b/test/unit/modules/test_sfp_countryname.py
index 22658fc6..88778493 100644
--- a/test/unit/modules/test_sfp_countryname.py
+++ b/test/unit/modules/test_sfp_countryname.py
@@ -34,6 +34,47 @@ class TestModuleCountryName(unittest.TestCase):
module = sfp_countryname()
self.assertIsInstance(module.producedEvents(), list)
+ def test_handleEvent_phone_number_event_data_containing_countrycode_should_create_country_name_event(self):
+ sf = SpiderFoot(self.default_options)
+
+ module = sfp_countryname()
+ module.setup(sf, dict())
+
+ target_value = 'spiderfoot.net'
+ target_type = 'INTERNET_NAME'
+ target = SpiderFootTarget(target_value, target_type)
+ module.setTarget(target)
+
+ def new_notifyListeners(self, event):
+ expected = 'COUNTRY_NAME'
+ if str(event.eventType) != expected:
+ raise Exception(f"{event.eventType} != {expected}")
+
+ expected = "United States"
+ if str(event.data) != expected:
+ raise Exception(f"{event.data} != {expected}")
+
+ raise Exception("OK")
+
+ module.notifyListeners = new_notifyListeners.__get__(module, sfp_countryname)
+
+ event_type = 'ROOT'
+ event_data = 'example data'
+ event_module = ''
+ source_event = ''
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+
+ event_type = 'PHONE_NUMBER'
+ event_data = '+12345678901'
+ 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_domain_whois_event_data_containing_countryname_string_should_create_country_name_event(self):
sf = SpiderFoot(self.default_options)