6use Wikimedia\TestingAccessWrapper;
29 if ( !$this->config ) {
30 $this->config = new \HashConfig();
37 if ( !$this->manager ) {
40 $this->validity = \Status::newGood();
42 $provider = $this->getMockBuilder( LocalPasswordPrimaryAuthenticationProvider::class )
43 ->setMethods( [
'checkPasswordValidity' ] )
44 ->setConstructorArgs( [ [
'loginOnly' => $loginOnly ] ] )
46 $provider->expects( $this->any() )->method(
'checkPasswordValidity' )
47 ->will( $this->returnCallback(
function () {
50 $provider->setConfig(
$config );
51 $provider->setLogger(
new \Psr\Log\NullLogger() );
52 $provider->setManager( $this->manager );
59 $userName =
$user->getName();
60 $lowerInitialUserName = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
66 $provider->accountCreationType()
69 $this->assertTrue( $provider->testUserExists( $userName ) );
70 $this->assertTrue( $provider->testUserExists( $lowerInitialUserName ) );
71 $this->assertFalse( $provider->testUserExists(
'DoesNotExist' ) );
72 $this->assertFalse( $provider->testUserExists(
'<invalid>' ) );
78 $provider->accountCreationType()
81 $this->assertTrue( $provider->testUserExists( $userName ) );
82 $this->assertFalse( $provider->testUserExists(
'DoesNotExist' ) );
86 $req->username =
'<invalid>';
87 $provider->providerChangeAuthenticationData(
$req );
92 $userName =
$user->getName();
97 $this->assertFalse( $provider->testUserCanAuthenticate(
'<invalid>' ) );
99 $this->assertFalse( $provider->testUserCanAuthenticate(
'DoesNotExist' ) );
101 $this->assertTrue( $provider->testUserCanAuthenticate( $userName ) );
102 $lowerInitialUserName = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
103 $this->assertTrue( $provider->testUserCanAuthenticate( $lowerInitialUserName ) );
108 [
'user_name' => $userName ]
110 $this->assertFalse( $provider->testUserCanAuthenticate( $userName ) );
115 [
'user_password' =>
'0123456789abcdef0123456789abcdef' ],
116 [
'user_name' => $userName ]
118 $this->assertTrue( $provider->testUserCanAuthenticate( $userName ) );
126 $this->
setMwGlobals( [
'wgPasswordExpireGrace' => 100 ] );
128 $this->config->set(
'PasswordExpireGrace', 100 );
129 $this->config->set(
'InvalidPasswordReset',
true );
132 $provider->setConfig( $this->config );
133 $provider->setLogger(
new \Psr\Log\NullLogger() );
134 $provider->setManager( $this->manager );
135 $providerPriv = TestingAccessWrapper::newFromObject( $provider );
138 $userName =
$user->getName();
140 $row = $dbw->selectRow(
143 [
'user_name' => $userName ],
147 $this->manager->removeAuthenticationSessionData(
null );
148 $row->user_password_expires =
wfTimestamp( TS_MW, time() + 200 );
149 $providerPriv->setPasswordResetFlag( $userName, \Status::newGood(), $row );
150 $this->assertNull( $this->manager->getAuthenticationSessionData(
'reset-pass' ) );
152 $this->manager->removeAuthenticationSessionData(
null );
153 $row->user_password_expires =
wfTimestamp( TS_MW, time() - 200 );
154 $providerPriv->setPasswordResetFlag( $userName, \Status::newGood(), $row );
155 $ret = $this->manager->getAuthenticationSessionData(
'reset-pass' );
156 $this->assertNotNull(
$ret );
157 $this->assertSame(
'resetpass-expired',
$ret->msg->getKey() );
158 $this->assertTrue(
$ret->hard );
160 $this->manager->removeAuthenticationSessionData(
null );
161 $row->user_password_expires =
wfTimestamp( TS_MW, time() - 1 );
162 $providerPriv->setPasswordResetFlag( $userName, \Status::newGood(), $row );
163 $ret = $this->manager->getAuthenticationSessionData(
'reset-pass' );
164 $this->assertNotNull(
$ret );
165 $this->assertSame(
'resetpass-expired-soft',
$ret->msg->getKey() );
166 $this->assertFalse(
$ret->hard );
168 $this->manager->removeAuthenticationSessionData(
null );
169 $row->user_password_expires =
null;
172 $providerPriv->setPasswordResetFlag( $userName,
$status, $row );
173 $ret = $this->manager->getAuthenticationSessionData(
'reset-pass' );
174 $this->assertNotNull(
$ret );
175 $this->assertSame(
'resetpass-validity-soft',
$ret->msg->getKey() );
176 $this->assertFalse(
$ret->hard );
181 $userName = $testUser->getUser()->getName();
184 $id = \User::idFromName( $userName );
188 $reqs = [ PasswordAuthenticationRequest::class =>
$req ];
195 $provider->beginPrimaryAuthentication( [] )
198 $req->username =
'foo';
199 $req->password =
null;
202 $provider->beginPrimaryAuthentication( $reqs )
205 $req->username =
null;
206 $req->password =
'bar';
209 $provider->beginPrimaryAuthentication( $reqs )
212 $req->username =
'<invalid>';
213 $req->password =
'WhoCares';
214 $ret = $provider->beginPrimaryAuthentication( $reqs );
217 $provider->beginPrimaryAuthentication( $reqs )
220 $req->username =
'DoesNotExist';
221 $req->password =
'DoesNotExist';
222 $ret = $provider->beginPrimaryAuthentication( $reqs );
229 $ret->message->getKey()
233 $req->username = $userName;
234 $req->password = $testUser->getPassword();
235 $this->validity = \Status::newFatal(
'arbitrary-failure' );
236 $ret = $provider->beginPrimaryAuthentication( $reqs );
243 $ret->message->getKey()
247 $this->manager->removeAuthenticationSessionData(
null );
248 $this->validity = \Status::newGood();
251 $provider->beginPrimaryAuthentication( $reqs )
253 $this->assertNull( $this->manager->getAuthenticationSessionData(
'reset-pass' ) );
256 $this->manager->removeAuthenticationSessionData(
null );
257 $this->validity = \Status::newGood();
258 $req->username = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
261 $provider->beginPrimaryAuthentication( $reqs )
263 $this->assertNull( $this->manager->getAuthenticationSessionData(
'reset-pass' ) );
264 $req->username = $userName;
267 $this->manager->removeAuthenticationSessionData(
null );
268 $this->validity->error(
'arbitrary-warning' );
271 $provider->beginPrimaryAuthentication( $reqs )
273 $this->assertNotNull( $this->manager->getAuthenticationSessionData(
'reset-pass' ) );
276 $this->validity = \Status::newGood();
277 $req->password =
'Wrong';
278 $ret = $provider->beginPrimaryAuthentication( $reqs );
285 $ret->message->getKey()
289 $password =
':B:salt:' . md5(
'salt-' . md5(
"\xe1\xe9\xed\xf3\xfa" ) );
290 $dbw->update(
'user', [
'user_password' => $password ], [
'user_name' => $userName ] );
291 $req->password =
'áéíóú';
292 $ret = $provider->beginPrimaryAuthentication( $reqs );
299 $ret->message->getKey()
302 $this->config->set(
'LegacyEncoding',
true );
305 $provider->beginPrimaryAuthentication( $reqs )
308 $req->password =
'áéíóú Wrong';
309 $ret = $provider->beginPrimaryAuthentication( $reqs );
316 $ret->message->getKey()
320 $this->config->set(
'PasswordSalt',
false );
321 $password = md5(
'FooBar' );
322 $dbw->update(
'user', [
'user_password' => $password ], [
'user_name' => $userName ] );
323 $req->password =
'FooBar';
326 $provider->beginPrimaryAuthentication( $reqs )
329 $this->config->set(
'PasswordSalt',
true );
330 $password = md5(
"$id-" . md5(
'FooBar' ) );
331 $dbw->update(
'user', [
'user_password' => $password ], [
'user_name' => $userName ] );
332 $req->password =
'FooBar';
335 $provider->beginPrimaryAuthentication( $reqs )
350 if (
$type === PasswordAuthenticationRequest::class ) {
352 } elseif (
$type === PasswordDomainAuthenticationRequest::class ) {
359 $req->password =
'NewPassword';
360 $req->retype =
'NewPassword';
364 $this->assertEquals( $expect1, $provider->providerAllowsAuthenticationDataChange(
$req,
false ) );
365 $this->assertEquals( $expect2, $provider->providerAllowsAuthenticationDataChange(
$req,
true ) );
367 $req->retype =
'BadRetype';
370 $provider->providerAllowsAuthenticationDataChange(
$req,
false )
373 $expect2->
getValue() ===
'ignored' ? $expect2 : \StatusValue::newFatal(
'badretype' ),
374 $provider->providerAllowsAuthenticationDataChange(
$req,
true )
379 \StatusValue::newGood(
'ignored' ),
380 $provider->providerAllowsAuthenticationDataChange(
$req,
true ),
381 'loginOnly mode should claim to ignore all changes'
386 $err = \StatusValue::newGood();
387 $err->error(
'arbitrary-warning' );
390 [ AuthenticationRequest::class,
'UTSysop', \Status::newGood(),
391 \StatusValue::newGood(
'ignored' ), \StatusValue::newGood(
'ignored' ) ],
392 [ PasswordAuthenticationRequest::class,
'UTSysop', \Status::newGood(),
393 \StatusValue::newGood(), \StatusValue::newGood() ],
394 [ PasswordAuthenticationRequest::class,
'uTSysop', \Status::newGood(),
395 \StatusValue::newGood(), \StatusValue::newGood() ],
396 [ PasswordAuthenticationRequest::class,
'UTSysop', \Status::wrap( $err ),
397 \StatusValue::newGood(), $err ],
398 [ PasswordAuthenticationRequest::class,
'UTSysop', \Status::newFatal(
'arbitrary-error' ),
399 \StatusValue::newGood(), \StatusValue::newFatal(
'arbitrary-error' ) ],
400 [ PasswordAuthenticationRequest::class,
'DoesNotExist', \Status::newGood(),
401 \StatusValue::newGood(), \StatusValue::newGood(
'ignored' ) ],
402 [ PasswordDomainAuthenticationRequest::class,
'UTSysop', \Status::newGood(),
403 \StatusValue::newGood(
'ignored' ), \StatusValue::newGood(
'ignored' ) ],
415 $usernameTransform,
$type, $loginOnly, $changed ) {
417 $user = $testUser->getUser()->getName();
418 if ( is_callable( $usernameTransform ) ) {
419 $user = call_user_func( $usernameTransform,
$user );
421 $cuser = ucfirst(
$user );
422 $oldpass = $testUser->getPassword();
423 $newpass =
'NewPassword';
426 $oldExpiry = $dbw->selectField(
'user',
'user_password_expires', [
'user_name' => $cuser ] );
429 'ResetPasswordExpiration' => [
function (
$user, &$expires ) {
430 $expires =
'30001231235959';
439 $loginReq->username =
$user;
440 $loginReq->password = $oldpass;
441 $loginReqs = [ PasswordAuthenticationRequest::class => $loginReq ];
444 $provider->beginPrimaryAuthentication( $loginReqs ),
448 if (
$type === PasswordAuthenticationRequest::class ) {
449 $changeReq =
new $type();
451 $changeReq = $this->createMock(
$type );
454 $changeReq->username =
$user;
455 $changeReq->password = $newpass;
456 $provider->providerChangeAuthenticationData( $changeReq );
458 if ( $loginOnly && $changed ) {
461 $expectExpiry =
null;
462 } elseif ( $changed ) {
465 $expectExpiry =
'30001231235959';
469 $expectExpiry = $oldExpiry;
472 $loginReq->password = $oldpass;
473 $ret = $provider->beginPrimaryAuthentication( $loginReqs );
474 if ( $old ===
'pass' ) {
478 'old password should pass'
484 'old password should fail'
488 $ret->message->getKey(),
489 'old password should fail'
493 $loginReq->password = $newpass;
494 $ret = $provider->beginPrimaryAuthentication( $loginReqs );
495 if ( $new ===
'pass' ) {
499 'new password should pass'
505 'new password should fail'
509 $ret->message->getKey(),
510 'new password should fail'
516 $dbw->selectField(
'user',
'user_password_expires', [
'user_name' => $cuser ] )
522 [
false, AuthenticationRequest::class,
false,
false ],
523 [
false, PasswordAuthenticationRequest::class,
false,
true ],
524 [
false, AuthenticationRequest::class,
true,
false ],
525 [
false, PasswordAuthenticationRequest::class,
true,
true ],
526 [
'ucfirst', PasswordAuthenticationRequest::class,
false,
true ],
527 [
'ucfirst', PasswordAuthenticationRequest::class,
true,
true ],
532 $user = \User::newFromName(
'foo' );
535 $req->username =
'Foo';
536 $req->password =
'Bar';
537 $req->retype =
'Bar';
538 $reqs = [ PasswordAuthenticationRequest::class =>
$req ];
542 \StatusValue::newGood(),
543 $provider->testForAccountCreation(
$user,
$user, [] ),
544 'No password request'
548 \StatusValue::newGood(),
549 $provider->testForAccountCreation(
$user,
$user, $reqs ),
550 'Password request, validated'
553 $req->retype =
'Baz';
555 \StatusValue::newFatal(
'badretype' ),
556 $provider->testForAccountCreation(
$user,
$user, $reqs ),
557 'Password request, bad retype'
559 $req->retype =
'Bar';
561 $this->validity->error(
'arbitrary warning' );
562 $expect = \StatusValue::newGood();
563 $expect->error(
'arbitrary warning' );
566 $provider->testForAccountCreation(
$user,
$user, $reqs ),
567 'Password request, not validated'
571 $this->validity->error(
'arbitrary warning' );
573 \StatusValue::newGood(),
574 $provider->testForAccountCreation(
$user,
$user, $reqs ),
575 'Password request, not validated, loginOnly'
580 $user = \User::newFromName(
'Foo' );
584 $reqs = [ PasswordAuthenticationRequest::class =>
$req ];
588 $provider->beginPrimaryAccountCreation(
$user,
$user, [] );
589 $this->fail(
'Expected exception was not thrown' );
590 }
catch ( \BadMethodCallException $ex ) {
592 'Shouldn\'t call this when accountCreationType() is NONE', $ex->getMessage()
598 $this->fail(
'Expected exception was not thrown' );
599 }
catch ( \BadMethodCallException $ex ) {
601 'Shouldn\'t call this when accountCreationType() is NONE', $ex->getMessage()
609 $provider->beginPrimaryAccountCreation(
$user,
$user, [] )
612 $req->username =
'foo';
613 $req->password =
null;
616 $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs )
619 $req->username =
null;
620 $req->password =
'bar';
623 $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs )
626 $req->username =
'foo';
627 $req->password =
'bar';
630 $expect->createRequest = clone(
$req );
631 $expect->createRequest->username =
'Foo';
632 $this->assertEquals( $expect, $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs ) );
638 $user = \User::newFromName(
'UTSysop' );
640 $req->password =
'NewPassword';
642 $expect->createRequest =
$req;
644 $res2 = $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs );
645 $this->assertEquals( $expect, $res2,
'Sanity check' );
647 $ret = $provider->beginPrimaryAuthentication( $reqs );
650 $this->assertNull( $provider->finishAccountCreation(
$user,
$user, $res2 ) );
651 $ret = $provider->beginPrimaryAuthentication( $reqs );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
WebRequest clone which takes values from a provided array.
static newInvalidPassword()
Create an InvalidPassword.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
this hook is for auditing only $req
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
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
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 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
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
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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
processing should stop and the error should be shown to the user * false
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