From aa09b24d02a8be1a2b7ab7946d3261edef4ee8c1 Mon Sep 17 00:00:00 2001 From: Ne-Lexa Date: Wed, 6 Dec 2017 15:28:17 +0300 Subject: [PATCH] added an additional test of the encrypted archive --- src/PhpZip/Model/ZipModel.php | 2 +- src/PhpZip/Stream/ZipOutputStream.php | 1 - tests/PhpZip/ZipFileTest.php | 2 +- tests/PhpZip/ZipPasswordTest.php | 26 ++++++++++++++++++ .../PhpZip/resources/aes_password_archive.zip | Bin 0 -> 193 bytes 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/PhpZip/resources/aes_password_archive.zip diff --git a/src/PhpZip/Model/ZipModel.php b/src/PhpZip/Model/ZipModel.php index 9adcf4e..ac62b17 100644 --- a/src/PhpZip/Model/ZipModel.php +++ b/src/PhpZip/Model/ZipModel.php @@ -224,7 +224,7 @@ class ZipModel implements \Countable if (isset($this->outEntries[$entryName])) { return $this->outEntries[$entryName]; } - throw new ZipNotFoundEntry('Zip entry ' . $entryName . ' not found'); + throw new ZipNotFoundEntry('Zip entry "' . $entryName . '" not found'); } /** diff --git a/src/PhpZip/Stream/ZipOutputStream.php b/src/PhpZip/Stream/ZipOutputStream.php index 13cf2c5..c1c875d 100644 --- a/src/PhpZip/Stream/ZipOutputStream.php +++ b/src/PhpZip/Stream/ZipOutputStream.php @@ -239,7 +239,6 @@ class ZipOutputStream implements ZipOutputStreamInterface $field = $extraFieldsCollection->get(WinZipAesEntryExtraField::getHeaderId()); if (null !== $field) { $method = $field->getMethod(); - $entry->setMethod($method); } } diff --git a/tests/PhpZip/ZipFileTest.php b/tests/PhpZip/ZipFileTest.php index 774288d..2adf1ee 100644 --- a/tests/PhpZip/ZipFileTest.php +++ b/tests/PhpZip/ZipFileTest.php @@ -1672,7 +1672,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\ZipNotFoundEntry - * @expectedExceptionMessage Zip entry bad entry name not found + * @expectedExceptionMessage Zip entry "bad entry name" not found */ public function testNotFoundEntry() { diff --git a/tests/PhpZip/ZipPasswordTest.php b/tests/PhpZip/ZipPasswordTest.php index 46a969c..1321530 100644 --- a/tests/PhpZip/ZipPasswordTest.php +++ b/tests/PhpZip/ZipPasswordTest.php @@ -370,4 +370,30 @@ class ZipPasswordTest extends ZipFileAddDirTest $this->assertEquals($zipFile['codes.csv'], $contents); $zipFile->close(); } + + public function testReadAesEncryptedAndRewriteArchive() + { + $file = __DIR__ . '/resources/aes_password_archive.zip'; + $password = '1234567890'; + + $zipFile = new ZipFile(); + $zipFile->openFile($file); + $zipFile->setReadPassword($password); + $zipFile->setEntryComment('contents.txt', 'comment'); // change entry, but not changed contents + $zipFile->saveAsFile($this->outputFilename); + + $zipFile2 = new ZipFile(); + $zipFile2->openFile($this->outputFilename); + $zipFile2->setReadPassword($password); + $this->assertEquals($zipFile2->getListFiles(), $zipFile->getListFiles()); + foreach ($zipFile as $name => $contents) { + $this->assertNotEmpty($name); + $this->assertNotEmpty($contents); + $this->assertContains('test contents', $contents); + $this->assertEquals($zipFile2[$name], $contents); + } + $zipFile2->close(); + + $zipFile->close(); + } } diff --git a/tests/PhpZip/resources/aes_password_archive.zip b/tests/PhpZip/resources/aes_password_archive.zip new file mode 100644 index 0000000000000000000000000000000000000000..7de71ae7e9de6fda86ad53915846563a50e1c497 GIT binary patch literal 193 zcmWIWW@a&FW@Jca*j(A>%>V?3KrGG9z`(=6&5)d*SCX1nQmj`}QNlQroq>tL(Up;d zVdaA?Dff(`)VTcX!nLc*FHZDiywU1#VBwGTOO#g|s85-t|E9_RMu_+KWhSRjzT(t7 o5a7+oWY3J-9+15Z3s02-e!(*OVf literal 0 HcmV?d00001