SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
sfscan: update unit tests
Brendan Coles84ba088d1607
diff --git a/sfscan.py b/sfscan.pyindex 651db6ca..5b51906e 100644--- a/sfscan.py+++ b/sfscan.py@@ -106,9 +106,6 @@ class SpiderFootScanner():self.__sf.dbh = self.__dbh# Create a unique ID for this scan in the back-end DB.- if not isinstance(scanId, str):- raise TypeError(f"scanId is {type(scanId)}; expected str()")-if scanId:self.__scanId = scanIdelse:diff --git a/test/unit/modules/test_sfp_template.py b/test/unit/modules/test_sfp_template.pyindex bb1348d5..caeef97e 100644--- a/test/unit/modules/test_sfp_template.py+++ b/test/unit/modules/test_sfp_template.py@@ -3,7 +3,6 @@ import unittestfrom modules.sfp_template import sfp_templatefrom sflib import SpiderFoot-from spiderfoot import SpiderFootEvent, SpiderFootTargetclass TestModuletemplate(unittest.TestCase):@@ -53,28 +52,3 @@ class TestModuletemplate(unittest.TestCase):def test_producedEvents_should_return_list(self):module = sfp_template()self.assertIsInstance(module.producedEvents(), list)-- @unittest.skip("todo")- def test_handleEvent(self):- """- Test handleEvent(self, event)- """- sf = SpiderFoot(self.default_options)-- module = sfp_template()- module.setup(sf, dict())-- target_value = 'example target value'- target_type = 'IP_ADDRESS'- target = SpiderFootTarget(target_value, target_type)- module.setTarget(target)-- event_type = 'ROOT'- event_data = 'example data'- event_module = ''- source_event = ''- evt = SpiderFootEvent(event_type, event_data, event_module, source_event)-- result = module.handleEvent(evt)-- self.assertIsNone(result)diff --git a/test/unit/test_spiderfootevent.py b/test/unit/test_spiderfootevent.pyindex 24cbe23b..229c8ea4 100644--- a/test/unit/test_spiderfootevent.py+++ b/test/unit/test_spiderfootevent.py@@ -283,6 +283,39 @@ class TestSpiderFootEvent(unittest.TestCase):with self.assertRaises(TypeError):evt.risk = invalid_type+ def test_actualSource_attribute_should_return_actual_source_as_string(self):+ event_type = 'ROOT'+ event_data = 'example event data'+ module = ''+ source_event = ''+ evt = SpiderFootEvent(event_type, event_data, module, source_event)++ actual_source = 'example actual source'+ evt.actualSource = actual_source++ self.assertEqual(actual_source, evt.actualSource)++ def test_sourceEventHash_attribute_should_return_source_event_hash_as_string(self):+ event_type = 'ROOT'+ event_data = 'example event data'+ module = ''+ source_event = ''+ evt = SpiderFootEvent(event_type, event_data, module, source_event)++ self.assertEqual("ROOT", evt.sourceEventHash)++ def test_moduleDataSource_attribute_should_return_module_data_source_as_string(self):+ event_type = 'ROOT'+ event_data = 'example event data'+ module = ''+ source_event = ''+ evt = SpiderFootEvent(event_type, event_data, module, source_event)++ module_data_source = 'example module data source'+ evt.moduleDataSource = module_data_source++ self.assertEqual(module_data_source, evt.moduleDataSource)+def test_asdict_root_event_should_return_event_as_a_dict(self):"""Test asDict(self)diff --git a/test/unit/test_spiderfootplugin.py b/test/unit/test_spiderfootplugin.pyindex addc0b55..a9683329 100644--- a/test/unit/test_spiderfootplugin.py+++ b/test/unit/test_spiderfootplugin.py@@ -210,19 +210,104 @@ class TestSpiderFootPlugin(unittest.TestCase):def test_notifyListeners_should_notify_listener_modules(self):"""Test notifyListeners(self, sfEvent)+ """+ sfp = SpiderFootPlugin()+ sfdb = SpiderFootDb(self.default_options, False)+ sfp.setDbh(sfdb)++ event_type = 'ROOT'+ event_data = 'test data'+ module = 'test module'+ source_event = None+ evt = SpiderFootEvent(event_type, event_data, module, source_event)+ sfp.notifyListeners(evt)++ self.assertEqual('TBD', 'TBD')++ def test_notifyListeners_output_filter_matched_should_notify_listener_modules(self):+ """+ Test notifyListeners(self, sfEvent)+ """+ sfp = SpiderFootPlugin()+ sfdb = SpiderFootDb(self.default_options, False)+ sfp.setDbh(sfdb)++ target = SpiderFootTarget("spiderfoot.net", "INTERNET_NAME")+ sfp.setTarget(target)++ event_type = 'ROOT'+ event_data = 'test data'+ module = 'test module'+ source_event = None+ evt = SpiderFootEvent(event_type, event_data, module, source_event)++ event_type = 'test event type'+ event_data = 'test data'+ module = 'test module'+ source_event = evt+ evt = SpiderFootEvent(event_type, event_data, module, source_event)++ sfp.__outputFilter__ = event_type++ sfp.notifyListeners(evt)++ self.assertEqual('TBD', 'TBD')- Todo:- Test with source event+ def test_notifyListeners_output_filter_unmatched_should_not_notify_listener_modules(self):+ """+ Test notifyListeners(self, sfEvent)"""sfp = SpiderFootPlugin()sfdb = SpiderFootDb(self.default_options, False)sfp.setDbh(sfdb)+ target = SpiderFootTarget("spiderfoot.net", "INTERNET_NAME")+ sfp.setTarget(target)+event_type = 'ROOT'event_data = 'test data'module = 'test module'source_event = Noneevt = SpiderFootEvent(event_type, event_data, module, source_event)++ event_type = 'test event type'+ event_data = 'test data'+ module = 'test module'+ source_event = evt+ evt = SpiderFootEvent(event_type, event_data, module, source_event)++ sfp.__outputFilter__ = "example unmatched event type"++ sfp.notifyListeners(evt)++ self.assertEqual('TBD', 'TBD')++ def test_notifyListeners_event_type_and_data_same_as_source_event_source_event_should_story_only(self):+ """+ Test notifyListeners(self, sfEvent)+ """+ sfp = SpiderFootPlugin()+ sfdb = SpiderFootDb(self.default_options, False)+ sfp.setDbh(sfdb)++ event_type = 'ROOT'+ event_data = 'test data'+ module = 'test module'+ source_event = None+ evt = SpiderFootEvent(event_type, event_data, module, source_event)++ event_type = 'test event type'+ event_data = 'test data'+ module = 'test module'+ source_event = evt+ evt = SpiderFootEvent(event_type, event_data, module, source_event)++ source_event = evt+ evt = SpiderFootEvent(event_type, event_data, module, source_event)++ source_event = evt+ evt = SpiderFootEvent(event_type, event_data, module, source_event)+sfp.notifyListeners(evt)self.assertEqual('TBD', 'TBD')diff --git a/test/unit/test_spiderfootscanner.py b/test/unit/test_spiderfootscanner.pyindex bbc45988..fabd555d 100644--- a/test/unit/test_spiderfootscanner.py+++ b/test/unit/test_spiderfootscanner.py@@ -166,7 +166,7 @@ class TestSpiderFootScanner(unittest.TestCase):module_list = list()with self.assertRaises(ValueError):- SpiderFootScanner("example scan name", scan_id, "spiderfoot.net", "IP_ADDRESS", module_list, dict(), start=False)+ SpiderFootScanner("example scan name", scan_id, "spiderfoot.net", "IP_ADDRESS", module_list, self.default_options, start=False)def test_init_argument_globalOpts_of_invalid_type_should_raise_TypeError(self):"""@@ -215,3 +215,33 @@ class TestSpiderFootScanner(unittest.TestCase):status = sfscan.statusself.assertIsInstance(status, str)++ def test__setStatus_argument_status_of_invalid_type_should_raise_TypeError(self):+ """+ Test __setStatus(self, status, started=None, ended=None)+ """+ opts = self.default_options+ opts['__modules__'] = dict()+ scan_id = str(uuid.uuid4())+ module_list = ['sfp__stor_db']++ sfscan = SpiderFootScanner("example scan name", scan_id, "spiderfoot.net", "IP_ADDRESS", module_list, opts, start=False)++ invalid_types = [None, list(), dict(), int()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError):+ sfscan._SpiderFootScanner__setStatus(invalid_type)++ def test__setStatus_argument_status_with_blank_value_should_raise_ValueError(self):+ """+ Test __setStatus(self, status, started=None, ended=None)+ """+ opts = self.default_options+ opts['__modules__'] = dict()+ scan_id = str(uuid.uuid4())+ module_list = ['sfp__stor_db']++ sfscan = SpiderFootScanner("example scan name", scan_id, "spiderfoot.net", "IP_ADDRESS", module_list, opts, start=False)+ with self.assertRaises(ValueError):+ sfscan._SpiderFootScanner__setStatus("example invalid scan status")diff --git a/test/unit/test_spiderfoottarget.py b/test/unit/test_spiderfoottarget.pyindex 3cdd5899..60cf3fc6 100644--- a/test/unit/test_spiderfoottarget.py+++ b/test/unit/test_spiderfoottarget.py@@ -60,7 +60,7 @@ class TestSpiderFootTarget(unittest.TestCase):self.assertEqual(target.targetType, target_type)self.assertEqual(target.targetValue, target_value)- def test_setAlias(self):+ def test_setAlias_invalid_alias_should_not_set_alias(self):"""Test setAlias(self, value, typeName)"""@@ -69,7 +69,36 @@ class TestSpiderFootTarget(unittest.TestCase):target = SpiderFootTarget(target_value, target_type)target.setAlias(None, None)- self.assertEqual('TBD', 'TBD')+ target.setAlias("", None)+ target.setAlias(None, "")+ target.setAlias("", "")+ target.setAlias("example value", None)+ target.setAlias(None, "example type")++ target_aliases = target.targetAliases+ self.assertIsInstance(target_aliases, list)+ self.assertEqual([], target_aliases)++ def test_setAlias_should_set_alias(self):+ """+ Test setAlias(self, value, typeName)+ """+ target_value = 'example target value'+ target_type = 'IP_ADDRESS'+ target = SpiderFootTarget(target_value, target_type)++ target.setAlias("example value", "example type")++ expected_aliases = [{'type': 'example type', 'value': 'example value'}]++ target_aliases = target.targetAliases+ self.assertEqual(expected_aliases, target_aliases)++ # check duplicated aliases aren't created+ target.setAlias("example value", "example type")++ target_aliases = target.targetAliases+ self.assertEqual(expected_aliases, target_aliases)def test_targetType_attribute_should_return_a_string(self):"""@@ -121,6 +150,17 @@ class TestSpiderFootTarget(unittest.TestCase):target = SpiderFootTarget(target_value, target_type)target.targetValue = invalid_type+ def test_targetValue_attribute_setter_empty_value_should_raise_ValueError(self):+ """+ Test targetValue attribute+ """+ target_value = 'example target value'+ target_type = 'IP_ADDRESS'++ with self.assertRaises(ValueError):+ target = SpiderFootTarget(target_value, target_type)+ target.targetValue = ""+def test_targetAliases_attribute_should_return_a_list(self):"""Test targetAliases attribute@@ -142,6 +182,22 @@ class TestSpiderFootTarget(unittest.TestCase):equivalents = target._getEquivalents(target_type)self.assertEqual(list, type(equivalents))+ def test_getEquivalents_should_return_alias_values(self):+ """+ Test _getEquivalents(self, typeName)+ """+ target_value = 'example target value'+ target_type = 'IP_ADDRESS'+ target = SpiderFootTarget(target_value, target_type)++ alias_type = "example type"+ alias_value = "example value"+ target.setAlias(alias_value, alias_type)++ equivalents = target._getEquivalents(alias_type)+ self.assertIsInstance(equivalents, list)+ self.assertEqual(equivalents[0], alias_value)+def test_getNames_should_return_a_list(self):"""Test getNames(self)