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
* @since 1.21
*/
public function exportSession() {
* @since 1.21
*/
public function exportSession() {
+ $session = MediaWiki\Session\SessionManager::getGlobalSession();
return array(
'ip' => $this->getRequest()->getIP(),
'headers' => $this->getRequest()->getAllHeaders(),
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()
);
}
'userId' => $this->getUser()->getId()
);
}
$oInfo = $context->exportSession();
$this->assertEquals( '127.0.0.1', $oInfo['ip'], "Correct initial IP address." );
$this->assertEquals( 0, $oInfo['userId'], "Correct initial user ID." );
$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();
$user = User::newFromName( 'UnitTestContextUser' );
$user->addToDatabase();
$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->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' );