aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Security/HasherTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Security/HasherTest.php')
-rw-r--r--tests/lib/Security/HasherTest.php70
1 files changed, 42 insertions, 28 deletions
diff --git a/tests/lib/Security/HasherTest.php b/tests/lib/Security/HasherTest.php
index 0eb233de485..33130f86a73 100644
--- a/tests/lib/Security/HasherTest.php
+++ b/tests/lib/Security/HasherTest.php
@@ -17,10 +17,7 @@ use OCP\IConfig;
* Class HasherTest
*/
class HasherTest extends \Test\TestCase {
- /**
- * @return array
- */
- public function versionHashProvider() {
+ public static function versionHashProvider(): array {
return [
['asf32äà$$a.|3', null],
['asf32äà$$a.|3|5', null],
@@ -30,7 +27,7 @@ class HasherTest extends \Test\TestCase {
];
}
- public function hashProviders70_71(): array {
+ public static function hashProviders70_71(): array {
return [
// Valid SHA1 strings
['password', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', true],
@@ -66,7 +63,7 @@ class HasherTest extends \Test\TestCase {
];
}
- public function hashProviders72(): array {
+ public static function hashProviders72(): array {
return [
// Valid ARGON2 hashes
['password', '2|$argon2i$v=19$m=1024,t=2,p=2$T3JGcEkxVFNOVktNSjZUcg$4/hyLtSejxNgAuzSFFV/HLM3qRQKBwEtKw61qPN4zWA', true],
@@ -83,7 +80,7 @@ class HasherTest extends \Test\TestCase {
];
}
- public function hashProviders73(): array {
+ public static function hashProviders73(): array {
return [
// Valid ARGON2ID hashes
['password', '2|$argon2id$v=19$m=65536,t=4,p=1$TEtIMnhUczliQzI0Y01WeA$BpMUDrApy25iagIogUAnlc0rNTPJmGs8lOEeVHujJ9Q', true],
@@ -122,24 +119,20 @@ class HasherTest extends \Test\TestCase {
$this->hasher = new Hasher($this->config);
}
- public function testHash() {
+ public function testHash(): void {
$hash = $this->hasher->hash('String To Hash');
$this->assertNotNull($hash);
}
- /**
- * @dataProvider versionHashProvider
- */
- public function testSplitHash($hash, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('versionHashProvider')]
+ public function testSplitHash($hash, $expected): void {
$relativePath = self::invokePrivate($this->hasher, 'splitHash', [$hash]);
$this->assertSame($expected, $relativePath);
}
- /**
- * @dataProvider hashProviders70_71
- */
- public function testVerify($password, $hash, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('hashProviders70_71')]
+ public function testVerify($password, $hash, $expected): void {
$this->config
->expects($this->any())
->method('getSystemValue')
@@ -154,10 +147,8 @@ class HasherTest extends \Test\TestCase {
$this->assertSame($expected, $result);
}
- /**
- * @dataProvider hashProviders72
- */
- public function testVerifyArgon2i($password, $hash, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('hashProviders72')]
+ public function testVerifyArgon2i($password, $hash, $expected): void {
if (!\defined('PASSWORD_ARGON2I')) {
$this->markTestSkipped('Need ARGON2 support to test ARGON2 hashes');
}
@@ -166,10 +157,8 @@ class HasherTest extends \Test\TestCase {
$this->assertSame($expected, $result);
}
- /**
- * @dataProvider hashProviders73
- */
- public function testVerifyArgon2id(string $password, string $hash, bool $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('hashProviders73')]
+ public function testVerifyArgon2id(string $password, string $hash, bool $expected): void {
if (!\defined('PASSWORD_ARGON2ID')) {
$this->markTestSkipped('Need ARGON2ID support to test ARGON2ID hashes');
}
@@ -178,7 +167,7 @@ class HasherTest extends \Test\TestCase {
$this->assertSame($expected, $result);
}
- public function testUpgradeHashBlowFishToArgon2() {
+ public function testUpgradeHashBlowFishToArgon2(): void {
if (!\defined('PASSWORD_ARGON2I')) {
$this->markTestSkipped('Need ARGON2 support to test ARGON2 hashes');
}
@@ -203,7 +192,7 @@ class HasherTest extends \Test\TestCase {
$this->assertFalse(password_needs_rehash($relativePath['hash'], $newAlg, []));
}
- public function testUsePasswordDefaultArgon2iVerify() {
+ public function testUsePasswordDefaultArgon2iVerify(): void {
if (!\defined('PASSWORD_ARGON2I')) {
$this->markTestSkipped('Need ARGON2 support to test ARGON2 hashes');
}
@@ -227,7 +216,7 @@ class HasherTest extends \Test\TestCase {
$this->assertTrue(password_verify($message, $relativePath['hash']));
}
- public function testDoNotUsePasswordDefaultArgon2idVerify() {
+ public function testDoNotUsePasswordDefaultArgon2idVerify(): void {
if (!\defined('PASSWORD_ARGON2ID')) {
$this->markTestSkipped('Need ARGON2ID support to test ARGON2ID hashes');
}
@@ -245,7 +234,7 @@ class HasherTest extends \Test\TestCase {
$this->assertNull($newHash);
}
- public function testHashUsePasswordDefault() {
+ public function testHashUsePasswordDefault(): void {
if (!\defined('PASSWORD_ARGON2I')) {
$this->markTestSkipped('Need ARGON2 support to test ARGON2 hashes');
}
@@ -264,4 +253,29 @@ class HasherTest extends \Test\TestCase {
$info = password_get_info($relativePath['hash']);
$this->assertEquals(PASSWORD_BCRYPT, $info['algo']);
}
+
+ public function testValidHash(): void {
+ $hash = '3|$argon2id$v=19$m=65536,t=4,p=1$czFCSjk3LklVdXppZ2VCWA$li0NgdXe2/jwSRxgteGQPWlzJU0E0xdtfHbCbrpych0';
+
+ $isValid = $this->hasher->validate($hash);
+
+ $this->assertTrue($isValid);
+ }
+
+ public function testValidGeneratedHash(): void {
+ $message = 'secret';
+ $hash = $this->hasher->hash($message);
+
+ $isValid = $this->hasher->validate($hash);
+
+ $this->assertTrue($isValid);
+ }
+
+ public function testInvalidHash(): void {
+ $invalidHash = 'someInvalidHash';
+
+ $isValid = $this->hasher->validate($invalidHash);
+
+ $this->assertFalse($isValid);
+ }
}