Skip to content

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

tests: update test_spiderfootcli tests

Brendan Coles490d8b93939d
diff --git a/sfcli.py b/sfcli.py
index 7a093b5c..312e153d 100755
--- a/sfcli.py
+++ b/sfcli.py
@@ -80,6 +80,13 @@ class SpiderFootCli(cmd.Cmd):
# Command completion for arguments
def complete_default(self, text, line, startidx, endidx):
ret = list()
+
+ if not isinstance(text, str):
+ return ret
+
+ if not isinstance(line, str):
+ return ret
+
if "-m" in line and line.find("-m") > line.find("-t"):
for m in self.modules:
if m.startswith(text):
@@ -197,6 +204,9 @@ class SpiderFootCli(cmd.Cmd):
# Print nice tables.
def pretty(self, data, titlemap=None):
+ if not data:
+ return ""
+
out = list()
# Get the column titles
maxsize = dict()
@@ -322,6 +332,14 @@ class SpiderFootCli(cmd.Cmd):
# Make a request to the SpiderFoot server
def request(self, url, post=None):
+ if not url:
+ self.edprint("Invalid request URL")
+ return None
+
+ if not isinstance(url, str):
+ self.edprint("Invalid request URL: %s" % url)
+ return None
+
#logging.basicConfig()
#logging.getLogger().setLevel(logging.DEBUG)
#requests_log = logging.getLogger("requests.packages.urllib3")
diff --git a/test/unit/test_spiderfootcli.py b/test/unit/test_spiderfootcli.py
index d43969ca..88252365 100644
--- a/test/unit/test_spiderfootcli.py
+++ b/test/unit/test_spiderfootcli.py
@@ -19,6 +19,7 @@ class TestSpiderFootCli(unittest.TestCase):
"cli.history_file": "",
"cli.spool": False,
"cli.spool_file": "",
+ "cli.ssl_verify": True,
"cli.username": "",
"cli.password": "",
"cli.server_baseurl": "http://127.0.0.1:5001"
@@ -53,45 +54,41 @@ class TestSpiderFootCli(unittest.TestCase):
self.assertIn("Unknown command", output)
- @unittest.skip("todo")
- def test_complete_start(self):
+ def test_complete_start_should_return_a_list(self):
"""
Test complete_start(self, text, line, startidx, endidx)
"""
sfcli = SpiderFootCli()
- sfcli.complete_start(None, None, None, None)
-
- self.assertEqual('TBD', 'TBD')
+ start = sfcli.complete_start(None, None, None, None)
+ self.assertIsInstance(start, list)
+ self.assertEqual([], start)
- @unittest.skip("todo")
- def test_complete_find(self):
+ def test_complete_find_should_return_a_list(self):
"""
Test complete_find(self, text, line, startidx, endidx)
"""
sfcli = SpiderFootCli()
- sfcli.complete_find(None, None, None, None)
+ find = sfcli.complete_find(None, None, None, None)
+ self.assertIsInstance(find, list)
+ self.assertEqual([], find)
- self.assertEqual('TBD', 'TBD')
-
- @unittest.skip("todo")
- def test_complete_data(self):
+ def test_complete_data_should_return_a_list(self):
"""
Test complete_data(self, text, line, startidx, endidx)
"""
sfcli = SpiderFootCli()
- sfcli.complete_data(None, None, None, None)
-
- self.assertEqual('TBD', 'TBD')
+ data = sfcli.complete_data(None, None, None, None)
+ self.assertIsInstance(data, list)
+ self.assertEqual([], data)
- @unittest.skip("todo")
def test_complete_default(self):
"""
Test complete_default(self, text, line, startidx, endidx)
"""
sfcli = SpiderFootCli()
- sfcli.complete_default(None, None, None, None)
-
- self.assertEqual('TBD', 'TBD')
+ default = sfcli.complete_default(None, None, None, None)
+ self.assertIsInstance(default, list)
+ self.assertEqual([], default)
def test_dprint(self):
"""
@@ -137,11 +134,31 @@ class TestSpiderFootCli(unittest.TestCase):
"""
Test do_history(self, line)
"""
- sfcli = SpiderFootCli()
+ sfcli = SpiderFootCli(self.default_options)
+
sfcli.do_history(None)
self.assertEqual('TBD', 'TBD')
+ @unittest.skip("todo")
+ def test_precmd_should_print_line(self):
+ """
+ Test precmd(self, line)
+ """
+ sfcli = SpiderFootCli()
+
+ line = "example line"
+
+ io_output = io.StringIO()
+ sys.stdout = io_output
+ precmd = sfcli.precmd(line)
+ sys.stdout = sys.__stdout__
+ output = io_output.getvalue()
+
+ self.assertEqual(line, precmd)
+
+ self.assertEqual('TBD', 'TBD')
+
@unittest.skip("todo")
def test_precmd_should_return_line(self):
"""
@@ -149,7 +166,8 @@ class TestSpiderFootCli(unittest.TestCase):
"""
sfcli = SpiderFootCli()
- line = 'example line'
+ line = "example line"
+
precmd = sfcli.precmd(line)
self.assertEqual(line, precmd)
@@ -187,15 +205,17 @@ class TestSpiderFootCli(unittest.TestCase):
self.assertIn("example debug output", output)
- @unittest.skip("todo")
- def test_pretty(self):
+ def test_pretty_should_return_a_string(self):
"""
Test pretty(self, data, titlemap=None)
"""
sfcli = SpiderFootCli()
- sfcli.pretty(None, None)
- self.assertEqual('TBD', 'TBD')
+ invalid_types = [None, "", list(), dict()]
+ for invalid_type in invalid_types:
+ with self.subTest(invalid_type=invalid_type):
+ pretty = sfcli.pretty(invalid_type)
+ self.assertEqual("", pretty)
@unittest.skip("todo")
def test_request(self):