Skip to content

Commit

Permalink
SpiderFootHelpers: move genScanInstanceId to SpiderFootHelpers (smica…
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles authored Jul 7, 2021
1 parent f3ec4b4 commit ea8b71c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def start_scan(sfConfig, sfModules, args):

# Start running a new scan
scanName = target
scanId = sf.genScanInstanceId()
scanId = SpiderFootHelpers.genScanInstanceId()
try:
p = mp.Process(target=SpiderFootScanner, args=(scanName, scanId, target, targetType, modlist, cfg))
p.daemon = True
Expand Down
4 changes: 2 additions & 2 deletions sfscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import dns.resolver

from sflib import SpiderFoot
from spiderfoot import SpiderFootDb, SpiderFootEvent, SpiderFootPlugin, SpiderFootTarget
from spiderfoot import SpiderFootDb, SpiderFootEvent, SpiderFootPlugin, SpiderFootTarget, SpiderFootHelpers


class SpiderFootScanner():
Expand Down Expand Up @@ -112,7 +112,7 @@ def __init__(self, scanName, scanId, targetValue, targetType, moduleList, global
if scanId:
self.__scanId = scanId
else:
self.__scanId = self.__sf.genScanInstanceId()
self.__scanId = SpiderFootHelpers.genScanInstanceId()

self.__sf.scanId = self.__scanId
self.__dbh.scanInstanceCreate(self.__scanId, self.__scanName, self.__targetValue)
Expand Down
8 changes: 3 additions & 5 deletions sfwebui.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ def rerunscan(self, id):
# Snapshot the current configuration to be used by the scan
cfg = deepcopy(self.config)
modlist = list()
sf = SpiderFoot(cfg)
dbh = SpiderFootDb(cfg)
info = dbh.scanInstanceGet(id)

Expand Down Expand Up @@ -558,7 +557,7 @@ def rerunscan(self, id):
scantarget = scantarget.lower()

# Start running a new scan
scanId = sf.genScanInstanceId()
scanId = SpiderFootHelpers.genScanInstanceId()
try:
p = mp.Process(target=SpiderFootScanner, args=(scanname, scanId, scantarget, targetType, modlist, cfg))
p.daemon = True
Expand Down Expand Up @@ -588,7 +587,6 @@ def rerunscanmulti(self, ids):
# Snapshot the current configuration to be used by the scan
cfg = deepcopy(self.config)
modlist = list()
sf = SpiderFoot(cfg)
dbh = SpiderFootDb(cfg)

for id in ids.split(","):
Expand All @@ -614,7 +612,7 @@ def rerunscanmulti(self, ids):
return self.error("Invalid target type. Could not recognize it as a target SpiderFoot supports.")

# Start running a new scan
scanId = sf.genScanInstanceId()
scanId = SpiderFootHelpers.genScanInstanceId()
try:
p = mp.Process(target=SpiderFootScanner, args=(scanname, scanId, scantarget, targetType, modlist, cfg))
p.daemon = True
Expand Down Expand Up @@ -1189,7 +1187,7 @@ def startscan(self, scanname, scantarget, modulelist, typelist, usecase):
scantarget = scantarget.lower()

# Start running a new scan
scanId = sf.genScanInstanceId()
scanId = SpiderFootHelpers.genScanInstanceId()
try:
p = mp.Process(target=SpiderFootScanner, args=(scanname, scanId, scantarget, targetType, modlist, cfg))
p.daemon = True
Expand Down
12 changes: 12 additions & 0 deletions spiderfoot/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import random
import re
import uuid
from networkx import nx
from networkx.readwrite.gexf import GEXFWriter

Expand Down Expand Up @@ -308,6 +309,17 @@ def validLEI(lei):

return True

@staticmethod
def genScanInstanceId():
"""Generate an globally unique ID for this scan.
Returns:
str: scan instance unique ID
"""

return str(uuid.uuid4()).split("-")[0].upper()

@staticmethod
def parseRobotsTxt(robotsTxtData):
"""Parse the contents of robots.txt.
Expand Down
9 changes: 0 additions & 9 deletions test/unit/test_spiderfoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ def test_optValueToData_argument_val_invalid_type_should_return_None(self):
opt_data = sf.optValueToData(invalid_type)
self.assertEqual(opt_data, None)

def test_genScanInstanceId_should_return_a_string(self):
"""
Test genScanInstanceId(self)
"""
sf = SpiderFoot(dict())

scan_instance_id = sf.genScanInstanceId()
self.assertIsInstance(scan_instance_id, str)

def test_dblog_invalid_dbh_should_raise(self):
"""
Test _dblog(self, level, message, component=None)
Expand Down
7 changes: 7 additions & 0 deletions test/unit/test_spiderfoothelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ def test_dataParentChildToTree_should_return_dict(self):
tree = SpiderFootHelpers.dataParentChildToTree({"test": {"123": "456"}})
self.assertIsInstance(tree, dict)

def test_genScanInstanceId_should_return_a_string(self):
"""
Test genScanInstanceId()
"""
scan_instance_id = SpiderFootHelpers.genScanInstanceId()
self.assertIsInstance(scan_instance_id, str)

def test_validLEI_should_return_a_boolean(self):
"""
Test validLEI(lei)
Expand Down

0 comments on commit ea8b71c

Please sign in to comment.