2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* SessionTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model.Datasource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:13:11 +00:00
|
|
|
|
|
|
|
App::uses('CakeSession', 'Model/Datasource');
|
2012-03-24 20:32:31 +00:00
|
|
|
App::uses('DatabaseSession', 'Model/Datasource/Session');
|
|
|
|
App::uses('CacheSession', 'Model/Datasource/Session');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-04-04 07:21:01 +00:00
|
|
|
class TestCakeSession extends CakeSession {
|
2012-03-11 12:12:56 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
public static function setUserAgent($value) {
|
|
|
|
self::$_userAgent = $value;
|
2010-04-04 07:21:01 +00:00
|
|
|
}
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-07-22 09:09:48 +00:00
|
|
|
public static function setHost($host) {
|
|
|
|
self::_setHost($host);
|
|
|
|
}
|
2012-03-11 12:12:56 +00:00
|
|
|
|
2010-04-04 07:21:01 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 20:32:31 +00:00
|
|
|
class TestCacheSession extends CacheSession {
|
|
|
|
|
|
|
|
protected function _writeSession() {
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-03 03:23:53 +00:00
|
|
|
|
2012-03-24 20:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class TestDatabaseSession extends DatabaseSession {
|
|
|
|
|
|
|
|
protected function _writeSession() {
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-03 03:23:53 +00:00
|
|
|
|
2012-03-24 20:32:31 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-17 00:19:12 +00:00
|
|
|
* CakeSessionTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model.Datasource
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-01-17 00:19:12 +00:00
|
|
|
class CakeSessionTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-25 04:42:28 +00:00
|
|
|
protected static $_gcDivisor;
|
|
|
|
|
2009-04-13 19:47:40 +00:00
|
|
|
/**
|
|
|
|
* Fixtures used in the SessionTest
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.session');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2010-07-25 04:42:28 +00:00
|
|
|
* setup before class.
|
2009-03-26 14:25:47 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-07-25 04:42:28 +00:00
|
|
|
public static function setupBeforeClass() {
|
2009-03-26 14:25:47 +00:00
|
|
|
// Make sure garbage colector will be called
|
2010-07-25 04:42:28 +00:00
|
|
|
self::$_gcDivisor = ini_get('session.gc_divisor');
|
2009-03-26 14:25:47 +00:00
|
|
|
ini_set('session.gc_divisor', '1');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-26 14:25:47 +00:00
|
|
|
/**
|
2010-07-25 04:42:28 +00:00
|
|
|
* teardown after class
|
2009-03-26 14:25:47 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-07-25 04:42:28 +00:00
|
|
|
public static function teardownAfterClass() {
|
2009-03-26 14:25:47 +00:00
|
|
|
// Revert to the default setting
|
2010-07-25 04:42:28 +00:00
|
|
|
ini_set('session.gc_divisor', self::$_gcDivisor);
|
2009-03-26 14:25:47 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-26 14:25:47 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* setUp method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-04 21:27:51 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2010-07-25 04:42:28 +00:00
|
|
|
Configure::write('Session', array(
|
|
|
|
'defaults' => 'php',
|
|
|
|
'cookie' => 'cakephp',
|
|
|
|
'timeout' => 120,
|
|
|
|
'cookieTimeout' => 120,
|
|
|
|
'ini' => array(),
|
|
|
|
));
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::init();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-13 19:47:40 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-07-24 19:18:37 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function teardown() {
|
2010-07-27 02:38:40 +00:00
|
|
|
if (TestCakeSession::started()) {
|
2012-03-24 20:43:25 +00:00
|
|
|
session_write_close();
|
2010-07-27 02:38:40 +00:00
|
|
|
}
|
2010-07-25 04:42:28 +00:00
|
|
|
unset($_SESSION);
|
2010-09-28 04:03:23 +00:00
|
|
|
parent::teardown();
|
2010-07-25 04:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test setting ini properties with Session configuration.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSessionConfigIniSetting() {
|
2010-07-27 02:38:40 +00:00
|
|
|
$_SESSION = null;
|
2010-07-25 04:42:28 +00:00
|
|
|
|
|
|
|
Configure::write('Session', array(
|
2010-09-20 02:58:30 +00:00
|
|
|
'cookie' => 'test',
|
2010-07-27 02:38:40 +00:00
|
|
|
'checkAgent' => false,
|
2010-07-25 04:42:28 +00:00
|
|
|
'timeout' => 86400,
|
|
|
|
'ini' => array(
|
|
|
|
'session.referer_check' => 'example.com',
|
|
|
|
'session.use_trans_sid' => false
|
|
|
|
)
|
|
|
|
));
|
|
|
|
TestCakeSession::start();
|
|
|
|
$this->assertEquals('', ini_get('session.use_trans_sid'), 'Ini value is incorrect');
|
|
|
|
$this->assertEquals('example.com', ini_get('session.referer_check'), 'Ini value is incorrect');
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->assertEquals('test', ini_get('session.name'), 'Ini value is incorrect');
|
2010-07-25 04:42:28 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-01 16:52:05 +00:00
|
|
|
/**
|
|
|
|
* testSessionPath
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSessionPath() {
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::init('/index.php');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/', TestCakeSession::$path);
|
2009-06-03 16:22:00 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::init('/sub_dir/index.php');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/sub_dir/', TestCakeSession::$path);
|
2010-07-22 08:42:56 +00:00
|
|
|
}
|
2009-06-03 16:22:00 +00:00
|
|
|
|
2010-07-22 08:42:56 +00:00
|
|
|
/**
|
|
|
|
* testCakeSessionPathEmpty
|
|
|
|
*
|
|
|
|
* @return void
|
2011-04-17 10:35:21 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCakeSessionPathEmpty() {
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::init('');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/', TestCakeSession::$path, 'Session path is empty, with "" as $base needs to be /');
|
2009-06-01 16:52:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-22 08:42:56 +00:00
|
|
|
/**
|
|
|
|
* testCakeSessionPathContainsParams
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCakeSessionPathContainsQuestion() {
|
2010-07-22 08:42:56 +00:00
|
|
|
TestCakeSession::init('/index.php?');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/', TestCakeSession::$path);
|
2010-07-22 08:42:56 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 09:09:48 +00:00
|
|
|
/**
|
|
|
|
* testSetHost
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSetHost() {
|
2010-07-22 09:09:48 +00:00
|
|
|
TestCakeSession::init();
|
|
|
|
TestCakeSession::setHost('cakephp.org');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('cakephp.org', TestCakeSession::$host);
|
2010-07-22 09:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testSetHostWithPort
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSetHostWithPort() {
|
2010-07-22 09:09:48 +00:00
|
|
|
TestCakeSession::init();
|
|
|
|
TestCakeSession::setHost('cakephp.org:443');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('cakephp.org', TestCakeSession::$host);
|
2010-07-22 09:09:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-25 23:55:02 +00:00
|
|
|
/**
|
|
|
|
* test valid with bogus user agent.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testValidBogusUserAgent() {
|
2010-07-25 23:55:02 +00:00
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testValidTimeExpiry() {
|
2010-07-25 23:55:02 +00:00
|
|
|
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.');
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testCheck method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheck() {
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 'value');
|
|
|
|
$this->assertTrue(TestCakeSession::check('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase'), false);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testSimpleRead method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSimpleRead() {
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('testing', '1,2,3');
|
|
|
|
$result = TestCakeSession::read('testing');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('1,2,3', $result);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('testing', array('1' => 'one', '2' => 'two','3' => 'three'));
|
|
|
|
$result = TestCakeSession::read('testing.1');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('one', $result);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$result = TestCakeSession::read('testing');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(array('1' => 'one', '2' => 'two', '3' => 'three'), $result);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$result = TestCakeSession::read();
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(isset($result['testing']));
|
|
|
|
$this->assertTrue(isset($result['Config']));
|
|
|
|
$this->assertTrue(isset($result['Config']['userAgent']));
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('This.is.a.deep.array.my.friend', 'value');
|
|
|
|
$result = TestCakeSession::read('This.is.a.deep.array.my.friend');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('value', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-22 09:19:53 +00:00
|
|
|
/**
|
|
|
|
* testReadyEmpty
|
|
|
|
*
|
2010-07-22 09:24:11 +00:00
|
|
|
* @return void
|
2010-07-22 09:19:53 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadyEmpty() {
|
2010-07-22 09:19:53 +00:00
|
|
|
$this->assertFalse(TestCakeSession::read(''));
|
|
|
|
}
|
|
|
|
|
2010-07-16 03:54:01 +00:00
|
|
|
/**
|
|
|
|
* test writing a hash of values/
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testWriteArray() {
|
2010-07-16 03:54:01 +00:00
|
|
|
$result = TestCakeSession::write(array(
|
|
|
|
'one' => 1,
|
|
|
|
'two' => 2,
|
|
|
|
'three' => array('something'),
|
|
|
|
'null' => null
|
|
|
|
));
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEquals(1, TestCakeSession::read('one'));
|
|
|
|
$this->assertEquals(array('something'), TestCakeSession::read('three'));
|
|
|
|
$this->assertEquals(null, TestCakeSession::read('null'));
|
|
|
|
}
|
|
|
|
|
2010-07-22 09:24:11 +00:00
|
|
|
/**
|
|
|
|
* testWriteEmptyKey
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testWriteEmptyKey() {
|
2010-07-22 09:24:11 +00:00
|
|
|
$this->assertFalse(TestCakeSession::write('', 'graham'));
|
|
|
|
$this->assertFalse(TestCakeSession::write('', ''));
|
|
|
|
$this->assertFalse(TestCakeSession::write(''));
|
|
|
|
}
|
|
|
|
|
2012-03-27 01:50:53 +00:00
|
|
|
/**
|
|
|
|
* Test overwriting a string value as if it were an array.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testWriteOverwriteStringValue() {
|
|
|
|
TestCakeSession::write('Some.string', 'value');
|
|
|
|
$this->assertEquals('value', TestCakeSession::read('Some.string'));
|
|
|
|
|
|
|
|
TestCakeSession::write('Some.string.array', array('values'));
|
|
|
|
$this->assertEquals(
|
|
|
|
array('values'),
|
|
|
|
TestCakeSession::read('Some.string.array')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testId method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testId() {
|
2010-12-11 03:00:44 +00:00
|
|
|
TestCakeSession::destroy();
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$result = TestCakeSession::id();
|
2010-12-10 04:55:38 +00:00
|
|
|
$expected = session_id();
|
2010-12-11 03:00:44 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::id('MySessionId');
|
|
|
|
$result = TestCakeSession::id();
|
2010-12-11 03:00:44 +00:00
|
|
|
$this->assertEquals('MySessionId', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testStarted method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testStarted() {
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($_SESSION);
|
2010-01-15 03:47:49 +00:00
|
|
|
$_SESSION = null;
|
2010-12-10 04:55:38 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertFalse(TestCakeSession::started());
|
|
|
|
$this->assertTrue(TestCakeSession::start());
|
2010-07-25 23:55:02 +00:00
|
|
|
$this->assertTrue(TestCakeSession::started());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testError method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testError() {
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::read('Does.not.exist');
|
|
|
|
$result = TestCakeSession::error();
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals("Does.not.exist doesn't exist", $result);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::delete('Failing.delete');
|
|
|
|
$result = TestCakeSession::error();
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals("Failing.delete doesn't exist", $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testDel method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDelete() {
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertTrue(TestCakeSession::write('Delete.me', 'Clearing out'));
|
|
|
|
$this->assertTrue(TestCakeSession::delete('Delete.me'));
|
|
|
|
$this->assertFalse(TestCakeSession::check('Delete.me'));
|
|
|
|
$this->assertTrue(TestCakeSession::check('Delete'));
|
|
|
|
|
|
|
|
$this->assertTrue(TestCakeSession::write('Clearing.sale', 'everything must go'));
|
|
|
|
$this->assertTrue(TestCakeSession::delete('Clearing'));
|
|
|
|
$this->assertFalse(TestCakeSession::check('Clearing.sale'));
|
|
|
|
$this->assertFalse(TestCakeSession::check('Clearing'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testDestroy method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDestroy() {
|
2012-02-23 23:29:53 +00:00
|
|
|
TestCakeSession::write('bulletProof', 'invincible');
|
2010-07-05 07:01:22 +00:00
|
|
|
$id = TestCakeSession::id();
|
|
|
|
TestCakeSession::destroy();
|
2010-07-08 03:33:38 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertFalse(TestCakeSession::check('bulletProof'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertNotEquals(TestCakeSession::id(), $id);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testCheckingSavedEmpty method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheckingSavedEmpty() {
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertTrue(TestCakeSession::write('SessionTestCase', 0));
|
|
|
|
$this->assertTrue(TestCakeSession::check('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertTrue(TestCakeSession::write('SessionTestCase', '0'));
|
|
|
|
$this->assertTrue(TestCakeSession::check('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertTrue(TestCakeSession::write('SessionTestCase', false));
|
|
|
|
$this->assertTrue(TestCakeSession::check('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertTrue(TestCakeSession::write('SessionTestCase', null));
|
|
|
|
$this->assertFalse(TestCakeSession::check('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testCheckKeyWithSpaces method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheckKeyWithSpaces() {
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertTrue(TestCakeSession::write('Session Test', "test"));
|
2011-12-04 20:43:27 +00:00
|
|
|
$this->assertTrue(TestCakeSession::check('Session Test'));
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::delete('Session Test');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertTrue(TestCakeSession::write('Session Test.Test Case', "test"));
|
|
|
|
$this->assertTrue(TestCakeSession::check('Session Test.Test Case'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-22 09:11:53 +00:00
|
|
|
/**
|
|
|
|
* testCheckEmpty
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheckEmpty() {
|
2010-07-22 09:11:53 +00:00
|
|
|
$this->assertFalse(TestCakeSession::check());
|
|
|
|
}
|
|
|
|
|
2009-11-22 01:44:35 +00:00
|
|
|
/**
|
|
|
|
* test key exploitation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testKeyExploit() {
|
2009-11-22 01:44:35 +00:00
|
|
|
$key = "a'] = 1; phpinfo(); \$_SESSION['a";
|
2010-07-05 07:01:22 +00:00
|
|
|
$result = TestCakeSession::write($key, 'haxored');
|
2009-11-22 01:44:35 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
$result = TestCakeSession::read($key);
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('haxored', $result);
|
2009-11-22 01:44:35 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testReadingSavedEmpty method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadingSavedEmpty() {
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 0);
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(0, TestCakeSession::read('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', '0');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('0', TestCakeSession::read('SessionTestCase'));
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertFalse(TestCakeSession::read('SessionTestCase') === 0);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', false);
|
|
|
|
$this->assertFalse(TestCakeSession::read('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', null);
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(null, TestCakeSession::read('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 23:57:30 +00:00
|
|
|
/**
|
|
|
|
* testCheckUserAgentFalse method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 23:57:30 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheckUserAgentFalse() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Configure::write('Session.checkAgent', false);
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::setUserAgent(md5('http://randomdomainname.com' . Configure::read('Security.salt')));
|
|
|
|
$this->assertTrue(TestCakeSession::valid());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 23:57:30 +00:00
|
|
|
/**
|
|
|
|
* testCheckUserAgentTrue method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 23:57:30 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheckUserAgentTrue() {
|
2008-05-30 11:40:08 +00:00
|
|
|
Configure::write('Session.checkAgent', true);
|
2010-07-08 03:33:38 +00:00
|
|
|
TestCakeSession::$error = false;
|
|
|
|
$agent = md5('http://randomdomainname.com' . Configure::read('Security.salt'));
|
|
|
|
|
|
|
|
TestCakeSession::write('Config.userAgent', md5('Hacking you!'));
|
|
|
|
TestCakeSession::setUserAgent($agent);
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertFalse(TestCakeSession::valid());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 23:57:30 +00:00
|
|
|
/**
|
2012-03-30 19:10:44 +00:00
|
|
|
* testReadAndWriteWithCakeStorage method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 23:57:30 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadAndWriteWithCakeStorage() {
|
2010-07-25 05:14:41 +00:00
|
|
|
Configure::write('Session.defaults', 'cake');
|
|
|
|
|
|
|
|
TestCakeSession::init();
|
2010-07-27 02:38:40 +00:00
|
|
|
TestCakeSession::start();
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 0);
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(0, TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', '0');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('0', TestCakeSession::read('SessionTestCase'));
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertFalse(TestCakeSession::read('SessionTestCase') === 0);
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', false);
|
|
|
|
$this->assertFalse(TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', null);
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(null, TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 'This is a Test');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('This is a Test', TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 'This is a Test');
|
|
|
|
TestCakeSession::write('SessionTestCase', 'This was updated');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('This was updated', TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::destroy();
|
2010-07-16 03:48:02 +00:00
|
|
|
$this->assertNull(TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-25 23:09:29 +00:00
|
|
|
/**
|
2011-06-20 00:28:40 +00:00
|
|
|
* test using a handler from app/Model/Datasource/Session.
|
2010-07-25 23:09:29 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUsingAppLibsHandler() {
|
2010-07-25 23:09:29 +00:00
|
|
|
App::build(array(
|
2011-04-10 19:32:19 +00:00
|
|
|
'Model/Datasource/Session' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS . 'Datasource' . DS . 'Session' . DS
|
2011-04-10 19:32:19 +00:00
|
|
|
),
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2010-07-25 23:09:29 +00:00
|
|
|
Configure::write('Session', array(
|
|
|
|
'defaults' => 'cake',
|
|
|
|
'handler' => array(
|
|
|
|
'engine' => 'TestAppLibSession'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
TestCakeSession::destroy();
|
|
|
|
$this->assertTrue(TestCakeSession::started());
|
|
|
|
|
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test using a handler from a plugin.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUsingPluginHandler() {
|
2010-07-25 23:09:29 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2011-12-04 20:43:27 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-07-25 23:09:29 +00:00
|
|
|
Configure::write('Session', array(
|
|
|
|
'defaults' => 'cake',
|
|
|
|
'handler' => array(
|
|
|
|
'engine' => 'TestPlugin.TestPluginSession'
|
|
|
|
)
|
|
|
|
));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-07-25 23:09:29 +00:00
|
|
|
TestCakeSession::destroy();
|
|
|
|
$this->assertTrue(TestCakeSession::started());
|
|
|
|
|
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
2012-03-30 19:10:44 +00:00
|
|
|
* testReadAndWriteWithCacheStorage method
|
2008-06-10 22:38:05 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadAndWriteWithCacheStorage() {
|
2010-07-25 05:14:41 +00:00
|
|
|
Configure::write('Session.defaults', 'cache');
|
2012-03-24 20:32:31 +00:00
|
|
|
Configure::write('Session.handler.engine', 'TestCacheSession');
|
2010-07-25 05:14:41 +00:00
|
|
|
|
|
|
|
TestCakeSession::init();
|
|
|
|
TestCakeSession::destroy();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 0);
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(0, TestCakeSession::read('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', '0');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('0', TestCakeSession::read('SessionTestCase'));
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertFalse(TestCakeSession::read('SessionTestCase') === 0);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', false);
|
|
|
|
$this->assertFalse(TestCakeSession::read('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', null);
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(null, TestCakeSession::read('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 'This is a Test');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('This is a Test', TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 'This is a Test');
|
|
|
|
TestCakeSession::write('SessionTestCase', 'This was updated');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('This was updated', TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::destroy();
|
2010-07-16 03:48:02 +00:00
|
|
|
$this->assertNull(TestCakeSession::read('SessionTestCase'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-25 17:37:56 +00:00
|
|
|
/**
|
|
|
|
* test that changing the config name of the cache config works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadAndWriteWithCustomCacheConfig() {
|
2010-07-25 17:37:56 +00:00
|
|
|
Configure::write('Session.defaults', 'cache');
|
2012-03-24 20:32:31 +00:00
|
|
|
Configure::write('Session.handler.engine', 'TestCacheSession');
|
2010-07-25 17:37:56 +00:00
|
|
|
Configure::write('Session.handler.config', 'session_test');
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-07-25 17:37:56 +00:00
|
|
|
Cache::config('session_test', array(
|
|
|
|
'engine' => 'File',
|
|
|
|
'prefix' => 'session_test_',
|
|
|
|
));
|
|
|
|
|
|
|
|
TestCakeSession::init();
|
2010-07-27 02:38:40 +00:00
|
|
|
TestCakeSession::start();
|
2010-07-25 17:37:56 +00:00
|
|
|
|
|
|
|
TestCakeSession::write('SessionTestCase', 'Some value');
|
|
|
|
$this->assertEquals('Some value', TestCakeSession::read('SessionTestCase'));
|
2010-07-27 02:38:40 +00:00
|
|
|
$id = TestCakeSession::id();
|
2010-07-25 17:37:56 +00:00
|
|
|
|
2010-07-27 02:38:40 +00:00
|
|
|
Cache::delete($id, 'session_test');
|
2010-07-25 17:37:56 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-10 22:38:05 +00:00
|
|
|
* testReadAndWriteWithDatabaseStorage method
|
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadAndWriteWithDatabaseStorage() {
|
2010-07-25 05:14:41 +00:00
|
|
|
Configure::write('Session.defaults', 'database');
|
2012-03-24 20:32:31 +00:00
|
|
|
Configure::write('Session.handler.engine', 'TestDatabaseSession');
|
2010-07-25 15:42:05 +00:00
|
|
|
Configure::write('Session.handler.table', 'sessions');
|
|
|
|
Configure::write('Session.handler.model', 'Session');
|
2010-09-20 02:58:30 +00:00
|
|
|
Configure::write('Session.handler.database', 'test');
|
2010-07-25 05:14:41 +00:00
|
|
|
|
|
|
|
TestCakeSession::init();
|
2012-03-30 19:10:44 +00:00
|
|
|
$this->assertNull(TestCakeSession::id());
|
|
|
|
|
2010-07-27 02:38:40 +00:00
|
|
|
TestCakeSession::start();
|
2012-03-30 19:10:44 +00:00
|
|
|
$expected = session_id();
|
|
|
|
$this->assertEquals($expected, TestCakeSession::id());
|
|
|
|
|
|
|
|
TestCakeSession::renew();
|
|
|
|
$this->assertFalse($expected == TestCakeSession::id());
|
|
|
|
|
|
|
|
$expected = session_id();
|
|
|
|
$this->assertEquals($expected, TestCakeSession::id());
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 0);
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(0, TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', '0');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('0', TestCakeSession::read('SessionTestCase'));
|
2010-07-05 07:01:22 +00:00
|
|
|
$this->assertFalse(TestCakeSession::read('SessionTestCase') === 0);
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', false);
|
|
|
|
$this->assertFalse(TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', null);
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(null, TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 'This is a Test');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('This is a Test', TestCakeSession::read('SessionTestCase'));
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2010-07-27 02:38:40 +00:00
|
|
|
TestCakeSession::write('SessionTestCase', 'Some additional data');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals('Some additional data', TestCakeSession::read('SessionTestCase'));
|
2009-04-13 19:47:40 +00:00
|
|
|
|
2010-07-05 07:01:22 +00:00
|
|
|
TestCakeSession::destroy();
|
2010-07-16 03:48:02 +00:00
|
|
|
$this->assertNull(TestCakeSession::read('SessionTestCase'));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-09-30 03:01:23 +00:00
|
|
|
Configure::write('Session', array(
|
|
|
|
'defaults' => 'php'
|
|
|
|
));
|
|
|
|
TestCakeSession::init();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-01-21 16:59:49 +00:00
|
|
|
|
2010-07-25 21:50:08 +00:00
|
|
|
/**
|
|
|
|
* testSessionTimeout method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSessionTimeout() {
|
2010-07-25 21:50:08 +00:00
|
|
|
Configure::write('debug', 2);
|
2012-03-24 20:32:31 +00:00
|
|
|
Configure::write('Session.defaults', 'cake');
|
2010-07-27 02:42:32 +00:00
|
|
|
Configure::write('Session.autoRegenerate', false);
|
2010-07-25 21:50:08 +00:00
|
|
|
|
|
|
|
$timeoutSeconds = Configure::read('Session.timeout') * 60;
|
|
|
|
|
|
|
|
TestCakeSession::destroy();
|
|
|
|
TestCakeSession::write('Test', 'some value');
|
|
|
|
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(time() + $timeoutSeconds, CakeSession::$sessionTime);
|
|
|
|
$this->assertEquals(10, $_SESSION['Config']['countdown']);
|
|
|
|
$this->assertEquals(CakeSession::$sessionTime, $_SESSION['Config']['time']);
|
|
|
|
$this->assertEquals(time(), CakeSession::$time);
|
|
|
|
$this->assertEquals(time() + $timeoutSeconds, $_SESSION['Config']['time']);
|
2010-07-25 21:50:08 +00:00
|
|
|
|
|
|
|
Configure::write('Session.harden', true);
|
|
|
|
TestCakeSession::destroy();
|
|
|
|
|
|
|
|
TestCakeSession::write('Test', 'some value');
|
2010-12-11 03:03:53 +00:00
|
|
|
$this->assertEquals(time() + $timeoutSeconds, CakeSession::$sessionTime);
|
|
|
|
$this->assertEquals(10, $_SESSION['Config']['countdown']);
|
|
|
|
$this->assertEquals(CakeSession::$sessionTime, $_SESSION['Config']['time']);
|
|
|
|
$this->assertEquals(time(), CakeSession::$time);
|
|
|
|
$this->assertEquals(CakeSession::$time + $timeoutSeconds, $_SESSION['Config']['time']);
|
2010-07-25 21:50:08 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 12:12:56 +00:00
|
|
|
/**
|
|
|
|
* Test that cookieTimeout matches timeout when unspecified.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCookieTimeoutFallback() {
|
|
|
|
$_SESSION = null;
|
|
|
|
Configure::write('Session', array(
|
2012-03-24 20:32:31 +00:00
|
|
|
'defaults' => 'cake',
|
2012-03-11 12:12:56 +00:00
|
|
|
'timeout' => 400,
|
|
|
|
));
|
|
|
|
TestCakeSession::start();
|
|
|
|
$this->assertEquals(400, Configure::read('Session.cookieTimeout'));
|
|
|
|
$this->assertEquals(400, Configure::read('Session.timeout'));
|
|
|
|
|
|
|
|
$_SESSION = null;
|
|
|
|
Configure::write('Session', array(
|
2012-03-24 20:32:31 +00:00
|
|
|
'defaults' => 'cake',
|
2012-03-11 12:12:56 +00:00
|
|
|
'timeout' => 400,
|
|
|
|
'cookieTimeout' => 600
|
|
|
|
));
|
|
|
|
TestCakeSession::start();
|
|
|
|
$this->assertEquals(600, Configure::read('Session.cookieTimeout'));
|
|
|
|
$this->assertEquals(400, Configure::read('Session.timeout'));
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|