Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security] Fix clearing remember-me cookie after deauthentication
- Loading branch information
Robin Chalas
committed
Nov 28, 2019
1 parent
fa783f9
commit e83fa6c
Showing
9 changed files
with
180 additions
and
8 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
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
75 changes: 75 additions & 0 deletions
75
src/Symfony/Bundle/SecurityBundle/Tests/Functional/RememberMeDeauthenticationTest.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,75 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional; | ||
|
||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Security\Core\User\InMemoryUserProvider; | ||
use Symfony\Component\Security\Core\User\User; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Symfony\Component\Security\Core\User\UserProviderInterface; | ||
|
||
class RememberMeDeauthenticationTest extends AbstractWebTestCase | ||
{ | ||
public function testRememberMeCookieGetsClearedOnUserChange() | ||
{ | ||
$client = $this->createClient(['test_case' => 'RememberMeDeauthentication', 'root_config' => 'config.yml']); | ||
|
||
$client->request('POST', '/login', [ | ||
'_username' => 'johannes', | ||
'_password' => 'test', | ||
]); | ||
|
||
$cookieJar = $client->getCookieJar(); | ||
$this->assertNotNull($cookieJar->get('REMEMBERME')); | ||
|
||
$client->request('GET', '/foo'); | ||
$this->assertNull($cookieJar->get('REMEMBERME')); | ||
} | ||
} | ||
|
||
class RememberMeFooController | ||
{ | ||
public function __invoke(UserInterface $user) | ||
{ | ||
return new Response($user->getUsername()); | ||
} | ||
} | ||
|
||
class RememberMeUserProvider implements UserProviderInterface | ||
{ | ||
private $inner; | ||
|
||
public function __construct(InMemoryUserProvider $inner) | ||
{ | ||
$this->inner = $inner; | ||
} | ||
|
||
public function loadUserByUsername($username) | ||
{ | ||
return $this->inner->loadUserByUsername($username); | ||
} | ||
|
||
public function refreshUser(UserInterface $user) | ||
{ | ||
$user = $this->inner->refreshUser($user); | ||
|
||
$alterUser = \Closure::bind(function (User $user) { $user->password = 'foo'; }, null, User::class); | ||
$alterUser($user); | ||
|
||
return $user; | ||
} | ||
|
||
public function supportsClass($class) | ||
{ | ||
return $this->inner->supportsClass($class); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...Symfony/Bundle/SecurityBundle/Tests/Functional/app/RememberMeDeauthentication/bundles.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,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Symfony\Bundle\SecurityBundle\SecurityBundle; | ||
|
||
return [ | ||
new FrameworkBundle(), | ||
new SecurityBundle(), | ||
]; |
32 changes: 32 additions & 0 deletions
32
src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/RememberMeDeauthentication/config.yml
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,32 @@ | ||
imports: | ||
- { resource: ./../config/framework.yml } | ||
|
||
security: | ||
encoders: | ||
Symfony\Component\Security\Core\User\User: plaintext | ||
|
||
providers: | ||
in_memory: | ||
memory: | ||
users: | ||
johannes: { password: test, roles: [ROLE_USER] } | ||
|
||
firewalls: | ||
default: | ||
form_login: | ||
check_path: login | ||
remember_me: true | ||
remember_me: | ||
always_remember_me: true | ||
secret: key | ||
anonymous: ~ | ||
logout_on_user_change: true | ||
|
||
access_control: | ||
- { path: ^/foo, roles: ROLE_USER } | ||
|
||
services: | ||
Symfony\Bundle\SecurityBundle\Tests\Functional\RememberMeUserProvider: | ||
public: true | ||
decorates: security.user.provider.concrete.in_memory | ||
arguments: ['@Symfony\Bundle\SecurityBundle\Tests\Functional\RememberMeUserProvider.inner'] |
7 changes: 7 additions & 0 deletions
7
...Symfony/Bundle/SecurityBundle/Tests/Functional/app/RememberMeDeauthentication/routing.yml
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,7 @@ | ||
login: | ||
path: /login | ||
|
||
foo: | ||
path: /foo | ||
defaults: | ||
_controller: Symfony\Bundle\SecurityBundle\Tests\Functional\RememberMeFooController |
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