From: Brad Jorsch Date: Wed, 27 Jan 2016 22:14:21 +0000 (-0500) Subject: RequestContext::exportSession() should only export persisted session IDs X-Git-Tag: 1.31.0-rc.0~8181 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=7c4bd85d2152fd9fa975ea0fb5ffb1a0b804f99b;p=lhc%2Fweb%2Fwiklou.git RequestContext::exportSession() should only export persisted session IDs If a non-persisted session ID is exported, then when the session is reloaded by RequestContext::importScopedSession() the session_start() will wind up persisting it. Bug: T124971 Change-Id: If03d130acca6bb98029cfa3cc520cd46f42ff15e --- diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 3b868a1a36..73e11b5b79 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -510,10 +510,11 @@ class RequestContext implements IContextSource, MutableContext { * @since 1.21 */ public function exportSession() { + $session = MediaWiki\Session\SessionManager::getGlobalSession(); return array( 'ip' => $this->getRequest()->getIP(), 'headers' => $this->getRequest()->getAllHeaders(), - 'sessionId' => MediaWiki\Session\SessionManager::getGlobalSession()->getId(), + 'sessionId' => $session->isPersistent() ? $session->getId() : '', 'userId' => $this->getUser()->getId() ); } diff --git a/tests/phpunit/includes/context/RequestContextTest.php b/tests/phpunit/includes/context/RequestContextTest.php index 25969e6bb8..e0487c23f0 100644 --- a/tests/phpunit/includes/context/RequestContextTest.php +++ b/tests/phpunit/includes/context/RequestContextTest.php @@ -50,6 +50,8 @@ class RequestContextTest extends MediaWikiTestCase { $oInfo = $context->exportSession(); $this->assertEquals( '127.0.0.1', $oInfo['ip'], "Correct initial IP address." ); $this->assertEquals( 0, $oInfo['userId'], "Correct initial user ID." ); + $this->assertFalse( MediaWiki\Session\SessionManager::getGlobalSession()->isPersistent(), + 'Global session isn\'t persistent to start' ); $user = User::newFromName( 'UnitTestContextUser' ); $user->addToDatabase(); @@ -109,5 +111,7 @@ class RequestContextTest extends MediaWikiTestCase { $this->assertEquals( $oInfo['headers'], $info['headers'], "Correct restored headers." ); $this->assertEquals( $oInfo['sessionId'], $info['sessionId'], "Correct restored session ID." ); $this->assertEquals( $oInfo['userId'], $info['userId'], "Correct restored user ID." ); + $this->assertFalse( MediaWiki\Session\SessionManager::getGlobalSession()->isPersistent(), + 'Global session isn\'t persistent after restoring the context' ); } }