*/
public function storeLoginInfo($clientIpId)
{
- // Generate unique random number (different than phpsessionid)
- $this->session['uid'] = sha1(uniqid('', true) . '_' . mt_rand());
$this->session['ip'] = $clientIpId;
$this->session['username'] = $this->conf->get('credentials.login');
$this->extendTimeValidityBy(self::$SHORT_TIMEOUT);
public function logout()
{
if (isset($this->session)) {
- unset($this->session['uid']);
unset($this->session['ip']);
unset($this->session['expires_on']);
unset($this->session['username']);
*/
public function hasSessionExpired()
{
- if (empty($this->session['uid'])) {
- return true;
- }
if (time() >= $this->session['expires_on']) {
return true;
}
{
$this->sessionManager->storeLoginInfo('ip_id');
- $this->assertTrue(isset($this->session['uid']));
$this->assertGreaterThan(time(), $this->session['expires_on']);
$this->assertEquals('ip_id', $this->session['ip']);
$this->assertEquals('johndoe', $this->session['username']);
public function testLogout()
{
$this->session = [
- 'uid' => 'some-uid',
'ip' => 'ip_id',
'expires_on' => time() + 1000,
'username' => 'johndoe',
];
$this->sessionManager->logout();
- $this->assertFalse(isset($this->session['uid']));
$this->assertFalse(isset($this->session['ip']));
$this->assertFalse(isset($this->session['expires_on']));
$this->assertFalse(isset($this->session['username']));
$this->assertFalse(isset($this->session['untaggedonly']));
}
- /**
- * The session is considered as expired because the UID is missing
- */
- public function testHasExpiredNoUid()
- {
- $this->assertTrue($this->sessionManager->hasSessionExpired());
- }
-
/**
* The session is active and expiration time has been reached
*/
public function testHasExpiredTimeElapsed()
{
- $this->session['uid'] = 'some-uid';
$this->session['expires_on'] = time() - 10;
$this->assertTrue($this->sessionManager->hasSessionExpired());
*/
public function testHasNotExpired()
{
- $this->session['uid'] = 'some-uid';
$this->session['expires_on'] = time() + 1000;
$this->assertFalse($this->sessionManager->hasSessionExpired());