Skip to content

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

Tests: Use empty bytes() for type tests (#1697)

bcoles368fe2b0b917
diff --git a/test/unit/spiderfoot/test_spiderfootevent.py b/test/unit/spiderfoot/test_spiderfootevent.py
index b926ad54..08c52cf6 100644
--- a/test/unit/spiderfoot/test_spiderfootevent.py
+++ b/test/unit/spiderfoot/test_spiderfootevent.py
@@ -5,14 +5,8 @@ from spiderfoot import SpiderFootEvent
class TestSpiderFootEvent(unittest.TestCase):
- """
- Test SpiderFootEvent
- """
def test_init_root_event_should_create_event(self):
- """
- Test __init__(self, eventType, data, module, sourceEvent)
- """
event_data = 'example event data'
module = 'example module'
source_event = ''
@@ -22,9 +16,6 @@ class TestSpiderFootEvent(unittest.TestCase):
self.assertIsInstance(evt, SpiderFootEvent)
def test_init_nonroot_event_with_root_sourceEvent_should_create_event(self):
- """
- Test __init__(self, eventType, data, module, sourceEvent)
- """
event_type = 'ROOT'
event_data = 'example event data'
module = ''
@@ -38,9 +29,6 @@ class TestSpiderFootEvent(unittest.TestCase):
self.assertIsInstance(evt, SpiderFootEvent)
def test_init_argument_eventType_of_invalid_type_should_raise_TypeError(self):
- """
- Test __init__(self, eventType, data, module, sourceEvent)
- """
event_type = 'ROOT'
event_data = 'example event data'
module = ''
@@ -49,7 +37,7 @@ class TestSpiderFootEvent(unittest.TestCase):
module = 'example module'
- invalid_types = [None, list(), dict()]
+ invalid_types = [None, bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -69,14 +57,11 @@ class TestSpiderFootEvent(unittest.TestCase):
SpiderFootEvent(event_type, event_data, module, source_event)
def test_init_argument_data_of_invalid_type_should_raise_TypeError(self):
- """
- Test __init__(self, eventType, data, module, sourceEvent)
- """
event_type = 'ROOT'
module = ''
source_event = ''
- invalid_types = [None, list(), dict()]
+ invalid_types = [None, bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -97,16 +82,13 @@ class TestSpiderFootEvent(unittest.TestCase):
SpiderFootEvent(event_type, event_data, module, source_event)
def test_init_argument_module_of_invalid_type_should_raise_TypeError(self):
- """
- Test __init__(self, eventType, data, module, sourceEvent)
- """
event_type = 'ROOT'
event_data = 'example event data'
module = ''
source_event = SpiderFootEvent(event_type, event_data, module, "ROOT")
event_type = 'example non-root event type'
- invalid_types = [None, list(), dict()]
+ invalid_types = [None, bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -127,16 +109,13 @@ class TestSpiderFootEvent(unittest.TestCase):
SpiderFootEvent(event_type, event_data, module, source_event)
def test_init_argument_sourceEvent_of_invalid_type_should_raise_TypeError(self):
- """
- Test __init__(self, eventType, data, module, sourceEvent)
- """
event_type = 'ROOT'
event_data = 'example event data'
module = ''
event_type = 'example non-root event type'
module = 'example module'
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -148,7 +127,7 @@ class TestSpiderFootEvent(unittest.TestCase):
module = ''
source_event = ''
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -174,7 +153,7 @@ class TestSpiderFootEvent(unittest.TestCase):
module = ''
source_event = ''
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -200,7 +179,7 @@ class TestSpiderFootEvent(unittest.TestCase):
module = ''
source_event = ''
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -239,7 +218,7 @@ class TestSpiderFootEvent(unittest.TestCase):
source_event = ''
evt = SpiderFootEvent(event_type, event_data, module, source_event)
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -264,7 +243,7 @@ class TestSpiderFootEvent(unittest.TestCase):
source_event = ''
evt = SpiderFootEvent(event_type, event_data, module, source_event)
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -289,7 +268,7 @@ class TestSpiderFootEvent(unittest.TestCase):
source_event = ''
evt = SpiderFootEvent(event_type, event_data, module, source_event)
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -329,9 +308,6 @@ class TestSpiderFootEvent(unittest.TestCase):
self.assertEqual(module_data_source, evt.moduleDataSource)
def test_asdict_root_event_should_return_event_as_a_dict(self):
- """
- Test asDict(self)
- """
event_data = 'example event data'
module = 'example module data'
source_event = ''
@@ -346,9 +322,6 @@ class TestSpiderFootEvent(unittest.TestCase):
self.assertEqual(evt_dict['module'], module)
def test_asdict_nonroot_event_should_return_event_as_a_dict(self):
- """
- Test asDict(self)
- """
event_type = 'ROOT'
event_data = 'example event data'
module = ''
diff --git a/test/unit/spiderfoot/test_spiderfoothelpers.py b/test/unit/spiderfoot/test_spiderfoothelpers.py
index 0f396781..6917ee66 100644
--- a/test/unit/spiderfoot/test_spiderfoothelpers.py
+++ b/test/unit/spiderfoot/test_spiderfoothelpers.py
@@ -7,35 +7,20 @@ from spiderfoot import SpiderFootHelpers
@pytest.mark.usefixtures
class TestSpiderFootHelpers(unittest.TestCase):
- """
- Test SpiderFootHelpers
- """
def test_data_path_should_return_a_string(self):
- """
- Test dataPath()
- """
data_path = SpiderFootHelpers.dataPath()
self.assertIsInstance(data_path, str)
def test_cache_path_should_return_a_string(self):
- """
- Test cachePath()
- """
cache_path = SpiderFootHelpers.cachePath()
self.assertIsInstance(cache_path, str)
def test_log_path_should_return_a_string(self):
- """
- Test logPath()
- """
log_path = SpiderFootHelpers.logPath()
self.assertIsInstance(log_path, str)
def test_target_type(self):
- """
- Test targetType(target)
- """
target_type = SpiderFootHelpers.targetTypeFromString("0.0.0.0")
self.assertEqual('IP_ADDRESS', target_type)
target_type = SpiderFootHelpers.targetTypeFromString("[email protected]")
@@ -58,9 +43,6 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertEqual('BITCOIN_ADDRESS', target_type)
def test_target_type_invalid_seed_should_return_none(self):
- """
- Test targetType(target)
- """
target_type = SpiderFootHelpers.targetTypeFromString(None)
self.assertEqual(None, target_type)
@@ -113,26 +95,17 @@ class TestSpiderFootHelpers(unittest.TestCase):
SpiderFootHelpers.usernamesFromWordlists(['does not exist'])
def test_buildGraphData_invalid_data_type_should_raise_TypeError(self):
- """
- Test buildGraphData(data, flt=list())
- """
- invalid_types = [None, "", dict(), int()]
+ invalid_types = [None, "", bytes(), dict(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
SpiderFootHelpers.buildGraphData(invalid_type)
def test_buildGraphData_empty_data_should_raise_ValueError(self):
- """
- Test buildGraphData(data, flt=list())
- """
with self.assertRaises(ValueError):
SpiderFootHelpers.buildGraphData([])
def test_buildGraphData_data_row_with_invalid_number_of_columns_should_raise_ValueError(self):
- """
- Test buildGraphData(data, flt=list())
- """
with self.assertRaises(ValueError):
SpiderFootHelpers.buildGraphData(
[
@@ -151,51 +124,33 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertEqual('TBD', 'TBD')
def test_buildGraphGexf_should_return_bytes(self):
- """
- Test buildGraphGexf(root, title, data, flt=[])
- """
gexf = SpiderFootHelpers.buildGraphGexf('test root', 'test title', [["test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "ENTITY", "test", "test", "test"]])
self.assertIsInstance(gexf, bytes)
self.assertEqual('TBD', 'TBD')
def test_buildGraphJson_should_return_a_string(self):
- """
- Test buildGraphJson(root, data, flt=list())
- """
json = SpiderFootHelpers.buildGraphJson('test root', [["test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "ENTITY", "test", "test", "test"]])
self.assertIsInstance(json, str)
self.assertEqual('TBD', 'TBD')
def test_dataParentChildToTree_invalid_data_type_should_return_TypeError(self):
- """
- Test dataParentChildToTree(data)
- """
- invalid_types = [None, "", list(), int()]
+ invalid_types = [None, "", bytes(), list(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
SpiderFootHelpers.dataParentChildToTree(invalid_type)
def test_dataParentChildToTree_empty_data_should_return_ValueError(self):
- """
- Test dataParentChildToTree(data)
- """
with self.assertRaises(ValueError):
SpiderFootHelpers.dataParentChildToTree(dict())
def test_dataParentChildToTree_should_return_dict(self):
- """
- Test dataParentChildToTree(data)
- """
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)
@@ -222,28 +177,28 @@ class TestSpiderFootHelpers(unittest.TestCase):
)
def test_extractLinksFromHtml_invalid_url_should_raise_TypeError(self):
- invalid_types = [None, list(), dict()]
+ invalid_types = [None, bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
SpiderFootHelpers.extractLinksFromHtml(invalid_type, 'example html content', 'domains')
def test_extractLinksFromHtml_invalid_data_should_raise_TypeError(self):
- invalid_types = [None, list(), dict()]
+ invalid_types = [None, bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
SpiderFootHelpers.extractLinksFromHtml("", invalid_type, 'domains')
def test_extractLinksFromHtml_invalid_domains_should_return_a_dict(self):
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
parse_links = SpiderFootHelpers.extractLinksFromHtml('url', 'example html content', invalid_type)
self.assertIsInstance(parse_links, dict)
def test_extractHashesFromText_should_return_a_list(self):
- invalid_types = [None, list(), dict(), int()]
+ invalid_types = [None, list(), bytes(), dict(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
hashes = SpiderFootHelpers.extractHashesFromText(invalid_type)
@@ -264,7 +219,7 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertIn(("SHA512", sha512_hash), hashes)
def test_valid_email_should_return_a_boolean(self):
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
valid_email = SpiderFootHelpers.validEmail(invalid_type)
@@ -292,7 +247,7 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertTrue(valid_email)
def test_validPhoneNumber_should_return_a_boolean(self):
- invalid_types = [None, "", list(), dict(), int()]
+ invalid_types = [None, "", bytes(), list(), dict(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
valid_phone = SpiderFootHelpers.validPhoneNumber(invalid_type)
@@ -312,7 +267,7 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertTrue(valid_phone)
def test_validLEI_should_return_a_boolean(self):
- invalid_types = [None, "", list(), dict(), int()]
+ invalid_types = [None, "", bytes(), list(), dict(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
valid_phone = SpiderFootHelpers.validLEI(invalid_type)
@@ -351,7 +306,7 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertIn('[email protected]', emails)
def test_extractEmailsFromText_invalid_data_should_return_list(self):
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
emails = SpiderFootHelpers.extractEmailsFromText(invalid_type)
@@ -367,7 +322,7 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertEqual(len(keys), 2)
def test_extractIbansFromText_should_return_a_list(self):
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
ibans = SpiderFootHelpers.extractIbansFromText(invalid_type)
@@ -475,7 +430,7 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertNotIn(iban, extract_ibans)
def test_extractCreditCardsFromText_should_return_a_list(self):
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
cards = SpiderFootHelpers.extractCreditCardsFromText(invalid_type)
@@ -486,7 +441,7 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertEqual(["4111111111111111"], cards)
def test_extractUrlsFromText_should_extract_urls_from_string(self):
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
cards = SpiderFootHelpers.extractUrlsFromText(invalid_type)
@@ -498,7 +453,7 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertIn("http://example.spiderfoot.net:1337/path", urls)
def test_extractUrlsFromRobotsTxt_should_return_list(self):
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
robots_txt = SpiderFootHelpers.extractUrlsFromRobotsTxt(invalid_type)
@@ -513,9 +468,6 @@ class TestSpiderFootHelpers(unittest.TestCase):
self.assertIn("/disallowed/path", robots_txt)
def test_sanitise_input(self):
- """
- Test sanitiseInput(self, cmd)
- """
safe = SpiderFootHelpers.sanitiseInput("example-string")
self.assertIsInstance(safe, bool)
self.assertTrue(safe)
diff --git a/test/unit/spiderfoot/test_spiderfoottarget.py b/test/unit/spiderfoot/test_spiderfoottarget.py
index 60cf3fc6..ba98f016 100644
--- a/test/unit/spiderfoot/test_spiderfoottarget.py
+++ b/test/unit/spiderfoot/test_spiderfoottarget.py
@@ -5,9 +5,6 @@ from spiderfoot import SpiderFootTarget
class TestSpiderFootTarget(unittest.TestCase):
- """
- Test SpiderFootTarget
- """
valid_target_types = [
'IP_ADDRESS', 'IPV6_ADDRESS', 'NETBLOCK_OWNER', 'INTERNET_NAME',
@@ -16,41 +13,29 @@ class TestSpiderFootTarget(unittest.TestCase):
]
def test_init_argument_targetValue_invalid_type_should_raise_TypeError(self):
- """
- Test __init__(self, targetValue, typeName)
- """
target_type = 'IP_ADDRESS'
- invalid_types = [None, list(), dict(), int()]
+ invalid_types = [None, list(), bytes(), dict(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
SpiderFootTarget(invalid_type, target_type)
def test_init_argument_targetType_invalid_type_should_raise_TypeError(self):
- """
- Test __init__(self, targetValue, typeName)
- """
target_value = 'example target value'
- invalid_types = [None, list(), dict(), int()]
+ invalid_types = [None, list(), bytes(), dict(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
SpiderFootTarget(target_value, invalid_type)
def test_init_argument_targetType_invalid_should_raise_ValueError(self):
- """
- Test __init__(self, targetValue, typeName)
- """
target_value = 'example target value'
with self.assertRaises(ValueError):
SpiderFootTarget(target_value, 'invalid target type')
def test_init_supported_target_types(self):
- """
- Test __init__(self, targetValue, typeName)
- """
target_value = 'example target value'
for target_type in self.valid_target_types:
@@ -61,9 +46,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertEqual(target.targetValue, target_value)
def test_setAlias_invalid_alias_should_not_set_alias(self):
- """
- Test setAlias(self, value, typeName)
- """
target_value = 'example target value'
target_type = 'IP_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
@@ -80,9 +62,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertEqual([], target_aliases)
def test_setAlias_should_set_alias(self):
- """
- Test setAlias(self, value, typeName)
- """
target_value = 'example target value'
target_type = 'IP_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
@@ -101,9 +80,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertEqual(expected_aliases, target_aliases)
def test_targetType_attribute_should_return_a_string(self):
- """
- Test targetType attribute
- """
target_value = 'example target value'
target_type = 'IP_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
@@ -112,13 +88,10 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertEqual(target_type, target.targetType)
def test_targetType_attribute_setter_invalid_type_should_raise_TypeError(self):
- """
- Test targetType attribute
- """
target_value = 'example target value'
target_type = 'IP_ADDRESS'
- invalid_types = [None, list(), dict(), int()]
+ invalid_types = [None, list(), bytes(), dict(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -126,9 +99,6 @@ class TestSpiderFootTarget(unittest.TestCase):
target.targetType = invalid_type
def test_targetValue_attribute_should_return_a_string(self):
- """
- Test targetValue attribute
- """
target_value = 'example target value'
target_type = 'IP_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
@@ -137,13 +107,10 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertEqual(target_value, target.targetValue)
def test_targetValue_attribute_setter_invalid_type_should_raise_TypeError(self):
- """
- Test targetValue attribute
- """
target_value = 'example target value'
target_type = 'IP_ADDRESS'
- invalid_types = [None, list(), dict(), int()]
+ invalid_types = [None, list(), bytes(), dict(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
with self.assertRaises(TypeError):
@@ -151,9 +118,6 @@ class TestSpiderFootTarget(unittest.TestCase):
target.targetValue = invalid_type
def test_targetValue_attribute_setter_empty_value_should_raise_ValueError(self):
- """
- Test targetValue attribute
- """
target_value = 'example target value'
target_type = 'IP_ADDRESS'
@@ -162,9 +126,6 @@ class TestSpiderFootTarget(unittest.TestCase):
target.targetValue = ""
def test_targetAliases_attribute_should_return_a_list(self):
- """
- Test targetAliases attribute
- """
target_value = 'example target value'
target_type = 'IP_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
@@ -228,23 +189,17 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertEqual(list, type(addresses))
def test_matches_argument_value_invalid_type_should_return_False(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = 'example target value'
target_type = 'IP_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
- invalid_types = [None, list(), dict(), int()]
+ invalid_types = [None, list(), bytes(), dict(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
matches = target.matches(invalid_type)
self.assertFalse(matches)
def test_matches_argument_value_matching_ipv4_address_should_return_True(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = '1.1.1.1'
target_type = 'IP_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
@@ -253,9 +208,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertTrue(matches)
def test_matches_argument_value_unmatching_ipv4_address_should_return_False(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = '1.1.1.1'
target_type = 'IP_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
@@ -264,9 +216,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertFalse(matches)
def test_matches_argument_value_unmatching_ipv4_address_in_same_subnet_when_targetType_is_netblock_should_return_True(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = '127.0.0.0/24'
target_type = 'NETBLOCK_OWNER'
target = SpiderFootTarget(target_value, target_type)
@@ -275,9 +224,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertTrue(matches)
def test_matches_argument_value_matching_ipv6_address_should_return_True(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = '::1'
target_type = 'IPV6_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
@@ -286,9 +232,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertTrue(matches)
def test_matches_argument_value_unmatching_ipv6_address_should_return_False(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = '::1'
target_type = 'IPV6_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
@@ -297,9 +240,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertFalse(matches)
def test_matches_argument_value_matching_internet_name_should_return_True(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = 'spiderfoot.net'
target_type = 'INTERNET_NAME'
target = SpiderFootTarget(target_value, target_type)
@@ -308,9 +248,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertTrue(matches)
def test_matches_argument_value_unmatching_internet_name_should_return_False(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = 'spiderfoot.net'
target_type = 'INTERNET_NAME'
target = SpiderFootTarget(target_value, target_type)
@@ -319,9 +256,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertFalse(matches)
def test_matches_argument_includeChildren_true_with_matching_target_subdomain_should_return_True(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = 'spiderfoot.net'
target_type = 'INTERNET_NAME'
target = SpiderFootTarget(target_value, target_type)
@@ -330,9 +264,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertTrue(matches)
def test_matches_argument_includeParents_true_with_matching_target_parent_domain_should_return_True(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
parent_domain = 'spiderfoot.net'
target_value = f"test.{parent_domain}"
target_type = 'INTERNET_NAME'
@@ -342,9 +273,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertTrue(matches)
def test_matches_argument_value_any_human_name_should_return_True(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = 'SpiderFoot'
target_type = 'HUMAN_NAME'
target = SpiderFootTarget(target_value, target_type)
@@ -353,9 +281,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertTrue(matches)
def test_matches_argument_value_any_phone_number_should_return_True(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = 'SpiderFoot'
target_type = 'PHONE_NUMBER'
target = SpiderFootTarget(target_value, target_type)
@@ -364,9 +289,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertTrue(matches)
def test_matches_argument_value_any_bitcoin_address_should_return_True(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = 'SpiderFoot'
target_type = 'BITCOIN_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
@@ -375,9 +297,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertTrue(matches)
def test_matches_argument_value_any_username_should_return_True(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = 'SpiderFoot'
target_type = 'USERNAME'
target = SpiderFootTarget(target_value, target_type)
@@ -386,9 +305,6 @@ class TestSpiderFootTarget(unittest.TestCase):
self.assertTrue(matches)
def test_matches_argument_value_with_empty_value_should_return_False(self):
- """
- Test matches(self, value, includeParents=False, includeChildren=True)
- """
target_value = 'example target value'
target_type = 'IP_ADDRESS'
target = SpiderFootTarget(target_value, target_type)
diff --git a/test/unit/test_spiderfoot.py b/test/unit/test_spiderfoot.py
index ac14bd75..d94d2995 100644
--- a/test/unit/test_spiderfoot.py
+++ b/test/unit/test_spiderfoot.py
@@ -7,9 +7,6 @@ from sflib import SpiderFoot
@pytest.mark.usefixtures
class TestSpiderFoot(unittest.TestCase):
- """
- Test SpiderFoot
- """
default_modules = [
"sfp_binstring",
@@ -32,25 +29,16 @@ class TestSpiderFoot(unittest.TestCase):
test_tlds = "// ===BEGIN ICANN DOMAINS===\n\ncom\nnet\norg\n\n// // ===END ICANN DOMAINS===\n"
def test_init_argument_options_of_invalid_type_should_raise_TypeError(self):
- """
- Test __init__(self, options):
- """
- invalid_types = [None, "", list(), int()]
+ invalid_types = [None, "", bytes(), list(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type), self.assertRaises(TypeError):
SpiderFoot(invalid_type)
def test_init_argument_options_with_empty_dict(self):
- """
- Test __init__(self, options):
- """
sf = SpiderFoot(dict())
self.assertIsInstance(sf, SpiderFoot)
def test_init_argument_options_with_default_options(self):
- """
- Test __init__(self, options):
- """
sf = SpiderFoot(self.default_options)
self.assertIsInstance(sf, SpiderFoot)
@@ -73,9 +61,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual('new socket', sf.socksProxy)
def test_optValueToData_should_return_data_as_string(self):
- """
- Test optValueToData(self, val)
- """
sf = SpiderFoot(self.default_options)
test_string = "example string"
@@ -84,9 +69,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual(test_string, opt_data)
def test_optValueToData_argument_val_filename_should_return_file_contents_as_string(self):
- """
- Test optValueToData(self, val)
- """
sf = SpiderFoot(self.default_options)
test_string = "@VERSION"
@@ -95,30 +77,21 @@ class TestSpiderFoot(unittest.TestCase):
self.assertTrue(opt_data.startswith("SpiderFoot"))
def test_optValueToData_argument_val_invalid_type_should_return_None(self):
- """
- Test optValueToData(self, val)
- """
sf = SpiderFoot(self.default_options)
- invalid_types = [None, list(), int(), dict()]
+ invalid_types = [None, bytes(), list(), int(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
opt_data = sf.optValueToData(invalid_type)
self.assertEqual(opt_data, None)
def test_error(self):
- """
- Test error(self, error):
- """
sf = SpiderFoot(self.default_options)
sf.error(None)
self.assertEqual('TBD', 'TBD')
def test_fatal_should_exit(self):
- """
- Test fatal(self, error)
- """
sf = SpiderFoot(self.default_options)
with self.assertRaises(SystemExit) as cm:
@@ -127,36 +100,24 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual(cm.exception.code, -1)
def test_status(self):
- """
- Test status(self, message)
- """
sf = SpiderFoot(self.default_options)
sf.status(None)
self.assertEqual('TBD', 'TBD')
def test_info(self):
- """
- Test info(self, message)
- """
sf = SpiderFoot(self.default_options)
sf.info(None)
self.assertEqual('TBD', 'TBD')
def test_debug(self):
- """
- Test debug(self, message)
- """
sf = SpiderFoot(self.default_options)
sf.debug(None)
self.assertEqual('TBD', 'TBD')
def test_hash_string_should_return_a_string(self):
- """
- Test hashstring(self, string)
- """
sf = SpiderFoot(dict())
hash_string = sf.hashstring('example string')
@@ -164,10 +125,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual("aedfb92b3053a21a114f4f301a02a3c6ad5dff504d124dc2cee6117623eec706", hash_string)
def test_cache_get_should_return_a_string(self):
- """
- Test cachePut(self, label, data)
- Test cacheGet(self, label, timeoutHrs)
- """
sf = SpiderFoot(dict())
label = 'test-cache-label'
@@ -180,72 +137,48 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual(data, cache_get)
def test_config_serialize_invalid_opts_should_raise(self):
- """
- Test configSerialize(self, opts, filterSystem=True)
- """
sf = SpiderFoot(dict())
with self.assertRaises(TypeError):
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)
def test_config_unserialize_invalid_opts_should_raise(self):
- """
- Test configUnserialize(self, opts, referencePoint, filterSystem=True)
- """
sf = SpiderFoot(dict())
with self.assertRaises(TypeError):
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):
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(dict(), dict(), True)
self.assertIsInstance(config, dict)
def test_cache_get_invalid_label_should_return_none(self):
- """
- Test cacheGet(self, label, timeoutHrs)
- """
sf = SpiderFoot(dict())
cache_get = sf.cacheGet('', sf.opts.get('cacheperiod', 0))
self.assertEqual(None, cache_get)
def test_cache_get_invalid_timeout_should_return_none(self):
- """
- Test cacheGet(self, label, timeoutHrs)
- """
sf = SpiderFoot(dict())
cache_get = sf.cacheGet('', None)
self.assertEqual(None, cache_get)
def test_modulesProducing_argument_events_should_return_a_list(self):
- """
- Test modulesProducing(self, events)
- """
sf = SpiderFoot(self.default_options)
events = ['IP_ADDRESS', 'DOMAIN_NAME', 'INTERNET_NAME']
@@ -254,18 +187,12 @@ class TestSpiderFoot(unittest.TestCase):
self.assertIsInstance(modules_producing, list)
def test_modulesProducing_argument_events_with_empty_value_should_return_a_list(self):
- """
- Test modulesProducing(self, events)
- """
sf = SpiderFoot(dict())
modules_producing = sf.modulesProducing(list())
self.assertIsInstance(modules_producing, list)
def test_modulesConsuming_argument_events_should_return_a_list(self):
- """
- Test modulesConsuming(self, events)
- """
sf = SpiderFoot(self.default_options)
events = ['IP_ADDRESS', 'DOMAIN_NAME', 'INTERNET_NAME']
@@ -274,54 +201,36 @@ class TestSpiderFoot(unittest.TestCase):
self.assertIsInstance(modules_consuming, list)
def test_modulesConsuming_argument_events_with_empty_value_should_return_a_list(self):
- """
- Test modulesConsuming(self, events)
- """
sf = SpiderFoot(dict())
modules_consuming = sf.modulesConsuming(list())
self.assertIsInstance(modules_consuming, list)
def test_eventsFromModules_argument_modules_with_empty_value_should_return_a_list(self):
- """
- Test eventsFromModules(self, modules)
- """
sf = SpiderFoot(self.default_options)
events_from_modules = sf.eventsFromModules(list())
self.assertIsInstance(events_from_modules, list)
def test_eventsFromModules_argument_modules_should_return_events(self):
- """
- Test eventsFromModules(self, modules)
- """
sf = SpiderFoot(self.default_options)
events_from_modules = sf.eventsFromModules(self.default_modules)
self.assertIsInstance(events_from_modules, list)
def test_eventsToModules_argument_modules_with_empty_value_should_return_a_list(self):
- """
- Test eventsToModules(self, modules)
- """
sf = SpiderFoot(self.default_options)
events_to_modules = sf.eventsToModules(list())
self.assertIsInstance(events_to_modules, list)
def test_eventsToModules_argument_modules_should_return_events(self):
- """
- Test eventsToModules(self, modules)
- """
sf = SpiderFoot(self.default_options)
events_to_modules = sf.eventsToModules(self.default_modules)
self.assertIsInstance(events_to_modules, list)
def test_url_fqdn_should_return_a_string(self):
- """
- Test urlFQDN(self, url)
- """
sf = SpiderFoot(dict())
fqdn = sf.urlFQDN('http://localhost.local')
@@ -329,9 +238,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual("localhost.local", fqdn)
def test_domain_keyword_should_return_a_string(self):
- """
- Test domainKeyword(self, domain, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
@@ -344,9 +250,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual('spiderfööt', keyword)
def test_domain_keyword_invalid_domain_should_return_none(self):
- """
- Test domainKeyword(self, domain, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
@@ -364,9 +267,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual(None, keyword)
def test_domain_keywords_should_return_a_set(self):
- """
- Test domainKeywords(self, domainList, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
@@ -377,9 +277,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertIn('example', keywords)
def test_domain_keywords_invalid_domainlist_should_return_a_set(self):
- """
- Test domainKeyword(self, domain, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
@@ -391,9 +288,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertIsInstance(keywords, set)
def test_host_domain_invalid_host_should_return_none(self):
- """
- Test hostDomain(self, hostname, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
@@ -401,9 +295,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual(None, host_domain)
def test_host_domain_should_return_a_string(self):
- """
- Test hostDomain(self, hostname, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
@@ -420,18 +311,12 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual('spiderfoot.net', host_domain)
def test_host_domain_invalid_tldlist_should_return_none(self):
- """
- Test hostDomain(self, hostname, tldList)
- """
sf = SpiderFoot(dict())
host_domain = sf.hostDomain('spiderfoot.net', None)
self.assertEqual(None, host_domain)
def test_is_domain_valid_domain_should_return_true(self):
- """
- Test isDomain(self, hostname, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
@@ -440,13 +325,10 @@ class TestSpiderFoot(unittest.TestCase):
self.assertTrue(is_domain)
def test_is_domain_invalid_domain_should_return_false(self):
- """
- Test isDomain(self, hostname, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
is_domain = sf.isDomain(invalid_type, sf.opts.get('_internettlds'))
@@ -462,9 +344,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertFalse(is_domain)
def test_is_domain_invalid_tldlist_should_return_false(self):
- """
- Test isDomain(self, hostname, tldList)
- """
sf = SpiderFoot(self.default_options)
is_domain = sf.isDomain('spiderfoot.net', None)
@@ -472,9 +351,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertFalse(is_domain)
def test_is_domain_invalid_tld_should_return_false(self):
- """
- Test isDomain(self, hostname, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
@@ -483,9 +359,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertFalse(is_domain)
def test_valid_host_invalid_tldlist_should_return_false(self):
- """
- Test validHost(self, hostname, tldList)
- """
sf = SpiderFoot(self.default_options)
is_host = sf.validHost('spiderfoot.net', None)
@@ -493,9 +366,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertFalse(is_host)
def test_valid_host_valid_host_should_return_true(self):
- """
- Test validHost(self, hostname, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
@@ -504,13 +374,10 @@ class TestSpiderFoot(unittest.TestCase):
self.assertTrue(is_host)
def test_valid_host_invalid_host_should_return_false(self):
- """
- Test validHost(self, hostname, tldList)
- """
sf = SpiderFoot(self.default_options)
sf.opts['_internettlds'] = self.test_tlds
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
is_valid = sf.validHost(invalid_type, sf.opts.get('_internettlds'))
@@ -534,9 +401,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertFalse(is_valid)
def test_valid_ip_should_return_a_boolean(self):
- """
- Test validIP(self, address)
- """
sf = SpiderFoot(dict())
valid_ip = sf.validIP('0.0.0.0')
@@ -544,9 +408,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertTrue(valid_ip)
def test_valid_ip6_should_return_a_boolean(self):
- """
- Test validIP6(self, address)
- """
sf = SpiderFoot(dict())
valid_ip6 = sf.validIP6('::1')
@@ -554,12 +415,9 @@ class TestSpiderFoot(unittest.TestCase):
self.assertTrue(valid_ip6)
def test_valid_ip_network_should_return_a_boolean(self):
- """
- Test validIpNetwork(self, cidr)
- """
sf = SpiderFoot(dict())
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
valid_ip_network = sf.validIpNetwork(invalid_type)
@@ -574,16 +432,15 @@ class TestSpiderFoot(unittest.TestCase):
self.assertIsInstance(valid_ip_network, bool)
self.assertTrue(valid_ip_network)
- def test_isPublicIpAddress_should_return_a_boolean(self):
- """
- Test isPublicIpAddress(self, ip)
- """
+ def test_isPublicIpAddress_argument_ip_public_ip_address_should_return_True(self):
sf = SpiderFoot(dict())
-
self.assertTrue(sf.isPublicIpAddress('1.1.1.1'))
+ self.assertTrue(sf.isPublicIpAddress('8.8.8.8'))
+
+ def test_isPublicIpAddress_argument_ip_nonpublic_ip_address_should_return_False(self):
+ sf = SpiderFoot(dict())
ips = [
- 'invalid ip address',
'0.0.0.0',
'127.0.0.1',
'10.1.1.1',
@@ -602,33 +459,32 @@ class TestSpiderFoot(unittest.TestCase):
with self.subTest(ip=ip):
self.assertFalse(sf.isPublicIpAddress(ip))
- def test_normalize_dns(self):
- """
- Test normalizeDNS(self, res)
- """
- sf = SpiderFoot(self.default_options)
+ def test_isPublicIpAddress_argument_ip_invalid_ip_address_should_return_False(self):
+ sf = SpiderFoot(dict())
+ self.assertFalse(sf.isPublicIpAddress('invalid ip address'))
+
+ invalid_types = [None, "", bytes(), list(), dict()]
+ for invalid_type in invalid_types:
+ with self.subTest(invalid_type=invalid_type):
+ self.assertFalse(sf.isPublicIpAddress(invalid_type))
+ def test_normalizeDNS_should_strip_trailing_dots(self):
+ sf = SpiderFoot(self.default_options)
dns = sf.normalizeDNS(["example.local.", ["spiderfoot.net."]])
self.assertIsInstance(dns, list)
self.assertIn("example.local", dns)
self.assertIn("spiderfoot.net", dns)
- def test_normalize_dns_should_return_list(self):
- """
- Test normalizeDNS(self, res)
- """
+ def test_normalizeDNS_should_return_list(self):
sf = SpiderFoot(self.default_options)
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
dns = sf.normalizeDNS(invalid_type)
self.assertIsInstance(dns, list)
def test_resolve_host_should_return_list(self):
- """
- Test resolveHost(self, host)
- """
sf = SpiderFoot(self.default_options)
addrs = sf.resolveHost('one.one.one.one')
@@ -641,9 +497,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertIsInstance(addrs, list)
def test_resolve_ip_should_return_list(self):
- """
- Test resolveIP(self, ipaddr)
- """
sf = SpiderFoot(self.default_options)
addrs = sf.resolveIP('1.1.1.1')
@@ -669,9 +522,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertIsInstance(addrs, list)
def test_resolve_host6_should_return_a_list(self):
- """
- Test resolveHost6(self, hostname)
- """
sf = SpiderFoot(self.default_options)
addrs = sf.resolveHost6('one.one.one.one')
@@ -687,9 +537,6 @@ class TestSpiderFoot(unittest.TestCase):
self.assertIsInstance(addrs, list)
def test_validate_ip_should_return_bool(self):
- """
- Test validateIP(self, host, ip)
- """
sf = SpiderFoot(self.default_options)
validate_ip = sf.validateIP(None, None)
@@ -702,9 +549,6 @@ class TestSpiderFoot(unittest.TestCase):
@unittest.skip("todo")
def test_safe_socket(self):
- """
- Test safeSocket(self, host, port, timeout)
- """
sf = SpiderFoot(self.default_options)
sf.safeSocket(None, None, None)
@@ -712,19 +556,13 @@ class TestSpiderFoot(unittest.TestCase):
@unittest.skip("todo")
def test_safe_ssl_socket(self):
- """
- Test safeSSLSocket(self, host, port, timeout)
- """
sf = SpiderFoot(self.default_options)
sf.safeSSLSocket(None, None, None, None)
self.assertEqual('TBD', 'TBD')
@unittest.skip("todo")
- def test_ssl_der_to_pem(self):
- """
- Test sslDerToPem(self, der)
- """
+ def test_sslDerToPem(self):
sf = SpiderFoot(self.default_options)
pem = sf.sslDerToPem(None)
@@ -732,21 +570,15 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual('TBD', 'TBD')
- def test_ssl_der_to_pem_invalid_cert_should_return_none(self):
- """
- Test sslDerToPem(self, der)
- """
+ def test_sslDerToPem_invalid_cert_should_raise_TypeError(self):
sf = SpiderFoot(self.default_options)
- invalid_types = [None, "", list()]
+ invalid_types = [None, "", list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type), self.assertRaises(TypeError):
sf.sslDerToPem(invalid_type)
def test_parse_cert_should_return_a_dict(self):
- """
- Test parseCert(self, rawcert, fqdn=None, expiringdays=30)
- """
sf = SpiderFoot(self.default_options)
cert = "-----BEGIN CERTIFICATE-----\r\nMIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMTDkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0NlowSjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMTGkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EFq6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWAa6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0TAQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIGCCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNvbTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9kc3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAwVAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcCARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAzMDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwuY3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsFAAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJouM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwuX4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlGPfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\r\n-----END CERTIFICATE-----"
@@ -758,93 +590,66 @@ class TestSpiderFoot(unittest.TestCase):
self.assertIsInstance(parse_cert, dict)
def test_parse_cert_invalid_cert_should_return_none(self):
- """
- Test parseCert(self, rawcert, fqdn=None, expiringdays=30)
- """
sf = SpiderFoot(self.default_options)
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
parse_cert = sf.parseCert(invalid_type, 'spiderfoot.net', 30)
self.assertEqual(None, parse_cert)
def test_parse_cert_invalid_fqdn_should_return_none(self):
- """
- Test parseCert(self, rawcert, fqdn=None, expiringdays=30)
- """
sf = SpiderFoot(self.default_options)
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
parse_cert = sf.parseCert(None, invalid_type, 30)
self.assertEqual(None, parse_cert)
def test_parse_cert_invalid_expiringdays_should_return_none(self):
- """
- Test parseCert(self, rawcert, fqdn=None, expiringdays=30)
- """
sf = SpiderFoot(self.default_options)
- invalid_types = [None, "", list()]
+ invalid_types = [None, "", bytes(), list()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
parse_cert = sf.parseCert(None, 'spiderfoot.net', invalid_type)
self.assertEqual(None, parse_cert)
- def test_url_encode_unicode_should_return_a_string(self):
- """
- Test urlEncodeUnicode(self, url)
- """
- sf = SpiderFoot(self.default_options)
-
- url_encode_unicode = sf.urlEncodeUnicode('url')
- self.assertIsInstance(url_encode_unicode, str)
-
def test_get_session_should_return_a_session(self):
- """
- Test getSession(self)
- """
sf = SpiderFoot(self.default_options)
session = sf.getSession()
self.assertIn("requests.sessions.Session", str(session))
def test_remove_url_creds_should_remove_credentials_from_url(self):
- """
- Test removeUrlCreds(self, url):
- """
url = "http://local/?key=secret&pass=secret&user=secret&password=secret"
sf = SpiderFoot(self.default_options)
new_url = sf.removeUrlCreds(url)
self.assertNotIn("secret", new_url)
- def test_isValidLocalOrLoopbackIp_argument_ip_should_return_a_bool(self):
- """
- Test isValidLocalOrLoopbackIp(self, ip: str) -> bool:
- """
+ def test_isValidLocalOrLoopbackIp_argument_ip_valid_local_or_loopback_should_return_True(self):
sf = SpiderFoot(self.default_options)
-
self.assertTrue(sf.isValidLocalOrLoopbackIp('127.0.0.1'))
self.assertTrue(sf.isValidLocalOrLoopbackIp('127.0.0.2'))
self.assertTrue(sf.isValidLocalOrLoopbackIp('::1'))
-
self.assertTrue(sf.isValidLocalOrLoopbackIp('10.1.1.1'))
self.assertTrue(sf.isValidLocalOrLoopbackIp('fdd1:a677:c70c:b8c5:1234:1234:1234:1234'))
+ def test_isValidLocalOrLoopbackIp_argument_ip_remote_ip_should_return_False(self):
+ sf = SpiderFoot(self.default_options)
self.assertFalse(sf.isValidLocalOrLoopbackIp('1.1.1.1'))
self.assertFalse(sf.isValidLocalOrLoopbackIp('2606:4700:4700::1111'))
+ def test_isValidLocalOrLoopbackIp_argument_ip_invalid_ip_should_return_False(self):
+ sf = SpiderFoot(self.default_options)
+ self.assertFalse(sf.isValidLocalOrLoopbackIp('0'))
self.assertFalse(sf.isValidLocalOrLoopbackIp('invalid ip address'))
- def test_useProxyForUrl_argument_url_should_return_a_bool(self):
- """
- Test useProxyForUrl(self, url)
- """
+ def test_useProxyForUrl_argument_url_with_private_host_should_return_False(self):
opts = self.default_options
- proxy_host = 'spiderfoot.net'
+ proxy_host = 'proxy.spiderfoot.net'
opts['_socks1type'] = '5'
opts['_socks2addr'] = proxy_host
@@ -857,8 +662,32 @@ class TestSpiderFoot(unittest.TestCase):
self.assertFalse(sf.useProxyForUrl('127.0.0.1'))
self.assertFalse(sf.useProxyForUrl('localhost'))
self.assertFalse(sf.useProxyForUrl('test.local'))
+
+ def test_useProxyForUrl_argument_url_with_proxy_host_should_return_False(self):
+ opts = self.default_options
+
+ proxy_host = 'proxy.spiderfoot.net'
+
+ opts['_socks1type'] = '5'
+ opts['_socks2addr'] = proxy_host
+ opts['_socks3port'] = '8080'
+
+ sf = SpiderFoot(opts)
self.assertFalse(sf.useProxyForUrl(proxy_host))
+ def test_useProxyForUrl_argument_url_with_public_host_should_return_True(self):
+ opts = self.default_options
+
+ proxy_host = 'proxy.spiderfoot.net'
+
+ opts['_socks1type'] = '5'
+ opts['_socks2addr'] = proxy_host
+ opts['_socks3port'] = '8080'
+
+ sf = SpiderFoot(opts)
+ self.assertTrue(sf.useProxyForUrl('spiderfoot.net'))
+ self.assertTrue(sf.useProxyForUrl('1.1.1.1'))
+
def test_fetchUrl_argument_url_should_return_http_response_as_dict(self):
sf = SpiderFoot(self.default_options)
@@ -878,7 +707,7 @@ class TestSpiderFoot(unittest.TestCase):
def test_fetchUrl_argument_url_invalid_type_should_return_none(self):
sf = SpiderFoot(self.default_options)
- invalid_types = [None, list(), dict(), int()]
+ invalid_types = [None, list(), bytes(), dict(), int()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
res = sf.fetchUrl(invalid_type)
@@ -900,21 +729,15 @@ class TestSpiderFoot(unittest.TestCase):
self.assertEqual(None, res)
def test_check_dns_wildcard_invalid_target_should_return_none(self):
- """
- Test checkDnsWildcard(self, target)
- """
sf = SpiderFoot(self.default_options)
- invalid_types = [None, "", list(), dict()]
+ invalid_types = [None, "", bytes(), list(), dict()]
for invalid_type in invalid_types:
with self.subTest(invalid_type=invalid_type):
check_dns_wildcard = sf.checkDnsWildcard(invalid_type)
self.assertIsInstance(check_dns_wildcard, bool)
def test_check_dns_wildcard_should_return_a_boolean(self):
- """
- Test checkDnsWildcard(self, target)
- """
sf = SpiderFoot(self.default_options)
check_dns_wildcard = sf.checkDnsWildcard('local')
@@ -922,9 +745,6 @@ class TestSpiderFoot(unittest.TestCase):
@unittest.skip("todo")
def test_google_iterate(self):
- """
- Test googleIterate(self, searchString, opts=dict())
- """
sf = SpiderFoot(self.default_options)
sf.googleIterate(None, None)
@@ -932,9 +752,6 @@ class TestSpiderFoot(unittest.TestCase):
@unittest.skip("todo")
def test_bing_iterate(self):
- """
- Test bingIterate(self, searchString, opts=dict())
- """
sf = SpiderFoot(self.default_options)
sf.bingIterate(None, None)