mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-10 18:16:34 +00:00
Add encrypted XLSX streaming coverage
This commit is contained in:
@@ -263,6 +263,25 @@ class AgileEncryptionTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testDecryptFileClosesInputWhenOutputCannotBeOpened(): void
|
||||
{
|
||||
$package = AgileEncryption::encrypt('package', 'password', 128, 'SHA1', 10);
|
||||
$inputFilename = tempnam(sys_get_temp_dir(), 'phpspreadsheet-input-');
|
||||
$outputDirectory = sys_get_temp_dir() . '/phpspreadsheet-output-' . uniqid();
|
||||
self::assertNotFalse($inputFilename);
|
||||
mkdir($outputDirectory);
|
||||
file_put_contents($inputFilename, $package['encryptedPackage']);
|
||||
|
||||
try {
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage('Could not open XLSX package for decryption');
|
||||
AgileEncryption::decryptFile(AgileEncryption::parse($package['encryptionInfo']), $inputFilename, $outputDirectory, 'password');
|
||||
} finally {
|
||||
unlink($inputFilename);
|
||||
rmdir($outputDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
public function testRejectsUnrepresentableEncryptedPackageSize(): void
|
||||
{
|
||||
$method = new ReflectionMethod(AgileEncryption::class, 'unpackSize');
|
||||
|
||||
@@ -87,7 +87,8 @@ class OLETest extends TestCase
|
||||
|
||||
// Fixture generated by Microsoft Excel 16.111.2; password-to-open: open.
|
||||
// The encrypted workbook contains A1 = 'agile encryption fixture' and B1 = 42.
|
||||
self::assertSame('0400040040000000', bin2hex(substr($ole->getDataByName('EncryptionInfo'), 0, 8)));
|
||||
$encryptionInfo = $ole->getDataByName('EncryptionInfo');
|
||||
self::assertSame('0400040040000000', bin2hex(substr($encryptionInfo, 0, 8)));
|
||||
$encryptedPackage = $ole->getDataByName('EncryptedPackage');
|
||||
self::assertSame(6280, strlen($encryptedPackage));
|
||||
$output = tmpfile();
|
||||
@@ -100,6 +101,16 @@ class OLETest extends TestCase
|
||||
} finally {
|
||||
fclose($output);
|
||||
}
|
||||
$output = tmpfile();
|
||||
self::assertNotFalse($output);
|
||||
|
||||
try {
|
||||
$ole->copyDataByName('EncryptionInfo', $output);
|
||||
rewind($output);
|
||||
self::assertSame($encryptionInfo, stream_get_contents($output));
|
||||
} finally {
|
||||
fclose($output);
|
||||
}
|
||||
}
|
||||
|
||||
public function testNamedStreamMustExist(): void
|
||||
|
||||
Reference in New Issue
Block a user