Get denatured viruses from encrypted zip to avoid alarming scanners,

this allows test cases to pass again after last commit.
This commit is contained in:
Stuart D. Gathman
2019-08-10 20:28:48 -04:00
parent edc2f73375
commit a1714f4838
2 changed files with 33 additions and 7 deletions
+16 -3
View File
@@ -29,6 +29,7 @@
from __future__ import print_function
import unittest
import mime
import zipfile
import socket
try:
from StringIO import StringIO
@@ -51,6 +52,14 @@ hostname = socket.gethostname()
class MimeTestCase(unittest.TestCase):
def setUp(self):
self.zf = zipfile.ZipFile('test/virus.zip','r')
self.zf.setpassword('denatured')
def tearDown(self):
self.zf.close()
self.zf = None
# test mime parameter parsing
def testParam(self):
plist = mime._parseparam('; boundary="----=_NextPart_000_4e56_490d_48e3"')
@@ -90,8 +99,12 @@ class MimeTestCase(unittest.TestCase):
def testDefang(self,vname='virus1',part=1,
fname='LOVE-LETTER-FOR-YOU.TXT.vbs'):
with open('test/'+vname,"rb") as fp:
msg = mime.message_from_file(fp)
try:
with self.zf.open(vname,"r") as fp:
msg = mime.message_from_file(fp)
except KeyError:
with open('test/'+vname,"rb") as fp:
msg = mime.message_from_file(fp)
mime.defang(msg,scan_zip=True)
self.assertTrue(msg.ismodified(),"virus not removed")
oname = vname + '.out'
@@ -118,7 +131,7 @@ class MimeTestCase(unittest.TestCase):
# virus6 has no parts - the virus is directly inline
def testDefang6(self,vname="virus6",fname='FAX20.exe'):
with open('test/'+vname,"rb") as fp:
with self.zf.open(vname,"r") as fp:
msg = mime.message_from_file(fp)
mime.defang(msg)
oname = vname + '.out'