forked from smicallef/spiderfoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sfp_names: Fix HUMAN_NAME extraction from email addresses (smicallef#…
- Loading branch information
Showing
2 changed files
with
103 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,26 +34,107 @@ def test_producedEvents_should_return_list(self): | |
module = sfp_names() | ||
self.assertIsInstance(module.producedEvents(), list) | ||
|
||
def test_handleEvent(self): | ||
""" | ||
Test handleEvent(self, event) | ||
""" | ||
def test_handleEvent_event_data_email_address_containing_human_names_should_return_event(self): | ||
sf = SpiderFoot(self.default_options) | ||
|
||
module = sfp_names() | ||
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 = 'HUMAN_NAME' | ||
if str(event.eventType) != expected: | ||
raise Exception(f"{event.eventType} != {expected}") | ||
|
||
expected = "Firstname Lastname" | ||
if str(event.data) != expected: | ||
raise Exception(f"{event.data} != {expected}") | ||
|
||
raise Exception("OK") | ||
|
||
module.notifyListeners = new_notifyListeners.__get__(module, sfp_names) | ||
|
||
event_type = 'ROOT' | ||
event_data = 'example data' | ||
event_module = '' | ||
source_event = '' | ||
evt = SpiderFootEvent(event_type, event_data, event_module, source_event) | ||
|
||
event_type = 'EMAILADDR' | ||
event_data = '[email protected]' | ||
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_email_address_containing_human_names_containing_numbers_should_not_return_event(self): | ||
sf = SpiderFoot(self.default_options) | ||
|
||
module = sfp_names() | ||
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): | ||
raise Exception(f"Raised event {event.eventType}: {event.data}") | ||
|
||
module.notifyListeners = new_notifyListeners.__get__(module, sfp_names) | ||
|
||
event_type = 'ROOT' | ||
event_data = 'example data' | ||
event_module = '' | ||
source_event = '' | ||
evt = SpiderFootEvent(event_type, event_data, event_module, source_event) | ||
|
||
event_type = 'EMAILADDR' | ||
event_data = '[email protected]' | ||
event_module = 'example module' | ||
source_event = evt | ||
evt = SpiderFootEvent(event_type, event_data, event_module, source_event) | ||
|
||
result = module.handleEvent(evt) | ||
|
||
self.assertIsNone(result) | ||
|
||
def test_handleEvent_event_data_email_address_not_containing_names_should_not_return_event(self): | ||
sf = SpiderFoot(self.default_options) | ||
|
||
module = sfp_names() | ||
module.setup(sf, dict()) | ||
|
||
target_value = 'example target value' | ||
target_type = 'IP_ADDRESS' | ||
target_value = 'spiderfoot.net' | ||
target_type = 'INTERNET_NAME' | ||
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_names) | ||
|
||
event_type = 'ROOT' | ||
event_data = 'example data' | ||
event_module = '' | ||
source_event = '' | ||
evt = SpiderFootEvent(event_type, event_data, event_module, source_event) | ||
|
||
event_type = 'EMAILADDR' | ||
event_data = '[email protected]' | ||
event_module = 'example module' | ||
source_event = evt | ||
evt = SpiderFootEvent(event_type, event_data, event_module, source_event) | ||
|
||
result = module.handleEvent(evt) | ||
|
||
self.assertIsNone(result) |