aboutsummaryrefslogtreecommitdiffstats
path: root/tests/session
diff options
context:
space:
mode:
Diffstat (limited to 'tests/session')
-rw-r--r--tests/session/check_ban_test.php7
-rw-r--r--tests/session/fixtures/sessions_garbage.xml45
-rw-r--r--tests/session/garbage_collection_test.php88
-rw-r--r--tests/session/testable_factory.php4
4 files changed, 131 insertions, 13 deletions
diff --git a/tests/session/check_ban_test.php b/tests/session/check_ban_test.php
index 16a65b0ade..0ee655f4ac 100644
--- a/tests/session/check_ban_test.php
+++ b/tests/session/check_ban_test.php
@@ -17,6 +17,7 @@ class phpbb_session_check_ban_test extends phpbb_session_test_case
{
protected $user_id = 4;
protected $key_id = 4;
+ /** @var \phpbb\session */
protected $session;
protected $backup_cache;
@@ -37,7 +38,7 @@ class phpbb_session_check_ban_test extends phpbb_session_test_case
);
}
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
// Get session here so that config is mocked correctly
@@ -59,7 +60,7 @@ class phpbb_session_check_ban_test extends phpbb_session_test_case
);
}
- public function tearDown()
+ public function tearDown(): void
{
parent::tearDown();
// Set cache back to what it was before the test changed it
@@ -75,7 +76,7 @@ class phpbb_session_check_ban_test extends phpbb_session_test_case
$ban = $this->session->check_ban($user_id, $user_ips, $user_email, $return);
$is_banned = !empty($ban);
}
- catch (PHPUnit_Framework_Error_Notice $e)
+ catch (PHPUnit\Framework\Error\Notice $e)
{
// User error was triggered, user must have been banned
$is_banned = true;
diff --git a/tests/session/fixtures/sessions_garbage.xml b/tests/session/fixtures/sessions_garbage.xml
index 5eace839d0..59a2dc2ebe 100644
--- a/tests/session/fixtures/sessions_garbage.xml
+++ b/tests/session/fixtures/sessions_garbage.xml
@@ -5,11 +5,23 @@
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
+ <column>user_lastpage</column>
+ <column>user_lastvisit</column>
<row>
<value>4</value>
<value>bar</value>
<value></value>
<value></value>
+ <value>oldpage_user_bar.php</value>
+ <value>1400000000</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>foo</value>
+ <value></value>
+ <value></value>
+ <value>oldpage_user_foo.php</value>
+ <value>1400000000</value>
</row>
</table>
<table name="phpbb_sessions">
@@ -18,12 +30,16 @@
<column>session_ip</column>
<column>session_browser</column>
<column>session_admin</column>
+ <column>session_page</column>
+ <column>session_time</column>
<row>
<value>anon_session00000000000000000000</value>
<value>1</value>
<value>127.0.0.1</value>
<value>anonymous user agent</value>
<value>0</value>
+ <value></value>
+ <value>1500000005</value>
</row>
<row>
<value>bar_session000000000000000000000</value>
@@ -31,6 +47,35 @@
<value>127.0.0.1</value>
<value>user agent</value>
<value>1</value>
+ <value>newpage_user_bar.php</value>
+ <value>1500000000</value>
+ </row>
+ <row>
+ <value>bar_session000000000000000000002</value>
+ <value>4</value>
+ <value>127.0.0.1</value>
+ <value>user agent</value>
+ <value>1</value>
+ <value>oldpage_user_bar.php</value>
+ <value>1400000000</value>
+ </row>
+ <row>
+ <value>foo_session000000000000000000000</value>
+ <value>5</value>
+ <value>127.0.0.1</value>
+ <value>user agent</value>
+ <value>0</value>
+ <value>newpage_user_foo.php</value>
+ <value>1500000000</value>
+ </row>
+ <row>
+ <value>foo_session000000000000000000002</value>
+ <value>5</value>
+ <value>127.0.0.1</value>
+ <value>user agent</value>
+ <value>0</value>
+ <value>oldpage_user_foo.php</value>
+ <value>1400000000</value>
</row>
</table>
<table name="phpbb_login_attempts">
diff --git a/tests/session/garbage_collection_test.php b/tests/session/garbage_collection_test.php
index 3dc591a328..ec248b2904 100644
--- a/tests/session/garbage_collection_test.php
+++ b/tests/session/garbage_collection_test.php
@@ -22,7 +22,7 @@ class phpbb_session_garbage_collection_test extends phpbb_session_test_case
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_garbage.xml');
}
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
$this->session = $this->session_factory->get_session($this->db);
@@ -41,19 +41,91 @@ class phpbb_session_garbage_collection_test extends phpbb_session_test_case
);
}
+ public function test_session_gc()
+ {
+ global $config;
+ $config['session_length'] = 3600;
+
+ $this->check_expired_sessions_recent(
+ [
+ [
+ 'session_user_id' => 4,
+ 'recent_time' => 1500000000,
+ ],
+ [
+ 'session_user_id' => 5,
+ 'recent_time' => 1500000000,
+ ],
+ ],
+ 'Before test, should get recent expired sessions only.'
+ );
+
+ $this->check_user_session_data(
+ [
+ [
+ 'username_clean' => 'bar',
+ 'user_lastvisit' => 1400000000,
+ 'user_lastpage' => 'oldpage_user_bar.php',
+ ],
+ [
+ 'username_clean' => 'foo',
+ 'user_lastvisit' => 1400000000,
+ 'user_lastpage' => 'oldpage_user_foo.php',
+ ],
+ ],
+ 'Before test, users session data is not updated yet.'
+ );
+
+ // There is an error unless the captcha plugin is set
+ $config['captcha_plugin'] = 'core.captcha.plugins.nogd';
+ $this->session->session_gc();
+ $this->check_expired_sessions_recent(
+ [],
+ 'After garbage collection, all expired sessions should be removed.'
+ );
+
+ $this->check_user_session_data(
+ [
+ [
+ 'username_clean' => 'bar',
+ 'user_lastvisit' => '1500000000',
+ 'user_lastpage' => 'newpage_user_bar.php',
+ ],
+ [
+ 'username_clean' => 'foo',
+ 'user_lastvisit' => '1500000000',
+ 'user_lastpage' => 'newpage_user_foo.php',
+ ],
+ ],
+ 'After garbage collection, users session data should be updated to the recent expired sessions data.'
+ );
+ }
+
public function test_cleanup_all()
{
$this->check_sessions_equals(
- array(
- array(
+ [
+ [
'session_id' => 'anon_session00000000000000000000',
'session_user_id' => 1,
- ),
- array(
+ ],
+ [
'session_id' => 'bar_session000000000000000000000',
'session_user_id' => 4,
- ),
- ),
+ ],
+ [
+ 'session_id' => 'bar_session000000000000000000002',
+ 'session_user_id' => 4,
+ ],
+ [
+ 'session_id' => 'foo_session000000000000000000000',
+ 'session_user_id' => 5,
+ ],
+ [
+ 'session_id' => 'foo_session000000000000000000002',
+ 'session_user_id' => 5,
+ ],
+ ],
'Before test, should have some sessions.'
);
// Set session length so it clears all
@@ -63,7 +135,7 @@ class phpbb_session_garbage_collection_test extends phpbb_session_test_case
$config['captcha_plugin'] = 'core.captcha.plugins.nogd';
$this->session->session_gc();
$this->check_sessions_equals(
- array(),
+ [],
'After setting session time to 0, should remove all.'
);
}
diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php
index 6f8b49122b..d381b4cbbd 100644
--- a/tests/session/testable_factory.php
+++ b/tests/session/testable_factory.php
@@ -120,10 +120,10 @@ class phpbb_session_testable_factory
/**
* Check if the cache used for the generated session contains correct data.
*
- * @param PHPUnit_Framework_Assert $test The test case to call assert methods
+ * @param PHPUnit\Framework\Assert $test The test case to call assert methods
* on
*/
- public function check(PHPUnit_Framework_Assert $test)
+ public function check(PHPUnit\Framework\Assert $test)
{
$this->cache->check($test, $this->get_cache_data());
}