RequestContext::exportSession() should only export persisted session IDs
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 27 Jan 2016 22:14:21 +0000 (17:14 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 27 Jan 2016 22:14:21 +0000 (17:14 -0500)
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

includes/context/RequestContext.php
tests/phpunit/includes/context/RequestContextTest.php

index 3b868a1..73e11b5 100644 (file)
@@ -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()
                );
        }
index 25969e6..e0487c2 100644 (file)
@@ -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' );
        }
 }