SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
test: add tests for sf.parseEmails
Amr Awadfbf5df3168ae
diff --git a/sflib.py b/sflib.pyindex 7f4d6193..323d0f85 100644--- a/sflib.py+++ b/sflib.py@@ -1036,7 +1036,7 @@ class SpiderFoot:# Find all emails within the supplied content# Returns an Arraydef parseEmails(self, data):- emails = list()+ emails = set()matches = re.findall(r'([\%a-zA-Z\.0-9_\-\+]+@[a-zA-Z\.0-9\-]+\.[a-zA-Z\.0-9\-]+)', data)for match in matches:@@ -1057,9 +1057,9 @@ class SpiderFoot:self.debug("Skipped incomplete e-mail address: " + match)continue- emails.append(match)+ emails.add(match)- return list(set(emails))+ return list(emails)# Return a PEM for a DERdef sslDerToPem(self, der):diff --git a/tests/test_sflib.py b/tests/test_sflib.pynew file mode 100644index 00000000..221147f7--- /dev/null+++ b/tests/test_sflib.py@@ -0,0 +1,18 @@+import pytest+from sflib import SpiderFoot+++class TestSflib:+ @pytest.mark.parametrize(+ "test_string,parsed_emails",+ [+ ("[email protected]", ["[email protected]"]), # valid email+ ("b@f.", []), # too short (less than 5 charachters), should be ignored+ ("better%[email protected]", []), # contains '%' should be ignored+ ("amr@wh...", []), # truncated, should be ignored+ ],+ )+ def test_parse_emails(self, test_string, parsed_emails):+ sf = SpiderFoot(options={"_debug": False})++ assert sf.parseEmails(test_string) == parsed_emails