LogoutTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\SecurityBundle\Tests\Functional;
  11. class LogoutTest extends WebTestCase
  12. {
  13. public function testSessionLessRememberMeLogout()
  14. {
  15. $client = $this->createClient(array('test_case' => 'RememberMeLogout', 'root_config' => 'config.yml'));
  16. $client->request('POST', '/login', array(
  17. '_username' => 'johannes',
  18. '_password' => 'test',
  19. ));
  20. $cookieJar = $client->getCookieJar();
  21. $cookieJar->expire(session_name());
  22. $this->assertNotNull($cookieJar->get('REMEMBERME'));
  23. $client->request('GET', '/logout');
  24. $this->assertNull($cookieJar->get('REMEMBERME'));
  25. }
  26. public function testCsrfTokensAreClearedOnLogout()
  27. {
  28. $client = $this->createClient(array('test_case' => 'LogoutWithoutSessionInvalidation', 'root_config' => 'config.yml'));
  29. $client->getContainer()->get('security.csrf.token_storage')->setToken('foo', 'bar');
  30. $client->request('POST', '/login', array(
  31. '_username' => 'johannes',
  32. '_password' => 'test',
  33. ));
  34. $this->assertTrue($client->getContainer()->get('security.csrf.token_storage')->hasToken('foo'));
  35. $this->assertSame('bar', $client->getContainer()->get('security.csrf.token_storage')->getToken('foo'));
  36. $client->request('GET', '/logout');
  37. $this->assertFalse($client->getContainer()->get('security.csrf.token_storage')->hasToken('foo'));
  38. }
  39. public function testAccessControlDoesNotApplyOnLogout()
  40. {
  41. $client = $this->createClient(array('test_case' => 'LogoutAccess', 'root_config' => 'config.yml'));
  42. $client->request('POST', '/login', array('_username' => 'johannes', '_password' => 'test'));
  43. $client->request('GET', '/logout');
  44. $this->assertRedirect($client->getResponse(), '/');
  45. }
  46. }