MediaWiki  1.28.0
BotPasswordTest.php
Go to the documentation of this file.
1 <?php
2 
5 
11 
13  private $testUser;
14 
16  private $testUserName;
17 
18  protected function setUp() {
19  parent::setUp();
20 
21  $this->setMwGlobals( [
22  'wgEnableBotPasswords' => true,
23  'wgBotPasswordsDatabase' => false,
24  'wgCentralIdLookupProvider' => 'BotPasswordTest OkMock',
25  'wgGrantPermissions' => [
26  'test' => [ 'read' => true ],
27  ],
28  'wgUserrightsInterwikiDelimiter' => '@',
29  ] );
30 
31  $this->testUser = $this->getMutableTestUser();
32  $this->testUserName = $this->testUser->getUser()->getName();
33 
34  $mock1 = $this->getMockForAbstractClass( 'CentralIdLookup' );
35  $mock1->expects( $this->any() )->method( 'isAttached' )
36  ->will( $this->returnValue( true ) );
37  $mock1->expects( $this->any() )->method( 'lookupUserNames' )
38  ->will( $this->returnValue( [ $this->testUserName => 42, 'UTDummy' => 43, 'UTInvalid' => 0 ] ) );
39  $mock1->expects( $this->never() )->method( 'lookupCentralIds' );
40 
41  $mock2 = $this->getMockForAbstractClass( 'CentralIdLookup' );
42  $mock2->expects( $this->any() )->method( 'isAttached' )
43  ->will( $this->returnValue( false ) );
44  $mock2->expects( $this->any() )->method( 'lookupUserNames' )
45  ->will( $this->returnArgument( 0 ) );
46  $mock2->expects( $this->never() )->method( 'lookupCentralIds' );
47 
48  $this->mergeMwGlobalArrayValue( 'wgCentralIdLookupProviders', [
49  'BotPasswordTest OkMock' => [ 'factory' => function () use ( $mock1 ) {
50  return $mock1;
51  } ],
52  'BotPasswordTest FailMock' => [ 'factory' => function () use ( $mock2 ) {
53  return $mock2;
54  } ],
55  ] );
56 
58  }
59 
60  public function addDBData() {
61  $passwordFactory = new \PasswordFactory();
62  $passwordFactory->init( \RequestContext::getMain()->getConfig() );
63  $passwordHash = $passwordFactory->newFromPlaintext( 'foobaz' );
64 
65  $dbw = wfGetDB( DB_MASTER );
66  $dbw->delete(
67  'bot_passwords',
68  [ 'bp_user' => [ 42, 43 ], 'bp_app_id' => 'BotPassword' ],
69  __METHOD__
70  );
71  $dbw->insert(
72  'bot_passwords',
73  [
74  [
75  'bp_user' => 42,
76  'bp_app_id' => 'BotPassword',
77  'bp_password' => $passwordHash->toString(),
78  'bp_token' => 'token!',
79  'bp_restrictions' => '{"IPAddresses":["127.0.0.0/8"]}',
80  'bp_grants' => '["test"]',
81  ],
82  [
83  'bp_user' => 43,
84  'bp_app_id' => 'BotPassword',
85  'bp_password' => $passwordHash->toString(),
86  'bp_token' => 'token!',
87  'bp_restrictions' => '{"IPAddresses":["127.0.0.0/8"]}',
88  'bp_grants' => '["test"]',
89  ],
90  ],
91  __METHOD__
92  );
93  }
94 
95  public function testBasics() {
96  $user = $this->testUser->getUser();
97  $bp = BotPassword::newFromUser( $user, 'BotPassword' );
98  $this->assertInstanceOf( 'BotPassword', $bp );
99  $this->assertTrue( $bp->isSaved() );
100  $this->assertSame( 42, $bp->getUserCentralId() );
101  $this->assertSame( 'BotPassword', $bp->getAppId() );
102  $this->assertSame( 'token!', trim( $bp->getToken(), " \0" ) );
103  $this->assertEquals( '{"IPAddresses":["127.0.0.0/8"]}', $bp->getRestrictions()->toJson() );
104  $this->assertSame( [ 'test' ], $bp->getGrants() );
105 
106  $this->assertNull( BotPassword::newFromUser( $user, 'DoesNotExist' ) );
107 
108  $this->setMwGlobals( [
109  'wgCentralIdLookupProvider' => 'BotPasswordTest FailMock'
110  ] );
111  $this->assertNull( BotPassword::newFromUser( $user, 'BotPassword' ) );
112 
113  $this->assertSame( '@', BotPassword::getSeparator() );
114  $this->setMwGlobals( [
115  'wgUserrightsInterwikiDelimiter' => '#',
116  ] );
117  $this->assertSame( '#', BotPassword::getSeparator() );
118  }
119 
120  public function testUnsaved() {
121  $user = $this->testUser->getUser();
122  $bp = BotPassword::newUnsaved( [
123  'user' => $user,
124  'appId' => 'DoesNotExist'
125  ] );
126  $this->assertInstanceOf( 'BotPassword', $bp );
127  $this->assertFalse( $bp->isSaved() );
128  $this->assertSame( 42, $bp->getUserCentralId() );
129  $this->assertSame( 'DoesNotExist', $bp->getAppId() );
130  $this->assertEquals( MWRestrictions::newDefault(), $bp->getRestrictions() );
131  $this->assertSame( [], $bp->getGrants() );
132 
133  $bp = BotPassword::newUnsaved( [
134  'username' => 'UTDummy',
135  'appId' => 'DoesNotExist2',
136  'restrictions' => MWRestrictions::newFromJson( '{"IPAddresses":["127.0.0.0/8"]}' ),
137  'grants' => [ 'test' ],
138  ] );
139  $this->assertInstanceOf( 'BotPassword', $bp );
140  $this->assertFalse( $bp->isSaved() );
141  $this->assertSame( 43, $bp->getUserCentralId() );
142  $this->assertSame( 'DoesNotExist2', $bp->getAppId() );
143  $this->assertEquals( '{"IPAddresses":["127.0.0.0/8"]}', $bp->getRestrictions()->toJson() );
144  $this->assertSame( [ 'test' ], $bp->getGrants() );
145 
146  $user = $this->testUser->getUser();
147  $bp = BotPassword::newUnsaved( [
148  'centralId' => 45,
149  'appId' => 'DoesNotExist'
150  ] );
151  $this->assertInstanceOf( 'BotPassword', $bp );
152  $this->assertFalse( $bp->isSaved() );
153  $this->assertSame( 45, $bp->getUserCentralId() );
154  $this->assertSame( 'DoesNotExist', $bp->getAppId() );
155 
156  $user = $this->testUser->getUser();
157  $bp = BotPassword::newUnsaved( [
158  'user' => $user,
159  'appId' => 'BotPassword'
160  ] );
161  $this->assertInstanceOf( 'BotPassword', $bp );
162  $this->assertFalse( $bp->isSaved() );
163 
164  $this->assertNull( BotPassword::newUnsaved( [
165  'user' => $user,
166  'appId' => '',
167  ] ) );
168  $this->assertNull( BotPassword::newUnsaved( [
169  'user' => $user,
170  'appId' => str_repeat( 'X', BotPassword::APPID_MAXLENGTH + 1 ),
171  ] ) );
172  $this->assertNull( BotPassword::newUnsaved( [
173  'user' => $this->testUserName,
174  'appId' => 'Ok',
175  ] ) );
176  $this->assertNull( BotPassword::newUnsaved( [
177  'username' => 'UTInvalid',
178  'appId' => 'Ok',
179  ] ) );
180  $this->assertNull( BotPassword::newUnsaved( [
181  'appId' => 'Ok',
182  ] ) );
183  }
184 
185  public function testGetPassword() {
187 
188  $password = $bp->getPassword();
189  $this->assertInstanceOf( 'Password', $password );
190  $this->assertTrue( $password->equals( 'foobaz' ) );
191 
192  $bp->centralId = 44;
193  $password = $bp->getPassword();
194  $this->assertInstanceOf( 'InvalidPassword', $password );
195 
197  $dbw = wfGetDB( DB_MASTER );
198  $dbw->update(
199  'bot_passwords',
200  [ 'bp_password' => 'garbage' ],
201  [ 'bp_user' => 42, 'bp_app_id' => 'BotPassword' ],
202  __METHOD__
203  );
204  $password = $bp->getPassword();
205  $this->assertInstanceOf( 'InvalidPassword', $password );
206  }
207 
211 
212  $this->assertNotInstanceOf( 'InvalidPassword', $bp1->getPassword(), 'sanity check' );
213  $this->assertNotInstanceOf( 'InvalidPassword', $bp2->getPassword(), 'sanity check' );
214  BotPassword::invalidateAllPasswordsForUser( $this->testUserName );
215  $this->assertInstanceOf( 'InvalidPassword', $bp1->getPassword() );
216  $this->assertNotInstanceOf( 'InvalidPassword', $bp2->getPassword() );
217 
219  $this->assertInstanceOf( 'InvalidPassword', $bp->getPassword() );
220  }
221 
222  public function testRemoveAllPasswordsForUser() {
223  $this->assertNotNull( BotPassword::newFromCentralId( 42, 'BotPassword' ), 'sanity check' );
224  $this->assertNotNull( BotPassword::newFromCentralId( 43, 'BotPassword' ), 'sanity check' );
225 
226  BotPassword::removeAllPasswordsForUser( $this->testUserName );
227 
228  $this->assertNull( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
229  $this->assertNotNull( BotPassword::newFromCentralId( 43, 'BotPassword' ) );
230  }
231 
235  public function testCanonicalizeLoginData( $username, $password, $expectedResult ) {
237  if ( is_array( $expectedResult ) ) {
238  $this->assertArrayEquals( $expectedResult, $result, true, true );
239  } else {
240  $this->assertSame( $expectedResult, $result );
241  }
242  }
243 
244  public function provideCanonicalizeLoginData() {
245  return [
246  [ 'user', 'pass', false ],
247  [ 'user', 'abc@def', false ],
248  [ 'legacy@user', 'pass', false ],
249  [ 'user@bot', '12345678901234567890123456789012',
250  [ 'user@bot', '12345678901234567890123456789012', true ] ],
251  [ 'user', 'bot@12345678901234567890123456789012',
252  [ 'user@bot', '12345678901234567890123456789012', true ] ],
253  [ 'user', 'bot@12345678901234567890123456789012345',
254  [ 'user@bot', '12345678901234567890123456789012345', true ] ],
255  [ 'user', 'bot@x@12345678901234567890123456789012',
256  [ 'user@bot@x', '12345678901234567890123456789012', true ] ],
257  ];
258  }
259 
260  public function testLogin() {
261  // Test failure when bot passwords aren't enabled
262  $this->setMwGlobals( 'wgEnableBotPasswords', false );
263  $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', new FauxRequest );
264  $this->assertEquals( Status::newFatal( 'botpasswords-disabled' ), $status );
265  $this->setMwGlobals( 'wgEnableBotPasswords', true );
266 
267  // Test failure when BotPasswordSessionProvider isn't configured
268  $manager = new SessionManager( [
269  'logger' => new Psr\Log\NullLogger,
270  'store' => new EmptyBagOStuff,
271  ] );
273  $this->assertNull(
274  $manager->getProvider( MediaWiki\Session\BotPasswordSessionProvider::class ),
275  'sanity check'
276  );
277  $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', new FauxRequest );
278  $this->assertEquals( Status::newFatal( 'botpasswords-no-provider' ), $status );
279  ScopedCallback::consume( $reset );
280 
281  // Now configure BotPasswordSessionProvider for further tests...
282  $mainConfig = RequestContext::getMain()->getConfig();
283  $config = new HashConfig( [
284  'SessionProviders' => $mainConfig->get( 'SessionProviders' ) + [
287  'args' => [ [ 'priority' => 40 ] ],
288  ]
289  ],
290  ] );
291  $manager = new SessionManager( [
292  'config' => new MultiConfig( [ $config, RequestContext::getMain()->getConfig() ] ),
293  'logger' => new Psr\Log\NullLogger,
294  'store' => new EmptyBagOStuff,
295  ] );
297 
298  // No "@"-thing in the username
299  $status = BotPassword::login( $this->testUserName, 'foobaz', new FauxRequest );
300  $this->assertEquals( Status::newFatal( 'botpasswords-invalid-name', '@' ), $status );
301 
302  // No base user
303  $status = BotPassword::login( 'UTDummy@BotPassword', 'foobaz', new FauxRequest );
304  $this->assertEquals( Status::newFatal( 'nosuchuser', 'UTDummy' ), $status );
305 
306  // No bot password
307  $status = BotPassword::login( "{$this->testUserName}@DoesNotExist", 'foobaz', new FauxRequest );
308  $this->assertEquals(
309  Status::newFatal( 'botpasswords-not-exist', $this->testUserName, 'DoesNotExist' ),
310  $status
311  );
312 
313  // Failed restriction
314  $request = $this->getMock( 'FauxRequest', [ 'getIP' ] );
315  $request->expects( $this->any() )->method( 'getIP' )
316  ->will( $this->returnValue( '10.0.0.1' ) );
317  $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', $request );
318  $this->assertEquals( Status::newFatal( 'botpasswords-restriction-failed' ), $status );
319 
320  // Wrong password
321  $status = BotPassword::login(
322  "{$this->testUserName}@BotPassword", $this->testUser->getPassword(), new FauxRequest );
323  $this->assertEquals( Status::newFatal( 'wrongpassword' ), $status );
324 
325  // Success!
326  $request = new FauxRequest;
327  $this->assertNotInstanceOf(
328  MediaWiki\Session\BotPasswordSessionProvider::class,
329  $request->getSession()->getProvider(),
330  'sanity check'
331  );
332  $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', $request );
333  $this->assertInstanceOf( 'Status', $status );
334  $this->assertTrue( $status->isGood() );
335  $session = $status->getValue();
336  $this->assertInstanceOf( MediaWiki\Session\Session::class, $session );
337  $this->assertInstanceOf(
338  MediaWiki\Session\BotPasswordSessionProvider::class, $session->getProvider()
339  );
340  $this->assertSame( $session->getId(), $request->getSession()->getId() );
341 
342  ScopedCallback::consume( $reset );
343  }
344 
349  public function testSave( $password ) {
350  $passwordFactory = new \PasswordFactory();
351  $passwordFactory->init( \RequestContext::getMain()->getConfig() );
352 
353  $bp = BotPassword::newUnsaved( [
354  'centralId' => 42,
355  'appId' => 'TestSave',
356  'restrictions' => MWRestrictions::newFromJson( '{"IPAddresses":["127.0.0.0/8"]}' ),
357  'grants' => [ 'test' ],
358  ] );
359  $this->assertFalse( $bp->isSaved(), 'sanity check' );
360  $this->assertNull(
361  BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST ), 'sanity check'
362  );
363 
364  $passwordHash = $password ? $passwordFactory->newFromPlaintext( $password ) : null;
365  $this->assertFalse( $bp->save( 'update', $passwordHash ) );
366  $this->assertTrue( $bp->save( 'insert', $passwordHash ) );
367  $bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST );
368  $this->assertInstanceOf( 'BotPassword', $bp2 );
369  $this->assertEquals( $bp->getUserCentralId(), $bp2->getUserCentralId() );
370  $this->assertEquals( $bp->getAppId(), $bp2->getAppId() );
371  $this->assertEquals( $bp->getToken(), $bp2->getToken() );
372  $this->assertEquals( $bp->getRestrictions(), $bp2->getRestrictions() );
373  $this->assertEquals( $bp->getGrants(), $bp2->getGrants() );
374  $pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
375  if ( $password === null ) {
376  $this->assertInstanceOf( 'InvalidPassword', $pw );
377  } else {
378  $this->assertTrue( $pw->equals( $password ) );
379  }
380 
381  $token = $bp->getToken();
382  $this->assertFalse( $bp->save( 'insert' ) );
383  $this->assertTrue( $bp->save( 'update' ) );
384  $this->assertNotEquals( $token, $bp->getToken() );
385  $bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST );
386  $this->assertInstanceOf( 'BotPassword', $bp2 );
387  $this->assertEquals( $bp->getToken(), $bp2->getToken() );
388  $pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
389  if ( $password === null ) {
390  $this->assertInstanceOf( 'InvalidPassword', $pw );
391  } else {
392  $this->assertTrue( $pw->equals( $password ) );
393  }
394 
395  $passwordHash = $passwordFactory->newFromPlaintext( 'XXX' );
396  $token = $bp->getToken();
397  $this->assertTrue( $bp->save( 'update', $passwordHash ) );
398  $this->assertNotEquals( $token, $bp->getToken() );
399  $pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
400  $this->assertTrue( $pw->equals( 'XXX' ) );
401 
402  $this->assertTrue( $bp->delete() );
403  $this->assertFalse( $bp->isSaved() );
404  $this->assertNull( BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST ) );
405 
406  $this->assertFalse( $bp->save( 'foobar' ) );
407  }
408 
409  public static function provideSave() {
410  return [
411  [ null ],
412  [ 'foobar' ],
413  ];
414  }
415 }
mergeMwGlobalArrayValue($name, $values)
Merges the given values into a MW global array variable.
static getSeparator()
Get the separator for combined user name + app ID.
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static newFatal($message)
Factory function for fatal errors.
Definition: StatusValue.php:63
const APPID_MAXLENGTH
Definition: BotPassword.php:29
static setSessionManagerSingleton(SessionManager $manager=null)
Override the singleton for unit testing.
Definition: TestUtils.php:17
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
A helper class for throttling authentication attempts.
const DB_MASTER
Definition: defines.php:23
static newUnsaved(array $data, $flags=self::READ_NORMAL)
Create an unsaved BotPassword.
static newFromCentralId($centralId, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1934
static removeAllPasswordsForUser($username)
Remove all passwords for a user, by name.
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
Definition: hooks.txt:1936
static getMain()
Static methods.
static invalidateAllPasswordsForUser($username)
Invalidate all passwords for a user, by name.
A BagOStuff object with no objects in it.
static newFromJson($json)
Provides a fallback sequence for Config objects.
Definition: MultiConfig.php:28
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
Definition: hooks.txt:242
static newFromUser(User $user, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
Definition: BotPassword.php:89
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
Definition: injection.txt:35
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:802
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2573
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
static canonicalizeLoginData($username, $password)
There are two ways to login with a bot password: "username@appId", "password" and "username"...
static resetCache()
Reset internal cache for unit testing.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1046
static getMutableTestUser($groups=[])
Convenience method for getting a mutable test user.
static newDefault()
This serves as the entry point to the MediaWiki session handling system.
static newFromObject($object)
Return the same object, without access restrictions.
static login($username, $password, WebRequest $request)
Try to log the user in.
setMwGlobals($pairs, $value=null)
A Config instance which stores all settings as a member variable.
Definition: HashConfig.php:28
BotPassword Database.
testCanonicalizeLoginData($username, $password, $expectedResult)
provideCanonicalizeLoginData
testSave($password)
provideSave