forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature Sylius#10080 Password hashing - multiple encoders support (pa…
…mil) This PR was merged into the 1.4-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.4 | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Related tickets | Sylius#9560, Sylius#10008 | License | MIT It reverses the BC break made in Sylius#10008 which forced end-users to change their security settings. This PR makes it opt-in for old installations and is enabled by default for new ones. <!-- - Bug fixes must be submitted against the 1.2 or 1.3 branch (the lowest possible) - Features and deprecations must be submitted against the master branch - Make sure that the correct base branch is set --> Commits ------- d694c5f Fix backwards compatibility for security configuration 43aa742 Add encoder name to the User model 983729f Add possibity to setup default encoder for new users c4872d2 Set up default encoders for Sylius application
- Loading branch information
Showing
20 changed files
with
260 additions
and
34 deletions.
There are no files selected for viewing
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,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Sylius\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20190109160409 extends AbstractMigration | ||
{ | ||
public function up(Schema $schema) : void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE sylius_shop_user ADD encoder_name VARCHAR(255) DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE sylius_admin_user ADD encoder_name VARCHAR(255) DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema) : void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE sylius_admin_user DROP encoder_name'); | ||
$this->addSql('ALTER TABLE sylius_shop_user DROP encoder_name'); | ||
} | ||
} |
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,3 +12,6 @@ parameters: | |
sylius_shop: | ||
product_grid: | ||
include_all_descendants: true | ||
|
||
sylius_user: | ||
encoder: argon2i |
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
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
33 changes: 33 additions & 0 deletions
33
src/Sylius/Bundle/UserBundle/Factory/UserWithEncoderFactory.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\UserBundle\Factory; | ||
|
||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Sylius\Component\User\Model\UserInterface; | ||
|
||
final class UserWithEncoderFactory implements FactoryInterface | ||
{ | ||
/** @var FactoryInterface */ | ||
private $decoratedUserFactory; | ||
|
||
/** @var string */ | ||
private $encoderName; | ||
|
||
public function __construct(FactoryInterface $decoratedUserFactory, string $encoderName) | ||
{ | ||
$this->decoratedUserFactory = $decoratedUserFactory; | ||
$this->encoderName = $encoderName; | ||
} | ||
|
||
public function createNew(): UserInterface | ||
{ | ||
/** @var UserInterface $user */ | ||
$user = $this->decoratedUserFactory->createNew(); | ||
|
||
$user->setEncoderName($this->encoderName); | ||
|
||
return $user; | ||
} | ||
} |
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
94 changes: 94 additions & 0 deletions
94
src/Sylius/Bundle/UserBundle/Tests/DependencyInjection/SyliusUserExtensionTest.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,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\UserBundle\Tests\DependencyInjection; | ||
|
||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; | ||
use PHPUnit\Framework\Assert; | ||
use Sylius\Bundle\UserBundle\DependencyInjection\SyliusUserExtension; | ||
use Sylius\Bundle\UserBundle\Factory\UserWithEncoderFactory; | ||
use Sylius\Component\Resource\Factory\Factory; | ||
|
||
final class SyliusUserExtensionTest extends AbstractExtensionTestCase | ||
{ | ||
/** @test */ | ||
public function it_creates_default_resource_factory_by_default(): void | ||
{ | ||
$this->load([ | ||
'resources' => [ | ||
'admin' => [ | ||
'user' => [], | ||
], | ||
], | ||
]); | ||
|
||
$factoryDefinition = $this->container->getDefinition('sylius.factory.admin_user'); | ||
|
||
Assert::assertSame(Factory::class, $factoryDefinition->getClass()); | ||
} | ||
|
||
/** @test */ | ||
public function it_decorates_user_factory_if_its_configuration_has_encoder_specified(): void | ||
{ | ||
$this->load([ | ||
'resources' => [ | ||
'admin' => [ | ||
'user' => [ | ||
'encoder' => 'customencoder', | ||
], | ||
], | ||
], | ||
]); | ||
|
||
$factoryDefinition = $this->container->getDefinition('sylius.factory.admin_user'); | ||
|
||
Assert::assertSame(UserWithEncoderFactory::class, $factoryDefinition->getClass()); | ||
Assert::assertSame('customencoder', $factoryDefinition->getArgument(1)); | ||
} | ||
|
||
/** @test */ | ||
public function it_decorates_user_factory_if_there_is_a_global_encoder_specified_in_the_configuration(): void | ||
{ | ||
$this->load([ | ||
'encoder' => 'customencoder', | ||
'resources' => [ | ||
'admin' => [ | ||
'user' => [], | ||
], | ||
], | ||
]); | ||
|
||
$factoryDefinition = $this->container->getDefinition('sylius.factory.admin_user'); | ||
|
||
Assert::assertSame(UserWithEncoderFactory::class, $factoryDefinition->getClass()); | ||
Assert::assertSame('customencoder', $factoryDefinition->getArgument(1)); | ||
} | ||
|
||
/** @test */ | ||
public function it_decorates_user_factory_using_the_most_specific_encoder_configured(): void | ||
{ | ||
$this->load([ | ||
'encoder' => 'customencoder', | ||
'resources' => [ | ||
'admin' => [ | ||
'user' => [ | ||
'encoder' => 'evenmorecustomencoder', | ||
], | ||
], | ||
], | ||
]); | ||
|
||
$factoryDefinition = $this->container->getDefinition('sylius.factory.admin_user'); | ||
|
||
Assert::assertSame(UserWithEncoderFactory::class, $factoryDefinition->getClass()); | ||
Assert::assertSame('evenmorecustomencoder', $factoryDefinition->getArgument(1)); | ||
} | ||
|
||
protected function getContainerExtensions(): iterable | ||
{ | ||
return [ | ||
new SyliusUserExtension(), | ||
]; | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/Sylius/Bundle/UserBundle/spec/Factory/UserWithEncoderFactorySpec.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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\Bundle\UserBundle\Factory; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Sylius\Component\User\Model\UserInterface; | ||
|
||
final class UserWithEncoderFactorySpec extends ObjectBehavior | ||
{ | ||
function let(FactoryInterface $decoratedUserFactory) | ||
{ | ||
$this->beConstructedWith($decoratedUserFactory, 'encodername'); | ||
} | ||
|
||
function it_is_a_factory(): void | ||
{ | ||
$this->shouldHaveType(FactoryInterface::class); | ||
} | ||
|
||
function it_sets_the_given_encoder_name_on_created_user(FactoryInterface $decoratedUserFactory, UserInterface $user): void | ||
{ | ||
$decoratedUserFactory->createNew()->willReturn($user); | ||
|
||
$user->setEncoderName('encodername')->shouldBeCalled(); | ||
|
||
$this->createNew()->shouldReturn($user); | ||
} | ||
} |
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
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.