* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Csrf\Tests\TokenStorage; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage; /** * @author Bernhard Schussek */ class SessionTokenStorageTest extends TestCase { const SESSION_NAMESPACE = 'foobar'; /** * @var Session */ private $session; /** * @var SessionTokenStorage */ private $storage; protected function setUp() { $this->session = new Session(new MockArraySessionStorage()); $this->storage = new SessionTokenStorage($this->session, self::SESSION_NAMESPACE); } public function testStoreTokenInNotStartedSessionStartsTheSession() { $this->storage->setToken('token_id', 'TOKEN'); $this->assertTrue($this->session->isStarted()); } public function testStoreTokenInActiveSession() { $this->session->start(); $this->storage->setToken('token_id', 'TOKEN'); $this->assertSame('TOKEN', $this->session->get(self::SESSION_NAMESPACE.'/token_id')); } public function testCheckTokenInClosedSession() { $this->session->set(self::SESSION_NAMESPACE.'/token_id', 'RESULT'); $this->assertTrue($this->storage->hasToken('token_id')); $this->assertTrue($this->session->isStarted()); } public function testCheckTokenInActiveSession() { $this->session->start(); $this->session->set(self::SESSION_NAMESPACE.'/token_id', 'RESULT'); $this->assertTrue($this->storage->hasToken('token_id')); } public function testGetExistingTokenFromClosedSession() { $this->session->set(self::SESSION_NAMESPACE.'/token_id', 'RESULT'); $this->assertSame('RESULT', $this->storage->getToken('token_id')); $this->assertTrue($this->session->isStarted()); } public function testGetExistingTokenFromActiveSession() { $this->session->start(); $this->session->set(self::SESSION_NAMESPACE.'/token_id', 'RESULT'); $this->assertSame('RESULT', $this->storage->getToken('token_id')); } /** * @expectedException \Symfony\Component\Security\Csrf\Exception\TokenNotFoundException */ public function testGetNonExistingTokenFromClosedSession() { $this->storage->getToken('token_id'); } /** * @expectedException \Symfony\Component\Security\Csrf\Exception\TokenNotFoundException */ public function testGetNonExistingTokenFromActiveSession() { $this->session->start(); $this->storage->getToken('token_id'); } public function testRemoveNonExistingTokenFromClosedSession() { $this->assertNull($this->storage->removeToken('token_id')); } public function testRemoveNonExistingTokenFromActiveSession() { $this->session->start(); $this->assertNull($this->storage->removeToken('token_id')); } public function testRemoveExistingTokenFromClosedSession() { $this->session->set(self::SESSION_NAMESPACE.'/token_id', 'TOKEN'); $this->assertSame('TOKEN', $this->storage->removeToken('token_id')); } public function testRemoveExistingTokenFromActiveSession() { $this->session->start(); $this->session->set(self::SESSION_NAMESPACE.'/token_id', 'TOKEN'); $this->assertSame('TOKEN', $this->storage->removeToken('token_id')); } } __halt_compiler();----SIGNATURE:----Dj4s1QZt5tD3suYnOoJb0XORfwSjLyJyl3I5+iCtTM+SK7SuzBxztVJNpmKkFsZVGkc2kRlWNNpE38KGqWVJfNHKFCfqw4T1JU2r+X0ySoiw2tlqBDjFtBCQ/NtxFCkGxZYeNE8fG9CDtyICBcVWxEh4zN4iMI8MvlQyFhf+5IAWvjrjkY+kSbmw41UGXwYdkK8HgqxFPasMi/dsltimGDp0nArOpyAgajfkKAsRcbf0JIzOJmEh8FJDvXWr+Rd/Lzh4jey9uuZIYaE2jZ4rEhjJ4pBQaHoG0vUpXhnDXGs2sb8WSlcV9lv0x9bhbDCTfGi7e0nYtKJ83E0+IZWc94LTgVv47rLF19R+qWNSuTyEITL02bqb9399DfWA0YeyDqoqizlCs5yCJ32FAuOsP1+QLmeac5lm7F8vJavSNjP4zZVI+HyLwhskXlTPu5R36tuCuEE44a9fdQyNj0bg5viXYBlj3LqLJ5324LcrSl85MWURw3CEJk1gufWBtmrAzYbId8NuTq2RMe6GaQyViAL6JrBnsxjliBc0TC3DSQkRp7U9FeX5Uh60k4S0wnDfNdFKayH7SJDMR/23PpARaazb08+KT4fnfTc5h483WAYMJ+/7zQjv3jYi0lFBsH6EMVgE43b8daVE5K8z4BleydEe5KqbAEGhk09k+W3cozU=----ATTACHMENT:----MjI1ODMxMjU0NDUxMjY3NCA0MjExMjcxMTc1MDA1OTI1IDU3MTU3MjQwMjcyNjUyMDE=