Skip to content

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

sfscan: move startScan() functionality out of init()

Brendan Coles5bd5dedbd56c
diff --git a/sf.py b/sf.py
index 10ee72a7..861835d2 100755
--- a/sf.py
+++ b/sf.py
@@ -320,7 +320,6 @@ if __name__ == '__main__':
if sfConfig['__logging']:
print(("[*] Modules enabled (" + str(len(modlist)) + "): " + ",".join(modlist)))
cfg = sf.configUnserialize(dbh.configGet(), sfConfig)
- scanId = sf.genScanInstanceGUID(target)
# Debug mode is a variable that gets stored to the DB, so re-apply it
if args.debug:
@@ -332,10 +331,20 @@ if __name__ == '__main__':
if args.x and args.t:
cfg['__outputfilter'] = args.t.split(",")
- t = SpiderFootScanner(target, target, targetType, scanId,
- modlist, cfg, dict())
- t.daemon = True
- t.run()
+ try:
+ s = SpiderFootScanner(target, target, targetType, scanId, modlist, cfg)
+ scanId = s.getId()
+ except BaseException as e:
+ print("[-] Failed to initialize scan: %s" % e)
+ sys.exit(-1)
+
+ try:
+ p = mp.Process(target=s.startScan())
+ p.daemon = True
+ p.start()
+ except BaseException as e:
+ print("[-] Scan [%s] failed: %s" % (scanId, e))
+ sys.exit(-1)
# If field headers weren't disabled, print them
if not args.H and args.o != "json":
diff --git a/sflib.py b/sflib.py
index e637a6d7..274bd246 100644
--- a/sflib.py
+++ b/sflib.py
@@ -369,12 +369,9 @@ class SpiderFoot:
"""Set the GUID this instance of SpiderFoot is being used in."""
self.GUID = uid
- def genScanInstanceGUID(self, scanName):
+ def genScanInstanceGUID(self):
"""Generate an globally unique ID for this scan.
- Args:
- scanName (str): scan name
-
Returns:
str: scan instance unique GUID
"""
@@ -636,11 +633,25 @@ class SpiderFoot:
# Configuration process
#
- # Convert a Python dictionary to something storable
- # in the database.
def configSerialize(self, opts, filterSystem=True):
+ """Convert a Python dictionary to something storable in the database.
+
+ Args:
+ opts (dict): TBD
+ filterSystem (bool): TBD
+
+ Returns:
+ dict: config options
+ """
+
+ if not isinstance(opts, dict):
+ raise TypeError("opts is %s; expected dict()" % type(opts))
+
storeopts = dict()
+ if not opts:
+ return storeopts
+
for opt in list(opts.keys()):
# Filter out system temporary variables like GUID and others
if opt.startswith('__') and filterSystem:
@@ -657,7 +668,7 @@ class SpiderFoot:
if type(opts[opt]) is list:
storeopts[opt] = ','.join(opts[opt])
- if '__modules__' not in opts:
+ if opts['__modules__'] is None:
return storeopts
for mod in opts['__modules__']:
@@ -680,11 +691,26 @@ class SpiderFoot:
return storeopts
- # Take strings, etc. from the database or UI and convert them
- # to a dictionary for Python to process.
- # referencePoint is needed to know the actual types the options
- # are supposed to be.
def configUnserialize(self, opts, referencePoint, filterSystem=True):
+ """Take strings, etc. from the database or UI and convert them
+ to a dictionary for Python to process.
+ referencePoint is needed to know the actual types the options
+ are supposed to be.
+
+ Args:
+ opts (dict): TBD
+ referencePoint (dict): TBD
+ filterSystem (bool): TBD
+
+ Returns:
+ dict: TBD
+ """
+
+ if not isinstance(opts, dict):
+ raise TypeError("opts is %s; expected dict()" % type(opts))
+ if not isinstance(referencePoint, dict):
+ raise TypeError("referencePoint is %s; expected dict()" % type(referencePoint))
+
returnOpts = referencePoint
# Global options
@@ -2535,14 +2561,16 @@ class SpiderFootTarget(object):
targetAliases = list()
def __init__(self, targetValue, typeName):
+ if not isinstance(targetValue, str):
+ raise TypeError("Invalid target value %s; expected %s" % type(targetValue))
if typeName not in self._validTypes:
raise ValueError("Invalid target type %s; expected %s" % (typeName, self._validTypes))
self.targetType = typeName
- if type(targetValue) != str:
- self.targetValue = str(targetValue).lower()
- else:
+ if isinstance(targetValue, str):
self.targetValue = targetValue
+ else:
+ self.targetValue = str(targetValue).lower()
self.targetAliases = list()
def getType(self):
diff --git a/sfscan.py b/sfscan.py
index 5255b856..1a63634e 100644
--- a/sfscan.py
+++ b/sfscan.py
@@ -22,22 +22,15 @@ from sflib import SpiderFoot, SpiderFootEvent, SpiderFootTarget, \
# Eventually change this to be able to control multiple scan instances
class SpiderFootScanner():
- # Temporary storage
- temp = None
-
- def __init__(self, scanName, scanTarget, targetType, scanId, moduleList,
- globalOpts, moduleOpts):
- """Initialize SpiderFootScanner object and immediately start a scan
- of the specified target.
+ def __init__(self, scanName, scanTarget, targetType, moduleList, globalOpts):
+ """Initialize SpiderFootScanner object.
Args:
scanName (str): name of the scan
scanTarget (str): scan target
targetType (str): scan target type
- scanId (str): scan identifier
moduleList (list): list of modules to run
globalOpts (dict): scan options
- moduleOpts (dict): unused
Returns:
None
@@ -47,27 +40,64 @@ class SpiderFootScanner():
raise TypeError("scanName is %s; expected str()" % type(scanName))
if not isinstance(scanTarget, str):
raise TypeError("scanTarget is %s; expected str()" % type(scanTarget))
- if not isinstance(scanId, str):
- raise TypeError("scanId is %s; expected str()" % type(scanId))
+ if not isinstance(targetType, str):
+ raise TypeError("targetType is %s; expected str()" % type(targetType))
if not isinstance(moduleList, list):
raise TypeError("moduleList is %s; expected list()" % type(moduleList))
if not isinstance(globalOpts, dict):
raise TypeError("globalOpts is %s; expected dict()" % type(globalOpts))
-
- self.temp = dict()
- self.temp['config'] = deepcopy(globalOpts)
- self.temp['targetValue'] = scanTarget
- self.temp['targetType'] = targetType
- self.temp['moduleList'] = moduleList
- self.temp['scanName'] = scanName
- self.temp['scanId'] = scanId
- self.startScan()
+ if not globalOpts:
+ raise ValueError("globalOpts is empty")
+
+ self.moduleInstances = dict()
+ self.config = deepcopy(globalOpts)
+ self.sf = SpiderFoot(self.config)
+ self.dbh = SpiderFootDb(self.config)
+ self.targetValue = scanTarget
+ self.targetType = targetType
+ self.moduleList = moduleList
+ self.modconfig = dict()
+ self.scanName = scanName
+ self.sf.setDbh(self.dbh)
+
+ # Create a unique ID for this scan and create it in the back-end DB.
+ self.scanId = self.sf.genScanInstanceGUID()
+ self.sf.setGUID(self.scanId)
+ self.dbh.scanInstanceCreate(self.scanId, self.scanName, self.targetValue)
+
+ # Create our target
+ try:
+ self.target = SpiderFootTarget(self.targetValue, self.targetType)
+ except ValueError as e:
+ self.sf.status("Scan [%s] failed: %s" % (self.scanId, e))
+ self.setStatus("ERROR-FAILED", None, time.time() * 1000)
+ raise ValueError("Invalid target: %s" % e)
+ except TypeError as e:
+ self.sf.status("Scan [%s] failed: %s" % (self.scanId, e))
+ self.setStatus("ERROR-FAILED", None, time.time() * 1000)
+ raise TypeError("Invalid target: %s" % e)
+
+ # Save the config current set for this scan
+ self.config['_modulesenabled'] = self.moduleList
+ self.dbh.scanConfigSet(self.scanId, self.sf.configSerialize(deepcopy(self.config)))
+
+ self.setStatus("INITIALIZING", time.time() * 1000, None)
+
+ def getId(self):
+ """Retrieve the unique scan identifier.
+
+ Returns:
+ str: scan id
+ """
+ if hasattr(self, 'scanId'):
+ return self.scanId
+ return None
def setStatus(self, status, started=None, ended=None):
"""Set the status of the currently running scan (if any).
Args:
- status (str): scan status ("RUNNING", "STARTING", "STARTED", "ABORT-REQUESTED", "ABORTED", "FINISHED", "ERROR-FAILED")
+ status (str): scan status
started (str): TBD
ended (str): TBD
@@ -75,60 +105,21 @@ class SpiderFootScanner():
None
"""
- #if self is None:
- # print(("Internal Error: Status set attempted before " + \
- # "SpiderFootScanner was ready."))
- # exit(-1)
+ if status not in ["INITIALIZING", "STARTING", "STARTED", "RUNNING", "ABORT-REQUESTED", "ABORTED", "FINISHED", "ERROR-FAILED"]:
+ raise ValueError("Invalid scan status '%s'" % status)
self.status = status
self.dbh.scanInstanceSet(self.scanId, started, ended, status)
return None
- def run(self):
- """Start running a scan."""
- self.startScan()
-
- def getId(self):
- if hasattr(self, 'scanId'):
- return self.scanId
- return None
-
def startScan(self):
"""Start running a scan."""
- self.moduleInstances = dict()
- self.sf = SpiderFoot(self.temp['config'])
- self.config = deepcopy(self.temp['config'])
- self.dbh = SpiderFootDb(self.temp['config'])
- self.targetValue = self.temp['targetValue']
- self.targetType = self.temp['targetType']
- self.moduleList = self.temp['moduleList']
- self.modconfig = dict()
- self.scanName = self.temp['scanName']
- self.scanId = self.temp['scanId']
+
aborted = False
- self.sf.setDbh(self.dbh)
- # Create a unique ID for this scan and create it in the back-end DB.
- self.sf.setGUID(self.scanId)
- self.dbh.scanInstanceCreate(self.scanId,
- self.scanName, self.targetValue)
self.setStatus("STARTING", time.time() * 1000, None)
-
- # Create our target
- try:
- target = SpiderFootTarget(self.targetValue, self.targetType)
- except BaseException as e:
- self.sf.status("Scan [%s] failed: %s" % (self.scanId, e))
- self.setStatus("ERROR-FAILED", None, time.time() * 1000)
- return None
-
- # Save the config current set for this scan
- self.config['_modulesenabled'] = self.moduleList
- self.dbh.scanConfigSet(self.scanId,
- self.sf.configSerialize(deepcopy(self.config)))
-
self.sf.status("Scan [" + self.scanId + "] initiated.")
- # moduleList = list of modules the user wants to run
+
try:
# Process global options that point to other places for data
@@ -183,6 +174,7 @@ class SpiderFootScanner():
else:
self.config["_internettlds"] = tlddata.splitlines()
+ # moduleList = list of modules the user wants to run
for modName in self.moduleList:
if modName == '':
continue
@@ -214,9 +206,9 @@ class SpiderFootScanner():
# Give modules a chance to 'enrich' the original target with
# aliases of that target.
- newTarget = mod.enrichTarget(target)
+ newTarget = mod.enrichTarget(self.target)
if newTarget is not None:
- target = newTarget
+ self.target = newTarget
self.moduleInstances[modName] = mod
# Override the module's local socket module
@@ -233,7 +225,7 @@ class SpiderFootScanner():
# Register listener modules and then start all modules sequentially
for module in list(self.moduleInstances.values()):
# Register the target with the module
- module.setTarget(target)
+ module.setTarget(self.target)
for listenerModule in list(self.moduleInstances.values()):
# Careful not to register twice or you will get duplicate events
@@ -251,7 +243,7 @@ class SpiderFootScanner():
# Create a pseudo module for the root event to originate from
psMod = SpiderFootPlugin()
psMod.__name__ = "SpiderFoot UI"
- psMod.setTarget(target)
+ psMod.setTarget(self.target)
psMod.setDbh(self.dbh)
psMod.clearListeners()
for mod in list(self.moduleInstances.values()):
diff --git a/sfwebui.py b/sfwebui.py
index c401a620..5c4bc2c3 100644
--- a/sfwebui.py
+++ b/sfwebui.py
@@ -335,7 +335,6 @@ class SpiderFootWebUi:
def rerunscan(self, id):
# Snapshot the current configuration to be used by the scan
cfg = deepcopy(self.config)
- modopts = dict() # Not used yet as module options are set globally
modlist = list()
sf = SpiderFoot(cfg)
dbh = SpiderFootDb(cfg)
@@ -363,27 +362,35 @@ class SpiderFootWebUi:
scantarget = scantarget.lower()
# Start running a new scan
- newId = sf.genScanInstanceGUID(scanname)
- p = mp.Process(target=SpiderFootScanner, args=(scanname, scantarget, targetType, newId,
- modlist, cfg, modopts))
- p.start()
+ try:
+ s = SpiderFootScanner(scanname, scantarget, targetType, modlist, cfg)
+ scanId = s.getId()
+ except BaseException as e:
+ print("[-] Failed to initialize scan: %s" % e)
+ return self.error("Failed to initialize scan: %s" % e)
+ try:
+ p = mp.Process(target=s.startScan())
+ p.daemon = True
+ p.start()
+ except BaseException as e:
+ print("[-] Scan [%s] failed: %s" % (scanId, e))
+ return self.error("Scan [%s] failed: %s" % (scanId, e))
# Wait until the scan has initialized
- while dbh.scanInstanceGet(newId) == None:
+ while dbh.scanInstanceGet(scanId) == None:
print("[info] Waiting for the scan to initialize...")
time.sleep(1)
templ = Template(filename='dyn/scaninfo.tmpl', lookup=self.lookup)
- return templ.render(id=newId, name=str(scanname), docroot=self.docroot,
- status=dbh.scanInstanceGet(newId), pageid="SCANLIST")
+ return templ.render(id=scanId, name=str(scanname), docroot=self.docroot,
+ status=dbh.scanInstanceGet(scanId), pageid="SCANLIST")
rerunscan.exposed = True
def rerunscanmulti(self, ids):
# Snapshot the current configuration to be used by the scan
cfg = deepcopy(self.config)
- modopts = dict() # Not used yet as module options are set globally
modlist = list()
sf = SpiderFoot(cfg)
dbh = SpiderFootDb(cfg)
@@ -409,13 +416,23 @@ class SpiderFootWebUi:
"a human name, IP address, IP subnet, ASN, domain name or host name.")
# Start running a new scan
- newId = sf.genScanInstanceGUID(scanname)
- p = mp.Process(target=SpiderFootScanner, args=(scanname, scantarget.lower(),
- targetType, newId, modlist, cfg, modopts))
- p.start()
+ try:
+ s = SpiderFootScanner(scanname, scantarget, targetType, modlist, cfg)
+ s.getId()
+ except BaseException as e:
+ print("[-] Failed to initialize scan: %s" % e)
+ return self.error("Failed to initialize scan: %s" % e)
+
+ try:
+ p = mp.Process(target=s.startScan())
+ p.daemon = True
+ p.start()
+ except BaseException as e:
+ print("[-] Scan [%s] failed: %s" % (scanId, e))
+ return self.error("Scan [%s] failed: %s" % (scanId, e))
# Wait until the scan has initialized
- while dbh.scanInstanceGet(newId) == None:
+ while dbh.scanInstanceGet(scanId) == None:
print("[info] Waiting for the scan to initialize...")
time.sleep(1)
@@ -769,7 +786,6 @@ class SpiderFootWebUi:
# Snapshot the current configuration to be used by the scan
cfg = deepcopy(self.config)
- modopts = dict() # Not used yet as module options are set globally
modlist = list()
sf = SpiderFoot(cfg)
targetType = None
@@ -835,15 +851,25 @@ class SpiderFootWebUi:
modlist.remove("sfp__stor_stdout")
# Start running a new scan
- scanId = sf.genScanInstanceGUID(scanname)
if targetType in [ "HUMAN_NAME", "USERNAME" ]:
scantarget = scantarget.replace("\"", "")
else:
scantarget = scantarget.lower()
- p = mp.Process(target=SpiderFootScanner, args=(scanname, scantarget, targetType, scanId,
- modlist, cfg, modopts))
- p.daemon = True
- p.start()
+
+ try:
+ s = SpiderFootScanner(scanname, scantarget, targetType, modlist, cfg)
+ scanId = s.getId()
+ except BaseException as e:
+ print("[-] Failed to initialize scan: %s" % e)
+ return self.error("Failed to initialize scan: %s" % e)
+
+ try:
+ p = mp.Process(target=s.startScan())
+ p.daemon = True
+ p.start()
+ except BaseException as e:
+ print("[-] Scan [%s] failed: %s" % (scanId, e))
+ return self.error("Scan [%s] failed: %s" % (scanId, e))
# Wait until the scan has initialized
# Check the database for the scan status results
diff --git a/test/unit/test_spiderfoot.py b/test/unit/test_spiderfoot.py
index 58cccff8..4664aa37 100644
--- a/test/unit/test_spiderfoot.py
+++ b/test/unit/test_spiderfoot.py
@@ -18,8 +18,9 @@ class TestSpiderFoot(unittest.TestCase):
'_fetchtimeout': 5, # number of seconds before giving up on a fetch
'_internettlds': 'https://publicsuffix.org/list/effective_tld_names.dat',
'_internettlds_cache': 72,
+ '_genericusers': "abuse,admin,billing,compliance,devnull,dns,ftp,hostmaster,inoc,ispfeedback,ispsupport,list-request,list,maildaemon,marketing,noc,no-reply,noreply,null,peering,peering-notify,peering-request,phish,phishing,postmaster,privacy,registrar,registry,root,routing-registry,rr,sales,security,spam,support,sysadmin,tech,undisclosed-recipients,unsubscribe,usenet,uucp,webmaster,www",
'__version__': '3.0',
- '__database': 'spiderfoot.db',
+ '__database': 'spiderfoot.test.db', # note: test database file
'__webaddr': '127.0.0.1',
'__webport': 5001,
'__docroot': '', # don't put trailing /
@@ -149,11 +150,11 @@ class TestSpiderFoot(unittest.TestCase):
def test_gen_scan_instance_guid_should_return_a_string(self):
"""
- Test genScanInstanceGUID(self, scanName)
+ Test genScanInstanceGUID(self)
"""
sf = SpiderFoot(dict())
- scan_instance_id = sf.genScanInstanceGUID(None)
+ scan_instance_id = sf.genScanInstanceGUID()
self.assertIsInstance(scan_instance_id, str)
def test_dblog_invalid_dbh_should_raise(self):
@@ -266,27 +267,49 @@ class TestSpiderFoot(unittest.TestCase):
self.assertIsInstance(cache_get, str)
self.assertEqual(data, cache_get)
- @unittest.skip("todo")
- def test_config_serialize_should_return_a_dict(self):
+ def test_config_serialize_invalid_opts_should_raise(self):
"""
Test configSerialize(self, opts, filterSystem=True)
"""
sf = SpiderFoot(dict())
- config = sf.configSerialize(None, None)
- self.assertIsInstance(config, dict)
+ with self.assertRaises(TypeError) as cm:
+ config = sf.configSerialize(None, None)
+
+ def test_config_serialize_should_return_a_dict(self):
+ """
+ Test configSerialize(self, opts, filterSystem=True)
+ """
+ sf = SpiderFoot(dict())
config = sf.configSerialize(dict(), None)
self.assertIsInstance(config, dict)
- @unittest.skip("todo")
+ def test_config_unserialize_invalid_opts_should_raise(self):
+ """
+ Test configUnserialize(self, opts, referencePoint, filterSystem=True)
+ """
+ sf = SpiderFoot(dict())
+
+ with self.assertRaises(TypeError) as cm:
+ config = sf.configUnserialize(None, dict(), None)
+
+ def test_config_unserialize_invalid_reference_point_should_raise(self):
+ """
+ Test configUnserialize(self, opts, referencePoint, filterSystem=True)
+ """
+ sf = SpiderFoot(dict())
+
+ with self.assertRaises(TypeError) as cm:
+ config = sf.configUnserialize(dict(), None, None)
+
def test_config_unserialize_should_return_a_dict(self):
"""
Test configUnserialize(self, opts, referencePoint, filterSystem=True)
"""
sf = SpiderFoot(dict())
- config = sf.configUnserialize(None, None, None)
+ config = sf.configUnserialize(dict(), dict(), True)
self.assertIsInstance(config, dict)
def test_cache_get_invalid_label_should_return_none(self):
diff --git a/test/unit/test_spiderfootdb.py b/test/unit/test_spiderfootdb.py
index 90ccfc79..ab90b6a7 100644
--- a/test/unit/test_spiderfootdb.py
+++ b/test/unit/test_spiderfootdb.py
@@ -17,6 +17,7 @@ class TestSpiderFootDb(unittest.TestCase):
'_fetchtimeout': 5,
'_internettlds': 'https://publicsuffix.org/list/effective_tld_names.dat',
'_internettlds_cache': 72,
+ '_genericusers': "abuse,admin,billing,compliance,devnull,dns,ftp,hostmaster,inoc,ispfeedback,ispsupport,list-request,list,maildaemon,marketing,noc,no-reply,noreply,null,peering,peering-notify,peering-request,phish,phishing,postmaster,privacy,registrar,registry,root,routing-registry,rr,sales,security,spam,support,sysadmin,tech,undisclosed-recipients,unsubscribe,usenet,uucp,webmaster,www",
'__version__': '3.0',
'__database': 'spiderfoot.test.db', # note: test database file
'__webaddr': '127.0.0.1',
diff --git a/test/unit/test_spiderfootscanner.py b/test/unit/test_spiderfootscanner.py
index bbf496ab..e502cf0e 100644
--- a/test/unit/test_spiderfootscanner.py
+++ b/test/unit/test_spiderfootscanner.py
@@ -2,49 +2,105 @@
from sfscan import SpiderFootScanner
import unittest
-class TestSpiderFootScanStatus(unittest.TestCase):
+class TestSpiderFootScanner(unittest.TestCase):
"""
Test SpiderFootScanStatus
"""
+ default_options = {
+ '_debug': False,
+ '__logging': True,
+ '__outputfilter': None,
+ '__blocknotif': False,
+ '_fatalerrors': False,
+ '_useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0',
+ '_dnsserver': '',
+ '_fetchtimeout': 5,
+ '_internettlds': 'https://publicsuffix.org/list/effective_tld_names.dat',
+ '_internettlds_cache': 72,
+ '_genericusers': "abuse,admin,billing,compliance,devnull,dns,ftp,hostmaster,inoc,ispfeedback,ispsupport,list-request,list,maildaemon,marketing,noc,no-reply,noreply,null,peering,peering-notify,peering-request,phish,phishing,postmaster,privacy,registrar,registry,root,routing-registry,rr,sales,security,spam,support,sysadmin,tech,undisclosed-recipients,unsubscribe,usenet,uucp,webmaster,www",
+ '__version__': '3.0',
+ '__database': 'spiderfoot.test.db', # note: test database file
+ '__webaddr': '127.0.0.1',
+ '__webport': 5001,
+ '__docroot': '',
+ '__modules__': None,
+ '_socks1type': '',
+ '_socks2addr': '',
+ '_socks3port': '',
+ '_socks4user': '',
+ '_socks5pwd': '',
+ '_socks6dns': True,
+ '_torctlport': 9051,
+ '__logstdout': False
+ }
- def test_init_no_options_should_raise(self):
+ def test_init(self):
+ """
+ Test __init__(self, scanName, scanTarget, targetType, moduleList, globalOpts)
+ """
+ sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), self.default_options)
+ self.assertIsInstance(sfscan, SpiderFootScanner)
+
+ def test_init_invalid_scan_name_should_raise(self):
"""
- Test __init__(self, scanName, scanTarget, targetType, scanId, moduleList, globalOpts, moduleOpts)
+ Test __init__(self, scanName, scanTarget, targetType, moduleList, globalOpts)
"""
with self.assertRaises(TypeError) as cm:
- sfscan = SpiderFootScanner(None, None, None, None, None, None, None)
-
- @unittest.skip("todo")
- def test_init(self):
+ sfscan = SpiderFootScanner(None, "", "IP_ADDRESS", list(), self.default_options)
+
+ def test_init_invalid_scan_target_should_raise(self):
"""
- Test __init__(self, scanName, scanTarget, targetType, scanId, moduleList, globalOpts, moduleOpts)
+ Test __init__(self, scanName, scanTarget, targetType, moduleList, globalOpts)
"""
- #sfscan = SpiderFootScanner("", "", "", "", list(), dict(), dict())
- self.assertEqual('TBD', 'TBD')
+ with self.assertRaises(TypeError) as cm:
+ sfscan = SpiderFootScanner("", None, "IP_ADDRESS", list(), self.default_options)
- @unittest.skip("todo")
- def test_set_status_should_return_none(self):
+ def test_init_invalid_scan_target_type_should_raise(self):
"""
- Test def setStatus(self, status, started=None, ended=None)
+ Test __init__(self, scanName, scanTarget, targetType, moduleList, globalOpts)
"""
- self.assertEqual('TBD', 'TBD')
+ with self.assertRaises(TypeError) as cm:
+ sfscan = SpiderFootScanner("", "", None, list(), self.default_options)
- @unittest.skip("todo")
- def test_run_should_return_none(self):
+ def test_init_invalid_module_list_should_raise(self):
"""
- Test def run(self)
+ Test __init__(self, scanName, scanTarget, targetType, moduleList, globalOpts)
"""
- self.assertEqual('TBD', 'TBD')
+ with self.assertRaises(TypeError) as cm:
+ sfscan = SpiderFootScanner("", "", "IP_ADDRESS", None, self.default_options)
- @unittest.skip("todo")
- def test_get_id_should_return_none(self):
+ def test_init_invalid_options_should_raise(self):
+ """
+ Test __init__(self, scanName, scanTarget, targetType, moduleList, globalOpts)
+ """
+ with self.assertRaises(TypeError) as cm:
+ sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), None)
+
+ with self.assertRaises(ValueError) as cm:
+ sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), dict())
+
+ def test_set_status_invalid_status_should_raise(self):
+ """
+ Test def setStatus(self, status, started=None, ended=None)
+ """
+ sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), self.default_options)
+ self.assertIsInstance(sfscan, SpiderFootScanner)
+
+ with self.assertRaises(ValueError) as cm:
+ sfscan.setStatus("invalid status", None, None)
+
+ def test_get_id_should_return_a_scan_id(self):
"""
Test def getId(self)
"""
- self.assertEqual('TBD', 'TBD')
+ sfscan = SpiderFootScanner("", "", "IP_ADDRESS", list(), self.default_options)
+ self.assertIsInstance(sfscan, SpiderFootScanner)
+
+ scan_id = sfscan.getId()
+ self.assertIsInstance(scan_id, str)
@unittest.skip("todo")
- def test_start_scan_should_return_none(self):
+ def test_start_scan_should_start_a_scan(self):
"""
Test def startScan(self)
"""
diff --git a/test/unit/test_spiderfoottarget.py b/test/unit/test_spiderfoottarget.py
index 49e5f10c..9139a2ba 100644
--- a/test/unit/test_spiderfoottarget.py
+++ b/test/unit/test_spiderfoottarget.py
@@ -12,15 +12,19 @@ class TestSpiderFootTarget(unittest.TestCase):
'EMAILADDR', 'HUMAN_NAME', 'BGP_AS_OWNER', 'PHONE_NUMBER', "USERNAME"
]
- def test_init_unsupported_target_type_should_raise(self):
+ def test_init_invalid_target_value_should_raise(self):
"""
Test __init__(self, targetValue, typeName)
"""
- target_value = 'example target value'
+ with self.assertRaises(TypeError) as cm:
+ target = SpiderFootTarget(None, 'IP_ADDRESS')
+ def test_init_unsupported_target_type_should_raise(self):
+ """
+ Test __init__(self, targetValue, typeName)
+ """
with self.assertRaises(ValueError) as cm:
- target_type = 'example target type'
- target = SpiderFootTarget(target_value, target_type)
+ target = SpiderFootTarget('example target value', 'example target type')
def test_init_supported_target_types(self):
"""
diff --git a/test/unit/test_spiderfootwebui.py b/test/unit/test_spiderfootwebui.py
index 885a8f70..1215d642 100644
--- a/test/unit/test_spiderfootwebui.py
+++ b/test/unit/test_spiderfootwebui.py
@@ -17,6 +17,7 @@ class TestSpiderFootWebUi(unittest.TestCase):
'_fetchtimeout': 5,
'_internettlds': 'https://publicsuffix.org/list/effective_tld_names.dat',
'_internettlds_cache': 72,
+ '_genericusers': "abuse,admin,billing,compliance,devnull,dns,ftp,hostmaster,inoc,ispfeedback,ispsupport,list-request,list,maildaemon,marketing,noc,no-reply,noreply,null,peering,peering-notify,peering-request,phish,phishing,postmaster,privacy,registrar,registry,root,routing-registry,rr,sales,security,spam,support,sysadmin,tech,undisclosed-recipients,unsubscribe,usenet,uucp,webmaster,www",
'__version__': '3.0',
'__database': 'spiderfoot.test.db', # note: test database file
'__webaddr': '127.0.0.1',