MediaWiki  master
TemporaryPasswordPrimaryAuthenticationProviderTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Auth;
4 
11 
12  private $manager = null;
13  private $config = null;
14  private $validity = null;
15 
16  protected function setUp() {
18 
19  parent::setUp();
20  if ( $wgDisableAuthManager ) {
21  $this->markTestSkipped( '$wgDisableAuthManager is set' );
22  }
23  }
24 
34  protected function getProvider( $params = [] ) {
35  if ( !$this->config ) {
36  $this->config = new \HashConfig( [
37  'EmailEnabled' => true,
38  ] );
39  }
40  $config = new \MultiConfig( [
41  $this->config,
42  \ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
43  ] );
44 
45  if ( !$this->manager ) {
46  $this->manager = new AuthManager( new \FauxRequest(), $config );
47  }
48  $this->validity = \Status::newGood();
49 
50  $mockedMethods[] = 'checkPasswordValidity';
51  $provider = $this->getMock(
53  $mockedMethods,
54  [ $params ]
55  );
56  $provider->expects( $this->any() )->method( 'checkPasswordValidity' )
57  ->will( $this->returnCallback( function () {
58  return $this->validity;
59  } ) );
60  $provider->setConfig( $config );
61  $provider->setLogger( new \Psr\Log\NullLogger() );
62  $provider->setManager( $this->manager );
63 
64  return $provider;
65  }
66 
67  protected function hookMailer( $func = null ) {
68  \Hooks::clear( 'AlternateUserMailer' );
69  if ( $func ) {
70  \Hooks::register( 'AlternateUserMailer', $func );
71  // Safety
72  \Hooks::register( 'AlternateUserMailer', function () {
73  return false;
74  } );
75  } else {
76  \Hooks::register( 'AlternateUserMailer', function () {
77  $this->fail( 'AlternateUserMailer hook called unexpectedly' );
78  return false;
79  } );
80  }
81 
82  return new \ScopedCallback( function () {
83  \Hooks::clear( 'AlternateUserMailer' );
84  \Hooks::register( 'AlternateUserMailer', function () {
85  return false;
86  } );
87  } );
88  }
89 
90  public function testBasics() {
92 
93  $this->assertSame(
95  $provider->accountCreationType()
96  );
97 
98  $this->assertTrue( $provider->testUserExists( 'UTSysop' ) );
99  $this->assertTrue( $provider->testUserExists( 'uTSysop' ) );
100  $this->assertFalse( $provider->testUserExists( 'DoesNotExist' ) );
101  $this->assertFalse( $provider->testUserExists( '<invalid>' ) );
102 
104  $req->action = AuthManager::ACTION_CHANGE;
105  $req->username = '<invalid>';
106  $provider->providerChangeAuthenticationData( $req );
107  }
108 
109  public function testConfig() {
110  $config = new \HashConfig( [
111  'EnableEmail' => false,
112  'NewPasswordExpiry' => 100,
113  'PasswordReminderResendTime' => 101,
114  ] );
115 
117  $p->setConfig( $config );
118  $this->assertSame( false, $p->emailEnabled );
119  $this->assertSame( 100, $p->newPasswordExpiry );
120  $this->assertSame( 101, $p->passwordReminderResendTime );
121 
123  'emailEnabled' => true,
124  'newPasswordExpiry' => 42,
125  'passwordReminderResendTime' => 43,
126  ] ) );
127  $p->setConfig( $config );
128  $this->assertSame( true, $p->emailEnabled );
129  $this->assertSame( 42, $p->newPasswordExpiry );
130  $this->assertSame( 43, $p->passwordReminderResendTime );
131  }
132 
133  public function testTestUserCanAuthenticate() {
134  $dbw = wfGetDB( DB_MASTER );
135 
136  $passwordFactory = new \PasswordFactory();
137  $passwordFactory->init( \RequestContext::getMain()->getConfig() );
138  // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
139  $passwordFactory->setDefaultType( 'A' );
140  $pwhash = $passwordFactory->newFromPlaintext( 'password' )->toString();
141 
142  $provider = $this->getProvider();
143  $providerPriv = \TestingAccessWrapper::newFromObject( $provider );
144 
145  $this->assertFalse( $provider->testUserCanAuthenticate( '<invalid>' ) );
146  $this->assertFalse( $provider->testUserCanAuthenticate( 'DoesNotExist' ) );
147 
148  $dbw->update(
149  'user',
150  [
151  'user_newpassword' => \PasswordFactory::newInvalidPassword()->toString(),
152  'user_newpass_time' => null,
153  ],
154  [ 'user_name' => 'UTSysop' ]
155  );
156  $this->assertFalse( $provider->testUserCanAuthenticate( 'UTSysop' ) );
157 
158  $dbw->update(
159  'user',
160  [
161  'user_newpassword' => $pwhash,
162  'user_newpass_time' => null,
163  ],
164  [ 'user_name' => 'UTSysop' ]
165  );
166  $this->assertTrue( $provider->testUserCanAuthenticate( 'UTSysop' ) );
167  $this->assertTrue( $provider->testUserCanAuthenticate( 'uTSysop' ) );
168 
169  $dbw->update(
170  'user',
171  [
172  'user_newpassword' => $pwhash,
173  'user_newpass_time' => $dbw->timestamp( time() - 10 ),
174  ],
175  [ 'user_name' => 'UTSysop' ]
176  );
177  $providerPriv->newPasswordExpiry = 100;
178  $this->assertTrue( $provider->testUserCanAuthenticate( 'UTSysop' ) );
179  $providerPriv->newPasswordExpiry = 1;
180  $this->assertFalse( $provider->testUserCanAuthenticate( 'UTSysop' ) );
181 
182  $dbw->update(
183  'user',
184  [
185  'user_newpassword' => \PasswordFactory::newInvalidPassword()->toString(),
186  'user_newpass_time' => null,
187  ],
188  [ 'user_name' => 'UTSysop' ]
189  );
190  }
191 
198  public function testGetAuthenticationRequests( $action, $options, $expected ) {
199  $actual = $this->getProvider()->getAuthenticationRequests( $action, $options );
200  foreach ( $actual as $req ) {
201  if ( $req instanceof TemporaryPasswordAuthenticationRequest && $req->password !== null ) {
202  $req->password = 'random';
203  }
204  }
205  $this->assertEquals( $expected, $actual );
206  }
207 
208  public static function provideGetAuthenticationRequests() {
209  $anon = [ 'username' => null ];
210  $loggedIn = [ 'username' => 'UTSysop' ];
211 
212  return [
213  [ AuthManager::ACTION_LOGIN, $anon, [
215  ] ],
216  [ AuthManager::ACTION_LOGIN, $loggedIn, [
218  ] ],
219  [ AuthManager::ACTION_CREATE, $anon, [] ],
220  [ AuthManager::ACTION_CREATE, $loggedIn, [
222  ] ],
223  [ AuthManager::ACTION_LINK, $anon, [] ],
224  [ AuthManager::ACTION_LINK, $loggedIn, [] ],
225  [ AuthManager::ACTION_CHANGE, $anon, [
227  ] ],
228  [ AuthManager::ACTION_CHANGE, $loggedIn, [
230  ] ],
231  [ AuthManager::ACTION_REMOVE, $anon, [
233  ] ],
234  [ AuthManager::ACTION_REMOVE, $loggedIn, [
236  ] ],
237  ];
238  }
239 
240  public function testAuthentication() {
241  $password = 'TemporaryPassword';
242  $hash = ':A:' . md5( $password );
243  $dbw = wfGetDB( DB_MASTER );
244  $dbw->update(
245  'user',
246  [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() - 10 ) ],
247  [ 'user_name' => 'UTSysop' ]
248  );
249 
253 
254  $provider = $this->getProvider();
255  $providerPriv = \TestingAccessWrapper::newFromObject( $provider );
256 
257  $providerPriv->newPasswordExpiry = 100;
258 
259  // General failures
260  $this->assertEquals(
262  $provider->beginPrimaryAuthentication( [] )
263  );
264 
265  $req->username = 'foo';
266  $req->password = null;
267  $this->assertEquals(
269  $provider->beginPrimaryAuthentication( $reqs )
270  );
271 
272  $req->username = null;
273  $req->password = 'bar';
274  $this->assertEquals(
276  $provider->beginPrimaryAuthentication( $reqs )
277  );
278 
279  $req->username = '<invalid>';
280  $req->password = 'WhoCares';
281  $ret = $provider->beginPrimaryAuthentication( $reqs );
282  $this->assertEquals(
284  $provider->beginPrimaryAuthentication( $reqs )
285  );
286 
287  $req->username = 'DoesNotExist';
288  $req->password = 'DoesNotExist';
289  $ret = $provider->beginPrimaryAuthentication( $reqs );
290  $this->assertEquals(
292  $provider->beginPrimaryAuthentication( $reqs )
293  );
294 
295  // Validation failure
296  $req->username = 'UTSysop';
297  $req->password = $password;
298  $this->validity = \Status::newFatal( 'arbitrary-failure' );
299  $ret = $provider->beginPrimaryAuthentication( $reqs );
300  $this->assertEquals(
302  $ret->status
303  );
304  $this->assertEquals(
305  'arbitrary-failure',
306  $ret->message->getKey()
307  );
308 
309  // Successful auth
310  $this->manager->removeAuthenticationSessionData( null );
311  $this->validity = \Status::newGood();
312  $this->assertEquals(
313  AuthenticationResponse::newPass( 'UTSysop' ),
314  $provider->beginPrimaryAuthentication( $reqs )
315  );
316  $this->assertNotNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
317 
318  $this->manager->removeAuthenticationSessionData( null );
319  $this->validity = \Status::newGood();
320  $req->username = 'uTSysop';
321  $this->assertEquals(
322  AuthenticationResponse::newPass( 'UTSysop' ),
323  $provider->beginPrimaryAuthentication( $reqs )
324  );
325  $this->assertNotNull( $this->manager->getAuthenticationSessionData( 'reset-pass' ) );
326  $req->username = 'UTSysop';
327 
328  // Expired password
329  $providerPriv->newPasswordExpiry = 1;
330  $ret = $provider->beginPrimaryAuthentication( $reqs );
331  $this->assertEquals(
333  $ret->status
334  );
335  $this->assertEquals(
336  'wrongpassword',
337  $ret->message->getKey()
338  );
339 
340  // Bad password
341  $providerPriv->newPasswordExpiry = 100;
342  $this->validity = \Status::newGood();
343  $req->password = 'Wrong';
344  $ret = $provider->beginPrimaryAuthentication( $reqs );
345  $this->assertEquals(
347  $ret->status
348  );
349  $this->assertEquals(
350  'wrongpassword',
351  $ret->message->getKey()
352  );
353 
354  }
355 
365  \StatusValue $expect1, \StatusValue $expect2
366  ) {
369  ) {
370  $req = new $type();
371  } else {
372  $req = $this->getMock( $type );
373  }
375  $req->username = $user;
376  $req->password = 'NewPassword';
377 
378  $provider = $this->getProvider();
379  $this->validity = $validity;
380  $this->assertEquals( $expect1, $provider->providerAllowsAuthenticationDataChange( $req, false ) );
381  $this->assertEquals( $expect2, $provider->providerAllowsAuthenticationDataChange( $req, true ) );
382  }
383 
385  $err = \StatusValue::newGood();
386  $err->error( 'arbitrary-warning' );
387 
388  return [
390  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
392  \StatusValue::newGood( 'ignored' ), \StatusValue::newGood( 'ignored' ) ],
398  \StatusValue::newGood(), $err ],
400  \Status::newFatal( 'arbitrary-error' ), \StatusValue::newGood(),
401  \StatusValue::newFatal( 'arbitrary-error' ) ],
406  ];
407  }
408 
415  public function testProviderChangeAuthenticationData( $user, $type, $changed ) {
416  $cuser = ucfirst( $user );
417  $oldpass = 'OldTempPassword';
418  $newpass = 'NewTempPassword';
419 
420  $hash = ':A:' . md5( $oldpass );
421  $dbw = wfGetDB( DB_MASTER );
422  $dbw->update(
423  'user',
424  [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() + 10 ) ],
425  [ 'user_name' => 'UTSysop' ]
426  );
427 
428  $dbw = wfGetDB( DB_MASTER );
429  $oldHash = $dbw->selectField( 'user', 'user_newpassword', [ 'user_name' => $cuser ] );
430  $cb = new \ScopedCallback( function () use ( $dbw, $cuser, $oldHash ) {
431  $dbw->update( 'user', [ 'user_newpassword' => $oldHash ], [ 'user_name' => $cuser ] );
432  } );
433 
434  $provider = $this->getProvider();
435 
436  // Sanity check
437  $loginReq = new PasswordAuthenticationRequest();
438  $loginReq->action = AuthManager::ACTION_CHANGE;
439  $loginReq->username = $user;
440  $loginReq->password = $oldpass;
441  $loginReqs = [ PasswordAuthenticationRequest::class => $loginReq ];
442  $this->assertEquals(
444  $provider->beginPrimaryAuthentication( $loginReqs ),
445  'Sanity check'
446  );
447 
450  ) {
451  $changeReq = new $type();
452  } else {
453  $changeReq = $this->getMock( $type );
454  }
455  $changeReq->action = AuthManager::ACTION_CHANGE;
456  $changeReq->username = $user;
457  $changeReq->password = $newpass;
458  $resetMailer = $this->hookMailer();
459  $provider->providerChangeAuthenticationData( $changeReq );
460  \ScopedCallback::consume( $resetMailer );
461 
462  $loginReq->password = $oldpass;
463  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
464  $this->assertEquals(
466  $ret->status,
467  'old password should fail'
468  );
469  $this->assertEquals(
470  'wrongpassword',
471  $ret->message->getKey(),
472  'old password should fail'
473  );
474 
475  $loginReq->password = $newpass;
476  $ret = $provider->beginPrimaryAuthentication( $loginReqs );
477  if ( $changed ) {
478  $this->assertEquals(
480  $ret,
481  'new password should pass'
482  );
483  $this->assertNotNull(
484  $dbw->selectField( 'user', 'user_newpass_time', [ 'user_name' => $cuser ] )
485  );
486  } else {
487  $this->assertEquals(
489  $ret->status,
490  'new password should fail'
491  );
492  $this->assertEquals(
493  'wrongpassword',
494  $ret->message->getKey(),
495  'new password should fail'
496  );
497  $this->assertNull(
498  $dbw->selectField( 'user', 'user_newpass_time', [ 'user_name' => $cuser ] )
499  );
500  }
501  }
502 
503  public static function provideProviderChangeAuthenticationData() {
504  return [
505  [ 'UTSysop', AuthenticationRequest::class, false ],
508  ];
509  }
510 
512  $dbw = wfGetDB( DB_MASTER );
513  $dbw->update(
514  'user',
515  [ 'user_newpass_time' => $dbw->timestamp( time() - 5 * 3600 ) ],
516  [ 'user_name' => 'UTSysop' ]
517  );
518 
519  $user = \User::newFromName( 'UTSysop' );
520  $reset = new \ScopedCallback( function ( $email ) use ( $user ) {
521  $user->setEmail( $email );
522  $user->saveSettings();
523  }, [ $user->getEmail() ] );
524 
525  $user->setEmail( '[email protected]' );
526  $user->saveSettings();
527 
529  $req->username = $user->getName();
530  $req->mailpassword = true;
531 
532  $provider = $this->getProvider( [ 'emailEnabled' => false ] );
533  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
534  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-emaildisabled' ), $status );
535  $req->hasBackchannel = true;
536  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
537  $this->assertFalse( $status->hasMessage( 'passwordreset-emaildisabled' ) );
538  $req->hasBackchannel = false;
539 
540  $provider = $this->getProvider( [ 'passwordReminderResendTime' => 10 ] );
541  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
542  $this->assertEquals( \StatusValue::newFatal( 'throttled-mailpassword', 10 ), $status );
543 
544  $provider = $this->getProvider( [ 'passwordReminderResendTime' => 3 ] );
545  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
546  $this->assertFalse( $status->hasMessage( 'throttled-mailpassword' ) );
547 
548  $dbw->update(
549  'user',
550  [ 'user_newpass_time' => $dbw->timestamp( time() + 5 * 3600 ) ],
551  [ 'user_name' => 'UTSysop' ]
552  );
553  $provider = $this->getProvider( [ 'passwordReminderResendTime' => 0 ] );
554  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
555  $this->assertFalse( $status->hasMessage( 'throttled-mailpassword' ) );
556 
557  $req->caller = null;
558  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
559  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-nocaller' ), $status );
560 
561  $req->caller = '127.0.0.256';
562  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
563  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-nosuchcaller', '127.0.0.256' ),
564  $status );
565 
566  $req->caller = '<Invalid>';
567  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
568  $this->assertEquals( \StatusValue::newFatal( 'passwordreset-nosuchcaller', '<Invalid>' ),
569  $status );
570 
571  $req->caller = '127.0.0.1';
572  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
573  $this->assertEquals( \StatusValue::newGood(), $status );
574 
575  $req->caller = 'UTSysop';
576  $status = $provider->providerAllowsAuthenticationDataChange( $req, true );
577  $this->assertEquals( \StatusValue::newGood(), $status );
578 
579  $mailed = false;
580  $resetMailer = $this->hookMailer( function ( $headers, $to, $from, $subject, $body )
581  use ( &$mailed, $req )
582  {
583  $mailed = true;
584  $this->assertSame( '[email protected]', $to[0]->address );
585  $this->assertContains( $req->password, $body );
586  return false;
587  } );
588  $provider->providerChangeAuthenticationData( $req );
589  \ScopedCallback::consume( $resetMailer );
590  $this->assertTrue( $mailed );
591 
592  $priv = \TestingAccessWrapper::newFromObject( $provider );
593  $req->username = '<invalid>';
594  $status = $priv->sendPasswordResetEmail( $req );
595  $this->assertEquals( \Status::newFatal( 'noname' ), $status );
596  }
597 
598  public function testTestForAccountCreation() {
599  $user = \User::newFromName( 'foo' );
601  $req->username = 'Foo';
602  $req->password = 'Bar';
604 
605  $provider = $this->getProvider();
606  $this->assertEquals(
608  $provider->testForAccountCreation( $user, $user, [] ),
609  'No password request'
610  );
611 
612  $this->assertEquals(
614  $provider->testForAccountCreation( $user, $user, $reqs ),
615  'Password request, validated'
616  );
617 
618  $this->validity->error( 'arbitrary warning' );
619  $expect = \StatusValue::newGood();
620  $expect->error( 'arbitrary warning' );
621  $this->assertEquals(
622  $expect,
623  $provider->testForAccountCreation( $user, $user, $reqs ),
624  'Password request, not validated'
625  );
626  }
627 
628  public function testAccountCreation() {
629  $resetMailer = $this->hookMailer();
630 
631  $user = \User::newFromName( 'Foo' );
632 
635 
636  $authreq = new PasswordAuthenticationRequest();
637  $authreq->action = AuthManager::ACTION_CREATE;
638  $authreqs = [ PasswordAuthenticationRequest::class => $authreq ];
639 
640  $provider = $this->getProvider();
641 
642  $this->assertEquals(
644  $provider->beginPrimaryAccountCreation( $user, $user, [] )
645  );
646 
647  $req->username = 'foo';
648  $req->password = null;
649  $this->assertEquals(
651  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
652  );
653 
654  $req->username = null;
655  $req->password = 'bar';
656  $this->assertEquals(
658  $provider->beginPrimaryAccountCreation( $user, $user, $reqs )
659  );
660 
661  $req->username = 'foo';
662  $req->password = 'bar';
663 
664  $expect = AuthenticationResponse::newPass( 'Foo' );
665  $expect->createRequest = clone( $req );
666  $expect->createRequest->username = 'Foo';
667  $this->assertEquals( $expect, $provider->beginPrimaryAccountCreation( $user, $user, $reqs ) );
668  $this->assertNull( $this->manager->getAuthenticationSessionData( 'no-email' ) );
669 
670  // We have to cheat a bit to avoid having to add a new user to
671  // the database to test the actual setting of the password works right
672  $user = \User::newFromName( 'UTSysop' );
673  $req->username = $authreq->username = $user->getName();
674  $req->password = $authreq->password = 'NewPassword';
675  $expect = AuthenticationResponse::newPass( 'UTSysop' );
676  $expect->createRequest = $req;
677 
678  $res2 = $provider->beginPrimaryAccountCreation( $user, $user, $reqs );
679  $this->assertEquals( $expect, $res2, 'Sanity check' );
680 
681  $ret = $provider->beginPrimaryAuthentication( $authreqs );
682  $this->assertEquals( AuthenticationResponse::FAIL, $ret->status, 'sanity check' );
683 
684  $this->assertSame( null, $provider->finishAccountCreation( $user, $user, $res2 ) );
685 
686  $ret = $provider->beginPrimaryAuthentication( $authreqs );
687  $this->assertEquals( AuthenticationResponse::PASS, $ret->status, 'new password is set' );
688  }
689 
690  public function testAccountCreationEmail() {
691  $creator = \User::newFromName( 'Foo' );
692  $user = \User::newFromName( 'UTSysop' );
693  $reset = new \ScopedCallback( function ( $email ) use ( $user ) {
694  $user->setEmail( $email );
695  $user->saveSettings();
696  }, [ $user->getEmail() ] );
697 
698  $user->setEmail( null );
699 
701  $req->username = $user->getName();
702  $req->mailpassword = true;
703 
704  $provider = $this->getProvider( [ 'emailEnabled' => false ] );
705  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
706  $this->assertEquals( \StatusValue::newFatal( 'emaildisabled' ), $status );
707  $req->hasBackchannel = true;
708  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
709  $this->assertFalse( $status->hasMessage( 'emaildisabled' ) );
710  $req->hasBackchannel = false;
711 
712  $provider = $this->getProvider( [ 'emailEnabled' => true ] );
713  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
714  $this->assertEquals( \StatusValue::newFatal( 'noemailcreate' ), $status );
715  $req->hasBackchannel = true;
716  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
717  $this->assertFalse( $status->hasMessage( 'noemailcreate' ) );
718  $req->hasBackchannel = false;
719 
720  $user->setEmail( '[email protected]' );
721  $status = $provider->testForAccountCreation( $user, $creator, [ $req ] );
722  $this->assertEquals( \StatusValue::newGood(), $status );
723 
724  $mailed = false;
725  $resetMailer = $this->hookMailer( function ( $headers, $to, $from, $subject, $body )
726  use ( &$mailed, $req )
727  {
728  $mailed = true;
729  $this->assertSame( '[email protected]', $to[0]->address );
730  $this->assertContains( $req->password, $body );
731  return false;
732  } );
733 
734  $expect = AuthenticationResponse::newPass( 'UTSysop' );
735  $expect->createRequest = clone( $req );
736  $expect->createRequest->username = 'UTSysop';
737  $res = $provider->beginPrimaryAccountCreation( $user, $creator, [ $req ] );
738  $this->assertEquals( $expect, $res );
739  $this->assertTrue( $this->manager->getAuthenticationSessionData( 'no-email' ) );
740  $this->assertFalse( $mailed );
741 
742  $this->assertSame( 'byemail', $provider->finishAccountCreation( $user, $creator, $res ) );
743  $this->assertTrue( $mailed );
744 
745  \ScopedCallback::consume( $resetMailer );
746  $this->assertTrue( $mailed );
747  }
748 
749 }
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:522
testProviderAllowsAuthenticationDataChange($type, $user,\Status $validity,\StatusValue $expect1,\StatusValue $expect2)
provideProviderAllowsAuthenticationDataChange
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
testProviderChangeAuthenticationData($user, $type, $changed)
provideProviderChangeAuthenticationData
static wrap($sv)
Succinct helper method to wrap a StatusValue.
Definition: Status.php:79
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
Generic operation result class Has warning/error list, boolean status and arbitrary value...
Definition: Status.php:40
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static newFatal($message)
Factory function for fatal errors.
Definition: Status.php:89
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:1816
static register($name, $callback)
Attach an event handler to a given hook.
Definition: Hooks.php:49
static getMain()
Static methods.
static clear($name)
Clears hooks registered via Hooks::register().
Definition: Hooks.php:66
const FAIL
Indicates that the authentication failed.
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 and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1020
$res
Definition: database.txt:21
const ACTION_CHANGE
Change a user's credentials.
Definition: AuthManager.php:60
A primary authentication provider that uses the temporary password field in the 'user' table...
$params
const PASS
Indicates that the authentication succeeded.
Generic operation result class Has warning/error list, boolean status and arbitrary value...
Definition: StatusValue.php:42
static newGood($value=null)
Factory function for good results.
Definition: StatusValue.php:76
This serves as the entry point to the authentication system.
Definition: AuthManager.php:43
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:1816
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
const ACTION_LINK
Link an existing user to a third-party account.
Definition: AuthManager.php:55
This represents the intention to set a temporary password for the user.
static newInvalidPassword()
Create an InvalidPassword.
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
This is a value object for authentication requests with a username and password.
String $action
Cache what action this request is.
Definition: MediaWiki.php:42
static getDefaultInstance()
AuthManager Database MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider.
$from
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 $req
Definition: hooks.txt:981
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 newRandom()
Return an instance with a new, random password.
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
const ACTION_REMOVE
Remove a user's credentials.
Definition: AuthManager.php:62
$wgDisableAuthManager
Disable AuthManager.
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:1020
static consume(ScopedCallback &$sc=null)
Trigger a scoped callback and destroy it.
const ACTION_CREATE
Create a new user.
Definition: AuthManager.php:50
const DB_MASTER
Definition: Defines.php:47
static newFromObject($object)
Return the same object, without access restrictions.
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
Definition: AuthManager.php:45
testGetAuthenticationRequests($action, $options, $expected)
provideGetAuthenticationRequests
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2376
static newGood($value=null)
Factory function for good results.
Definition: Status.php:101