* * 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:----oFytRX4t2wW+mhNHbi7E229gPcPVeZ6dcwswaL1dtwWmznAAuDz2/QKJJmSKgT9rjkNW5VQh1Mmd+U41mS+qrlYIS+fkjT3VTBqldw1I9w7Hf2JBanyDHJl+6sI3ZCN5zO5A5i+PZRhdcwQ6r0cisrYD6GildTm+A8sRl3nIi3bOt4D6EgDS70cIYmC9ITWUDYujDEuMKiWw0UJhWZ6YPDVqZqGf3WAKbOn8rxPtGo1OZVKVKrK+0+QDilL4wGD5FcxNaRuTASGgOreGAJSQQPUQ+t/TJSV6e8omNkyRa4DrlHE+QdeWdUGGobx3Gzb9vWMH8UMEXmhUailPyY23AOYjJzQj+rUnm9dzi9Bnm2oGQeBFHblnUau4xNs8BqJ7QGD/A9Y3Eevwwgw61EO5GC4sVkB8tqdvE4eJqFA0XyL4Y1/WcvWvsR050fjD0GVIKpYct1Rq+/Jk0v3vfzEugYMNoLg/GPJoK2+Keo1v+Vq+PHgvJxSef0b9Dk5OFgQhCJ7LgRRMBeh2HSXR8KPa4aLsWXFK6cW5pP4ixdPXN3z/2uI8Z/yhJXHB+Z9JNf3hUN9BuPHNhSQyyKG0LBKidxoxeLsEkRxx84NkLFlv9nFaJElID419IT3dZ/LK2yibxR5yhhO1UMephmKsQwDa2gFDwmrIcUjnPBzzRTA2mj4=----ATTACHMENT:----MjQ3MjQ2MDY3ODI3MTU3MCA3NjEwNDQ1MTcxNzE2NjM2IDc3OTc4ODE0MzQwNjMwMjI=