MediaWiki  1.30.0
TemporaryPasswordPrimaryAuthenticationProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Auth;
4 
6 use Wikimedia\ScopedCallback;
7 use Wikimedia\TestingAccessWrapper;
8 
15 
16  private $manager = null;
17  private $config = null;
18  private $validity = null;
19 
29  protected function getProvider( $params = [] ) {
30  if ( !$this->config ) {
31  $this->config = new \HashConfig( [
32  'EmailEnabled' => true,
33  ] );
34  }
35  $config = new \MultiConfig( [
36  $this->config,
37  MediaWikiServices::getInstance()->getMainConfig()
38  ] );
39 
40  if ( !$this->manager ) {
41  $this->manager = new AuthManager( new \FauxRequest(), $config );
42  }
43  $this->validity = \Status::newGood();
44 
45  $mockedMethods[] = 'checkPasswordValidity';
46  $provider = $this->getMockBuilder( TemporaryPasswordPrimaryAuthenticationProvider::class )
47  ->setMethods( $mockedMethods )
48  ->setConstructorArgs( [ $params ] )
49  ->getMock();
50  $provider->expects( $this->any() )->method( 'checkPasswordValidity' )
51  ->will( $this->returnCallback( function () {
52  return $this->validity;
53  } ) );
54  $provider->setConfig( $config );
55  $provider->setLogger( new \Psr\Log\NullLogger() );
56  $provider->setManager( $this->manager );
57 
58  return $provider;
59  }
60 
61  protected function hookMailer( $func = null ) {
62  \Hooks::clear( 'AlternateUserMailer' );
63  if ( $func ) {
64  \Hooks::register( 'AlternateUserMailer', $func );
65  // Safety
66  \Hooks::register( 'AlternateUserMailer', function () {
67  return false;
68  } );
69  } else {
70  \Hooks::register( 'AlternateUserMailer', function () {
71  $this->fail( 'AlternateUserMailer hook called unexpectedly' );
72  return false;
73  } );
74  }
75 
76  return new ScopedCallback( function () {
77  \Hooks::clear( 'AlternateUserMailer' );
78  \Hooks::register( 'AlternateUserMailer', function () {
79  return false;
80  } );
81  } );
82  }
83 
84  public function testBasics() {
86 
87  $this->assertSame(
89  $provider->accountCreationType()
90  );
91 
92  $this->assertTrue( $provider->testUserExists( 'UTSysop' ) );
93  $this->assertTrue( $provider->testUserExists( 'uTSysop' ) );
94  $this->assertFalse( $provider->testUserExists( 'DoesNotExist' ) );
95  $this->assertFalse( $provider->testUserExists( '<invalid>' ) );
96 
99  $req->username = '<invalid>';
100  $provider->providerChangeAuthenticationData( $req );
101  }
102 
103  public function testConfig() {
104  $config = new \HashConfig( [
105  'EnableEmail' => false,
106  'NewPasswordExpiry' => 100,
107  'PasswordReminderResendTime' => 101,
108  ] );
109 
110  $p = TestingAccessWrapper::newFromObject( new TemporaryPasswordPrimaryAuthenticationProvider() );
111  $p->setConfig( $config );
112  $this->assertSame( false, $p->emailEnabled );
113  $this->assertSame( 100, $p->newPasswordExpiry );
114  $this->assertSame( 101, $p->passwordReminderResendTime );
115 
116  $p = TestingAccessWrapper::newFromObject( new TemporaryPasswordPrimaryAuthenticationProvider( [
117  'emailEnabled' => true,
118  'newPasswordExpiry' => 42,
119  'passwordReminderResendTime' => 43,
120  ] ) );
121  $p->setConfig( $config );
122  $this->assertSame( true, $p->emailEnabled );
123  $this->assertSame( 42, $p->newPasswordExpiry );
124  $this->assertSame( 43, $p->passwordReminderResendTime );
125  }
126 
127  public function testTestUserCanAuthenticate() {
128  $user = self::getMutableTestUser()->getUser();
129 
130  $dbw = wfGetDB( DB_MASTER );
131 
132  $passwordFactory = new \PasswordFactory();
133  $passwordFactory->init( \RequestContext::getMain()->getConfig() );
134  // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
135  $passwordFactory->setDefaultType( 'A' );
136  $pwhash = $passwordFactory->newFromPlaintext( 'password' )->toString();
137 
138  $provider = $this->getProvider();
139  $providerPriv = TestingAccessWrapper::newFromObject( $provider );
140 
141  $this->assertFalse( $provider->testUserCanAuthenticate( '<invalid>' ) );
142  $this->assertFalse( $provider->testUserCanAuthenticate( 'DoesNotExist' ) );
143 
144  $dbw->update(
145  'user',
146  [
147  'user_newpassword' => \PasswordFactory::newInvalidPassword()->toString(),
148  'user_newpass_time' => null,
149  ],
150  [ 'user_id' => $user->getId() ]
151  );
152  $this->assertFalse( $provider->testUserCanAuthenticate( $user->getName() ) );
153 
154  $dbw->update(
155  'user',
156  [
157  'user_newpassword' => $pwhash,
158  'user_newpass_time' => null,
159  ],
160  [ 'user_id' => $user->getId() ]
161  );
162  $this->assertTrue( $provider->testUserCanAuthenticate( $user->getName() ) );
163  $this->assertTrue( $provider->testUserCanAuthenticate( lcfirst( $user->getName() ) ) );
164 
165  $dbw->update(
166  'user',
167  [
168  'user_newpassword' => $pwhash,
169  'user_newpass_time' => $dbw->timestamp( time() - 10 ),
170  ],
171  [ 'user_id' => $user->getId() ]
172  );
173  $providerPriv->newPasswordExpiry = 100;
174  $this->assertTrue( $provider->testUserCanAuthenticate( $user->getName() ) );
175  $providerPriv->newPasswordExpiry = 1;
176  $this->assertFalse( $provider->testUserCanAuthenticate( $user->getName() ) );
177 
178  $dbw->update(
179  'user',
180  [
181  'user_newpassword' => \PasswordFactory::newInvalidPassword()->toString(),
182  'user_newpass_time' => null,
183  ],
184  [ 'user_id' => $user->getId() ]
185  );
186  }
187 
194  public function testGetAuthenticationRequests( $action, $options, $expected ) {
195  $actual = $this->getProvider()->getAuthenticationRequests( $action, $options );
196  foreach ( $actual as $req ) {
197  if ( $req instanceof TemporaryPasswordAuthenticationRequest && $req->password !== null ) {
198  $req->password = 'random';
199  }
200  }
201  $this->assertEquals( $expected, $actual );
202  }
203 
204  public static function provideGetAuthenticationRequests() {
205  $anon = [ 'username' => null ];
206  $loggedIn = [ 'username' => 'UTSysop' ];
207 
208  return [
209  [ AuthManager::ACTION_LOGIN, $anon, [
211  ] ],
212  [ AuthManager::ACTION_LOGIN, $loggedIn, [
214  ] ],
215  [ AuthManager::ACTION_CREATE, $anon, [] ],
216  [ AuthManager::ACTION_CREATE, $loggedIn, [
218  ] ],
219  [ AuthManager::ACTION_LINK, $anon, [] ],
220  [ AuthManager::ACTION_LINK, $loggedIn, [] ],
221  [ AuthManager::ACTION_CHANGE, $anon, [
223  ] ],
224  [ AuthManager::ACTION_CHANGE, $loggedIn, [
226  ] ],
227  [ AuthManager::ACTION_REMOVE, $anon, [
229  ] ],
230  [ AuthManager::ACTION_REMOVE, $loggedIn, [
232  ] ],
233  ];
234  }
235 
236  public function testAuthentication() {
237  $user = self::getMutableTestUser()->getUser();
238 
239  $password = 'TemporaryPassword';
240  $hash = ':A:' . md5( $password );
241  $dbw = wfGetDB( DB_MASTER );
242  $dbw->update(
243  'user',
244  [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() - 10 ) ],
245  [ 'user_id' => $user->getId() ]
246  );
247 
251 
252  $provider = $this->getProvider();
253  $providerPriv = TestingAccessWrapper::newFromObject( $provider );
254 
255  $providerPriv->newPasswordExpiry = 100;
256 
257  // General failures
258  $this->assertEquals(
260  $provider->beginPrimaryAuthentication( [] )
261  );
262 
263  $req->username = 'foo';
264  $req->password = null;
265  $this->assertEquals(
267  $provider->beginPrimaryAuthentication( $reqs )
268  );
269 
270  $req->username = null;
271  $req->password = 'bar';
272  $this->assertEquals(
274  $provider->beginPrimaryAuthentication( $reqs )
275  );
276 
277  $req->username = '<invalid>';
278  $req->password = 'WhoCares';
279  $ret = $provider->beginPrimaryAuthentication( $reqs );
280  $this->assertEquals(
282  $provider->beginPrimaryAuthentication( $reqs )
283  );
284 
285  $req->username = 'DoesNotExist';
286  $req->password = 'DoesNotExist';
287  $ret = $provider->beginPrimaryAuthentication( $reqs );
288  $this->assertEquals(
290  $provider->beginPrimaryAuthentication( $reqs )
291  );
292 
293  // Validation failure
294  $req->username = $user->getName();
295  $req->password = $password;
296  $this->validity = \Status::newFatal( 'arbitrary-failure' );
297  $ret = $provider->beginPrimaryAuthentication( $reqs );
298  $this->assertEquals(
300  $ret->status
301  );
302  $this->assertEquals(
303  'arbitrary-failure',
304  $ret->message->getKey()
305  );
306 
307  // Successful auth
308  $this->manager->removeAuthenticationSessionData( null );
309  $this->validity = \Status::newGood();
310  $this->assertEquals(
312  $provider->beginPrimaryAuthentication( $reqs )
313  );
314  $this->assertNotNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
315 
316  $this->manager->removeAuthenticationSessionData( null );
317  $this->validity = \Status::newGood();
318  $req->username = lcfirst( $user->getName() );
319  $this->assertEquals(
321  $provider->beginPrimaryAuthentication( $reqs )
322  );
323  $this->assertNotNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
324  $req->username = $user->getName();
325 
326  // Expired password
327  $providerPriv->newPasswordExpiry = 1;
328  $ret = $provider->beginPrimaryAuthentication( $reqs );
329  $this->assertEquals(
331  $ret->status
332  );
333  $this->assertEquals(
334  'wrongpassword',
335  $ret->message->getKey()
336  );
337 
338  // Bad password
339  $providerPriv->newPasswordExpiry = 100;
340  $this->validity = \Status::newGood();
341  $req->password = 'Wrong';
342  $ret = $provider->beginPrimaryAuthentication( $reqs );
343  $this->assertEquals(
345  $ret->status
346  );
347  $this->assertEquals(
348  'wrongpassword',
349  $ret->message->getKey()
350  );
351  }
352 
362  \StatusValue $expect1, \StatusValue $expect2
363  ) {
366  ) {
367  $req = new $type();
368  } else {
369  $req = $this->createMock( $type );
370  }
372  $req->username = $user;
373  $req->password = 'NewPassword';
374 
375  $provider = $this->getProvider();
376  $this->validity = $validity;
377  $this->assertEquals( $expect1, $provider->providerAllowsAuthenticationDataChange( $req, false ) );
378  $this->assertEquals( $expect2, $provider->providerAllowsAuthenticationDataChange( $req, true ) );
379  }
380 
382  $err = \StatusValue::newGood();
383  $err->error( 'arbitrary-warning' );
384 
385  return [
387  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
389  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
395  \StatusValue::newGood(), $err ],
397  \Status::newFatal( 'arbitrary-error' ), \StatusValue::newGood(),
398  \StatusValue::newFatal( 'arbitrary-error' ) ],
403  ];
404  }
405 
412  public function testProviderChangeAuthenticationData( $user, $type, $changed ) {
413  $cuser = ucfirst( $user );
414  $oldpass = 'OldTempPassword';
415  $newpass = 'NewTempPassword';
416 
417  $dbw = wfGetDB( DB_MASTER );
418  $oldHash = $dbw->selectField( 'user', 'user_newpassword', [ 'user_name' => $cuser ] );
419  $cb = new ScopedCallback( function () use ( $dbw, $cuser, $oldHash ) {
420  $dbw->update( 'user', [ 'user_newpassword' => $oldHash ], [ 'user_name' => $cuser ] );
421  } );
422 
423  $hash = ':A:' . md5( $oldpass );
424  $dbw->update(
425  'user',
426  [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() + 10 ) ],
427  [ 'user_name' => $cuser ]
428  );
429 
430  $provider = $this->getProvider();
431 
432  // Sanity check
433  $loginReq = new PasswordAuthenticationRequest();
434  $loginReq->action = AuthManager::ACTION_CHANGE;
435  $loginReq->username = $user;
436  $loginReq->password = $oldpass;
437  $loginReqs = [ PasswordAuthenticationRequest::class => $loginReq ];
438  $this->assertEquals(
440  $provider->beginPrimaryAuthentication( $loginReqs ),
441  'Sanity check'
442  );
443 
446  ) {
447  $changeReq = new $type();
448  } else {
449  $changeReq = $this->createMock( $type );
450  }
451  $changeReq->action = AuthManager::ACTION_CHANGE;
452  $changeReq->username = $user;
453  $changeReq->password = $newpass;
454  $resetMailer = $this->hookMailer();
455  $provider->providerChangeAuthenticationData( $changeReq );
456  ScopedCallback::consume( $resetMailer );
457 
458  $loginReq->password = $oldpass;
459  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
460  $this->assertEquals(
462  $ret->status,
463  'old password should fail'
464  );
465  $this->assertEquals(
466  'wrongpassword',
467  $ret->message->getKey(),
468  'old password should fail'
469  );
470 
471  $loginReq->password = $newpass;
472  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
473  if ( $changed ) {
474  $this->assertEquals(
476  $ret,
477  'new password should pass'
478  );
479  $this->assertNotNull(
480  $dbw->selectField( 'user', 'user_newpass_time', [ 'user_name' => $cuser ] )
481  );
482  } else {
483  $this->assertEquals(
485  $ret->status,
486  'new password should fail'
487  );
488  $this->assertEquals(
489  'wrongpassword',
490  $ret->message->getKey(),
491  'new password should fail'
492  );
493  $this->assertNull(
494  $dbw->selectField( 'user', 'user_newpass_time', [ 'user_name' => $cuser ] )
495  );
496  }
497  }
498 
499  public static function provideProviderChangeAuthenticationData() {
500  return [
501  [ 'UTSysop', AuthenticationRequest::class, false ],
504  ];
505  }
506 
508  $user = self::getMutableTestUser()->getUser();
509 
510  $dbw = wfGetDB( DB_MASTER );
511  $dbw->update(
512  'user',
513  [ 'user_newpass_time' => $dbw->timestamp( time() - 5 * 3600 ) ],
514  [ 'user_id' => $user->getId() ]
515  );
516 
518  $req->username = $user->getName();
519  $req->mailpassword = true;
520 
521  $provider = $this->getProvider( [ 'emailEnabled' => false ] );
522  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
523  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-emaildisabled' ), $status );
524 
525  $provider = $this->getProvider( [ 'passwordReminderResendTime' => 10 ] );
526  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
527  $this->assertEquals( \StatusValue::newFatal( 'throttled-mailpassword', 10 ), $status );
528 
529  $provider = $this->getProvider( [ 'passwordReminderResendTime' => 3 ] );
530  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
531  $this->assertFalse( $status->hasMessage( 'throttled-mailpassword' ) );
532 
533  $dbw->update(
534  'user',
535  [ 'user_newpass_time' => $dbw->timestamp( time() + 5 * 3600 ) ],
536  [ 'user_id' => $user->getId() ]
537  );
538  $provider = $this->getProvider( [ 'passwordReminderResendTime' => 0 ] );
539  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
540  $this->assertFalse( $status->hasMessage( 'throttled-mailpassword' ) );
541 
542  $req->caller = null;
543  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
544  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-nocaller' ), $status );
545 
546  $req->caller = '127.0.0.256';
547  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
548  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-nosuchcaller', '127.0.0.256' ),
549  $status );
550 
551  $req->caller = '<Invalid>';
552  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
553  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-nosuchcaller', '<Invalid>' ),
554  $status );
555 
556  $req->caller = '127.0.0.1';
557  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
558  $this->assertEquals( \StatusValue::newGood(), $status );
559 
560  $req->caller = $user->getName();
561  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
562  $this->assertEquals( \StatusValue::newGood(), $status );
563 
564  $mailed = false;
565  $resetMailer = $this->hookMailer( function ( $headers, $to, $from, $subject, $body )
566  use ( &$mailed, $req, $user )
567  {
568  $mailed = true;
569  $this->assertSame( $user->getEmail(), $to[0]->address );
570  $this->assertContains( $req->password, $body );
571  return false;
572  } );
573  $provider->providerChangeAuthenticationData( $req );
574  ScopedCallback::consume( $resetMailer );
575  $this->assertTrue( $mailed );
576 
577  $priv = TestingAccessWrapper::newFromObject( $provider );
578  $req->username = '<invalid>';
579  $status = $priv->sendPasswordResetEmail( $req );
580  $this->assertEquals( \Status::newFatal( 'noname' ), $status );
581  }
582 
583  public function testTestForAccountCreation() {
584  $user = \User::newFromName( 'foo' );
586  $req->username = 'Foo';
587  $req->password = 'Bar';
589 
590  $provider = $this->getProvider();
591  $this->assertEquals(
593  $provider->testForAccountCreation( $user, $user, [] ),
594  'No password request'
595  );
596 
597  $this->assertEquals(
599  $provider->testForAccountCreation( $user, $user, $reqs ),
600  'Password request, validated'
601  );
602 
603  $this->validity->error( 'arbitrary warning' );
604  $expect = \StatusValue::newGood();
605  $expect->error( 'arbitrary warning' );
606  $this->assertEquals(
607  $expect,
608  $provider->testForAccountCreation( $user, $user, $reqs ),
609  'Password request, not validated'
610  );
611  }
612 
613  public function testAccountCreation() {
614  $resetMailer = $this->hookMailer();
615 
616  $user = \User::newFromName( 'Foo' );
617 
620 
621  $authreq = new PasswordAuthenticationRequest();
622  $authreq->action = AuthManager::ACTION_CREATE;
623  $authreqs = [ PasswordAuthenticationRequest::class => $authreq ];
624 
625  $provider = $this->getProvider();
626 
627  $this->assertEquals(
629  $provider->beginPrimaryAccountCreation( $user, $user, [] )
630  );
631 
632  $req->username = 'foo';
633  $req->password = null;
634  $this->assertEquals(
636  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
637  );
638 
639  $req->username = null;
640  $req->password = 'bar';
641  $this->assertEquals(
643  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
644  );
645 
646  $req->username = 'foo';
647  $req->password = 'bar';
648 
649  $expect = AuthenticationResponse::newPass( 'Foo' );
650  $expect->createRequest = clone $req;
651  $expect->createRequest->username = 'Foo';
652  $this->assertEquals( $expect, $provider->beginPrimaryAccountCreation( $user, $user, $reqs ) );
653  $this->assertNull( $this->manager->getAuthenticationSessionData( 'no-email' ) );
654 
655  $user = self::getMutableTestUser()->getUser();
656  $req->username = $authreq->username = $user->getName();
657  $req->password = $authreq->password = 'NewPassword';
658  $expect = AuthenticationResponse::newPass( $user->getName() );
659  $expect->createRequest = $req;
660 
661  $res2 = $provider->beginPrimaryAccountCreation( $user, $user, $reqs );
662  $this->assertEquals( $expect, $res2, 'Sanity check' );
663 
664  $ret = $provider->beginPrimaryAuthentication( $authreqs );
665  $this->assertEquals( AuthenticationResponse::FAIL, $ret->status, 'sanity check' );
666 
667  $this->assertSame( null, $provider->finishAccountCreation( $user, $user, $res2 ) );
668 
669  $ret = $provider->beginPrimaryAuthentication( $authreqs );
670  $this->assertEquals( AuthenticationResponse::PASS, $ret->status, 'new password is set' );
671  }
672 
673  public function testAccountCreationEmail() {
674  $creator = \User::newFromName( 'Foo' );
675 
676  $user = self::getMutableTestUser()->getUser();
677  $user->setEmail( null );
678 
680  $req->username = $user->getName();
681  $req->mailpassword = true;
682 
683  $provider = $this->getProvider( [ 'emailEnabled' => false ] );
684  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
685  $this->assertEquals( \StatusValue::newFatal( 'emaildisabled' ), $status );
686 
687  $provider = $this->getProvider( [ 'emailEnabled' => true ] );
688  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
689  $this->assertEquals( \StatusValue::newFatal( 'noemailcreate' ), $status );
690 
691  $user->setEmail( 'test@localhost.localdomain' );
692  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
693  $this->assertEquals( \StatusValue::newGood(), $status );
694 
695  $mailed = false;
696  $resetMailer = $this->hookMailer( function ( $headers, $to, $from, $subject, $body )
697  use ( &$mailed, $req )
698  {
699  $mailed = true;
700  $this->assertSame( 'test@localhost.localdomain', $to[0]->address );
701  $this->assertContains( $req->password, $body );
702  return false;
703  } );
704 
705  $expect = AuthenticationResponse::newPass( $user->getName() );
706  $expect->createRequest = clone $req;
707  $expect->createRequest->username = $user->getName();
708  $res = $provider->beginPrimaryAccountCreation( $user, $creator, [ $req ] );
709  $this->assertEquals( $expect, $res );
710  $this->assertTrue( $this->manager->getAuthenticationSessionData( 'no-email' ) );
711  $this->assertFalse( $mailed );
712 
713  $this->assertSame( 'byemail', $provider->finishAccountCreation( $user, $creator, $res ) );
714  $this->assertTrue( $mailed );
715 
716  ScopedCallback::consume( $resetMailer );
717  $this->assertTrue( $mailed );
718  }
719 
720 }
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\provideGetAuthenticationRequests
static provideGetAuthenticationRequests()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:204
$user
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 account $user
Definition: hooks.txt:244
MediaWiki\Auth\PrimaryAuthenticationProvider\TYPE_CREATE
const TYPE_CREATE
Provider can create accounts.
Definition: PrimaryAuthenticationProvider.php:77
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
StatusValue
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:42
MediaWiki\$action
String $action
Cache what action this request is.
Definition: MediaWiki.php:47
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\getProvider
getProvider( $params=[])
Get an instance of the provider.
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:29
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testAccountCreation
testAccountCreation()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:613
$status
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action or null $user:User who performed the tagging when the tagging is subsequent to the action or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition: hooks.txt:1245
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$req
this hook is for auditing only $req
Definition: hooks.txt:988
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
$params
$params
Definition: styleTest.css.php:40
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:550
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testTestForAccountCreation
testTestForAccountCreation()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:583
$res
$res
Definition: database.txt:21
Hooks\clear
static clear( $name)
Clears hooks registered via Hooks::register().
Definition: Hooks.php:66
php
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
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
MediaWiki\Auth\AuthenticationResponse\newAbstain
static newAbstain()
Definition: AuthenticationResponse.php:170
MediaWiki\Auth\PasswordAuthenticationRequest
This is a value object for authentication requests with a username and password.
Definition: PasswordAuthenticationRequest.php:29
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest
AuthManager Database MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider.
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:14
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testGetAuthenticationRequests
testGetAuthenticationRequests( $action, $options, $expected)
provideGetAuthenticationRequests
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:194
Status\wrap
static wrap( $sv)
Succinct helper method to wrap a StatusValue.
Definition: Status.php:55
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testProviderChangeAuthenticationData
testProviderChangeAuthenticationData( $user, $type, $changed)
provideProviderChangeAuthenticationData
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:412
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\$manager
$manager
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:16
DB_MASTER
const DB_MASTER
Definition: defines.php:26
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testProviderAllowsAuthenticationDataChange
testProviderAllowsAuthenticationDataChange( $type, $user, \Status $validity, \StatusValue $expect1, \StatusValue $expect2)
provideProviderAllowsAuthenticationDataChange
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:361
MediaWiki\Auth\AuthenticationResponse\FAIL
const FAIL
Indicates that the authentication failed.
Definition: AuthenticationResponse.php:42
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\$config
$config
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:17
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:99
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
MediaWiki\Auth\AuthManager\ACTION_CREATE
const ACTION_CREATE
Create a new user.
Definition: AuthManager.php:89
Hooks\register
static register( $name, $callback)
Attach an event handler to a given hook.
Definition: Hooks.php:49
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testConfig
testConfig()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:103
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
MediaWikiTestCase\getMutableTestUser
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
Definition: MediaWikiTestCase.php:160
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testAuthentication
testAuthentication()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:236
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider
A primary authentication provider that uses the temporary password field in the 'user' table.
Definition: TemporaryPasswordPrimaryAuthenticationProvider.php:37
MediaWiki\Auth\AuthManager\ACTION_CHANGE
const ACTION_CHANGE
Change a user's credentials.
Definition: AuthManager.php:99
$ret
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
Definition: hooks.txt:1965
MediaWiki\Auth\AuthManager\ACTION_LINK
const ACTION_LINK
Link an existing user to a third-party account.
Definition: AuthManager.php:94
RequestContext\getMain
static getMain()
Static methods.
Definition: RequestContext.php:470
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\hookMailer
hookMailer( $func=null)
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:61
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:82
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\provideProviderChangeAuthenticationData
static provideProviderChangeAuthenticationData()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:499
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testBasics
testBasics()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:84
MediaWiki\Auth\AuthManager\ACTION_REMOVE
const ACTION_REMOVE
Remove a user's credentials.
Definition: AuthManager.php:101
PasswordFactory\newInvalidPassword
static newInvalidPassword()
Create an InvalidPassword.
Definition: PasswordFactory.php:214
$options
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 & $options
Definition: hooks.txt:1965
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testAccountCreationEmail
testAccountCreationEmail()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:673
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest
This represents the intention to set a temporary password for the user.
Definition: TemporaryPasswordAuthenticationRequest.php:31
MediaWiki\Auth\AuthManager\ACTION_LOGIN
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
Definition: AuthManager.php:84
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 just before the function returns a value If you return true
Definition: hooks.txt:1965
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\provideProviderAllowsAuthenticationDataChange
static provideProviderAllowsAuthenticationDataChange()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:381
class
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
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
MediaWiki\Auth\AuthenticationResponse\PASS
const PASS
Indicates that the authentication succeeded.
Definition: AuthenticationResponse.php:39
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\newRandom
static newRandom()
Return an instance with a new, random password.
Definition: TemporaryPasswordAuthenticationRequest.php:65
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\$validity
$validity
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:18
MediaWiki\Auth\AuthenticationResponse\newPass
static newPass( $username=null)
Definition: AuthenticationResponse.php:134
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testTestUserCanAuthenticate
testTestUserCanAuthenticate()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:127
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest\testProviderChangeAuthenticationDataEmail
testProviderChangeAuthenticationDataEmail()
Definition: TemporaryPasswordPrimaryAuthenticationProviderTest.php:507
$type
$type
Definition: testCompression.php:48