summaryrefslogtreecommitdiff
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-02-13 09:49:38 +0000
committerMartin v. Löwis <martin@v.loewis.de>2007-02-13 09:49:38 +0000
commit41cf400695a5d2cd4534d93986582600c214b19b (patch)
tree01d1725174743aa8138b2e3957c266d53d85113c /Lib/test/test_zipfile.py
parent27e2a7206589255b443c6abdcae7761e0ded66f7 (diff)
downloadcpython-41cf400695a5d2cd4534d93986582600c214b19b.tar.gz
Patch #698833: Support file decryption in zipfile.
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 54684f3bbe..2d206df5c3 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -349,8 +349,49 @@ class OtherTests(unittest.TestCase):
# and report that the first file in the archive was corrupt.
self.assertRaises(RuntimeError, zipf.testzip)
+
+class DecryptionTests(unittest.TestCase):
+ # This test checks that ZIP decryption works. Since the library does not
+ # support encryption at the moment, we use a pre-generated encrypted
+ # ZIP file
+
+ data = (
+ 'PK\x03\x04\x14\x00\x01\x00\x00\x00n\x92i.#y\xef?&\x00\x00\x00\x1a\x00'
+ '\x00\x00\x08\x00\x00\x00test.txt\xfa\x10\xa0gly|\xfa-\xc5\xc0=\xf9y'
+ '\x18\xe0\xa8r\xb3Z}Lg\xbc\xae\xf9|\x9b\x19\xe4\x8b\xba\xbb)\x8c\xb0\xdbl'
+ 'PK\x01\x02\x14\x00\x14\x00\x01\x00\x00\x00n\x92i.#y\xef?&\x00\x00\x00'
+ '\x1a\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x01\x00 \x00\xb6\x81'
+ '\x00\x00\x00\x00test.txtPK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x006\x00'
+ '\x00\x00L\x00\x00\x00\x00\x00' )
+
+ plain = 'zipfile.py encryption test'
+
+ def setUp(self):
+ fp = open(TESTFN, "wb")
+ fp.write(self.data)
+ fp.close()
+ self.zip = zipfile.ZipFile(TESTFN, "r")
+
+ def tearDown(self):
+ self.zip.close()
+ os.unlink(TESTFN)
+
+ def testNoPassword(self):
+ # Reading the encrypted file without password
+ # must generate a RunTime exception
+ self.assertRaises(RuntimeError, self.zip.read, "test.txt")
+
+ def testBadPassword(self):
+ self.zip.setpassword("perl")
+ self.assertRaises(RuntimeError, self.zip.read, "test.txt")
+
+ def testGoodPassword(self):
+ self.zip.setpassword("python")
+ self.assertEquals(self.zip.read("test.txt"), self.plain)
+
def test_main():
- run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests, PyZipFileTests)
+ run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests,
+ PyZipFileTests, DecryptionTests)
#run_unittest(TestZip64InSmallFiles)
if __name__ == "__main__":