mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-07-25 09:41:14 +02:00
refactoring zip64, add property softwareVersion, internal attrs, extracted os
This commit is contained in:
@@ -127,7 +127,10 @@ class PhpZipExtResourceTest extends ZipTestCase
|
||||
public function testBug70752()
|
||||
{
|
||||
if (\PHP_INT_SIZE === 4) { // php 32 bit
|
||||
$this->setExpectedException(RuntimeException::class, 'Traditional PKWARE Encryption is not supported in 32-bit PHP.');
|
||||
$this->setExpectedException(
|
||||
RuntimeException::class,
|
||||
'Traditional PKWARE Encryption is not supported in 32-bit PHP.'
|
||||
);
|
||||
} else { // php 64 bit
|
||||
$this->setExpectedException(
|
||||
ZipAuthenticationException::class,
|
||||
@@ -163,19 +166,11 @@ class PhpZipExtResourceTest extends ZipTestCase
|
||||
*/
|
||||
public function testPecl12414()
|
||||
{
|
||||
$filename = __DIR__ . '/php-zip-ext-test-resources/pecl12414.zip';
|
||||
$this->setExpectedException(ZipException::class, 'Corrupt zip file. Cannot read central dir entry.');
|
||||
|
||||
$entryName = 'MYLOGOV2.GFX';
|
||||
$filename = __DIR__ . '/php-zip-ext-test-resources/pecl12414.zip';
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->openFile($filename);
|
||||
|
||||
$info = $zipFile->getEntryInfo($entryName);
|
||||
static::assertTrue($info->getSize() > 0);
|
||||
|
||||
$contents = $zipFile[$entryName];
|
||||
static::assertSame(\strlen($contents), $info->getSize());
|
||||
|
||||
$zipFile->close();
|
||||
}
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ class ZipAlignTest extends ZipTestCase
|
||||
$zipFile->addFromString(
|
||||
'entry' . $i . '.txt',
|
||||
CryptoUtil::randomBytes(mt_rand(100, 4096)),
|
||||
ZipFileInterface::METHOD_STORED
|
||||
ZipFile::METHOD_STORED
|
||||
);
|
||||
}
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
@@ -95,7 +95,7 @@ class ZipAlignTest extends ZipTestCase
|
||||
$zipFile->addFromString(
|
||||
'entry' . $i . '.txt',
|
||||
CryptoUtil::randomBytes(mt_rand(100, 4096)),
|
||||
ZipFileInterface::METHOD_STORED
|
||||
ZipFile::METHOD_STORED
|
||||
);
|
||||
}
|
||||
$zipFile->setZipAlign(4);
|
||||
@@ -123,7 +123,7 @@ class ZipAlignTest extends ZipTestCase
|
||||
$zipFile->addFromString(
|
||||
'entry' . $i . '.txt',
|
||||
CryptoUtil::randomBytes(mt_rand(100, 4096)),
|
||||
ZipFileInterface::METHOD_STORED
|
||||
ZipFile::METHOD_STORED
|
||||
);
|
||||
}
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
@@ -149,8 +149,8 @@ class ZipAlignTest extends ZipTestCase
|
||||
'entry_new_' . ($isStored ? 'stored' : 'deflated') . '_' . $i . '.txt',
|
||||
CryptoUtil::randomBytes(mt_rand(100, 4096)),
|
||||
$isStored ?
|
||||
ZipFileInterface::METHOD_STORED :
|
||||
ZipFileInterface::METHOD_DEFLATED
|
||||
ZipFile::METHOD_STORED :
|
||||
ZipFile::METHOD_DEFLATED
|
||||
);
|
||||
}
|
||||
$zipFile->setZipAlign(4);
|
||||
|
@@ -909,12 +909,12 @@ class ZipFileTest extends ZipTestCase
|
||||
$entries = [
|
||||
'1' => [
|
||||
'data' => CryptoUtil::randomBytes(255),
|
||||
'method' => ZipFileInterface::METHOD_STORED,
|
||||
'method' => ZipFile::METHOD_STORED,
|
||||
'expected' => 'No compression',
|
||||
],
|
||||
'2' => [
|
||||
'data' => CryptoUtil::randomBytes(255),
|
||||
'method' => ZipFileInterface::METHOD_DEFLATED,
|
||||
'method' => ZipFile::METHOD_DEFLATED,
|
||||
'expected' => 'Deflate',
|
||||
],
|
||||
];
|
||||
@@ -922,7 +922,7 @@ class ZipFileTest extends ZipTestCase
|
||||
if (\extension_loaded('bz2')) {
|
||||
$entries['3'] = [
|
||||
'data' => CryptoUtil::randomBytes(255),
|
||||
'method' => ZipFileInterface::METHOD_BZIP2,
|
||||
'method' => ZipFile::METHOD_BZIP2,
|
||||
'expected' => 'Bzip2',
|
||||
];
|
||||
}
|
||||
@@ -938,7 +938,7 @@ class ZipFileTest extends ZipTestCase
|
||||
static::assertCorrectZipArchive($this->outputFilename);
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
$zipFile->setCompressionLevel(ZipFileInterface::LEVEL_BEST_COMPRESSION);
|
||||
$zipFile->setCompressionLevel(ZipFile::LEVEL_BEST_COMPRESSION);
|
||||
$zipAllInfo = $zipFile->getAllInfo();
|
||||
|
||||
foreach ($zipAllInfo as $entryName => $info) {
|
||||
@@ -1693,14 +1693,14 @@ class ZipFileTest extends ZipTestCase
|
||||
$files['file' . $i . '.txt'] = CryptoUtil::randomBytes(255);
|
||||
}
|
||||
|
||||
$methods = [ZipFileInterface::METHOD_STORED, ZipFileInterface::METHOD_DEFLATED];
|
||||
$methods = [ZipFile::METHOD_STORED, ZipFile::METHOD_DEFLATED];
|
||||
|
||||
if (\extension_loaded('bz2')) {
|
||||
$methods[] = ZipFileInterface::METHOD_BZIP2;
|
||||
$methods[] = ZipFile::METHOD_BZIP2;
|
||||
}
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->setCompressionLevel(ZipFileInterface::LEVEL_BEST_SPEED);
|
||||
$zipFile->setCompressionLevel(ZipFile::LEVEL_BEST_SPEED);
|
||||
|
||||
foreach ($files as $entryName => $content) {
|
||||
$zipFile->addFromString($entryName, $content, $methods[array_rand($methods)]);
|
||||
@@ -1985,14 +1985,14 @@ class ZipFileTest extends ZipTestCase
|
||||
{
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile
|
||||
->addFromString('file', 'content', ZipFileInterface::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file', ZipFileInterface::LEVEL_BEST_COMPRESSION)
|
||||
->addFromString('file2', 'content', ZipFileInterface::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file2', ZipFileInterface::LEVEL_FAST)
|
||||
->addFromString('file3', 'content', ZipFileInterface::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file3', ZipFileInterface::LEVEL_SUPER_FAST)
|
||||
->addFromString('file4', 'content', ZipFileInterface::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file4', ZipFileInterface::LEVEL_DEFAULT_COMPRESSION)
|
||||
->addFromString('file', 'content', ZipFile::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file', ZipFile::LEVEL_BEST_COMPRESSION)
|
||||
->addFromString('file2', 'content', ZipFile::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file2', ZipFile::LEVEL_FAST)
|
||||
->addFromString('file3', 'content', ZipFile::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file3', ZipFile::LEVEL_SUPER_FAST)
|
||||
->addFromString('file4', 'content', ZipFile::METHOD_DEFLATED)
|
||||
->setCompressionLevelEntry('file4', ZipFile::LEVEL_DEFAULT_COMPRESSION)
|
||||
->saveAsFile($this->outputFilename)
|
||||
->close()
|
||||
;
|
||||
@@ -2003,22 +2003,22 @@ class ZipFileTest extends ZipTestCase
|
||||
static::assertSame(
|
||||
$zipFile->getEntryInfo('file')
|
||||
->getCompressionLevel(),
|
||||
ZipFileInterface::LEVEL_BEST_COMPRESSION
|
||||
ZipFile::LEVEL_BEST_COMPRESSION
|
||||
);
|
||||
static::assertSame(
|
||||
$zipFile->getEntryInfo('file2')
|
||||
->getCompressionLevel(),
|
||||
ZipFileInterface::LEVEL_FAST
|
||||
ZipFile::LEVEL_FAST
|
||||
);
|
||||
static::assertSame(
|
||||
$zipFile->getEntryInfo('file3')
|
||||
->getCompressionLevel(),
|
||||
ZipFileInterface::LEVEL_SUPER_FAST
|
||||
ZipFile::LEVEL_SUPER_FAST
|
||||
);
|
||||
static::assertSame(
|
||||
$zipFile->getEntryInfo('file4')
|
||||
->getCompressionLevel(),
|
||||
ZipFileInterface::LEVEL_DEFAULT_COMPRESSION
|
||||
ZipFile::LEVEL_DEFAULT_COMPRESSION
|
||||
);
|
||||
$zipFile->close();
|
||||
}
|
||||
@@ -2054,10 +2054,10 @@ class ZipFileTest extends ZipTestCase
|
||||
{
|
||||
$zipFile = new ZipFile();
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$zipFile->addFromString('file' . $i, 'content', ZipFileInterface::METHOD_DEFLATED);
|
||||
$zipFile->addFromString('file' . $i, 'content', ZipFile::METHOD_DEFLATED);
|
||||
}
|
||||
$zipFile
|
||||
->setCompressionLevel(ZipFileInterface::LEVEL_BEST_SPEED)
|
||||
->setCompressionLevel(ZipFile::LEVEL_BEST_SPEED)
|
||||
->saveAsFile($this->outputFilename)
|
||||
->close()
|
||||
;
|
||||
@@ -2069,7 +2069,7 @@ class ZipFileTest extends ZipTestCase
|
||||
array_walk(
|
||||
$infoList,
|
||||
function (ZipInfo $zipInfo) {
|
||||
$this->assertSame($zipInfo->getCompressionLevel(), ZipFileInterface::LEVEL_BEST_SPEED);
|
||||
$this->assertSame($zipInfo->getCompressionLevel(), ZipFile::LEVEL_BEST_SPEED);
|
||||
}
|
||||
);
|
||||
$zipFile->close();
|
||||
@@ -2082,13 +2082,13 @@ class ZipFileTest extends ZipTestCase
|
||||
public function testCompressionMethodEntry()
|
||||
{
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFromString('file', 'content', ZipFileInterface::METHOD_STORED);
|
||||
$zipFile->addFromString('file', 'content', ZipFile::METHOD_STORED);
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'No compression');
|
||||
$zipFile->setCompressionMethodEntry('file', ZipFileInterface::METHOD_DEFLATED);
|
||||
$zipFile->setCompressionMethodEntry('file', ZipFile::METHOD_DEFLATED);
|
||||
static::assertSame($zipFile->getEntryInfo('file')->getMethodName(), 'Deflate');
|
||||
|
||||
$zipFile->rewrite();
|
||||
@@ -2103,7 +2103,7 @@ class ZipFileTest extends ZipTestCase
|
||||
$this->setExpectedException(ZipUnsupportMethodException::class, 'Unsupported method');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFromString('file', 'content', ZipFileInterface::METHOD_STORED);
|
||||
$zipFile->addFromString('file', 'content', ZipFile::METHOD_STORED);
|
||||
$zipFile->setCompressionMethodEntry('file', 99);
|
||||
}
|
||||
|
||||
|
@@ -38,8 +38,16 @@ class ZipMatcherTest extends TestCase
|
||||
$matcher->match('~^[2][1-5]|[3][6-9]|40$~s');
|
||||
static::assertCount(10, $matcher);
|
||||
$actualMatches = [
|
||||
'21', '22', '23', '24', '25',
|
||||
'36', '37', '38', '39', '40',
|
||||
'21',
|
||||
'22',
|
||||
'23',
|
||||
'24',
|
||||
'25',
|
||||
'36',
|
||||
'37',
|
||||
'38',
|
||||
'39',
|
||||
'40',
|
||||
];
|
||||
static::assertSame($matcher->getMatches(), $actualMatches);
|
||||
$matcher->setPassword('qwerty');
|
||||
|
@@ -22,11 +22,15 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
* Test archive password.
|
||||
*
|
||||
* @throws ZipException
|
||||
* @noinspection PhpRedundantCatchClauseInspection
|
||||
*/
|
||||
public function testSetPassword()
|
||||
{
|
||||
if (\PHP_INT_SIZE === 4) { // php 32 bit
|
||||
$this->setExpectedException(RuntimeException::class, 'Traditional PKWARE Encryption is not supported in 32-bit PHP.');
|
||||
$this->setExpectedException(
|
||||
RuntimeException::class,
|
||||
'Traditional PKWARE Encryption is not supported in 32-bit PHP.'
|
||||
);
|
||||
}
|
||||
|
||||
$password = base64_encode(CryptoUtil::randomBytes(100));
|
||||
@@ -35,7 +39,7 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
// create encryption password with ZipCrypto
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addDir(__DIR__);
|
||||
$zipFile->setPassword($password, ZipFileInterface::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zipFile->setPassword($password, ZipFile::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
|
||||
@@ -66,7 +70,7 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
}
|
||||
|
||||
// change encryption method to WinZip Aes and update file
|
||||
$zipFile->setPassword($password, ZipFileInterface::ENCRYPTION_METHOD_WINZIP_AES);
|
||||
$zipFile->setPassword($password, ZipFile::ENCRYPTION_METHOD_WINZIP_AES);
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
|
||||
@@ -121,14 +125,17 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
public function testTraditionalEncryption()
|
||||
{
|
||||
if (\PHP_INT_SIZE === 4) { // php 32 bit
|
||||
$this->setExpectedException(RuntimeException::class, 'Traditional PKWARE Encryption is not supported in 32-bit PHP.');
|
||||
$this->setExpectedException(
|
||||
RuntimeException::class,
|
||||
'Traditional PKWARE Encryption is not supported in 32-bit PHP.'
|
||||
);
|
||||
}
|
||||
|
||||
$password = base64_encode(CryptoUtil::randomBytes(50));
|
||||
|
||||
$zip = new ZipFile();
|
||||
$zip->addDirRecursive($this->outputDirname);
|
||||
$zip->setPassword($password, ZipFileInterface::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zip->setPassword($password, ZipFile::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zip->saveAsFile($this->outputFilename);
|
||||
$zip->close();
|
||||
|
||||
@@ -187,10 +194,10 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
public function winZipKeyStrengthProvider()
|
||||
{
|
||||
return [
|
||||
[ZipFileInterface::ENCRYPTION_METHOD_WINZIP_AES_128, 128],
|
||||
[ZipFileInterface::ENCRYPTION_METHOD_WINZIP_AES_192, 192],
|
||||
[ZipFileInterface::ENCRYPTION_METHOD_WINZIP_AES, 256],
|
||||
[ZipFileInterface::ENCRYPTION_METHOD_WINZIP_AES_256, 256],
|
||||
[ZipFile::ENCRYPTION_METHOD_WINZIP_AES_128, 128],
|
||||
[ZipFile::ENCRYPTION_METHOD_WINZIP_AES_192, 192],
|
||||
[ZipFile::ENCRYPTION_METHOD_WINZIP_AES, 256],
|
||||
[ZipFile::ENCRYPTION_METHOD_WINZIP_AES_256, 256],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -201,7 +208,10 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
public function testEncryptionEntries()
|
||||
{
|
||||
if (\PHP_INT_SIZE === 4) { // php 32 bit
|
||||
$this->setExpectedException(RuntimeException::class, 'Traditional PKWARE Encryption is not supported in 32-bit PHP.');
|
||||
$this->setExpectedException(
|
||||
RuntimeException::class,
|
||||
'Traditional PKWARE Encryption is not supported in 32-bit PHP.'
|
||||
);
|
||||
}
|
||||
|
||||
$password1 = '353442434235424234';
|
||||
@@ -209,8 +219,8 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
|
||||
$zip = new ZipFile();
|
||||
$zip->addDir($this->outputDirname);
|
||||
$zip->setPasswordEntry('.hidden', $password1, ZipFileInterface::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zip->setPasswordEntry('text file.txt', $password2, ZipFileInterface::ENCRYPTION_METHOD_WINZIP_AES);
|
||||
$zip->setPasswordEntry('.hidden', $password1, ZipFile::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zip->setPasswordEntry('text file.txt', $password2, ZipFile::ENCRYPTION_METHOD_WINZIP_AES);
|
||||
$zip->saveAsFile($this->outputFilename);
|
||||
$zip->close();
|
||||
|
||||
@@ -248,7 +258,10 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
public function testEncryptionEntriesWithDefaultPassword()
|
||||
{
|
||||
if (\PHP_INT_SIZE === 4) { // php 32 bit
|
||||
$this->setExpectedException(RuntimeException::class, 'Traditional PKWARE Encryption is not supported in 32-bit PHP.');
|
||||
$this->setExpectedException(
|
||||
RuntimeException::class,
|
||||
'Traditional PKWARE Encryption is not supported in 32-bit PHP.'
|
||||
);
|
||||
}
|
||||
|
||||
$password1 = '353442434235424234';
|
||||
@@ -258,8 +271,8 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
$zip = new ZipFile();
|
||||
$zip->addDir($this->outputDirname);
|
||||
$zip->setPassword($defaultPassword);
|
||||
$zip->setPasswordEntry('.hidden', $password1, ZipFileInterface::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zip->setPasswordEntry('text file.txt', $password2, ZipFileInterface::ENCRYPTION_METHOD_WINZIP_AES);
|
||||
$zip->setPasswordEntry('.hidden', $password1, ZipFile::ENCRYPTION_METHOD_TRADITIONAL);
|
||||
$zip->setPasswordEntry('text file.txt', $password2, ZipFile::ENCRYPTION_METHOD_WINZIP_AES);
|
||||
$zip->saveAsFile($this->outputFilename);
|
||||
$zip->close();
|
||||
|
||||
@@ -350,7 +363,7 @@ class ZipPasswordTest extends ZipFileAddDirTest
|
||||
$this->setExpectedException(ZipException::class, 'Invalid encryption method');
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->addFromString('file', 'content', ZipFileInterface::METHOD_STORED);
|
||||
$zipFile->addFromString('file', 'content', ZipFile::METHOD_STORED);
|
||||
$zipFile->setPasswordEntry('file', 'pass', 99);
|
||||
}
|
||||
|
||||
|
@@ -129,7 +129,7 @@ abstract class ZipTestCase extends TestCase
|
||||
|
||||
static::assertContains('Empty zipfile', $output);
|
||||
}
|
||||
$actualEmptyZipData = pack('VVVVVv', EndOfCentralDirectory::END_OF_CENTRAL_DIRECTORY_RECORD_SIG, 0, 0, 0, 0, 0);
|
||||
$actualEmptyZipData = pack('VVVVVv', EndOfCentralDirectory::END_OF_CD_SIG, 0, 0, 0, 0, 0);
|
||||
static::assertStringEqualsFile($filename, $actualEmptyZipData);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user