def test_modified_message(self): """Test if the modified message gets archived correctly""" from fuglu.shared import Suspect import shutil import tempfile tempfilename = tempfile.mktemp(suffix='archive', prefix='fuglu-unittest', dir='/tmp') shutil.copy(TESTDATADIR + '/helloworld.eml', tempfilename) self.tempfiles.append(tempfilename) self.config.set('ArchivePlugin', 'storeoriginal', '0') candidate = ArchivePlugin(self.config) suspect = Suspect('*****@*****.**', '*****@*****.**', tempfilename) origmessage = suspect.get_source() # modify the mesg msgrep = suspect.get_message_rep() msgrep['X-Changed-Something'] = 'Yes' suspect.setMessageRep(msgrep) filename = candidate.archive(suspect) self.assertTrue(filename != None and filename) self.tempfiles.append(filename) archivedmessage = open(filename, 'r').read() self.assertNotEqual(origmessage.strip(), archivedmessage.strip( )), 'Archived message should have stored modified message'
def test_modified_message(self): """Test if the modified message gets archived correctly""" from fuglu.shared import Suspect import shutil import tempfile tempfilename = tempfile.mktemp( suffix='archive', prefix='fuglu-unittest', dir='/tmp') shutil.copy(TESTDATADIR + '/helloworld.eml', tempfilename) self.tempfiles.append(tempfilename) self.config.set('ArchivePlugin', 'storeoriginal', '0') candidate = ArchivePlugin(self.config) suspect = Suspect( '*****@*****.**', '*****@*****.**', tempfilename) origmessage = suspect.get_source() # modify the mesg msgrep = suspect.get_message_rep() msgrep['X-Changed-Something'] = 'Yes' suspect.setMessageRep(msgrep) filename = candidate.archive(suspect) self.assertTrue(filename != None and filename) self.tempfiles.append(filename) archivedmessage = open(filename, 'r').read() self.assertNotEqual(origmessage.strip(), archivedmessage.strip( )), 'Archived message should have stored modified message'
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)