* * 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:----gkC6hGHgkPmNJwZX+Vh9CDpUGN1ftXkX0TT6/PzHwmG52gT27JUqQ9t2iJ9otSSbkpe2u8Uw43RFmXzuRrtFp4LBgMKivrEiTbaasU8Qe7gnybNhnX8/ZNaGTtaynGVZKDdHB4sClQ95tcWxbX43Di5gLMkvepgO3zJ3Lu9sqwuOIRFObbKPNYrVPGv9XniDWQprKpgOjxmMrC2nqNDy2KIGN4hpMtGj+zd0kSR6XUf4eaqovQvbJaH1fg5Dhbo3JPYatbgnVF0ctyJV1M9GtcosQcnyO9DSrRGkOljidindIpkrK/nUGqLbnOQYJDaE5Q8l9AHAsfjosIM4nowoNlLlFu2sGVLZbo/yPhgVCuoZCZ3lcvYd7EYYkCJgjlqJGc4B2aotwePKXItwcezThhbLzq0V1Pu3BVEkTxzcSxmK94EzoS3Jhjdzuad47RPqWOMfUObjS5Dg03POjMM22f9HIfPVzBf8ZRdV4XHT+dp8UwBGLn0uqlzefNQbWVnxHPFuvmfXqEfnifStScFjQXhGpWcGoJIeeRU8Ela2mQz2/tzbqCeVhO3RRqPGiZkSzHbFrOqAVDiBrrBd0064uUyUKDRpL49W8VkY2PmRhHQBQECjoEoVB5AmUMoWd4QSj0v4BVxg3AtZmMpFNSCLNEQnLbCTYhKepIQrgCjFLEE=----ATTACHMENT:----ODg1NDgyMDMyNTk4OTI2MCAzMDI2NTg1NTkyMzczODY2IDY5MTA1MDU3NTY1NTQ5MjY=