21 'wgEnableBotPasswords' =>
true,
22 'wgBotPasswordsDatabase' =>
false,
23 'wgCentralIdLookupProvider' =>
'BotPasswordTest OkMock',
24 'wgGrantPermissions' => [
25 'test' => [
'read' =>
true ],
27 'wgUserrightsInterwikiDelimiter' =>
'@',
31 $this->testUserName = $this->testUser->getUser()->getName();
33 $mock1 = $this->getMockForAbstractClass(
'CentralIdLookup' );
34 $mock1->expects( $this->any() )->method(
'isAttached' )
35 ->will( $this->returnValue(
true ) );
36 $mock1->expects( $this->any() )->method(
'lookupUserNames' )
37 ->will( $this->returnValue( [ $this->testUserName => 42,
'UTDummy' => 43,
'UTInvalid' => 0 ] ) );
38 $mock1->expects( $this->never() )->method(
'lookupCentralIds' );
40 $mock2 = $this->getMockForAbstractClass(
'CentralIdLookup' );
41 $mock2->expects( $this->any() )->method(
'isAttached' )
42 ->will( $this->returnValue(
false ) );
43 $mock2->expects( $this->any() )->method(
'lookupUserNames' )
44 ->will( $this->returnArgument( 0 ) );
45 $mock2->expects( $this->never() )->method(
'lookupCentralIds' );
48 'BotPasswordTest OkMock' => [
'factory' =>
function ()
use ( $mock1 ) {
51 'BotPasswordTest FailMock' => [
'factory' =>
function ()
use ( $mock2 ) {
60 $passwordFactory = new \PasswordFactory();
62 $passwordHash = $passwordFactory->newFromPlaintext(
'foobaz' );
67 [
'bp_user' => [ 42, 43 ],
'bp_app_id' =>
'BotPassword' ],
75 'bp_app_id' =>
'BotPassword',
76 'bp_password' => $passwordHash->toString(),
77 'bp_token' =>
'token!',
78 'bp_restrictions' =>
'{"IPAddresses":["127.0.0.0/8"]}',
79 'bp_grants' =>
'["test"]',
83 'bp_app_id' =>
'BotPassword',
84 'bp_password' => $passwordHash->toString(),
85 'bp_token' =>
'token!',
86 'bp_restrictions' =>
'{"IPAddresses":["127.0.0.0/8"]}',
87 'bp_grants' =>
'["test"]',
95 $user = $this->testUser->getUser();
97 $this->assertInstanceOf(
'BotPassword', $bp );
98 $this->assertTrue( $bp->isSaved() );
99 $this->assertSame( 42, $bp->getUserCentralId() );
100 $this->assertSame(
'BotPassword', $bp->getAppId() );
101 $this->assertSame(
'token!', trim( $bp->getToken(),
" \0" ) );
102 $this->assertEquals(
'{"IPAddresses":["127.0.0.0/8"]}', $bp->getRestrictions()->toJson() );
103 $this->assertSame( [
'test' ], $bp->getGrants() );
108 'wgCentralIdLookupProvider' =>
'BotPasswordTest FailMock'
114 'wgUserrightsInterwikiDelimiter' =>
'#',
120 $user = $this->testUser->getUser();
123 'appId' =>
'DoesNotExist'
125 $this->assertInstanceOf(
'BotPassword', $bp );
126 $this->assertFalse( $bp->isSaved() );
127 $this->assertSame( 42, $bp->getUserCentralId() );
128 $this->assertSame(
'DoesNotExist', $bp->getAppId() );
130 $this->assertSame( [], $bp->getGrants() );
133 'username' =>
'UTDummy',
134 'appId' =>
'DoesNotExist2',
136 'grants' => [
'test' ],
138 $this->assertInstanceOf(
'BotPassword', $bp );
139 $this->assertFalse( $bp->isSaved() );
140 $this->assertSame( 43, $bp->getUserCentralId() );
141 $this->assertSame(
'DoesNotExist2', $bp->getAppId() );
142 $this->assertEquals(
'{"IPAddresses":["127.0.0.0/8"]}', $bp->getRestrictions()->toJson() );
143 $this->assertSame( [
'test' ], $bp->getGrants() );
145 $user = $this->testUser->getUser();
148 'appId' =>
'DoesNotExist'
150 $this->assertInstanceOf(
'BotPassword', $bp );
151 $this->assertFalse( $bp->isSaved() );
152 $this->assertSame( 45, $bp->getUserCentralId() );
153 $this->assertSame(
'DoesNotExist', $bp->getAppId() );
155 $user = $this->testUser->getUser();
158 'appId' =>
'BotPassword'
160 $this->assertInstanceOf(
'BotPassword', $bp );
161 $this->assertFalse( $bp->isSaved() );
172 'user' => $this->testUserName,
176 'username' =>
'UTInvalid',
187 $password = $bp->getPassword();
188 $this->assertInstanceOf(
'Password', $password );
189 $this->assertTrue( $password->equals(
'foobaz' ) );
192 $password = $bp->getPassword();
193 $this->assertInstanceOf(
'InvalidPassword', $password );
199 [
'bp_password' =>
'garbage' ],
200 [
'bp_user' => 42,
'bp_app_id' =>
'BotPassword' ],
203 $password = $bp->getPassword();
204 $this->assertInstanceOf(
'InvalidPassword', $password );
211 $this->assertNotInstanceOf(
'InvalidPassword', $bp1->getPassword(),
'sanity check' );
212 $this->assertNotInstanceOf(
'InvalidPassword', $bp2->getPassword(),
'sanity check' );
214 $this->assertInstanceOf(
'InvalidPassword', $bp1->getPassword() );
215 $this->assertNotInstanceOf(
'InvalidPassword', $bp2->getPassword() );
218 $this->assertInstanceOf(
'InvalidPassword', $bp->getPassword() );
240 'logger' =>
new Psr\Log\NullLogger,
249 $this->assertEquals(
Status::newFatal(
'botpasswords-no-provider' ), $status );
255 'SessionProviders' => $mainConfig->get(
'SessionProviders' ) + [
258 'args' => [ [
'priority' => 40 ] ],
264 'logger' =>
new Psr\Log\NullLogger,
271 $this->assertEquals(
Status::newFatal(
'botpasswords-invalid-name',
'@' ), $status );
275 $this->assertEquals(
Status::newFatal(
'nosuchuser',
'UTDummy' ), $status );
280 Status::newFatal(
'botpasswords-not-exist', $this->testUserName,
'DoesNotExist' ),
285 $request = $this->getMock(
'FauxRequest', [
'getIP' ] );
286 $request->expects( $this->any() )->method(
'getIP' )
287 ->will( $this->returnValue(
'10.0.0.1' ) );
289 $this->assertEquals(
Status::newFatal(
'botpasswords-restriction-failed' ), $status );
293 "{$this->testUserName}@BotPassword", $this->testUser->getPassword(),
new FauxRequest );
298 $this->assertNotInstanceOf(
299 MediaWiki\Session\BotPasswordSessionProvider::class,
300 $request->getSession()->getProvider(),
304 $this->assertInstanceOf(
'Status', $status );
305 $this->assertTrue( $status->isGood() );
306 $session = $status->getValue();
308 $this->assertInstanceOf(
309 MediaWiki\Session\BotPasswordSessionProvider::class, $session->getProvider()
311 $this->assertSame( $session->getId(),
$request->getSession()->getId() );
321 $passwordFactory = new \PasswordFactory();
326 'appId' =>
'TestSave',
328 'grants' => [
'test' ],
330 $this->assertFalse( $bp->isSaved(),
'sanity check' );
335 $passwordHash = $password ? $passwordFactory->newFromPlaintext( $password ) : null;
336 $this->assertFalse( $bp->save(
'update', $passwordHash ) );
337 $this->assertTrue( $bp->save(
'insert', $passwordHash ) );
339 $this->assertInstanceOf(
'BotPassword', $bp2 );
340 $this->assertEquals( $bp->getUserCentralId(), $bp2->getUserCentralId() );
341 $this->assertEquals( $bp->getAppId(), $bp2->getAppId() );
342 $this->assertEquals( $bp->getToken(), $bp2->getToken() );
343 $this->assertEquals( $bp->getRestrictions(), $bp2->getRestrictions() );
344 $this->assertEquals( $bp->getGrants(), $bp2->getGrants() );
346 if ( $password === null ) {
347 $this->assertInstanceOf(
'InvalidPassword', $pw );
349 $this->assertTrue( $pw->equals( $password ) );
352 $token = $bp->getToken();
353 $this->assertFalse( $bp->save(
'insert' ) );
354 $this->assertTrue( $bp->save(
'update' ) );
355 $this->assertNotEquals( $token, $bp->getToken() );
357 $this->assertInstanceOf(
'BotPassword', $bp2 );
358 $this->assertEquals( $bp->getToken(), $bp2->getToken() );
360 if ( $password === null ) {
361 $this->assertInstanceOf(
'InvalidPassword', $pw );
363 $this->assertTrue( $pw->equals( $password ) );
366 $passwordHash = $passwordFactory->newFromPlaintext(
'XXX' );
367 $token = $bp->getToken();
368 $this->assertTrue( $bp->save(
'update', $passwordHash ) );
369 $this->assertNotEquals( $token, $bp->getToken() );
371 $this->assertTrue( $pw->equals(
'XXX' ) );
373 $this->assertTrue( $bp->delete() );
374 $this->assertFalse( $bp->isSaved() );
377 $this->assertFalse( $bp->save(
'foobar' ) );
static getSeparator()
Get the separator for combined user name + app ID.
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static newFatal($message)
Factory function for fatal errors.
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.
static removeAllPasswordsForUser($username)
Remove all passwords for a user, by name.
static getMain()
Static methods.
static invalidateAllPasswordsForUser($username)
Invalidate all passwords for a user, by name.
testInvalidateAllPasswordsForUser()
A BagOStuff object with no objects in it.
static newFromJson($json)
Provides a fallback sequence for Config objects.
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
static newFromUser(User $user, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
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
error also a ContextSource you ll probably need to make sure the header is varied on $request
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
testRemoveAllPasswordsForUser()
WebRequest clone which takes values from a provided array.
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
static consume(ScopedCallback &$sc=null)
Trigger a scoped callback and destroy it.
static newFromObject($object)
Return the same object, without access restrictions.
static login($username, $password, WebRequest $request)
Try to log the user in.
A Config instance which stores all settings as a member variable.
testSave($password)
provideSave