SessionStoreTest.php in Auth0 Single Sign On 8.2
File
vendor/auth0/auth0-php/tests/Store/SessionStoreTest.php
View source
<?php
use Auth0\SDK\Store\SessionStore;
class SessionStoreTest extends PHPUnit_Framework_TestCase {
const TEST_KEY = 'never_compromise_on_identity';
const TEST_VALUE = '__Auth0__';
const COOKIE_LIFETIME = 604800;
public static $sessionStore;
public static $sessionKey;
public static function setUpBeforeClass() {
self::$sessionStore = new SessionStore();
self::$sessionKey = 'auth0__' . self::TEST_KEY;
}
public function testInitSession() {
@self::$sessionStore
->set(self::TEST_KEY, self::TEST_VALUE);
$this
->assertNotEmpty(session_id());
$cookieParams = session_get_cookie_params();
$this
->assertEquals(self::COOKIE_LIFETIME, $cookieParams['lifetime']);
}
public function testGetSessionKey() {
$test_this_key_name = self::$sessionStore
->getSessionKeyName(self::TEST_KEY);
$this
->assertEquals(self::$sessionKey, $test_this_key_name);
}
public function testSet() {
$this
->assertFalse(isset($_SESSION[self::$sessionKey]));
@self::$sessionStore
->set(self::TEST_KEY, self::TEST_VALUE);
$this
->assertEquals(self::TEST_VALUE, $_SESSION[self::$sessionKey]);
}
public function testGet() {
session_start();
$_SESSION[self::$sessionKey] = self::TEST_VALUE;
$this
->assertEquals(self::TEST_VALUE, self::$sessionStore
->get(self::TEST_KEY));
}
public function testDelete() {
session_start();
$_SESSION[self::$sessionKey] = self::TEST_VALUE;
$this
->assertTrue(isset($_SESSION[self::$sessionKey]));
self::$sessionStore
->delete(self::TEST_KEY);
$this
->assertNull(self::$sessionStore
->get(self::TEST_KEY));
$this
->assertFalse(isset($_SESSION[self::$sessionKey]));
}
public function testCustomSessionBaseName() {
$test_base_name = 'test_base_name';
self::$sessionStore = new SessionStore($test_base_name);
$test_this_key_name = self::$sessionStore
->getSessionKeyName(self::TEST_KEY);
$this
->assertEquals($test_base_name . '_' . self::TEST_KEY, $test_this_key_name);
@self::$sessionStore
->set(self::TEST_KEY, self::TEST_VALUE);
$this
->assertEquals(self::TEST_VALUE, self::$sessionStore
->get(self::TEST_KEY));
}
public function testCustomCookieExpires() {
$custom_expires = mt_rand(11111, 99999);
$this
->assertEmpty(session_id());
self::$sessionStore = new SessionStore(null, $custom_expires);
@self::$sessionStore
->set(self::TEST_KEY, self::TEST_VALUE);
$this
->assertNotEmpty(session_id());
$cookieParams = session_get_cookie_params();
$this
->assertEquals($custom_expires, $cookieParams['lifetime']);
}
}