The plan here is to take it out of 1.27.0-wmf.12 and put it back in 1.27.0-wmf.13. Since BotPasswords depends on SessionManager, that's getting temporarily removed too. This reverts the following commits: *6acd424e0dSessionManager: Notify AuthPlugin before calling hooks *4d1ad32d8aClose a loophole in CookieSessionProvider *fcdd643a46SessionManager: Don't save non-persisted sessions to backend storage *058aec4c76MessageCache: Don't get a ParserOptions for $wgUser before the end of Setup.php *b5c0c03bb7SessionManager: Save user name to metadata even if the user doesn't exist locally *13f2f09a19SECURITY: Fix User::setToken() call on User::newSystemUser *305bc75b27SessionManager: Don't generate user tokens when checking the tokens *7c4bd85d21RequestContext::exportSession() should only export persisted session IDs *296ccfd4a9SessionManager: Save 'persisted' flag in session metadata *94ba53f677Move CSRF token handling into MediaWiki\Session\Session *46a565d6b0Avoid false "added in both Session and $_SESSION" when value is null *c00d0b5d94Log backtrace for "User::loadFromSession called before the end of Setup.php" *4eeff5b559Use $wgSecureCookie to decide whether to actually mark secure cookies as 'secure' *7491b52f70Call session_cache_limiter() before starting a session *2c34aeea72SessionManager: Abstract forceHTTPS cookie setting *9aa53627a5Ignore auth cookies with value 'deleted' *43f904b51aSessionManager: Kill getPersistedSessionId() *50c5256352SessionManager: Add SessionBackend::setProviderMetadata() *f640d40315SessionManager: Notify AuthPlugin when auto-creating accounts *70b05d1ac1Add checks of $wgEnableBotPasswords in more places *bfed32eb78Do not raise a PHP warning when session write fails *722a7331adOnly check LoggedOut timestamp on the user loaded from session *4f5057b84bSessionManager: Change behavior of getSessionById() *66e82e614eFix typo in [[MediaWiki:Botpasswords-editexisting/en]] *f9fd9516d9Add "bot passwords" *d7716f1df0Add missing argument for wfDebugLog *a73c5b7395Add SessionManager Change-Id: I2389a8133e25ab929e9f27f41fa9a05df8147a50
96 lines
3.4 KiB
PHP
96 lines
3.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group Database
|
|
* @group RequestContext
|
|
*/
|
|
class RequestContextTest extends MediaWikiTestCase {
|
|
|
|
/**
|
|
* Test the relationship between title and wikipage in RequestContext
|
|
* @covers RequestContext::getWikiPage
|
|
* @covers RequestContext::getTitle
|
|
*/
|
|
public function testWikiPageTitle() {
|
|
$context = new RequestContext();
|
|
|
|
$curTitle = Title::newFromText( "A" );
|
|
$context->setTitle( $curTitle );
|
|
$this->assertTrue( $curTitle->equals( $context->getWikiPage()->getTitle() ),
|
|
"When a title is first set WikiPage should be created on-demand for that title." );
|
|
|
|
$curTitle = Title::newFromText( "B" );
|
|
$context->setWikiPage( WikiPage::factory( $curTitle ) );
|
|
$this->assertTrue( $curTitle->equals( $context->getTitle() ),
|
|
"Title must be updated when a new WikiPage is provided." );
|
|
|
|
$curTitle = Title::newFromText( "C" );
|
|
$context->setTitle( $curTitle );
|
|
$this->assertTrue(
|
|
$curTitle->equals( $context->getWikiPage()->getTitle() ),
|
|
"When a title is updated the WikiPage should be purged "
|
|
. "and recreated on-demand with the new title."
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers RequestContext::importScopedSession
|
|
*/
|
|
public function testImportScopedSession() {
|
|
$context = RequestContext::getMain();
|
|
|
|
$oInfo = $context->exportSession();
|
|
$this->assertEquals( '127.0.0.1', $oInfo['ip'], "Correct initial IP address." );
|
|
$this->assertEquals( 0, $oInfo['userId'], "Correct initial user ID." );
|
|
|
|
$user = User::newFromName( 'UnitTestContextUser' );
|
|
$user->addToDatabase();
|
|
|
|
$sinfo = array(
|
|
'sessionId' => 'd612ee607c87e749ef14da4983a702cd',
|
|
'userId' => $user->getId(),
|
|
'ip' => '192.0.2.0',
|
|
'headers' => array(
|
|
'USER-AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0'
|
|
)
|
|
);
|
|
// importScopedSession() sets these variables
|
|
$this->setMwGlobals( array(
|
|
'wgUser' => new User,
|
|
'wgRequest' => new FauxRequest,
|
|
) );
|
|
$sc = RequestContext::importScopedSession( $sinfo ); // load new context
|
|
|
|
$info = $context->exportSession();
|
|
$this->assertEquals( $sinfo['ip'], $info['ip'], "Correct IP address." );
|
|
$this->assertEquals( $sinfo['headers'], $info['headers'], "Correct headers." );
|
|
$this->assertEquals( $sinfo['sessionId'], $info['sessionId'], "Correct session ID." );
|
|
$this->assertEquals( $sinfo['userId'], $info['userId'], "Correct user ID." );
|
|
$this->assertEquals(
|
|
$sinfo['ip'],
|
|
$context->getRequest()->getIP(),
|
|
"Correct context IP address."
|
|
);
|
|
$this->assertEquals(
|
|
$sinfo['headers'],
|
|
$context->getRequest()->getAllHeaders(),
|
|
"Correct context headers."
|
|
);
|
|
$this->assertEquals( $sinfo['sessionId'], session_id(), "Correct context session ID." );
|
|
$this->assertEquals( true, $context->getUser()->isLoggedIn(), "Correct context user." );
|
|
$this->assertEquals( $sinfo['userId'], $context->getUser()->getId(), "Correct context user ID." );
|
|
$this->assertEquals(
|
|
'UnitTestContextUser',
|
|
$context->getUser()->getName(),
|
|
"Correct context user name."
|
|
);
|
|
|
|
unset( $sc ); // restore previous context
|
|
|
|
$info = $context->exportSession();
|
|
$this->assertEquals( $oInfo['ip'], $info['ip'], "Correct restored IP address." );
|
|
$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." );
|
|
}
|
|
}
|