diff options
author | Brad Jorsch <bjorsch@wikimedia.org> | 2016-01-29 18:02:11 -0500 |
---|---|---|
committer | BryanDavis <bdavis@wikimedia.org> | 2016-01-30 00:26:03 +0000 |
commit | fcdd643a46d87b677f6cdcc3ba9440e1472d8df7 (patch) | |
tree | 4e81f677b09ca24c96f0a21c4d7842da05cd6341 /tests/phpunit/includes/session | |
parent | 982869d6b0c145d7b53aad255efaf0702c434e1f (diff) | |
download | mediawikicore-fcdd643a46d87b677f6cdcc3ba9440e1472d8df7.tar.gz mediawikicore-fcdd643a46d87b677f6cdcc3ba9440e1472d8df7.zip |
SessionManager: Don't save non-persisted sessions to backend storage
This introduces an in-process cache (using a HashBagOStuff) for session
data, and only saves to the external cache when the session is
persisted.
Bug: T125267
Change-Id: Ie161e0f7522cd68515b060ad8cf8c151b7198b0b
Diffstat (limited to 'tests/phpunit/includes/session')
5 files changed, 18 insertions, 16 deletions
diff --git a/tests/phpunit/includes/session/CookieSessionProviderTest.php b/tests/phpunit/includes/session/CookieSessionProviderTest.php index 702f5563116f..2b7e0a1372c0 100644 --- a/tests/phpunit/includes/session/CookieSessionProviderTest.php +++ b/tests/phpunit/includes/session/CookieSessionProviderTest.php @@ -363,6 +363,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { 'idIsSafe' => true, ) ), $store, + $store, new \Psr\Log\NullLogger(), 10 ); @@ -449,6 +450,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { 'idIsSafe' => true, ) ), new \EmptyBagOStuff(), + new \EmptyBagOStuff(), new \Psr\Log\NullLogger(), 10 ); @@ -553,6 +555,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { 'idIsSafe' => true, ) ), $store, + $store, new \Psr\Log\NullLogger(), 10 ); diff --git a/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php b/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php index e06dfd5555ca..46f23f38418f 100644 --- a/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php +++ b/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php @@ -205,6 +205,7 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { 'idIsSafe' => true, ) ), new \EmptyBagOStuff(), + new \EmptyBagOStuff(), new \Psr\Log\NullLogger(), 10 ); diff --git a/tests/phpunit/includes/session/PHPSessionHandlerTest.php b/tests/phpunit/includes/session/PHPSessionHandlerTest.php index 125e1b664e09..1c54a20af3ee 100644 --- a/tests/phpunit/includes/session/PHPSessionHandlerTest.php +++ b/tests/phpunit/includes/session/PHPSessionHandlerTest.php @@ -172,14 +172,6 @@ class PHPSessionHandlerTest extends MediaWikiTestCase { $this->assertSame( $expect, $_SESSION ); } - // Test expiry - session_write_close(); - ini_set( 'session.gc_divisor', 1 ); - ini_set( 'session.gc_probability', 1 ); - sleep( 3 ); - session_start(); - $this->assertSame( array(), $_SESSION ); - // Re-fill the session, then test that session_destroy() works. $_SESSION['AuthenticationSessionTest'] = $rand; session_write_close(); diff --git a/tests/phpunit/includes/session/SessionBackendTest.php b/tests/phpunit/includes/session/SessionBackendTest.php index d06706bf637e..85fa9bdca0b0 100644 --- a/tests/phpunit/includes/session/SessionBackendTest.php +++ b/tests/phpunit/includes/session/SessionBackendTest.php @@ -59,7 +59,7 @@ class SessionBackendTest extends MediaWikiTestCase { ) ); $id = new SessionId( $info->getId() ); - $backend = new SessionBackend( $id, $info, $this->store, $logger, 10 ); + $backend = new SessionBackend( $id, $info, $this->store, $this->store, $logger, 10 ); $priv = \TestingAccessWrapper::newFromObject( $backend ); $priv->persist = false; $priv->requests = array( 100 => new \FauxRequest() ); @@ -87,7 +87,7 @@ class SessionBackendTest extends MediaWikiTestCase { $id = new SessionId( $info->getId() ); $logger = new \Psr\Log\NullLogger(); try { - new SessionBackend( $id, $info, $this->store, $logger, 10 ); + new SessionBackend( $id, $info, $this->store, $this->store, $logger, 10 ); $this->fail( 'Expected exception not thrown' ); } catch ( \InvalidArgumentException $ex ) { $this->assertSame( @@ -103,7 +103,7 @@ class SessionBackendTest extends MediaWikiTestCase { ) ); $id = new SessionId( $info->getId() ); try { - new SessionBackend( $id, $info, $this->store, $logger, 10 ); + new SessionBackend( $id, $info, $this->store, $this->store, $logger, 10 ); $this->fail( 'Expected exception not thrown' ); } catch ( \InvalidArgumentException $ex ) { $this->assertSame( 'Cannot create session without a provider', $ex->getMessage() ); @@ -118,7 +118,7 @@ class SessionBackendTest extends MediaWikiTestCase { ) ); $id = new SessionId( '!' . $info->getId() ); try { - new SessionBackend( $id, $info, $this->store, $logger, 10 ); + new SessionBackend( $id, $info, $this->store, $this->store, $logger, 10 ); $this->fail( 'Expected exception not thrown' ); } catch ( \InvalidArgumentException $ex ) { $this->assertSame( @@ -135,7 +135,7 @@ class SessionBackendTest extends MediaWikiTestCase { 'idIsSafe' => true, ) ); $id = new SessionId( $info->getId() ); - $backend = new SessionBackend( $id, $info, $this->store, $logger, 10 ); + $backend = new SessionBackend( $id, $info, $this->store, $this->store, $logger, 10 ); $this->assertSame( self::SESSIONID, $backend->getId() ); $this->assertSame( $id, $backend->getSessionId() ); $this->assertSame( $this->provider, $backend->getProvider() ); @@ -157,7 +157,7 @@ class SessionBackendTest extends MediaWikiTestCase { 'idIsSafe' => true, ) ); $id = new SessionId( $info->getId() ); - $backend = new SessionBackend( $id, $info, $this->store, $logger, 10 ); + $backend = new SessionBackend( $id, $info, $this->store, $this->store, $logger, 10 ); $this->assertSame( self::SESSIONID, $backend->getId() ); $this->assertSame( $id, $backend->getSessionId() ); $this->assertSame( $this->provider, $backend->getProvider() ); diff --git a/tests/phpunit/includes/session/SessionManagerTest.php b/tests/phpunit/includes/session/SessionManagerTest.php index f5bb07d1db69..4fde3410f9d6 100644 --- a/tests/phpunit/includes/session/SessionManagerTest.php +++ b/tests/phpunit/includes/session/SessionManagerTest.php @@ -103,7 +103,7 @@ class SessionManagerTest extends MediaWikiTestCase { $manager = \TestingAccessWrapper::newFromObject( $this->getManager() ); $this->assertSame( $this->config, $manager->config ); $this->assertSame( $this->logger, $manager->logger ); - $this->assertSame( $this->store, $manager->store ); + $this->assertSame( $this->store, $manager->permStore ); $manager = \TestingAccessWrapper::newFromObject( new SessionManager() ); $this->assertSame( \RequestContext::getMain()->getConfig(), $manager->config ); @@ -111,7 +111,7 @@ class SessionManagerTest extends MediaWikiTestCase { $manager = \TestingAccessWrapper::newFromObject( new SessionManager( array( 'config' => $this->config, ) ) ); - $this->assertSame( \ObjectCache::$instances['testSessionStore'], $manager->store ); + $this->assertSame( \ObjectCache::$instances['testSessionStore'], $manager->permStore ); foreach ( array( 'config' => '$options[\'config\'] must be an instance of Config', @@ -301,6 +301,9 @@ class SessionManagerTest extends MediaWikiTestCase { public function testGetSessionById() { $manager = $this->getManager(); + // Disable the in-process cache so our $this->store->setSession() takes effect. + \TestingAccessWrapper::newFromObject( $manager )->tempStore = new \EmptyBagOStuff; + try { $manager->getSessionById( 'bad' ); $this->fail( 'Expected exception not thrown' ); @@ -1083,6 +1086,9 @@ class SessionManagerTest extends MediaWikiTestCase { $manager->setLogger( $logger ); $request = new \FauxRequest(); + // Disable the in-process cache so our $this->store->setSession() takes effect. + \TestingAccessWrapper::newFromObject( $manager )->tempStore = new \EmptyBagOStuff; + // TestingAccessWrapper can't handle methods with reference arguments, sigh. $rClass = new \ReflectionClass( $manager ); $rMethod = $rClass->getMethod( 'loadSessionInfoFromStore' ); |