Skip to content

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

sflib: Ensure dataParentChildToTree returns a dict

Brendan Coles32c1a62dd103
diff --git a/sflib.py b/sflib.py
index a94caa5c..018bceb3 100644
--- a/sflib.py
+++ b/sflib.py
@@ -1244,9 +1244,21 @@ class SpiderFoot:
return list(wd.keys())
- # Converts a dictionary of k -> array to a nested
- # tree that can be digested by d3 for visualizations.
def dataParentChildToTree(self, data):
+ """Converts a dictionary of k -> array to a nested
+ tree that can be digested by d3 for visualizations.
+
+ Args:
+ data (dict): dictionary of k -> array
+
+ Returns:
+ dict: nested tree
+ """
+
+ if not isinstance(data, dict):
+ self.error("Data is not a dict", False)
+ return {}
+
def get_children(needle, haystack):
#print("called")
ret = list()
diff --git a/test/unit/test_spiderfoot.py b/test/unit/test_spiderfoot.py
index e47c604b..98da0cfc 100644
--- a/test/unit/test_spiderfoot.py
+++ b/test/unit/test_spiderfoot.py
@@ -618,7 +618,7 @@ class TestSpiderFoot(unittest.TestCase):
"""
Test dataParentChildToTree(self, data)
"""
- sf = SpiderFoot(dict())
+ sf = SpiderFoot(self.default_options)
tree = sf.dataParentChildToTree(None)
self.assertIsInstance(tree, dict)
@@ -629,6 +629,9 @@ class TestSpiderFoot(unittest.TestCase):
tree = sf.dataParentChildToTree("")
self.assertIsInstance(tree, dict)
+ tree = sf.dataParentChildToTree(dict())
+ self.assertIsInstance(tree, dict)
+
def test_resolve_host(self):
"""
Test resolveHost(self, host)