Skip to content

Commit 9c2c5b9

Browse files
committed
Added test
1 parent 7166485 commit 9c2c5b9

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

tests/integration/Core/Repository/UserServiceTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ public function testCreateUserWithWeakPasswordThrowsUserPasswordValidationExcept
13251325

13261326
try {
13271327
// This call will fail with a "UserPasswordValidationException" because the
1328-
// the password does not follow specified rules.
1328+
// password does not follow specified rules.
13291329
$this->createTestUserWithPassword('pass', $userContentType);
13301330
} catch (ContentFieldValidationException $e) {
13311331
// Exception is caught, as there is no other way to check exception properties.
@@ -2177,13 +2177,41 @@ public function testUpdateUserPasswordWithUnsupportedHashType(): void
21772177
$wrongHashType = 1;
21782178
$this->updateRawPasswordHash($user->getUserId(), $wrongHashType);
21792179
$newPassword = 'new_secret123';
2180-
// no need to invalidate cache since there was no load between create & raw database update
2180+
// no need to invalidate cache since there was no load between creation
2181+
// and raw database update
21812182
$user = $userService->updateUserPassword($user, $newPassword);
21822183

21832184
self::assertTrue($userService->checkUserCredentials($user, $newPassword));
21842185
self::assertNotEquals($oldPasswordHash, $user->passwordHash);
21852186
}
21862187

2188+
/**
2189+
* @throws \Doctrine\DBAL\Exception
2190+
* @throws \ErrorException
2191+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException
2192+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
2193+
*/
2194+
public function testUpdateUserPasswordHashToArgon2Id(): void
2195+
{
2196+
$repository = $this->getRepository();
2197+
$userService = $repository->getUserService();
2198+
2199+
$user = $this->createUser('john.doe', 'John', 'Doe');
2200+
$oldPasswordHash = $user->passwordHash;
2201+
2202+
$argon2IdHashType = User::PASSWORD_HASH_ARGON2ID;
2203+
$this->updateRawPasswordHash($user->getUserId(), $argon2IdHashType);
2204+
$newPassword = 'new_secret123';
2205+
// no need to invalidate cache since there was no load between creation
2206+
// and raw database update
2207+
$user = $userService->updateUserPassword($user, $newPassword);
2208+
$passwordInfo = password_get_info($user->passwordHash);
2209+
2210+
self::assertTrue($userService->checkUserCredentials($user, $newPassword));
2211+
self::assertNotEquals($oldPasswordHash, $user->passwordHash);
2212+
self::assertEquals(PASSWORD_ARGON2ID, $passwordInfo['algo']);
2213+
}
2214+
21872215
/**
21882216
* Test for the loadUserGroupsOfUser() method.
21892217
*

tests/lib/Repository/User/PasswordHashServiceTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function testGetSupportedHashTypes(): void
3030
[
3131
User::PASSWORD_HASH_BCRYPT,
3232
User::PASSWORD_HASH_PHP_DEFAULT,
33+
User::PASSWORD_HASH_ARGON2I,
34+
User::PASSWORD_HASH_ARGON2ID,
3335
User::PASSWORD_HASH_INVALID,
3436
],
3537
$this->passwordHashService->getSupportedHashTypes()

0 commit comments

Comments
 (0)