6use Wikimedia\TestingAccessWrapper;
19 $this->tablesUsed[] =
'bot_passwords';
24 'Bot passwords enabled' => [
true ],
25 'Bot passwords disabled' => [
false ],
33 $this->
setMwGlobals(
'wgEnableBotPasswords', $enableBotPasswords );
35 'action' =>
'paraminfo',
37 'helpformat' =>
'raw',
40 'apihelp-login-extended-description' . ( $enableBotPasswords ?
'' :
'-nobotpasswords' ),
41 $ret[0][
'paraminfo'][
'modules'][0][
'description'][1][
'key']
50 'wsTokenSecrets' => [
'login' =>
'foobar' ],
55 'lgpassword' => self::$users[
'sysop']->getPassword(),
56 'lgtoken' => (
string)(
new MediaWiki\Session\Token(
'foobar',
'' ) ),
58 $this->assertSame(
'Failed',
$ret[0][
'login'][
'result'] );
65 $this->
setMwGlobals(
'wgEnableBotPasswords', $enableBotPasswords );
71 'lgname' =>
$user->getUser()->getName(),
76 'apiwarn-deprecation-login-token' )->
text() ) ],
77 $ret[0][
'warnings'][
'login']
79 $this->assertSame(
'NeedToken',
$ret[0][
'login'][
'result'] );
83 'lgtoken' =>
$ret[0][
'login'][
'token'],
84 'lgname' =>
$user->getUser()->getName(),
85 'lgpassword' =>
$user->getPassword(),
90 'apiwarn-deprecation-login-' . ( $enableBotPasswords ?
'' :
'no' ) .
'botpw' )
92 $ret[0][
'warnings'][
'login']
96 'result' =>
'Success',
97 'lguserid' =>
$user->getUser()->getId(),
98 'lgusername' =>
$user->getUser()->getName(),
120 $this->assertArrayNotHasKey(
'warnings',
$ret );
125 'lgtoken' =>
$ret[0][
'query'][
'tokens'][
'logintoken'],
127 'lgpassword' => $password,
133 $user = self::$users[
'sysop'];
134 $userName =
$user->getUser()->getName();
135 $password =
$user->getPassword();
136 $user->getUser()->logout();
138 $ret = $this->
doUserLogin( $userName, $password, [
'lgtoken' =>
'invalid token' ] );
140 $this->assertSame(
'WrongToken',
$ret[0][
'login'][
'result'] );
144 $user = self::$users[
'sysop'];
145 $userName =
$user->getUser()->getName();
146 $user->getUser()->logout();
150 $this->assertSame(
'Failed',
$ret[0][
'login'][
'result'] );
157 $this->
setMwGlobals(
'wgEnableBotPasswords', $enableBotPasswords );
159 $user = self::$users[
'sysop'];
160 $userName =
$user->getUser()->getName();
161 $password =
$user->getPassword();
162 $user->getUser()->logout();
166 $this->assertSame(
'Success',
$ret[0][
'login'][
'result'] );
169 'apiwarn-deprecation-login-' . ( $enableBotPasswords ?
'' :
'no' ) .
'botpw' )->
171 $ret[0][
'warnings'][
'login']
179 $this->
setMwGlobals(
'wgEnableBotPasswords', $enableBotPasswords );
181 $mockProvider = $this->createMock(
182 MediaWiki\Auth\AbstractSecondaryAuthenticationProvider::class );
183 $mockProvider->method(
'beginSecondaryAuthentication' )->willReturn(
184 MediaWiki\Auth\AuthenticationResponse::newUI(
185 [
new MediaWiki\Auth\UsernameAuthenticationRequest ],
190 $mockProvider->method(
'getAuthenticationRequests' )
194 'secondaryauth' => [ [
195 'factory' =>
function ()
use ( $mockProvider ) {
196 return $mockProvider;
201 $user = self::$users[
'sysop'];
202 $userName =
$user->getUser()->getName();
203 $password =
$user->getPassword();
204 $user->getUser()->logout();
208 $this->assertSame( [
'login' => [
209 'result' =>
'Aborted',
211 'api-login-fail-aborted' . ( $enableBotPasswords ?
'' :
'-nobotpw' ) )->text() ),
220 $this->markTestIncomplete(
"The server can't do external HTTP requests, "
221 .
"and the internal one won't give cookies" );
225 $user = self::$users[
'sysop'];
226 $userName =
$user->getUser()->getName();
227 $password =
$user->getPassword();
229 $req = MWHttpRequest::factory(
230 self::$apiUrl .
'?action=login&format=json',
234 'lgname' => $userName,
235 'lgpassword' => $password,
244 $this->assertSame(
'NeedToken',
$content->login->result );
247 'lgtoken' =>
$content->login->token,
248 'lgname' => $userName,
249 'lgpassword' => $password,
253 $cj =
$req->getCookieJar();
254 $serverName = parse_url(
$wgServer, PHP_URL_HOST );
255 $this->assertNotEquals(
false, $serverName );
256 $serializedCookie = $cj->serializeToHttpRequest(
$wgScriptPath, $serverName );
258 '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . $userName .
'; .*Token=/',
274 'class' => BotPasswordSessionProvider::class,
275 'args' => [ [
'priority' => 40 ] ],
278 'wgEnableBotPasswords' =>
true,
279 'wgBotPasswordsDatabase' =>
false,
280 'wgCentralIdLookupProvider' =>
'local',
281 'wgGrantPermissions' => [
282 'test' => [
'read' =>
true ],
287 $manager = TestingAccessWrapper::newFromObject( SessionManager::singleton() );
288 if ( !isset( $manager->sessionProviders[BotPasswordSessionProvider::class] ) ) {
289 $tmp = $manager->sessionProviders;
290 $manager->sessionProviders =
null;
291 $manager->sessionProviders = $tmp + $manager->getProviders();
293 $this->assertNotNull(
294 SessionManager::singleton()->getProvider( BotPasswordSessionProvider::class ),
298 $user = self::$users[
'sysop'];
299 $centralId = CentralIdLookup::factory()->centralIdFromLocalUser(
$user->getUser() );
300 $this->assertNotSame( 0, $centralId,
'sanity check' );
302 $password =
'ngfhmjm64hv0854493hsj5nncjud2clk';
303 $passwordFactory = MediaWikiServices::getInstance()->getPasswordFactory();
305 $passwordHash = $passwordFactory->newFromPlaintext( $password );
311 'bp_user' => $centralId,
312 'bp_app_id' =>
'foo',
313 'bp_password' => $passwordHash->toString(),
316 'bp_grants' =>
'["test"]',
321 $lgName =
$user->getUser()->getName() . BotPassword::getSeparator() .
'foo';
323 return [ $lgName, $password ];
329 $this->assertSame(
'Success',
$ret[0][
'login'][
'result'] );
347 'result' =>
'Failed',
350 ],
$ret[0][
'login'] );
362 'result' =>
'Failed',
364 ],
$ret[0][
'login'] );
376 'errorformat' =>
'plaintext',
380 'result' =>
'Aborted',
382 'code' =>
'api-login-fail-sameorigin',
383 'text' =>
'Cannot log in when the same-origin policy is not applied.',
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
$wgSessionProviders
MediaWiki\Session\SessionProvider configuration.
$wgPasswordAttemptThrottle
Limit password attempts to X attempts per Y seconds per IP per account.
$wgScriptPath
The path we should point to.
$wgServer
URL of the server.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
testNoName()
Test result of attempted login with an empty username.
testDeprecatedUserLogin( $enableBotPasswords)
provideEnableBotPasswords
doUserLogin( $name, $password, array $params=[])
Attempts to log in with the given name and password, retrieves the returned token,...
testNoSameOriginSecurity()
testBotPasswordThrottled()
testGoodPass( $enableBotPasswords)
provideEnableBotPasswords
static provideEnableBotPasswords()
testExtendedDescription( $enableBotPasswords)
provideEnableBotPasswords
testUnsupportedAuthResponseType( $enableBotPasswords)
provideEnableBotPasswords
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this hook is for auditing only $req
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
Allows to change the fields on the form that will be generated $name
processing should stop and the error should be shown to the user * false
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))