def test_forward_modified_stripped(self): suspect = Suspect('*****@*****.**', '*****@*****.**', TESTDATADIR + '/helloworld.eml') action, message = self.saplugin.examine(suspect) self.assertEqual(DUNNO, action) try: self.assertIsNotNone(suspect.get_tag('SAPlugin.report')) except AttributeError: # Python 2.6 self.assertTrue(suspect.get_tag('SAPlugin.report') is not None)
def test_something(self): """Test if examine runs through""" from fuglu.shared import Suspect suspect=Suspect('*****@*****.**','*****@*****.**','/dev/null') self.candidate.examine(suspect) self.failIf(suspect.get_tag('ExamplePlugin.time')==None, "Examine didn't run through")
def test_headers(self): """Test full workflow and check headers""" myclass = self.__class__.__name__ functionNameAsString = sys._getframe().f_code.co_name loggername = "%s.%s" % (myclass,functionNameAsString) logger = logging.getLogger(loggername) config=ConfigParser.RawConfigParser() configfile =b""" [FuzorCheck] redis=redis:6379:1 ttl=10 timeout=1 headername=X-FuZor maxsize=600000 redispw= stripoversize=False """ try: config.readfp(BytesIO(configfile)) except TypeError: config.read_string(force_uString(configfile)) fuzorplugin = FuzorCheck(config) self.assertTrue(fuzorplugin.lint()) logger.debug("Create suspect") suspect = Suspect("*****@*****.**", "*****@*****.**", TESTDATADIR + '/fuzor_html.eml') logger.debug('generate test hash') mailhash = FuzorDigest(suspect.get_message_rep()).digest mailhash_expected = "df1d303855f0bf85d5a7e74c5a00f97166496b3a" self.assertEqual(mailhash, mailhash_expected, 'generated mail hash %s is different than expected hash %s' % (mailhash, mailhash_expected)) logger.debug("examine suspect") fuzorplugin.examine(suspect) tag = suspect.get_tag('SAPlugin.tempheader') self.assertIsNone(tag, "No header should have been added since hash should not have been found") fuzorplugin.backend.redis.set(mailhash, 1, px=50) fuzorplugin.examine(suspect) time.sleep(50*1.0e-3) # sleep for 50ms to make sure key has expired tag = suspect.get_tag('SAPlugin.tempheader') self.assertIsNotNone(tag, "A header should have been added") self.assertEqual(2, len(tag), "There should be two entries, one with the hash and one with the count") self.assertEqual(["X-FuZor-ID: %s" % mailhash, "X-FuZor-Lvl: 1"], tag)
def test_score(self): suspect=Suspect('*****@*****.**','*****@*****.**','/dev/null') stream="""Date: Mon, 08 Sep 2008 17:33:54 +0200 To: [email protected] From: [email protected] Subject: test scanner XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X """ suspect.setSource(stream) result=self.candidate.examine(suspect) if type(result) is tuple: result,message=result score=int( suspect.get_tag('SAPlugin.spamscore')) self.failUnless(score>999, "GTUBE mails should score ~1000 , we got %s"%score) self.failUnless(result==REJECT,'High spam should be rejected')
def test_score(self): suspect = Suspect('*****@*****.**', '*****@*****.**', '/dev/null') stream = """Date: Mon, 08 Sep 2008 17:33:54 +0200 To: [email protected] From: [email protected] Subject: test scanner XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X """ suspect.set_source(stream) result = self.candidate.examine(suspect) if type(result) is tuple: result, message = result score = int(suspect.get_tag('SAPlugin.spamscore')) self.failUnless(score > 999, "GTUBE mails should score ~1000 , we got %s" % score) self.failUnless(result == REJECT, 'High spam should be rejected')
def test_withSuspect(self): """Test unquoted href attribute in html part of mail""" myclass = self.__class__.__name__ functionNameAsString = sys._getframe().f_code.co_name loggername = "%s.%s" % (myclass,functionNameAsString) logger = logging.getLogger(loggername) logger.debug("Read file content") filecontent = BytesIO(mail_html).read() logger.debug("Create suspect") suspect = Suspect("*****@*****.**","*****@*****.**","/dev/null") suspect.set_source(filecontent) logger.debug("examine suspect") self.candidate.examine(suspect) uris = suspect.get_tag('body.uris') logger.debug('uris: '+",".join(uris)) self.assertTrue( "http://toBeDetected.com.br/Jul2018/En/Statement/Invoice-DDDDDDDDD-DDDDDD/" in uris)
def test_prepender(self): """Test prepender plugin raising exception""" config = RawConfigParser() # -------------# # config: main # # -------------# config.add_section("main") config.set('main', 'plugins', '') config.set('main', 'prependers', 'sessionhandler_test.RaiseExceptionPrepender') config.set('main', 'appenders', '') # ------------------- # # config: performance # # ------------------- # config.add_section("performance") # minimum scanner threads config.set('performance', 'minthreads', 1) # maximum scanner threads config.set('performance', 'maxthreads', 1) # Method for parallelism, either 'thread' or 'process' config.set('performance', 'backend', 'process') mc = MainController(config) mc.propagate_core_defaults() ok = mc.load_plugins() suspect = Suspect('*****@*****.**', '*****@*****.**', '/dev/null') shandler = SessionHandler(None, config, mc.prependers, mc.plugins, mc.appenders, 0) pluglist, applist = shandler.run_prependers(suspect) shandler.run_plugins(suspect, pluglist) ptags = suspect.get_tag("processingerrors") self.assertEqual([ 'Prepender RaiseExceptionPrepender failed: Prepender Plugin not implemented' ], ptags)
def test_withSuspect_TE(self): """Test using suspect, link is in the base64 transfer encoded part""" myclass = self.__class__.__name__ functionNameAsString = sys._getframe().f_code.co_name loggername = "%s.%s" % (myclass,functionNameAsString) logger = logging.getLogger(loggername) logger.debug("Read file content") filecontent = BytesIO(mail_base64).read() logger.debug("Create suspect") suspect = Suspect("*****@*****.**","*****@*****.**","/dev/null") suspect.set_source(filecontent) logger.debug("examine suspect") self.candidate.examine(suspect) uris = suspect.get_tag('body.uris') logger.debug('uris: '+",".join(uris)) self.assertTrue('www.co.uk' in uris)