From 48b69c53dca7d1c7889deea9e82ca25decadb39e Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Thu, 4 Jul 2024 16:57:09 -0700 Subject: [PATCH] test: Test hash validation Signed-off-by: Christopher Ng --- tests/lib/Security/HasherTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/lib/Security/HasherTest.php b/tests/lib/Security/HasherTest.php index 0eb233de485df..f51b4ee39db02 100644 --- a/tests/lib/Security/HasherTest.php +++ b/tests/lib/Security/HasherTest.php @@ -264,4 +264,29 @@ public function testHashUsePasswordDefault() { $info = password_get_info($relativePath['hash']); $this->assertEquals(PASSWORD_BCRYPT, $info['algo']); } + + public function testValidHash() { + $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() { + $message = 'secret'; + $hash = $this->hasher->hash($message); + + $isValid = $this->hasher->validate($hash); + + $this->assertTrue($isValid); + } + + public function testInvalidHash() { + $invalidHash = 'someInvalidHash'; + + $isValid = $this->hasher->validate($invalidHash); + + $this->assertFalse($isValid); + } }