2011-01-04 17:14:36 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package testing
|
|
|
|
* @copyright (c) 2008 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-19 20:40:32 -05:00
|
|
|
require_once dirname(__FILE__) . '/../mock/cache.php';
|
|
|
|
require_once dirname(__FILE__) . '/../mock/session_testable.php';
|
2011-01-04 17:14:36 +01:00
|
|
|
|
|
|
|
class phpbb_session_continue_test extends phpbb_database_test_case
|
|
|
|
{
|
|
|
|
public function getDataSet()
|
|
|
|
{
|
|
|
|
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_full.xml');
|
|
|
|
}
|
|
|
|
|
2011-01-06 23:06:59 +01:00
|
|
|
static public function session_begin_attempts()
|
|
|
|
{
|
2011-02-19 20:50:15 -05:00
|
|
|
global $_SID;
|
2011-01-06 23:06:59 +01:00
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'bar_session', '4', 'user agent',
|
|
|
|
array(
|
|
|
|
array('session_id' => 'anon_session', 'session_user_id' => 1),
|
|
|
|
array('session_id' => 'bar_session', 'session_user_id' => 4)
|
|
|
|
),
|
|
|
|
array(),
|
|
|
|
'Check if no new session was created',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'anon_session', '4', 'user agent',
|
|
|
|
array(
|
|
|
|
array('session_id' => 'bar_session', 'session_user_id' => 4),
|
|
|
|
array('session_id' => null, 'session_user_id' => 1) // use generated SID
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u' => array('1', null),
|
|
|
|
'k' => array(null, null),
|
|
|
|
'sid' => array($_SID, null),
|
|
|
|
),
|
|
|
|
'Check if an anonymous new session was created',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider session_begin_attempts
|
|
|
|
*/
|
|
|
|
public function test_session_begin_valid_session($session_id, $user_id, $user_agent, $expected_sessions, $expected_cookies, $message)
|
2011-01-04 17:14:36 +01:00
|
|
|
{
|
2011-02-20 08:45:59 -05:00
|
|
|
$this->markTestIncomplete('Test needs to be fixed');
|
|
|
|
|
2011-01-04 17:14:36 +01:00
|
|
|
$session = new phpbb_mock_session_testable;
|
|
|
|
$session->page = array('page' => 'page', 'forum' => 0);
|
|
|
|
|
|
|
|
// set up all the global variables used in session_create
|
|
|
|
global $SID, $_SID, $db, $config, $cache;
|
|
|
|
|
|
|
|
$config = $this->get_config();
|
|
|
|
$db = $this->new_dbal();
|
|
|
|
$cache_data = array(
|
|
|
|
'_bots' => array(),
|
|
|
|
);
|
|
|
|
$cache = new phpbb_mock_cache;
|
|
|
|
$SID = $_SID = null;
|
|
|
|
|
2011-01-06 23:06:59 +01:00
|
|
|
$_COOKIE['_sid'] = $session_id;
|
|
|
|
$_COOKIE['_u'] = $user_id;
|
|
|
|
$_SERVER['HTTP_USER_AGENT'] = $user_agent;
|
2011-01-04 17:14:36 +01:00
|
|
|
|
|
|
|
$config['session_length'] = time(); // need to do this to allow sessions started at time 0
|
|
|
|
$session->session_begin();
|
|
|
|
|
|
|
|
$sql = 'SELECT session_id, session_user_id
|
|
|
|
FROM phpbb_sessions';
|
|
|
|
|
2011-01-06 23:06:59 +01:00
|
|
|
// little tickery to allow using a dataProvider with dynamic expected result
|
|
|
|
foreach ($expected_sessions as $i => $s)
|
|
|
|
{
|
|
|
|
if (is_null($s['session_id']))
|
|
|
|
{
|
|
|
|
$expected_sessions[$i]['session_id'] = $session->session_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-19 20:44:59 -05:00
|
|
|
$this->assertSqlResultEquals(
|
2011-01-06 23:06:59 +01:00
|
|
|
$expected_sessions,
|
2011-02-19 20:44:59 -05:00
|
|
|
$sql,
|
2011-01-04 17:14:36 +01:00
|
|
|
'Check if no new session was created'
|
|
|
|
);
|
|
|
|
|
2011-01-06 23:06:59 +01:00
|
|
|
$session->check_cookies($this, $expected_cookies);
|
2011-01-04 17:14:36 +01:00
|
|
|
|
|
|
|
$cache->check($this, $cache_data);
|
|
|
|
}
|
|
|
|
static public function get_config()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'allow_autologin' => false,
|
|
|
|
'auth_method' => 'db',
|
|
|
|
'forwarded_for_check' => true,
|
|
|
|
'active_sessions' => 0, // disable
|
|
|
|
'rand_seed' => 'foo',
|
|
|
|
'rand_seed_last_update' => 0,
|
|
|
|
'max_autologin_time' => 0,
|
|
|
|
'session_length' => 100,
|
|
|
|
'form_token_lifetime' => 100,
|
|
|
|
'cookie_name' => '',
|
|
|
|
'limit_load' => 0,
|
|
|
|
'limit_search_load' => 0,
|
|
|
|
'ip_check' => 3,
|
|
|
|
'browser_check' => 1,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|