|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Security\Guard\Tests\Provider;
|
13 | 13 |
|
| 14 | +use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; |
14 | 15 | use Symfony\Component\Security\Guard\Provider\GuardAuthenticationProvider;
|
| 16 | +use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken; |
15 | 17 |
|
16 | 18 | /**
|
17 | 19 | * @author Ryan Weaver <weaverryan@gmail.com>
|
@@ -75,6 +77,22 @@ public function testAuthenticate()
|
75 | 77 | $this->assertSame($authedToken, $actualAuthedToken);
|
76 | 78 | }
|
77 | 79 |
|
| 80 | + public function testGuardWithNoLongerAuthenticatedTriggersLogout() |
| 81 | + { |
| 82 | + $providerKey = 'my_firewall_abc'; |
| 83 | + |
| 84 | + // create a token and mark it as NOT authenticated anymore |
| 85 | + // this mimics what would happen if a user "changed" between request |
| 86 | + $mockedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); |
| 87 | + $token = new PostAuthenticationGuardToken($mockedUser, $providerKey, array('ROLE_USER')); |
| 88 | + $token->setAuthenticated(false); |
| 89 | + |
| 90 | + $provider = new GuardAuthenticationProvider(array(), $this->userProvider, $providerKey, $this->userChecker); |
| 91 | + $actualToken = $provider->authenticate($token); |
| 92 | + // this should return the anonymous user |
| 93 | + $this->assertEquals(new AnonymousToken($providerKey, 'anon.'), $actualToken); |
| 94 | + } |
| 95 | + |
78 | 96 | protected function setUp()
|
79 | 97 | {
|
80 | 98 | $this->userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
|
|
0 commit comments