28 if ( !$this->config ) {
29 $this->config = new \HashConfig( [
30 'EmailEnabled' =>
true,
38 if ( !$this->manager ) {
43 $mockedMethods[] =
'checkPasswordValidity';
44 $provider = $this->getMock(
49 $provider->expects( $this->any() )->method(
'checkPasswordValidity' )
50 ->will( $this->returnCallback(
function () {
53 $provider->setConfig(
$config );
54 $provider->setLogger(
new \Psr\Log\NullLogger() );
55 $provider->setManager( $this->manager );
70 $this->fail(
'AlternateUserMailer hook called unexpectedly' );
75 return new ScopedCallback(
function () {
88 $provider->accountCreationType()
91 $this->assertTrue( $provider->testUserExists(
'UTSysop' ) );
92 $this->assertTrue( $provider->testUserExists(
'uTSysop' ) );
93 $this->assertFalse( $provider->testUserExists(
'DoesNotExist' ) );
94 $this->assertFalse( $provider->testUserExists(
'<invalid>' ) );
98 $req->username =
'<invalid>';
99 $provider->providerChangeAuthenticationData( $req );
104 'EnableEmail' =>
false,
105 'NewPasswordExpiry' => 100,
106 'PasswordReminderResendTime' => 101,
111 $this->assertSame(
false, $p->emailEnabled );
112 $this->assertSame( 100, $p->newPasswordExpiry );
113 $this->assertSame( 101, $p->passwordReminderResendTime );
116 'emailEnabled' =>
true,
117 'newPasswordExpiry' => 42,
118 'passwordReminderResendTime' => 43,
121 $this->assertSame(
true, $p->emailEnabled );
122 $this->assertSame( 42, $p->newPasswordExpiry );
123 $this->assertSame( 43, $p->passwordReminderResendTime );
127 $user = self::getMutableTestUser()->getUser();
131 $passwordFactory = new \PasswordFactory();
134 $passwordFactory->setDefaultType(
'A' );
135 $pwhash = $passwordFactory->newFromPlaintext(
'password' )->toString();
140 $this->assertFalse( $provider->testUserCanAuthenticate(
'<invalid>' ) );
141 $this->assertFalse( $provider->testUserCanAuthenticate(
'DoesNotExist' ) );
147 'user_newpass_time' => null,
149 [
'user_id' =>
$user->getId() ]
151 $this->assertFalse( $provider->testUserCanAuthenticate(
$user->getName() ) );
156 'user_newpassword' => $pwhash,
157 'user_newpass_time' => null,
159 [
'user_id' =>
$user->getId() ]
161 $this->assertTrue( $provider->testUserCanAuthenticate(
$user->getName() ) );
162 $this->assertTrue( $provider->testUserCanAuthenticate( lcfirst(
$user->getName() ) ) );
167 'user_newpassword' => $pwhash,
168 'user_newpass_time' => $dbw->timestamp( time() - 10 ),
170 [
'user_id' =>
$user->getId() ]
172 $providerPriv->newPasswordExpiry = 100;
173 $this->assertTrue( $provider->testUserCanAuthenticate(
$user->getName() ) );
174 $providerPriv->newPasswordExpiry = 1;
175 $this->assertFalse( $provider->testUserCanAuthenticate(
$user->getName() ) );
181 'user_newpass_time' => null,
183 [
'user_id' =>
$user->getId() ]
195 foreach ( $actual
as $req ) {
197 $req->password =
'random';
200 $this->assertEquals( $expected, $actual );
204 $anon = [
'username' => null ];
205 $loggedIn = [
'username' =>
'UTSysop' ];
236 $user = self::getMutableTestUser()->getUser();
238 $password =
'TemporaryPassword';
239 $hash =
':A:' . md5( $password );
243 [
'user_newpassword' => $hash,
'user_newpass_time' => $dbw->timestamp( time() - 10 ) ],
244 [
'user_id' =>
$user->getId() ]
254 $providerPriv->newPasswordExpiry = 100;
259 $provider->beginPrimaryAuthentication( [] )
262 $req->username =
'foo';
263 $req->password = null;
266 $provider->beginPrimaryAuthentication( $reqs )
269 $req->username = null;
270 $req->password =
'bar';
273 $provider->beginPrimaryAuthentication( $reqs )
276 $req->username =
'<invalid>';
277 $req->password =
'WhoCares';
278 $ret = $provider->beginPrimaryAuthentication( $reqs );
281 $provider->beginPrimaryAuthentication( $reqs )
284 $req->username =
'DoesNotExist';
285 $req->password =
'DoesNotExist';
286 $ret = $provider->beginPrimaryAuthentication( $reqs );
289 $provider->beginPrimaryAuthentication( $reqs )
294 $req->password = $password;
296 $ret = $provider->beginPrimaryAuthentication( $reqs );
303 $ret->message->getKey()
307 $this->manager->removeAuthenticationSessionData( null );
311 $provider->beginPrimaryAuthentication( $reqs )
313 $this->assertNotNull( $this->manager->getAuthenticationSessionData(
'reset-pass' ) );
315 $this->manager->removeAuthenticationSessionData( null );
317 $req->username = lcfirst(
$user->getName() );
320 $provider->beginPrimaryAuthentication( $reqs )
322 $this->assertNotNull( $this->manager->getAuthenticationSessionData(
'reset-pass' ) );
326 $providerPriv->newPasswordExpiry = 1;
327 $ret = $provider->beginPrimaryAuthentication( $reqs );
334 $ret->message->getKey()
338 $providerPriv->newPasswordExpiry = 100;
340 $req->password =
'Wrong';
341 $ret = $provider->beginPrimaryAuthentication( $reqs );
348 $ret->message->getKey()
373 $req->password =
'NewPassword';
377 $this->assertEquals( $expect1, $provider->providerAllowsAuthenticationDataChange(
$req,
false ) );
378 $this->assertEquals( $expect2, $provider->providerAllowsAuthenticationDataChange(
$req,
true ) );
383 $err->error(
'arbitrary-warning' );
413 $cuser = ucfirst(
$user );
414 $oldpass =
'OldTempPassword';
415 $newpass =
'NewTempPassword';
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 ] );
423 $hash =
':A:' . md5( $oldpass );
426 [
'user_newpassword' => $hash,
'user_newpass_time' => $dbw->timestamp( time() + 10 ) ],
427 [
'user_name' => $cuser ]
435 $loginReq->username =
$user;
436 $loginReq->password = $oldpass;
440 $provider->beginPrimaryAuthentication( $loginReqs ),
447 $changeReq =
new $type();
449 $changeReq = $this->getMock(
$type );
452 $changeReq->username =
$user;
453 $changeReq->password = $newpass;
455 $provider->providerChangeAuthenticationData( $changeReq );
456 ScopedCallback::consume( $resetMailer );
458 $loginReq->password = $oldpass;
459 $ret = $provider->beginPrimaryAuthentication( $loginReqs );
463 'old password should fail'
467 $ret->message->getKey(),
468 'old password should fail'
471 $loginReq->password = $newpass;
472 $ret = $provider->beginPrimaryAuthentication( $loginReqs );
477 'new password should pass'
479 $this->assertNotNull(
480 $dbw->selectField(
'user',
'user_newpass_time', [
'user_name' => $cuser ] )
486 'new password should fail'
490 $ret->message->getKey(),
491 'new password should fail'
494 $dbw->selectField(
'user',
'user_newpass_time', [
'user_name' => $cuser ] )
508 $user = self::getMutableTestUser()->getUser();
513 [
'user_newpass_time' => $dbw->timestamp( time() - 5 * 3600 ) ],
514 [
'user_id' =>
$user->getId() ]
519 $req->mailpassword =
true;
521 $provider = $this->
getProvider( [
'emailEnabled' =>
false ] );
522 $status = $provider->providerAllowsAuthenticationDataChange(
$req,
true );
524 $req->hasBackchannel =
true;
525 $status = $provider->providerAllowsAuthenticationDataChange(
$req,
true );
526 $this->assertFalse(
$status->hasMessage(
'passwordreset-emaildisabled' ) );
527 $req->hasBackchannel =
false;
529 $provider = $this->
getProvider( [
'passwordReminderResendTime' => 10 ] );
530 $status = $provider->providerAllowsAuthenticationDataChange(
$req,
true );
533 $provider = $this->
getProvider( [
'passwordReminderResendTime' => 3 ] );
534 $status = $provider->providerAllowsAuthenticationDataChange(
$req,
true );
535 $this->assertFalse(
$status->hasMessage(
'throttled-mailpassword' ) );
539 [
'user_newpass_time' => $dbw->timestamp( time() + 5 * 3600 ) ],
540 [
'user_id' =>
$user->getId() ]
542 $provider = $this->
getProvider( [
'passwordReminderResendTime' => 0 ] );
543 $status = $provider->providerAllowsAuthenticationDataChange(
$req,
true );
544 $this->assertFalse(
$status->hasMessage(
'throttled-mailpassword' ) );
547 $status = $provider->providerAllowsAuthenticationDataChange(
$req,
true );
550 $req->caller =
'127.0.0.256';
551 $status = $provider->providerAllowsAuthenticationDataChange(
$req,
true );
555 $req->caller =
'<Invalid>';
556 $status = $provider->providerAllowsAuthenticationDataChange(
$req,
true );
560 $req->caller =
'127.0.0.1';
561 $status = $provider->providerAllowsAuthenticationDataChange(
$req,
true );
565 $status = $provider->providerAllowsAuthenticationDataChange(
$req,
true );
569 $resetMailer = $this->
hookMailer(
function ( $headers, $to,
$from, $subject, $body )
573 $this->assertSame(
$user->getEmail(), $to[0]->address );
574 $this->assertContains(
$req->password, $body );
577 $provider->providerChangeAuthenticationData(
$req );
578 ScopedCallback::consume( $resetMailer );
579 $this->assertTrue( $mailed );
582 $req->username =
'<invalid>';
590 $req->username =
'Foo';
591 $req->password =
'Bar';
597 $provider->testForAccountCreation(
$user,
$user, [] ),
598 'No password request'
603 $provider->testForAccountCreation(
$user,
$user, $reqs ),
604 'Password request, validated'
607 $this->validity->error(
'arbitrary warning' );
609 $expect->error(
'arbitrary warning' );
612 $provider->testForAccountCreation(
$user,
$user, $reqs ),
613 'Password request, not validated'
633 $provider->beginPrimaryAccountCreation(
$user,
$user, [] )
636 $req->username =
'foo';
637 $req->password = null;
640 $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs )
643 $req->username = null;
644 $req->password =
'bar';
647 $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs )
650 $req->username =
'foo';
651 $req->password =
'bar';
654 $expect->createRequest = clone(
$req );
655 $expect->createRequest->username =
'Foo';
656 $this->assertEquals( $expect, $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs ) );
657 $this->assertNull( $this->manager->getAuthenticationSessionData(
'no-email' ) );
659 $user = self::getMutableTestUser()->getUser();
660 $req->username = $authreq->username = $user->getName();
661 $req->password = $authreq->password =
'NewPassword';
663 $expect->createRequest =
$req;
665 $res2 = $provider->beginPrimaryAccountCreation( $user, $user, $reqs );
666 $this->assertEquals( $expect, $res2,
'Sanity check' );
668 $ret = $provider->beginPrimaryAuthentication( $authreqs );
671 $this->assertSame( null, $provider->finishAccountCreation( $user, $user, $res2 ) );
673 $ret = $provider->beginPrimaryAuthentication( $authreqs );
680 $user = self::getMutableTestUser()->getUser();
681 $user->setEmail( null );
685 $req->mailpassword =
true;
687 $provider = $this->
getProvider( [
'emailEnabled' =>
false ] );
690 $req->hasBackchannel =
true;
692 $this->assertFalse(
$status->hasMessage(
'emaildisabled' ) );
693 $req->hasBackchannel =
false;
695 $provider = $this->
getProvider( [
'emailEnabled' =>
true ] );
698 $req->hasBackchannel =
true;
700 $this->assertFalse(
$status->hasMessage(
'noemailcreate' ) );
701 $req->hasBackchannel =
false;
703 $user->setEmail(
'test@localhost.localdomain' );
708 $resetMailer = $this->
hookMailer(
function ( $headers, $to,
$from, $subject, $body )
712 $this->assertSame(
'test@localhost.localdomain', $to[0]->address );
713 $this->assertContains(
$req->password, $body );
718 $expect->createRequest = clone(
$req );
719 $expect->createRequest->username =
$user->getName();
720 $res = $provider->beginPrimaryAccountCreation(
$user, $creator, [
$req ] );
721 $this->assertEquals( $expect,
$res );
722 $this->assertTrue( $this->manager->getAuthenticationSessionData(
'no-email' ) );
723 $this->assertFalse( $mailed );
725 $this->assertSame(
'byemail', $provider->finishAccountCreation(
$user, $creator,
$res ) );
726 $this->assertTrue( $mailed );
728 ScopedCallback::consume( $resetMailer );
729 $this->assertTrue( $mailed );
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
static wrap($sv)
Succinct helper method to wrap a StatusValue.
processing should stop and the error should be shown to the user * false
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
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static newFatal($message)
Factory function for fatal errors.
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
static register($name, $callback)
Attach an event handler to a given hook.
static getMain()
Static methods.
static clear($name)
Clears hooks registered via Hooks::register().
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
static newGood($value=null)
Factory function for good results.
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
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
static getDefaultInstance()
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
this hook is for auditing only $req
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
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 newFromObject($object)
Return the same object, without access restrictions.
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