aboutsummaryrefslogtreecommitdiffstats
path: root/tests/session/continue_test.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2011-07-11 00:29:45 +0200
committerAndreas Fischer <bantu@phpbb.com>2011-07-11 00:29:45 +0200
commitc8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff (patch)
treeb7e507311afa3db9e372f9d5b8b01455dbd50841 /tests/session/continue_test.php
parent7f21a5f46156660d7ea6a4bdb59166ac553e2be8 (diff)
parente6572b766f7fd5f8547b28fd52d25e4a96cfc2cd (diff)
downloadforums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar.gz
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar.bz2
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.tar.xz
forums-c8da5ad9f42d8ced1aead79a42cc5caee5c5a2ff.zip
Merge branch 'prep-release-3.0.9'
* prep-release-3.0.9: (359 commits) [prep-release-3.0.9] Bumping version number for 3.0.9 final. [prep-release-3.0.9] Update Changelog for 3.0.9-RC4 release. [prep-release-3.0.9] Decreasing version for an RC4 release. [ticket/9859] Changing all phpBB footers to match the new credit line [ticket/9859] New footer copyright line with registered symbol [ticket/10250] The site_logo hash is different depending on imageset & language [ticket/10250] Destroy cached md5 hash of site_logo on refreshing an imageset [ticket/10250] Overwrite the site_logo width&height when the phpbb logo is used [ticket/10247] Remove attempt_id as primary key from database_update.php [ticket/10250] Added the new phpBB Logo with the Registered Trademark Symbol [ticket/10247] Use COUNT(*) instead of COUNT(attempt_id) [prep-release-3.0.9] Update Changelog for 3.0.9 release. [prep-release-3.0.9] Bumping version number for the final 3.0.9 release. [ticket/10247] Removing attempt_id column from the 3.0.8 to 3.0.9-RC1 updater. [ticket/10247] Add a db_tools test for the removal of a primary key column. [ticket/10247] Add empty data section to database update for RC4 [ticket/10247] Remove unecessary attempt_id primary key column [prep-release-3.0.9] Bump database version to RC3 too. [prep-release-3.0.9] Update Changelog for 3.0.9-RC3 release. [prep-release-3.0.9] Bumping version number for 3.0.9-RC3. ...
Diffstat (limited to 'tests/session/continue_test.php')
-rw-r--r--tests/session/continue_test.php121
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php
new file mode 100644
index 0000000000..6737562a0a
--- /dev/null
+++ b/tests/session/continue_test.php
@@ -0,0 +1,121 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../mock/cache.php';
+require_once dirname(__FILE__) . '/testable_factory.php';
+
+class phpbb_session_continue_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_full.xml');
+ }
+
+ static public function session_begin_attempts()
+ {
+ // The session_id field is defined as CHAR(32) in the database schema.
+ // Thus the data we put in session_id fields has to have a length of 32 characters on stricter DBMSes.
+ // Thus we fill those strings up with zeroes until they have a string length of 32.
+
+ return array(
+ array(
+ 'bar_session000000000000000000000', '4', 'user agent', '127.0.0.1',
+ array(
+ array('session_id' => 'anon_session00000000000000000000', 'session_user_id' => 1),
+ array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
+ ),
+ array(),
+ 'If a request comes with a valid session id with matching user agent and IP, no new session should be created.',
+ ),
+ array(
+ 'anon_session00000000000000000000', '4', 'user agent', '127.0.0.1',
+ array(
+ array('session_id' => '__new_session_id__', 'session_user_id' => 1), // use generated SID
+ array('session_id' => 'bar_session000000000000000000000', 'session_user_id' => 4),
+ ),
+ array(
+ 'u' => array('1', null),
+ 'k' => array(null, null),
+ 'sid' => array('__new_session_id__', null),
+ ),
+ 'If a request comes with a valid session id and IP but different user id and user agent, a new anonymous session is created and the session matching the supplied session id is deleted.',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider session_begin_attempts
+ */
+ public function test_session_begin_valid_session($session_id, $user_id, $user_agent, $ip, $expected_sessions, $expected_cookies, $message)
+ {
+ $db = $this->new_dbal();
+ $session_factory = new phpbb_session_testable_factory;
+ $session_factory->set_cookies(array(
+ '_sid' => $session_id,
+ '_u' => $user_id,
+ ));
+ $session_factory->merge_config_data(array(
+ 'session_length' => time(), // need to do this to allow sessions started at time 0
+ ));
+ $session_factory->merge_server_data(array(
+ 'HTTP_USER_AGENT' => $user_agent,
+ 'REMOTE_ADDR' => $ip,
+ ));
+
+ $session = $session_factory->get_session($db);
+ $session->page = array('page' => 'page', 'forum' => 0);
+
+ $session->session_begin();
+
+ $sql = 'SELECT session_id, session_user_id
+ FROM phpbb_sessions
+ ORDER BY session_user_id';
+
+ $expected_sessions = $this->replace_session($expected_sessions, $session->session_id);
+ $expected_cookies = $this->replace_session($expected_cookies, $session->session_id);
+
+ $this->assertSqlResultEquals(
+ $expected_sessions,
+ $sql,
+ $message
+ );
+
+ $session->check_cookies($this, $expected_cookies);
+
+ $session_factory->check($this);
+ }
+
+ /**
+ * Replaces recursively the value __new_session_id__ with the given session
+ * id.
+ *
+ * @param array $array An array of data
+ * @param string $session_id The new session id to use instead of the
+ * placeholder.
+ * @return array The input array with all occurances of __new_session_id__
+ * replaced.
+ */
+ public function replace_session($array, $session_id)
+ {
+ foreach ($array as $key => &$value)
+ {
+ if ($value === '__new_session_id__')
+ {
+ $value = $session_id;
+ }
+
+ if (is_array($value))
+ {
+ $value = $this->replace_session($value, $session_id);
+ }
+ }
+
+ return $array;
+ }
+}