* * 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\Security\Csrf\TokenStorage\NativeSessionTokenStorage; /** * @author Bernhard Schussek * * @runTestsInSeparateProcesses * @preserveGlobalState disabled */ class NativeSessionTokenStorageTest extends TestCase { const SESSION_NAMESPACE = 'foobar'; /** * @var NativeSessionTokenStorage */ private $storage; protected function setUp() { $_SESSION = array(); $this->storage = new NativeSessionTokenStorage(self::SESSION_NAMESPACE); } public function testStoreTokenInClosedSession() { $this->storage->setToken('token_id', 'TOKEN'); $this->assertSame(array(self::SESSION_NAMESPACE => array('token_id' => 'TOKEN')), $_SESSION); } public function testStoreTokenInClosedSessionWithExistingSessionId() { session_id('foobar'); $this->assertSame(PHP_SESSION_NONE, session_status()); $this->storage->setToken('token_id', 'TOKEN'); $this->assertSame(PHP_SESSION_ACTIVE, session_status()); $this->assertSame(array(self::SESSION_NAMESPACE => array('token_id' => 'TOKEN')), $_SESSION); } public function testStoreTokenInActiveSession() { session_start(); $this->storage->setToken('token_id', 'TOKEN'); $this->assertSame(array(self::SESSION_NAMESPACE => array('token_id' => 'TOKEN')), $_SESSION); } /** * @depends testStoreTokenInClosedSession */ public function testCheckToken() { $this->assertFalse($this->storage->hasToken('token_id')); $this->storage->setToken('token_id', 'TOKEN'); $this->assertTrue($this->storage->hasToken('token_id')); } /** * @depends testStoreTokenInClosedSession */ public function testGetExistingToken() { $this->storage->setToken('token_id', 'TOKEN'); $this->assertSame('TOKEN', $this->storage->getToken('token_id')); } /** * @expectedException \Symfony\Component\Security\Csrf\Exception\TokenNotFoundException */ public function testGetNonExistingToken() { $this->storage->getToken('token_id'); } /** * @depends testCheckToken */ public function testRemoveNonExistingToken() { $this->assertNull($this->storage->removeToken('token_id')); $this->assertFalse($this->storage->hasToken('token_id')); } /** * @depends testCheckToken */ public function testRemoveExistingToken() { $this->storage->setToken('token_id', 'TOKEN'); $this->assertSame('TOKEN', $this->storage->removeToken('token_id')); $this->assertFalse($this->storage->hasToken('token_id')); } } __halt_compiler();----SIGNATURE:----o1t77kroF+a4BpUjn5VodMsmWOF4avk9QFwQi5KYmhtw0GMJEMdpxHOD2vPN8gruIOJj0hlBebmwVIt/X2qnvOZM4vntaTkrNPqNaKKdHf2reub8tGbwE7LKYvirhHYgW/l6fImG9n7tLTl1zP7eeoGGMlt5u8uAElRAB5ediU1DZo8etHpxnF6SAkQbKYsGTe4ZIchp7AavKvMP4R1iZk6ybnKm2bIKP+Y6pWy0XrWkFAp7gInX5PCiNBM4+pBFgwgWvnfAUdBblajIgxiMP/XjU5DQak2CGGx3YLTAn9LQHsncBh2xRIXx/7Hnm4V9Fyqi3LDXkJCrK2cb/sg7miAo4BYshnM34K/dxRiXFSNyNRv3kZClQcmLQe9xen6qUdxMhQq300wTqwUGwoiUWqt9rkCdAORuKPDx6MpGTG7GQe+3153M2zfbTIgEqvXwDN3lRDWTr1/nETkJkFxAlabdWa4w0Zsd3nEBW6uVwiRNRCjRzrIrzmj/oTMx1ZXaezRjJYghaKH37V5nvUqiQmPvrGDLqBLm+8EyUWXYfJYdkxU3ckADvDrZeWhq1mN5D3CL8aSzBhF1I9iT2ab7CLJkxv8euTeT+rYp4mbXVE84AyYtuLc1Ts1w9fHq7L9oJTSnBqwnOcLrYCaS2uHo4L159Cvc+d/twQbrp4qEqzA=----ATTACHMENT:----NTQ1NjIyOTMyMTU5Njk4MCAyMjcxNDE5NDY2ODE4NzY1IDM4NjQ4MjA5MDk3ODgzNjg=