SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
tests: update sfdb and sfwebui tests
Brendan Colese98a3536986c
diff --git a/sfdb.py b/sfdb.pyindex cf5e5eb8..d526cd06 100644--- a/sfdb.py+++ b/sfdb.py@@ -14,7 +14,7 @@ import sqlite3import reimport timeimport threading-from sflib import SpiderFoot+from sflib import SpiderFoot, SpiderFootEventclass SpiderFootDb:"""SpiderFoot database@@ -248,7 +248,8 @@ class SpiderFootDb:Args:opts (dict): TBD- init (bool): TBD+ init (bool): initialise the database schema.+ if the database file does not exist this option will be ignored.Returns:None: success@@ -263,7 +264,7 @@ class SpiderFootDb:raise TypeError("opts is %s; expected dict()" % type(opts))if not opts:raise ValueError("opts is empty")- if not opts['__database']:+ if not opts.get('__database'):raise ValueError("opts['__database'] is empty")self.sf = SpiderFoot(opts)@@ -356,7 +357,7 @@ class SpiderFootDb:self.dbh.close()def search(self, criteria, filterFp=False):- """Search database+ """Search database.Args:criteria (dict): search criteria such as:@@ -371,17 +372,19 @@ class SpiderFootDb:list: search resultsRaises:+ TypeError: arg type was invalid+ ValueError: arg value was invalidIOError: database I/O failedTodo:- Raise errors upon invalid ars+ Raise errors upon invalid args"""if not isinstance(criteria, dict):- return list()+ raise TypeError("criteria is %s; expected dict()" % type(criteria))- if list(criteria.values()).count(None) == 3:- return list()+ if list(criteria.values()).count(None) >= 3:+ raise ValueError("Invalid number of search criteria provided; expected at least 2")qvars = list()qry = "SELECT ROUND(c.generated) AS generated, c.data, \@@ -461,6 +464,14 @@ class SpiderFootDb:Todo:Do something smarter to handle database locks"""+ if not isinstance(instanceId, str):+ raise TypeError("instanceId is %s; expected str()" % type(instanceId))++ if not isinstance(classification, str):+ raise TypeError("classification is %s; expected str()" % type(classification))++ if not isinstance(message, str):+ raise TypeError("message is %s; expected str()" % type(message))if not component:component = "SpiderFoot"@@ -574,7 +585,9 @@ class SpiderFootDb:with self.dbhLock:try:self.dbh.execute(qry, qvars)- return self.dbh.fetchone()+ ret = self.dbh.fetchone()+ if not ret:+ return list()except sqlite3.Error as e:raise IOError("SQL error encountered when retrieving scan instance:" + e.args[0])@@ -590,9 +603,13 @@ class SpiderFootDb:list: scan instance infoRaises:+ ValueError: arg value was invalidIOError: database I/O failed"""+ if by not in ["type", "module", "entity"]:+ raise ValueError("Invalid filter by value: %s" % by)+if by == "type":qry = "SELECT r.type, e.event_descr, MAX(ROUND(generated)) AS last_in, \count(*) AS total, count(DISTINCT r.data) as utotal FROM \@@ -1032,8 +1049,8 @@ class SpiderFootDb:Validate args and modify error handling to raise instead of calling fatal()"""- #if not isinstance(sfEvent, SpiderFootEvent):- # raise TypeError("sfEvent is %s; expected SpiderFootEvent()" % type(sfEvent))+ if not isinstance(sfEvent, SpiderFootEvent):+ raise TypeError("sfEvent is %s; expected SpiderFootEvent()" % type(sfEvent))storeData = ''@@ -1140,9 +1157,13 @@ class SpiderFootDb:list: TBDRaises:+ TypeError: arg type was invalidIOError: database I/O failed"""+ if not isinstance(elementIdList, list):+ raise TypeError("elementIdList is %s; expected list()" % type(elementIdList))+# the output of this needs to be aligned with scanResultEvent,# as other functions call both expecting the same output.qry = "SELECT ROUND(c.generated) AS generated, c.data, \@@ -1178,9 +1199,13 @@ class SpiderFootDb:list: TBDRaises:+ TypeError: arg type was invalidIOError: database I/O failed"""+ if not isinstance(elementIdList, list):+ raise TypeError("elementIdList is %s; expected list()" % type(elementIdList))+# the output of this needs to be aligned with scanResultEvent,# as other functions call both expecting the same output.qry = "SELECT ROUND(c.generated) AS generated, c.data, \@@ -1217,8 +1242,18 @@ class SpiderFootDb:Returns:list: TBD++ Raises:+ TypeError: arg type was invalid+ ValueError: arg value was invalid+ IOError: database I/O failed"""+ if not isinstance(childData, list):+ raise TypeError("childData is %s; expected list()" % type(childData))+ if not childData:+ raise ValueError("childData is empty")+# Get the first round of source IDs for the leafskeepGoing = TruenextIds = list()diff --git a/sflib.py b/sflib.pyindex b3133d29..93d36dc4 100644--- a/sflib.py+++ b/sflib.py@@ -668,10 +668,12 @@ class SpiderFoot:if type(opts[opt]) is list:storeopts[opt] = ','.join(opts[opt])- # todo: ensure the __modules__ key value is in the expected formatif '__modules__' not in opts:return storeopts+ if not isinstance(opts['__modules__'], dict):+ raise TypeError("opts['__modules__'] is %s; expected dict()" % type(opts['__modules__']))+for mod in opts['__modules__']:for opt in opts['__modules__'][mod]['opts']:if opt.startswith('_') and filterSystem:@@ -743,6 +745,9 @@ class SpiderFoot:if '__modules__' not in referencePoint:return returnOpts+ if not isinstance(referencePoint['__modules__'], dict):+ raise TypeError("referencePoint['__modules__'] is %s; expected dict()" % type(referencePoint['__modules__']))+# Module options# A lot of mess to handle typing..for modName in referencePoint['__modules__']:diff --git a/sfwebui.py b/sfwebui.pyindex 1fee7b9f..6df8f042 100644--- a/sfwebui.py+++ b/sfwebui.py@@ -90,8 +90,19 @@ class SpiderFootWebUi:templ = Template(filename='dyn/error.tmpl', lookup=self.lookup)return templ.render(message='Not Found', docroot=self.docroot, status=status)- # Sanitize user inputdef cleanUserInput(self, inputList):+ """Sanitize user input, poorly.++ Args:+ inputList (list): TBD++ Returns:+ list: sanitized input+ """++ if not isinstance(inputList, list):+ raise TypeError("inputList is %s; expected list()" % type(inputList))+ret = list()for item in inputList:@@ -104,10 +115,23 @@ class SpiderFootWebUi:return retdef searchBase(self, id=None, eventType=None, value=None):+ """Search++ Args:+ id: TBD+ eventType: TBD+ value: TBD++ Returns:+ list: search results+ """++ retdata = []+regex = ""if [id, eventType, value].count('') == 3 or \[id, eventType, value].count(None) == 3:- return None+ return retdataif value.startswith("/") and value.endswith("/"):regex = value[1:len(value) - 1]@@ -126,8 +150,11 @@ class SpiderFootWebUi:'regex': None if regex == '' else regex}- data = dbh.search(criteria)- retdata = []+ try:+ data = dbh.search(criteria)+ except:+ return retdata+for row in data:lastseen = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(row[0]))escapeddata = html.escape(row[1])@@ -142,8 +169,18 @@ class SpiderFootWebUi:# USER INTERFACE PAGES#- # Get result data in CSV formatdef scaneventresultexport(self, id, type, dialect="excel"):+ """Get scan event result data in CSV format++ Args:+ id (str): scan ID+ type (str): TBD+ dialect (str): TBD++ Returns:+ string: results in CSV format+ """+dbh = SpiderFootDb(self.config)data = dbh.scanResultEvent(id, type)fileobj = StringIO()@@ -162,8 +199,17 @@ class SpiderFootWebUi:scaneventresultexport.exposed = True- # Get result data in CSV format for multiple scansdef scaneventresultexportmulti(self, ids, dialect="excel"):+ """Get scan event result data in CSV format for multiple scans++ Args:+ ids (str): comma separated list of scan IDs+ dialect (str): TBD++ Returns:+ string: results in CSV format+ """+dbh = SpiderFootDb(self.config)scaninfo = dict()data = list()@@ -764,6 +810,9 @@ class SpiderFootWebUi:cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"+ if not query:+ return json.dumps(["ERROR", "Invalid query."])+if not query.lower().startswith("select"):return json.dumps(["ERROR", "Non-SELECTs are unpredictable and not recommended."])@@ -1018,9 +1067,15 @@ class SpiderFootWebUi:# Summary of scan resultsdef scansummary(self, id, by):- dbh = SpiderFootDb(self.config)- data = dbh.scanResultSummary(id, by)retdata = []++ dbh = SpiderFootDb(self.config)++ try:+ data = dbh.scanResultSummary(id, by)+ except:+ return json.dumps(retdata)+for row in data:if row[0] == "ROOT":continue@@ -1032,9 +1087,15 @@ class SpiderFootWebUi:# Event results for a scandef scaneventresults(self, id, eventType, filterfp=False):- dbh = SpiderFootDb(self.config)- data = dbh.scanResultEvent(id, eventType, filterfp)retdata = []++ dbh = SpiderFootDb(self.config)++ try:+ data = dbh.scanResultEvent(id, eventType, filterfp)+ except:+ return json.dumps(retdata)+for row in data:lastseen = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(row[0]))escapeddata = html.escape(row[1])diff --git a/test/unit/test_spiderfootdb.py b/test/unit/test_spiderfootdb.pyindex ab90b6a7..bbea2454 100644--- a/test/unit/test_spiderfootdb.py+++ b/test/unit/test_spiderfootdb.py@@ -34,22 +34,27 @@ class TestSpiderFootDb(unittest.TestCase):'__logstdout': False}- @unittest.skip("todo")- def test_dbregex(self):+ def test_init_invalid_args_should_raise(self):"""- Test __dbregex__(qry, data)+ Test __init__(self, opts, init=False)"""- self.assertEqual('TBD', 'TBD')+ with self.assertRaises(TypeError) as cm:+ sfdb = SpiderFootDb(None)++ with self.assertRaises(TypeError) as cm:+ sfdb = SpiderFootDb([])def test_init_no_options_should_raise(self):"""Test __init__(self, opts, init=False)"""- with self.assertRaises(TypeError) as cm:- sfdb = SpiderFootDb(None, None)+ with self.assertRaises(ValueError) as cm:+ sfdb = SpiderFootDb(dict())with self.assertRaises(ValueError) as cm:- sfdb = SpiderFootDb(dict(), None)+ opts = dict()+ opts['example'] = 'example not-empty dict'+ sfdb = SpiderFootDb(opts)def test_init(self):"""@@ -80,12 +85,28 @@ class TestSpiderFootDb(unittest.TestCase):"""sfdb = SpiderFootDb(self.default_options, False)- search_results = sfdb.search(None, None)+ criteria = {+ 'scan_id': "",+ 'type': "",+ 'value': "",+ 'regex': ""+ }++ search_results = sfdb.search(criteria, False)self.assertIsInstance(search_results, list)self.assertFalse(search_results)- search_results = sfdb.search(dict(), False)- self.assertIsInstance(search_results, list)+ def test_search_invalid_criteria_should_raise(self):+ """+ Test search(self, criteria, filterFp=False)+ """+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, "", list()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ search_results = sfdb.search(invalid_type, False)criteria = {'scan_id': None,@@ -94,9 +115,8 @@ class TestSpiderFootDb(unittest.TestCase):'regex': None}- search_results = sfdb.search(criteria, False)- self.assertIsInstance(search_results, list)- self.assertFalse(search_results)+ with self.assertRaises(ValueError) as cm:+ search_results = sfdb.search(criteria, False)def test_event_types_should_return_a_list(self):"""@@ -106,15 +126,48 @@ class TestSpiderFootDb(unittest.TestCase):event_types = sfdb.eventTypes()self.assertIsInstance(event_types, list)- @unittest.skip("todo")def test_scan_log_event(self):"""Test scanLogEvent(self, instanceId, classification, message, component=None)"""sfdb = SpiderFootDb(self.default_options, False)- sfdb.scanLogEvent(None, None, None, None)+ sfdb.scanLogEvent("", "", "", None)- self.assertEqual('TBD', 'TBD')+ def test_scan_log_event_invalid_instance_id_should_raise(self):+ """+ Test scanLogEvent(self, instanceId, classification, message, component=None)+ """+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, list(), dict()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ sfdb.scanLogEvent(invalid_type, "", "")++ def test_scan_log_event_invalid_classification_should_raise(self):+ """+ Test scanLogEvent(self, instanceId, classification, message, component=None)+ """+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, list(), dict()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ sfdb.scanLogEvent("", invalid_type, "")++ def test_scan_log_event_invalid_message_should_raise(self):+ """+ Test scanLogEvent(self, instanceId, classification, message, component=None)+ """+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, list(), dict()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ sfdb.scanLogEvent("", "", invalid_type)@unittest.skip("todo")def test_scan_instance_create(self):@@ -126,17 +179,16 @@ class TestSpiderFootDb(unittest.TestCase):self.assertEqual('TBD', 'TBD')- @unittest.skip("todo")def test_scan_instance_set(self):"""Test scanInstanceSet(self, instanceId, started=None, ended=None, status=None)"""sfdb = SpiderFootDb(self.default_options, False)- sfdb.scanInstanceSet(None, None, None, None)+ scan_instance = 'example scan instance'+ sfdb.scanInstanceSet(scan_instance, None, None, None)self.assertEqual('TBD', 'TBD')- @unittest.skip("todo")def test_scan_instance_get_should_return_a_list(self):"""Test scanInstanceGet(self, instanceId)@@ -144,32 +196,71 @@ class TestSpiderFootDb(unittest.TestCase):sfdb = SpiderFootDb(self.default_options, False)scan_instance = 'example scan instance'+ sfdb.scanInstanceSet(scan_instance, None, None, None)+scan_instance_get = sfdb.scanInstanceGet(scan_instance)self.assertIsInstance(scan_instance_get, list)- self.assertIsIn(scan_instance, scan_instance_get)- self.assertEqual('TBD', 'TBD')+ def test_scan_result_summary_should_return_a_list(self):+ """+ Test scanResultSummary(self, instanceId, by="type")+ """+ sfdb = SpiderFootDb(self.default_options, False)- @unittest.skip("todo")- def test_scan_result_summary(self):+ scan_results_summary = sfdb.scanResultSummary("", "type")+ self.assertIsInstance(scan_results_summary, list)++ def test_scan_result_summary_invalid_type_should_raise(self):"""Test scanResultSummary(self, instanceId, by="type")"""- self.assertEqual('TBD', 'TBD')+ sfdb = SpiderFootDb(self.default_options, False)- @unittest.skip("todo")- def test_scan_result_event(self):+ with self.assertRaises(ValueError) as cm:+ scan_results_summary = sfdb.scanResultSummary(None, None)++ with self.assertRaises(ValueError) as cm:+ scan_results_summary = sfdb.scanResultSummary("", "invalid filter type")++ def test_scan_result_event_should_return_a_list(self):"""Test scanResultEvent(self, instanceId, eventType='ALL', filterFp=False)"""- self.assertEqual('TBD', 'TBD')+ sfdb = SpiderFootDb(self.default_options, False)+ scan_result_event = sfdb.scanResultEvent("", "", False)+ self.assertIsInstance(scan_result_event, list)- @unittest.skip("todo")- def test_scan_result_event_unique(self):+ def test_scan_result_event_invalid_event_type_should_raise(self):+ """+ Test scanResultEvent(self, instanceId, eventType='ALL', filterFp=False)+ """+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, list(), dict()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ scan_result_event = sfdb.scanResultEvent("", invalid_type, None)++ def test_scan_result_event_unique_should_return_a_list(self):"""Test scanResultEventUnique(self, instanceId, eventType='ALL', filterFp=False)"""- self.assertEqual('TBD', 'TBD')+ sfdb = SpiderFootDb(self.default_options, False)+ scan_result_event = sfdb.scanResultEventUnique("", "", False)+ self.assertIsInstance(scan_result_event, list)++ def test_scan_result_event_unique_invalid_event_type_should_raise(self):+ """+ Test scanResultEventUnique(self, instanceId, eventType='ALL', filterFp=False)+ """+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, list(), dict()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ scan_result_event = sfdb.scanResultEventUnique("", invalid_type, None)def test_scan_logs_should_return_a_list(self):"""@@ -206,12 +297,34 @@ class TestSpiderFootDb(unittest.TestCase):"""self.assertEqual('TBD', 'TBD')- @unittest.skip("todo")- def test_config_set(self):+ def test_config_set_should_set_config_opts(self):"""Test configSet(self, optMap=dict())"""- self.assertEqual('TBD', 'TBD')+ sfdb = SpiderFootDb(self.default_options, False)+ opts = dict()+ opts['example'] = 'example non-default config opt'+ sfdb.configSet(opts)++ config = sfdb.configGet()+ self.assertIsInstance(config, dict)+ self.assertIn('example', config)++ def test_config_set_invalid_optmap_should_raise(self):+ """+ Test configSet(self, optMap=dict())+ """+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, "", list()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ scan_result_event = sfdb.scanResultEventUnique("", invalid_type, None)+ sfdb.configSet(invalid_type)++ with self.assertRaises(ValueError) as cm:+ sfdb.configSet(dict())def test_config_get_should_return_a_dict(self):"""@@ -221,21 +334,40 @@ class TestSpiderFootDb(unittest.TestCase):config = sfdb.configGet()self.assertIsInstance(config, dict)- @unittest.skip("todo")- def test_config_clear(self):+ def test_config_clear_should_clear_config(self):"""Test configClear(self)"""sfdb = SpiderFootDb(self.default_options, False)- config = sfdb.configClear()- self.assertEqual('TBD', 'TBD')- @unittest.skip("todo")+ opts = dict()+ opts['example'] = 'example non-default config opt'+ sfdb.configSet(opts)++ config = sfdb.configGet()+ self.assertIsInstance(config, dict)+ self.assertIn('example', config)++ sfdb.configClear()++ config = sfdb.configGet()+ self.assertIsInstance(config, dict)+ self.assertNotIn('example', config)+def test_scan_config_set(self):"""Test scanConfigSet(self, id, optMap=dict())"""- self.assertEqual('TBD', 'TBD')+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, ""]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ sfdb.scanConfigSet("", invalid_type)++ with self.assertRaises(ValueError) as cm:+ sfdb.scanConfigSet("", dict())def test_scan_config_get_should_return_a_dict(self):"""@@ -245,12 +377,17 @@ class TestSpiderFootDb(unittest.TestCase):scan_config = sfdb.scanConfigGet(None)self.assertIsInstance(scan_config, dict)- @unittest.skip("todo")- def test_scan_event_store(self):+ def test_scan_event_store_invalid_event_should_raise(self):"""Test scanEventStore(self, instanceId, sfEvent, truncateSize=0)"""- self.assertEqual('TBD', 'TBD')+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, "", dict()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ sfdb.scanEventStore("", invalid_type)def test_scan_instance_list_should_return_a_list(self):"""@@ -282,18 +419,29 @@ class TestSpiderFootDb(unittest.TestCase):self.assertEqual('TBD', 'TBD')- @unittest.skip("todo")def test_scan_element_children_direct_should_return_a_list(self):"""Test scanElementChildrenDirect(self, instanceId, elementIdList)"""sfdb = SpiderFootDb(self.default_options, False)- scan_element_children_direct = sfdb.scanElementChildrenDirect(None, None)+ scan_element_children_direct = sfdb.scanElementChildrenDirect(None, list())self.assertIsInstance(scan_element_children_direct, list)self.assertEqual('TBD', 'TBD')+ def test_scan_element_children_direct_invalid_element_id_list_should_raise(self):+ """+ Test scanElementChildrenDirect(self, instanceId, elementIdList)+ """+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, "", dict()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ scan_element_children_direct = sfdb.scanElementChildrenDirect("", invalid_type)+@unittest.skip("todo")def test_scan_element_sources_all_should_return_a_list(self):"""@@ -301,23 +449,49 @@ class TestSpiderFootDb(unittest.TestCase):"""sfdb = SpiderFootDb(self.default_options, False)- scan_element_sources_all = sfdb.scanElementSourcesAll(None, None)+ scan_element_sources_all = sfdb.scanElementSourcesAll(None, list())self.assertIsInstance(scan_element_sources_all, list)self.assertEqual('TBD', 'TBD')- @unittest.skip("todo")+ def test_scan_element_sources_all_invalid_child_data_should_raise(self):+ """+ Test scanElementSourcesAll(self, instanceId, childData)+ """+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, "", dict()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ scan_element_sources_all = sfdb.scanElementSourcesAll("", invalid_type)++ with self.assertRaises(ValueError) as cm:+ scan_element_sources_all = sfdb.scanElementSourcesAll("", list())+def test_scan_element_children_all_should_return_a_list(self):"""Test scanElementChildrenAll(self, instanceId, parentIds)"""sfdb = SpiderFootDb(self.default_options, False)- scan_element_children_all = sfdb.scanElementChildrenAll(None, None)+ scan_element_children_all = sfdb.scanElementChildrenAll(None, list())self.assertIsInstance(scan_element_children_all, list)self.assertEqual('TBD', 'TBD')+ def test_scan_element_children_all_invalid_element_id_list_should_raise(self):+ """+ Test scanElementChildrenAll(self, instanceId, parentIds)+ """+ sfdb = SpiderFootDb(self.default_options, False)++ invalid_types = [None, "", dict()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ scan_element_children_all = sfdb.scanElementChildrenAll("", invalid_type)+if __name__ == '__main__':unittest.main()diff --git a/test/unit/test_spiderfootscanner.py b/test/unit/test_spiderfootscanner.pyindex e502cf0e..79c5f836 100644--- a/test/unit/test_spiderfootscanner.py+++ b/test/unit/test_spiderfootscanner.py@@ -38,7 +38,9 @@ class TestSpiderFootScanner(unittest.TestCase):"""Test __init__(self, scanName, scanTarget, targetType, moduleList, globalOpts)"""- sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), self.default_options)+ opts = self.default_options+ opts['__modules__'] = dict()+ sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), opts)self.assertIsInstance(sfscan, SpiderFootScanner)def test_init_invalid_scan_name_should_raise(self):@@ -83,7 +85,9 @@ class TestSpiderFootScanner(unittest.TestCase):"""Test def setStatus(self, status, started=None, ended=None)"""- sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), self.default_options)+ opts = self.default_options+ opts['__modules__'] = dict()+ sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), opts)self.assertIsInstance(sfscan, SpiderFootScanner)with self.assertRaises(ValueError) as cm:@@ -93,7 +97,9 @@ class TestSpiderFootScanner(unittest.TestCase):"""Test def getId(self)"""- sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), self.default_options)+ opts = self.default_options+ opts['__modules__'] = dict()+ sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), opts)self.assertIsInstance(sfscan, SpiderFootScanner)scan_id = sfscan.getId()diff --git a/test/unit/test_spiderfootwebui.py b/test/unit/test_spiderfootwebui.pyindex 1215d642..4ed65469 100644--- a/test/unit/test_spiderfootwebui.py+++ b/test/unit/test_spiderfootwebui.py@@ -68,40 +68,73 @@ class TestSpiderFootWebUi(unittest.TestCase):sfwebui = SpiderFootWebUi(self.default_options)sfwebui.error_page_404(None, None, None, None, None)- @unittest.skip("todo")- def test_cleanUserInput(self):+ def test_clean_user_input_should_return_a_list(self):"""Test cleanUserInput(self, inputList)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ clean_user_input = sfwebui.cleanUserInput(list())+ self.assertIsInstance(clean_user_input, list)- @unittest.skip("todo")- def test_search_base(self):+ def test_clean_user_input_invalid_input_should_raise(self):+ """+ Test cleanUserInput(self, inputList)+ """+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)++ invalid_types = [None, "", dict()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ with self.assertRaises(TypeError) as cm:+ clean_user_input = sfwebui.cleanUserInput(invalid_type)++ def test_search_base_should_return_a_list(self):"""Test searchBase(self, id=None, eventType=None, value=None)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ search_results = sfwebui.searchBase(None, None, None)+ self.assertIsInstance(search_results, list)- @unittest.skip("todo")- def test_scan_event_result_export(self):+ search_results = sfwebui.searchBase(None, None, "//")+ self.assertIsInstance(search_results, list)++ def test_scan_event_result_export_should_return_bytes(self):"""Test scaneventresultexport(self, id, type, dialect="excel")"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ search_results = sfwebui.scaneventresultexport("", "", "excel")+ self.assertIsInstance(search_results, bytes)- @unittest.skip("todo")def test_scan_event_result_export_multi(self):"""Test scaneventresultexportmulti(self, ids, dialect="excel")"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ search_results = sfwebui.scaneventresultexport("", "", "excel")+ self.assertIsInstance(search_results, bytes)@unittest.skip("todo")def test_scan_search_result_export(self):"""Test scansearchresultexport(self, id, eventType=None, value=None, dialect="excel")"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ search_results = sfwebui.scansearchresultexport("", "", "excel")+ self.assertIsInstance(search_results, bytes)@unittest.skip("todo")def test_scan_export_json_multi(self):@@ -111,18 +144,26 @@ class TestSpiderFootWebUi(unittest.TestCase):self.assertEqual('TBD', 'TBD')@unittest.skip("todo")- def test_scan_viz(self):+ def test_scan_viz_should_return_a_string(self):"""Test scanviz(self, id, gexf="0")"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_viz = sfwebui.scanviz(None, None)+ self.assertIsInstance(scan_viz, str)@unittest.skip("todo")- def test_scan_viz_multi(self):+ def test_scan_viz_multi_should_return_a_string(self):"""Test scanvizmulti(self, ids, gexf="1")"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_viz_multi = sfwebui.scanvizmulti(None, None)+ self.assertIsInstance(scan_viz_multi, str)@unittest.skip("todo")def test_scanopts(self):@@ -180,19 +221,25 @@ class TestSpiderFootWebUi(unittest.TestCase):"""self.assertEqual('TBD', 'TBD')- @unittest.skip("todo")- def test_optsexport(self):+ def test_optsexport_should_return_a_string(self):"""Test optsexport(self, pattern)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ opts_export = sfwebui.optsexport(None)+ self.assertIsInstance(opts_export, str)- @unittest.skip("todo")- def test_optsraw(self):+ def test_optsraw_should_return_a_string(self):"""Test optsraw(self)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ opts_raw = sfwebui.optsraw()+ self.assertIsInstance(opts_raw, str)@unittest.skip("todo")def test_error(self):@@ -236,33 +283,46 @@ class TestSpiderFootWebUi(unittest.TestCase):"""self.assertEqual('TBD', 'TBD')- @unittest.skip("todo")- def test_eventtypes(self):+ def test_eventtypes_should_return_a_string(self):"""Test eventtypes(self)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ event_types = sfwebui.eventtypes()+ self.assertIsInstance(event_types, str)- @unittest.skip("todo")- def test_modules(self):+ def test_modules_should_return_a_string(self):"""Test modules(self)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ modules = sfwebui.eventtypes()+ self.assertIsInstance(modules, str)- @unittest.skip("todo")- def test_ping(self):+ def test_ping_should_return_a_string(self):"""Test ping(self)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ ping = sfwebui.ping()+ self.assertIsInstance(ping, str)- @unittest.skip("todo")- def test_query(self):+ def test_query_should_perform_a_sql_query(self):"""Test query(self, query)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ query = sfwebui.query("SELECT 12345")+ self.assertIsInstance(query, str)+ self.assertIn("12345", query)@unittest.skip("todo")def test_start_scan(self):@@ -285,75 +345,108 @@ class TestSpiderFootWebUi(unittest.TestCase):"""self.assertEqual('TBD', 'TBD')- @unittest.skip("todo")- def test_scanlog(self):+ def test_scanlog_should_return_a_string(self):"""Test scanlog(self, id, limit=None, rowId=None, reverse=None)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_log = sfwebui.scanlog(None, None, None, None)+ self.assertIsInstance(scan_log, str)- @unittest.skip("todo")- def test_scanerrors(self):+ def test_scanerrors_should_return_a_string(self):"""Test scanerrors(self, id, limit=None)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_errors = sfwebui.scanerrors(None, None)+ self.assertIsInstance(scan_errors, str)- @unittest.skip("todo")- def test_scanlist(self):+ def test_scanlist_should_return_a_string(self):"""Test scanlist(self)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_list = sfwebui.scanlist()+ self.assertIsInstance(scan_list, str)@unittest.skip("todo")- def test_scanstatus(self):+ def test_scanstatus_should_return_a_string(self):"""Test scanstatus(self, id)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_status = sfwebui.scanstatus(None)+ self.assertIsInstance(scan_status, str)- @unittest.skip("todo")- def test_scansummary(self):+ def test_scansummary_should_return_a_string(self):"""Test scansummary(self, id, by)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_summary = sfwebui.scansummary(None, None)+ self.assertIsInstance(scan_summary, str)- @unittest.skip("todo")- def test_scaneventresults(self):+ def test_scaneventresults_should_return_a_string(self):"""Test scaneventresults(self, id, eventType, filterfp=False)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_results = sfwebui.scaneventresults(None, None, None)+ self.assertIsInstance(scan_results, str)@unittest.skip("todo")- def test_scaneventresultsunique(self):+ def test_scaneventresultsunique_should_return_a_string(self):"""Test scaneventresultsunique(self, id, eventType, filterfp=False)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_results = sfwebui.scaneventresultsunique(None, None, None)+ self.assertIsInstance(scan_results, str)- @unittest.skip("todo")- def test_search(self):+ def test_search_should_return_a_string(self):"""Test search(self, id=None, eventType=None, value=None)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ search_results = sfwebui.search(None, None, None)+ self.assertIsInstance(search_results, str)- @unittest.skip("todo")- def test_scan_history(self):+ def test_scan_history_should_return_a_string(self):"""Test scanhistory(self, id)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_history = sfwebui.scanhistory(None)+ self.assertIsInstance(scan_history, str)@unittest.skip("todo")- def test_scan_element_type_discovery(self):+ def test_scan_element_type_discovery_should_return_a_string(self):"""Test scanelementtypediscovery(self, id, eventType)"""- self.assertEqual('TBD', 'TBD')+ opts = self.default_options+ opts['__modules__'] = dict()+ sfwebui = SpiderFootWebUi(opts)+ scan_element_type_discovery = sfwebui.scanelementtypediscovery(None, None)+ self.assertIsInstance(scan_element_type_discovery, str)if __name__ == '__main__':unittest.main()