SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
SpiderFootHelpers: Add validLEI function (#1190)
bcolese890ec7ce641
diff --git a/spiderfoot/helpers.py b/spiderfoot/helpers.pyindex 42609655..802c61a0 100644--- a/spiderfoot/helpers.py+++ b/spiderfoot/helpers.py@@ -280,3 +280,24 @@ class SpiderFootHelpers():return {}return {"name": root, "children": get_children(root, data)}++ def validLEI(lei):+ """Check if the provided string is a valid Legal Entity Identifier (LEI).++ Args:+ lei (str): The LEI number to check.++ Returns:+ bool: string is a valid LEI++ Note:+ ISO 17442 has been withdrawn and is not accurate+ https://www.gleif.org/en/about-lei/iso-17442-the-lei-code-structure+ """+ if not isinstance(lei, str):+ return False++ if not re.match(r'^[A-Z0-9]{18}[0-9]{2}$', lei, re.IGNORECASE):+ return False++ return Truediff --git a/test/unit/test_spiderfoothelpers.py b/test/unit/test_spiderfoothelpers.pyindex 8d25399e..b69f35b0 100644--- a/test/unit/test_spiderfoothelpers.py+++ b/test/unit/test_spiderfoothelpers.py@@ -121,3 +121,22 @@ class TestSpiderFootHelpers(unittest.TestCase):tree = SpiderFootHelpers.dataParentChildToTree({"test": {"123": "456"}})self.assertIsInstance(tree, dict)++ def test_validLEI_should_return_a_boolean(self):+ """+ Test validLEI(self, lei)+ """+ invalid_types = [None, "", list(), dict(), int()]+ for invalid_type in invalid_types:+ with self.subTest(invalid_type=invalid_type):+ valid_phone = SpiderFootHelpers.validLEI(invalid_type)+ self.assertIsInstance(valid_phone, bool)+ self.assertFalse(valid_phone)++ valid_lei = SpiderFootHelpers.validLEI('7ZW8QJWVPR4P1J1KQYZZ')+ self.assertIsInstance(valid_lei, bool)+ self.assertFalse(valid_lei)++ valid_lei = SpiderFootHelpers.validLEI('7ZW8QJWVPR4P1J1KQY45')+ self.assertIsInstance(valid_lei, bool)+ self.assertTrue(valid_lei)