/** * Proves that invalid sessions will be destroyed and re-created * if invalid * * @return void */ public function testInvalidSessionRenew() { TestCakeSession::start(); $this->assertNotEmpty($_SESSION['Config']); $data = $_SESSION; session_write_close(); $_SESSION = null; TestCakeSession::start(); $this->assertEquals($data, $_SESSION); TestCakeSession::write('Foo', 'Bar'); session_write_close(); $_SESSION = null; TestCakeSession::userAgent('bogus!'); TestCakeSession::start(); $this->assertNotEquals($data, $_SESSION); $this->assertEquals('bogus!', $_SESSION['Config']['userAgent']); }
/** * testSessionTimeout method * * @return void */ public function testSessionTimeout() { Configure::write('debug', 2); Configure::write('Session.defaults', 'cake'); Configure::write('Session.autoRegenerate', false); $timeoutSeconds = Configure::read('Session.timeout') * 60; TestCakeSession::destroy(); TestCakeSession::write('Test', 'some value'); $this->assertWithinMargin(time() + $timeoutSeconds, CakeSession::$sessionTime, 1); $this->assertEquals(10, $_SESSION['Config']['countdown']); $this->assertWithinMargin(CakeSession::$sessionTime, $_SESSION['Config']['time'], 1); $this->assertWithinMargin(time(), CakeSession::$time, 1); $this->assertWithinMargin(time() + $timeoutSeconds, $_SESSION['Config']['time'], 1); Configure::write('Session.harden', true); TestCakeSession::destroy(); TestCakeSession::write('Test', 'some value'); $this->assertWithinMargin(time() + $timeoutSeconds, CakeSession::$sessionTime, 1); $this->assertEquals(10, $_SESSION['Config']['countdown']); $this->assertWithinMargin(CakeSession::$sessionTime, $_SESSION['Config']['time'], 1); $this->assertWithinMargin(time(), CakeSession::$time, 1); $this->assertWithinMargin(CakeSession::$time + $timeoutSeconds, $_SESSION['Config']['time'], 1); }