mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-20 11:50:42 +00:00
d0fae3f57a
* Eliminate Some Phpstan Annotations Some changes are possible due to Php8+ features like null-safe operators and Stringable. * Possible Uninitialized Variable Scrutinizer might be technically correct. * CellAddress Static -> Self I don't understand the use case for extending it, which would be the reason for using static rather than self. * Update Worksheet.php
45 lines
1.7 KiB
PHP
45 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Protection;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ProtectionTest extends TestCase
|
|
{
|
|
public function testVerifyPassword(): void
|
|
{
|
|
$protection = new Protection();
|
|
self::assertTrue($protection->verify('foo'), 'non-protected always pass');
|
|
|
|
$protection->setSheet(true);
|
|
self::assertTrue($protection->verify('foo'), 'no password will always pass 1');
|
|
self::assertTrue($protection->verify('xyz'), 'no password will always pass 2');
|
|
|
|
$protection->setPassword('foo', true);
|
|
$hashx1 = $protection->getPassword();
|
|
self::assertSame('foo', $hashx1, 'was not stored as-is, without hashing');
|
|
self::assertFalse($protection->verify('foo'), 'setting already hashed password will not match');
|
|
|
|
$protection->setPassword('foo');
|
|
$hashx2 = $protection->getPassword();
|
|
self::assertSame('CC40', $hashx2, 'was hashed');
|
|
self::assertTrue($protection->verify('foo'), 'setting non-hashed password will hash it and not match');
|
|
|
|
$protection->setAlgorithm(Protection::ALGORITHM_MD5);
|
|
self::assertFalse($protection->verify('foo'), 'changing algorithm will not match anymore');
|
|
|
|
$protection->setPassword('foo');
|
|
$hash1 = $protection->getPassword();
|
|
$protection->setPassword('foo');
|
|
$hash2 = $protection->getPassword();
|
|
|
|
self::assertSame(24, mb_strlen($hash1));
|
|
self::assertSame(24, mb_strlen($hash2));
|
|
self::assertNotSame($hash1, $hash2, 'was hashed with automatic salt');
|
|
self::assertTrue($protection->verify('foo'), 'setting password again, will hash with proper algorithm and will match');
|
|
}
|
|
}
|