|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
namespace JMS\SecurityExtraBundle\Tests\Security\Authentication\Provider; |
|
|
4 |
|
|
|
5 |
use JMS\SecurityExtraBundle\Security\Authentication\Token\RunAsUserToken; |
|
|
6 |
|
|
|
7 |
use JMS\SecurityExtraBundle\Security\Authentication\Provider\RunAsAuthenticationProvider; |
|
|
8 |
|
|
|
9 |
class RunAsAuthenticationProviderTest extends \PHPUnit_Framework_TestCase |
|
|
10 |
{ |
|
|
11 |
public function testAuthenticateReturnsNullIfTokenISUnsupported() |
|
|
12 |
{ |
|
|
13 |
$provider = new RunAsAuthenticationProvider('foo'); |
|
|
14 |
$token = $this->GetMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); |
|
|
15 |
|
|
|
16 |
$this->assertNull($provider->authenticate($token)); |
|
|
17 |
} |
|
|
18 |
|
|
|
19 |
/** |
|
|
20 |
* @expectedException Symfony\Component\Security\Core\Exception\BadCredentialsException |
|
|
21 |
*/ |
|
|
22 |
public function testAuthenticateThrowsExceptionWhenKeysDontMatch() |
|
|
23 |
{ |
|
|
24 |
$provider = new RunAsAuthenticationProvider('foo'); |
|
|
25 |
$token = $this->getSupportedToken(); |
|
|
26 |
$token |
|
|
27 |
->expects($this->once()) |
|
|
28 |
->method('getKey') |
|
|
29 |
->will($this->returnValue('moo')) |
|
|
30 |
; |
|
|
31 |
|
|
|
32 |
$provider->authenticate($token); |
|
|
33 |
} |
|
|
34 |
|
|
|
35 |
public function testAuthenticate() |
|
|
36 |
{ |
|
|
37 |
$provider = new RunAsAuthenticationProvider('foo'); |
|
|
38 |
$token = $this->getSupportedToken(); |
|
|
39 |
$token |
|
|
40 |
->expects($this->once()) |
|
|
41 |
->method('getKey') |
|
|
42 |
->will($this->returnValue('foo')) |
|
|
43 |
; |
|
|
44 |
|
|
|
45 |
$this->assertSame($token, $provider->authenticate($token)); |
|
|
46 |
} |
|
|
47 |
|
|
|
48 |
public function testSupportsDoesNotAcceptInvalidToken() |
|
|
49 |
{ |
|
|
50 |
$provider = new RunAsAuthenticationProvider('foo'); |
|
|
51 |
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); |
|
|
52 |
|
|
|
53 |
$this->assertFalse($provider->supports($token)); |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
public function testSupports() |
|
|
57 |
{ |
|
|
58 |
$provider = new RunAsAuthenticationProvider('foo'); |
|
|
59 |
|
|
|
60 |
$token = $this->getSupportedToken(); |
|
|
61 |
$this->assertTrue($provider->supports($token)); |
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
protected function getSupportedToken() |
|
|
65 |
{ |
|
|
66 |
return $this->getMockBuilder('JMS\SecurityExtraBundle\Security\Authentication\Token\RunAsUserToken') |
|
|
67 |
->disableOriginalConstructor() |
|
|
68 |
->getMock(); |
|
|
69 |
} |
|
|
70 |
} |