|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\UserBundle\Security; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Bundle\UserBundle\Security\UserPasswordEncoder; |
|
18
|
|
|
use Sylius\Component\User\Model\CredentialsHolderInterface; |
|
19
|
|
|
use Sylius\Component\User\Security\UserPasswordEncoderInterface; |
|
20
|
|
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; |
|
21
|
|
|
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Michał Marcinkowski <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
final class UserPasswordEncoderSpec extends ObjectBehavior |
|
27
|
|
|
{ |
|
28
|
|
|
function let(EncoderFactoryInterface $encoderFactory): void |
|
29
|
|
|
{ |
|
30
|
|
|
$this->beConstructedWith($encoderFactory); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function it_implements_password_updater_interface(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->shouldImplement(UserPasswordEncoderInterface::class); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_encodes_password( |
|
39
|
|
|
EncoderFactoryInterface $encoderFactory, |
|
40
|
|
|
PasswordEncoderInterface $passwordEncoder, |
|
41
|
|
|
CredentialsHolderInterface $user |
|
42
|
|
|
): void { |
|
43
|
|
|
$user->getPlainPassword()->willReturn('topSecretPlainPassword'); |
|
44
|
|
|
$user->getSalt()->willReturn('typicalSalt'); |
|
45
|
|
|
$encoderFactory->getEncoder(get_class($user->getWrappedObject()))->willReturn($passwordEncoder); |
|
46
|
|
|
$passwordEncoder->encodePassword('topSecretPlainPassword', 'typicalSalt')->willReturn('topSecretEncodedPassword'); |
|
47
|
|
|
|
|
48
|
|
|
$this->encode($user)->shouldReturn('topSecretEncodedPassword'); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|