-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-31462: Added command checking if there are any unsupported passwo…
…rd hash types (#99) * EZP-31462: Added command checking if there are any unsupported password hash types * EZP-31462: Added handling unsupported password hash type exception * EZP-31462: Changed password hash type to default when is not supported during the persistence value creation * fixup! EZP-31462: Fix integration test for case where during the persistence not supported password hash type changed to default
- Loading branch information
Showing
18 changed files
with
332 additions
and
26 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
eZ/Bundle/PlatformInstallerBundle/src/Command/ValidatePasswordHashesCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformInstallerBundle\Command; | ||
|
||
use eZ\Publish\Core\FieldType\User\UserStorage; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
final class ValidatePasswordHashesCommand extends Command | ||
{ | ||
/** @var \eZ\Publish\Core\FieldType\User\UserStorage */ | ||
private $userStorage; | ||
|
||
public function __construct( | ||
UserStorage $userStorage | ||
) { | ||
$this->userStorage = $userStorage; | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('ezplatform:user:validate-password-hashes'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$unsupportedHashesCounter = $this->userStorage->countUsersWithUnsupportedHashType(); | ||
|
||
if ($unsupportedHashesCounter > 0) { | ||
$output->writeln(sprintf('<error>Found %s users with unsupported password hash types</error>', $unsupportedHashesCounter)); | ||
$output->writeln('<info>For more details check documentation:</info> <href=https://doc.ezplatform.com/en/latest/releases/ez_platform_v3.0_deprecations/#password-hashes>https://doc.ezplatform.com/en/latest/releases/ez_platform_v3.0_deprecations/#password-hashes</>'); | ||
} else { | ||
$output->writeln('OK - <info>All users have supported password hash types</info>'); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
eZ/Publish/API/Repository/Exceptions/PasswordInUnsupportedFormatException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\API\Repository\Exceptions; | ||
|
||
use Symfony\Component\Security\Core\Exception\AuthenticationException; | ||
use Throwable; | ||
|
||
class PasswordInUnsupportedFormatException extends AuthenticationException | ||
{ | ||
public function __construct(Throwable $previous = null) | ||
{ | ||
parent::__construct("User's password is in a format which is not supported any more.", 0, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,7 +260,7 @@ public function getValidUpdateFieldData() | |
'login' => 'changeLogin', | ||
'email' => '[email protected]', | ||
'passwordHash' => '*2', | ||
'passwordHashType' => 1, | ||
'passwordHashType' => User::DEFAULT_PASSWORD_HASH, | ||
'enabled' => false, | ||
] | ||
); | ||
|
@@ -284,7 +284,7 @@ public function assertUpdatedFieldDataLoadedCorrect(Field $field) | |
'hasStoredLogin' => true, | ||
'login' => 'changeLogin', | ||
'email' => '[email protected]', | ||
'passwordHashType' => 1, | ||
'passwordHashType' => User::DEFAULT_PASSWORD_HASH, | ||
'enabled' => false, | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...lish/Core/FieldType/Tests/Integration/User/UserStorage/UserDoctrineStorageGatewayTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Integration\User\UserStorage; | ||
|
||
use eZ\Publish\Core\FieldType\Tests\Integration\User\UserStorage\UserStorageGatewayTest; | ||
use eZ\Publish\Core\FieldType\User\UserStorage\Gateway as UserStorageGateway; | ||
use eZ\Publish\Core\FieldType\User\UserStorage\Gateway\DoctrineStorage; | ||
|
||
final class UserDoctrineStorageGatewayTest extends UserStorageGatewayTest | ||
{ | ||
protected function getGateway(): UserStorageGateway | ||
{ | ||
return new DoctrineStorage($this->getDatabaseConnection()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
eZ/Publish/Core/FieldType/Tests/Integration/User/UserStorage/_fixtures/unsupported_hash.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ezuser: | ||
- { contentobject_id: 10, email: [email protected], login: anonymous, password_hash: $2y$10$35gOSQs6JK4u4whyERaeUuVeQBi2TUBIZIfP7HEj7sfz.MxvTuOeC, password_hash_type: 7 } | ||
- { contentobject_id: 16, email: [email protected], login: test, password_hash: $2y$10$35gOSQs6JK4u4whyERaeUuVeQBi2TUBIZIfP7HEj7sfz.MxvTuOeC, password_hash_type: 5 } | ||
- { contentobject_id: 14, email: [email protected], login: admin, password_hash: $2y$10$FDn9NPwzhq85cLLxfD5Wu.L3SL3Z/LNCvhkltJUV0wcJj7ciJg2oy, password_hash_type: 7 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,14 @@ | |
use eZ\Publish\Core\FieldType\User\Type; | ||
use eZ\Publish\Core\FieldType\User\Type as UserType; | ||
use eZ\Publish\Core\FieldType\User\Value as UserValue; | ||
use eZ\Publish\Core\Repository\Values\User\User as RepositoryUser; | ||
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException; | ||
use eZ\Publish\Core\FieldType\ValidationError; | ||
use eZ\Publish\Core\Persistence\Cache\UserHandler; | ||
use eZ\Publish\Core\Repository\User\PasswordHashServiceInterface; | ||
use eZ\Publish\Core\Repository\User\PasswordValidatorInterface; | ||
use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition as CoreFieldDefinition; | ||
use eZ\Publish\SPI\Persistence\Content\FieldValue; | ||
use eZ\Publish\SPI\Persistence\User; | ||
use PHPUnit\Framework\MockObject\Builder\InvocationMocker; | ||
|
||
|
@@ -579,6 +581,77 @@ public function testEmailAlreadyTaken(): void | |
], $validationErrors); | ||
} | ||
|
||
/** | ||
* @covers \eZ\Publish\Core\FieldType\User\Type::toPersistenceValue | ||
* | ||
* @dataProvider providerForTestCreatePersistenceValue | ||
*/ | ||
public function testCreatePersistenceValue(array $userValueDate, array $expectedFieldValueExternalData): void | ||
{ | ||
$passwordHashServiceMock = $this->createMock(PasswordHashServiceInterface::class); | ||
$passwordHashServiceMock->method('getDefaultHashType')->willReturn(RepositoryUser::DEFAULT_PASSWORD_HASH); | ||
$userType = new UserType( | ||
$this->createMock(UserHandler::class), | ||
$passwordHashServiceMock, | ||
$this->createMock(PasswordValidatorInterface::class) | ||
); | ||
|
||
$value = new UserValue($userValueDate); | ||
$fieldValue = $userType->toPersistenceValue($value); | ||
|
||
$expected = new FieldValue( | ||
[ | ||
'data' => null, | ||
'externalData' => $expectedFieldValueExternalData, | ||
'sortKey' => null, | ||
]); | ||
self::assertEquals($expected, $fieldValue); | ||
} | ||
|
||
public function providerForTestCreatePersistenceValue(): iterable | ||
{ | ||
$passwordUpdatedAt = new DateTimeImmutable(); | ||
$userData = [ | ||
'hasStoredLogin' => false, | ||
'contentId' => 46, | ||
'login' => 'validate_user', | ||
'email' => '[email protected]', | ||
'passwordHash' => '1234567890abcdef', | ||
'enabled' => true, | ||
'maxLogin' => 1000, | ||
'plainPassword' => '', | ||
'passwordUpdatedAt' => $passwordUpdatedAt, | ||
]; | ||
|
||
yield 'when password hash type is given' => [ | ||
$userValueData = [ | ||
'passwordHashType' => RepositoryUser::PASSWORD_HASH_PHP_DEFAULT, | ||
] + $userData, | ||
$expectedFieldValueExternalData = [ | ||
'passwordHashType' => RepositoryUser::PASSWORD_HASH_PHP_DEFAULT, | ||
'passwordUpdatedAt' => $passwordUpdatedAt->getTimestamp(), | ||
] + $userData, | ||
]; | ||
yield 'when password hash type is null' => [ | ||
$userValueData = [ | ||
'passwordHashType' => null, | ||
] + $userData, | ||
$expectedFieldValueExternalData = [ | ||
'passwordHashType' => RepositoryUser::DEFAULT_PASSWORD_HASH, | ||
'passwordUpdatedAt' => $passwordUpdatedAt->getTimestamp(), | ||
] + $userData, | ||
]; | ||
yield 'when password hash type is unsupported' => [ | ||
$userValueData = [ | ||
'passwordHashType' => '__UNSUPPORTED_HASH_TYPE__', | ||
] + $userData, | ||
$expectedFieldValueExternalData = [ | ||
'passwordHashType' => RepositoryUser::DEFAULT_PASSWORD_HASH, | ||
'passwordUpdatedAt' => $passwordUpdatedAt->getTimestamp(), | ||
] + $userData, | ||
]; | ||
} | ||
|
||
public function testEmailFreeToUse(): void | ||
{ | ||
$validateUserValue = new UserValue([ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.