diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index 0acedace6..f84315215 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -239,7 +239,7 @@ class CakeSession { self::_startSession(); $started = self::started(); - if (!self::id() && $started) { + if (self::id() && $started) { self::_checkValid(); } @@ -492,12 +492,11 @@ class CakeSession { * @return void */ public static function destroy() { - $_SESSION = array(); + $_SESSION = null; self::$id = null; self::init(self::$path); self::start(); self::renew(); - self::_checkValid(); } /** diff --git a/cake/tests/cases/libs/cake_session.test.php b/cake/tests/cases/libs/cake_session.test.php index c9307b07b..e0c21881e 100644 --- a/cake/tests/cases/libs/cake_session.test.php +++ b/cake/tests/cases/libs/cake_session.test.php @@ -111,7 +111,7 @@ class CakeSessionTest extends CakeTestCase { * @return void */ function testSessionConfigIniSetting() { - $_SESSION = array(); + $_SESSION = null; session_destroy(); Configure::write('Session', array( @@ -188,6 +188,34 @@ class CakeSessionTest extends CakeTestCase { $this->assertEqual('cakephp.org', TestCakeSession::$host); } +/** + * test valid with bogus user agent. + * + * @return void + */ + function testValidBogusUserAgent() { + Configure::write('Session.checkAgent', true); + TestCakeSession::start(); + $this->assertTrue(TestCakeSession::valid(), 'Newly started session should be valid'); + + TestCakeSession::userAgent('bogus!'); + $this->assertFalse(TestCakeSession::valid(), 'user agent mismatch should fail.'); + } + +/** + * test valid with bogus user agent. + * + * @return void + */ + function testValidTimeExpiry() { + Configure::write('Session.checkAgent', true); + TestCakeSession::start(); + $this->assertTrue(TestCakeSession::valid(), 'Newly started session should be valid'); + + TestCakeSession::$time = strtotime('next year'); + $this->assertFalse(TestCakeSession::valid(), 'time should cause failure.'); + } + /** * testCheck method * @@ -299,6 +327,7 @@ class CakeSessionTest extends CakeTestCase { $_SESSION = null; $this->assertFalse(TestCakeSession::started()); $this->assertTrue(TestCakeSession::start()); + $this->assertTrue(TestCakeSession::started()); } /**