1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the RememberMeRepositoryAuthenticationProviderTest class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\Security\Tests\Authentication; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\MVC\Symfony\Security\Authentication\RememberMeRepositoryAuthenticationProvider; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class RememberMeRepositoryAuthenticationProviderTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var RememberMeRepositoryAuthenticationProvider |
18
|
|
|
*/ |
19
|
|
|
private $authProvider; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\API\Repository\Repository |
23
|
|
|
*/ |
24
|
|
|
private $repository; |
25
|
|
|
|
26
|
|
|
protected function setUp() |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
|
30
|
|
|
$this->repository = $this->getMock('eZ\Publish\API\Repository\Repository'); |
31
|
|
|
$this->authProvider = new RememberMeRepositoryAuthenticationProvider( |
32
|
|
|
$this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface'), |
33
|
|
|
'my secret', |
34
|
|
|
'my provider secret' |
35
|
|
|
); |
36
|
|
|
$this->authProvider->setRepository($this->repository); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
public function testAuthenticateUnsupportedToken() |
40
|
|
|
{ |
41
|
|
|
$anonymousToken = $this |
42
|
|
|
->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken') |
43
|
|
|
->setConstructorArgs(['secret', $this->getMock('Symfony\Component\Security\Core\User\UserInterface')]) |
44
|
|
|
->getMock(); |
45
|
|
|
$this->assertEquals(null, $this->authProvider->authenticate($anonymousToken)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public function testAuthenticateWrongProviderKey() |
49
|
|
|
{ |
50
|
|
|
$token = $this |
51
|
|
|
->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken') |
52
|
|
|
->setConstructorArgs([$this->getMock('Symfony\Component\Security\Core\User\UserInterface')], 'wrong provider secret', 'my secret') |
53
|
|
|
->getMock(); |
54
|
|
|
$this->assertEquals(null, $this->authProvider->authenticate($token)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testAuthenticate() |
58
|
|
|
{ |
59
|
|
|
$this->repository |
60
|
|
|
->expects($this->once()) |
61
|
|
|
->method('getPermissionResolver') |
62
|
|
|
->will($this->returnValue($this->getPermissionResolverMock())); |
63
|
|
|
|
64
|
|
|
$this->getPermissionResolverMock() |
65
|
|
|
->expects($this->once()) |
66
|
|
|
->method('setCurrentUserReference'); |
67
|
|
|
|
68
|
|
|
$rememberMeToken = $this |
69
|
|
|
->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken') |
70
|
|
|
->setConstructorArgs([$this->getMock('Symfony\Component\Security\Core\User\UserInterface')], 'my provider secret', 'my secret') |
71
|
|
|
->getMock(); |
72
|
|
|
$this->assertSame($rememberMeToken, $this->authProvider->authenticate($rememberMeToken)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return \eZ\Publish\Core\Repository\Permission\PermissionResolver|\PHPUnit_Framework_MockObject_MockObject |
77
|
|
|
*/ |
78
|
|
|
private function getPermissionResolverMock() |
79
|
|
|
{ |
80
|
|
|
return $this |
81
|
|
|
->getMockBuilder('eZ\Publish\Core\Repository\Permission\PermissionResolver') |
82
|
|
|
->setMethods(null) |
83
|
|
|
->setConstructorArgs( |
84
|
|
|
[ |
85
|
|
|
$this |
86
|
|
|
->getMockBuilder('eZ\Publish\Core\Repository\Helper\RoleDomainMapper') |
87
|
|
|
->disableOriginalConstructor() |
88
|
|
|
->getMock(), |
89
|
|
|
$this |
90
|
|
|
->getMockBuilder('eZ\Publish\Core\Repository\Helper\LimitationService') |
91
|
|
|
->getMock(), |
92
|
|
|
$this |
93
|
|
|
->getMockBuilder('eZ\Publish\SPI\Persistence\User\Handler') |
94
|
|
|
->getMock(), |
95
|
|
|
$this |
96
|
|
|
->getMockBuilder('eZ\Publish\API\Repository\Values\User\UserReference') |
97
|
|
|
->getMock(), |
98
|
|
|
] |
99
|
|
|
) |
100
|
|
|
->getMock(); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|