26 if ( !$this->config ) {
27 $this->config = new \HashConfig();
34 if ( !$this->manager ) {
39 $provider = $this->getMock(
41 [
'checkPasswordValidity' ],
42 [ [
'loginOnly' => $loginOnly ] ]
44 $provider->expects( $this->any() )->method(
'checkPasswordValidity' )
45 ->will( $this->returnCallback(
function () {
48 $provider->setConfig(
$config );
49 $provider->setLogger(
new \Psr\Log\NullLogger() );
50 $provider->setManager( $this->manager );
57 $userName =
$user->getName();
58 $lowerInitialUserName = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
64 $provider->accountCreationType()
67 $this->assertTrue( $provider->testUserExists( $userName ) );
68 $this->assertTrue( $provider->testUserExists( $lowerInitialUserName ) );
69 $this->assertFalse( $provider->testUserExists(
'DoesNotExist' ) );
70 $this->assertFalse( $provider->testUserExists(
'<invalid>' ) );
76 $provider->accountCreationType()
79 $this->assertTrue( $provider->testUserExists( $userName ) );
80 $this->assertFalse( $provider->testUserExists(
'DoesNotExist' ) );
84 $req->username =
'<invalid>';
85 $provider->providerChangeAuthenticationData( $req );
90 $userName =
$user->getName();
95 $this->assertFalse( $provider->testUserCanAuthenticate(
'<invalid>' ) );
97 $this->assertFalse( $provider->testUserCanAuthenticate(
'DoesNotExist' ) );
99 $this->assertTrue( $provider->testUserCanAuthenticate( $userName ) );
100 $lowerInitialUserName = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
101 $this->assertTrue( $provider->testUserCanAuthenticate( $lowerInitialUserName ) );
106 [
'user_name' => $userName ]
108 $this->assertFalse( $provider->testUserCanAuthenticate( $userName ) );
113 [
'user_password' =>
'0123456789abcdef0123456789abcdef' ],
114 [
'user_name' => $userName ]
116 $this->assertTrue( $provider->testUserCanAuthenticate( $userName ) );
124 $this->
setMwGlobals( [
'wgPasswordExpireGrace' => 100 ] );
126 $this->config->set(
'PasswordExpireGrace', 100 );
127 $this->config->set(
'InvalidPasswordReset',
true );
130 $provider->setConfig( $this->config );
131 $provider->setLogger(
new \Psr\Log\NullLogger() );
132 $provider->setManager( $this->manager );
136 $userName =
$user->getName();
138 $row = $dbw->selectRow(
141 [
'user_name' => $userName ],
145 $this->manager->removeAuthenticationSessionData( null );
147 $providerPriv->setPasswordResetFlag( $userName, \
Status::newGood(), $row );
148 $this->assertNull( $this->manager->getAuthenticationSessionData(
'reset-pass' ) );
150 $this->manager->removeAuthenticationSessionData( null );
152 $providerPriv->setPasswordResetFlag( $userName, \
Status::newGood(), $row );
153 $ret = $this->manager->getAuthenticationSessionData(
'reset-pass' );
154 $this->assertNotNull(
$ret );
155 $this->assertSame(
'resetpass-expired',
$ret->msg->getKey() );
156 $this->assertTrue(
$ret->hard );
158 $this->manager->removeAuthenticationSessionData( null );
160 $providerPriv->setPasswordResetFlag( $userName, \
Status::newGood(), $row );
161 $ret = $this->manager->getAuthenticationSessionData(
'reset-pass' );
162 $this->assertNotNull(
$ret );
163 $this->assertSame(
'resetpass-expired-soft',
$ret->msg->getKey() );
164 $this->assertFalse(
$ret->hard );
166 $this->manager->removeAuthenticationSessionData( null );
167 $row->user_password_expires = null;
170 $providerPriv->setPasswordResetFlag( $userName,
$status, $row );
171 $ret = $this->manager->getAuthenticationSessionData(
'reset-pass' );
172 $this->assertNotNull(
$ret );
173 $this->assertSame(
'resetpass-validity-soft',
$ret->msg->getKey() );
174 $this->assertFalse(
$ret->hard );
179 $userName = $testUser->getUser()->getName();
193 $provider->beginPrimaryAuthentication( [] )
196 $req->username =
'foo';
197 $req->password = null;
200 $provider->beginPrimaryAuthentication( $reqs )
203 $req->username = null;
204 $req->password =
'bar';
207 $provider->beginPrimaryAuthentication( $reqs )
210 $req->username =
'<invalid>';
211 $req->password =
'WhoCares';
212 $ret = $provider->beginPrimaryAuthentication( $reqs );
215 $provider->beginPrimaryAuthentication( $reqs )
218 $req->username =
'DoesNotExist';
219 $req->password =
'DoesNotExist';
220 $ret = $provider->beginPrimaryAuthentication( $reqs );
223 $provider->beginPrimaryAuthentication( $reqs )
227 $req->username = $userName;
228 $req->password = $testUser->getPassword();
230 $ret = $provider->beginPrimaryAuthentication( $reqs );
237 $ret->message->getKey()
241 $this->manager->removeAuthenticationSessionData( null );
245 $provider->beginPrimaryAuthentication( $reqs )
247 $this->assertNull( $this->manager->getAuthenticationSessionData(
'reset-pass' ) );
250 $this->manager->removeAuthenticationSessionData( null );
252 $req->username = mb_strtolower( $userName[0] ) . substr( $userName, 1 );
255 $provider->beginPrimaryAuthentication( $reqs )
257 $this->assertNull( $this->manager->getAuthenticationSessionData(
'reset-pass' ) );
258 $req->username = $userName;
261 $this->manager->removeAuthenticationSessionData( null );
262 $this->validity->error(
'arbitrary-warning' );
265 $provider->beginPrimaryAuthentication( $reqs )
267 $this->assertNotNull( $this->manager->getAuthenticationSessionData(
'reset-pass' ) );
271 $req->password =
'Wrong';
272 $ret = $provider->beginPrimaryAuthentication( $reqs );
279 $ret->message->getKey()
283 $password =
':B:salt:' . md5(
'salt-' . md5(
"\xe1\xe9\xed\xf3\xfa" ) );
284 $dbw->update(
'user', [
'user_password' => $password ], [
'user_name' => $userName ] );
285 $req->password =
'áéíóú';
286 $ret = $provider->beginPrimaryAuthentication( $reqs );
293 $ret->message->getKey()
296 $this->config->set(
'LegacyEncoding',
true );
299 $provider->beginPrimaryAuthentication( $reqs )
302 $req->password =
'áéíóú Wrong';
303 $ret = $provider->beginPrimaryAuthentication( $reqs );
310 $ret->message->getKey()
314 $this->config->set(
'PasswordSalt',
false );
315 $password = md5(
'FooBar' );
316 $dbw->update(
'user', [
'user_password' => $password ], [
'user_name' => $userName ] );
317 $req->password =
'FooBar';
320 $provider->beginPrimaryAuthentication( $reqs )
323 $this->config->set(
'PasswordSalt',
true );
324 $password = md5(
"$id-" . md5(
'FooBar' ) );
325 $dbw->update(
'user', [
'user_password' => $password ], [
'user_name' => $userName ] );
326 $req->password =
'FooBar';
329 $provider->beginPrimaryAuthentication( $reqs )
354 $req->password =
'NewPassword';
355 $req->retype =
'NewPassword';
359 $this->assertEquals( $expect1, $provider->providerAllowsAuthenticationDataChange(
$req,
false ) );
360 $this->assertEquals( $expect2, $provider->providerAllowsAuthenticationDataChange(
$req,
true ) );
362 $req->retype =
'BadRetype';
365 $provider->providerAllowsAuthenticationDataChange(
$req,
false )
369 $provider->providerAllowsAuthenticationDataChange(
$req,
true )
375 $provider->providerAllowsAuthenticationDataChange(
$req,
true ),
376 'loginOnly mode should claim to ignore all changes'
382 $err->error(
'arbitrary-warning' );
410 $usernameTransform,
$type, $loginOnly, $changed ) {
412 $user = $testUser->getUser()->getName();
413 if ( is_callable( $usernameTransform ) ) {
414 $user = call_user_func( $usernameTransform,
$user );
416 $cuser = ucfirst(
$user );
417 $oldpass = $testUser->getPassword();
418 $newpass =
'NewPassword';
421 $oldExpiry = $dbw->selectField(
'user',
'user_password_expires', [
'user_name' => $cuser ] );
424 'ResetPasswordExpiration' => [
function (
$user, &$expires ) {
425 $expires =
'30001231235959';
434 $loginReq->username =
$user;
435 $loginReq->password = $oldpass;
439 $provider->beginPrimaryAuthentication( $loginReqs ),
444 $changeReq =
new $type();
446 $changeReq = $this->getMock(
$type );
449 $changeReq->username =
$user;
450 $changeReq->password = $newpass;
451 $provider->providerChangeAuthenticationData( $changeReq );
456 $expectExpiry = null;
457 } elseif ( $changed ) {
460 $expectExpiry =
'30001231235959';
464 $expectExpiry = $oldExpiry;
467 $loginReq->password = $oldpass;
468 $ret = $provider->beginPrimaryAuthentication( $loginReqs );
469 if ( $old ===
'pass' ) {
473 'old password should pass'
479 'old password should fail'
483 $ret->message->getKey(),
484 'old password should fail'
488 $loginReq->password = $newpass;
489 $ret = $provider->beginPrimaryAuthentication( $loginReqs );
490 if ( $new ===
'pass' ) {
494 'new password should pass'
500 'new password should fail'
504 $ret->message->getKey(),
505 'new password should fail'
511 $dbw->selectField(
'user',
'user_password_expires', [
'user_name' => $cuser ] )
530 $req->username =
'Foo';
531 $req->password =
'Bar';
532 $req->retype =
'Bar';
538 $provider->testForAccountCreation(
$user,
$user, [] ),
539 'No password request'
544 $provider->testForAccountCreation(
$user,
$user, $reqs ),
545 'Password request, validated'
548 $req->retype =
'Baz';
551 $provider->testForAccountCreation(
$user,
$user, $reqs ),
552 'Password request, bad retype'
554 $req->retype =
'Bar';
556 $this->validity->error(
'arbitrary warning' );
558 $expect->error(
'arbitrary warning' );
561 $provider->testForAccountCreation(
$user,
$user, $reqs ),
562 'Password request, not validated'
566 $this->validity->error(
'arbitrary warning' );
569 $provider->testForAccountCreation(
$user,
$user, $reqs ),
570 'Password request, not validated, loginOnly'
583 $provider->beginPrimaryAccountCreation(
$user,
$user, [] );
584 $this->fail(
'Expected exception was not thrown' );
585 }
catch ( \BadMethodCallException $ex ) {
587 'Shouldn\'t call this when accountCreationType() is NONE', $ex->getMessage()
593 $this->fail(
'Expected exception was not thrown' );
594 }
catch ( \BadMethodCallException $ex ) {
596 'Shouldn\'t call this when accountCreationType() is NONE', $ex->getMessage()
604 $provider->beginPrimaryAccountCreation(
$user,
$user, [] )
607 $req->username =
'foo';
608 $req->password = null;
611 $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs )
614 $req->username = null;
615 $req->password =
'bar';
618 $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs )
621 $req->username =
'foo';
622 $req->password =
'bar';
625 $expect->createRequest = clone(
$req );
626 $expect->createRequest->username =
'Foo';
627 $this->assertEquals( $expect, $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs ) );
635 $req->password =
'NewPassword';
637 $expect->createRequest =
$req;
639 $res2 = $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs );
640 $this->assertEquals( $expect, $res2,
'Sanity check' );
642 $ret = $provider->beginPrimaryAuthentication( $reqs );
645 $this->assertNull( $provider->finishAccountCreation(
$user,
$user, $res2 ) );
646 $ret = $provider->beginPrimaryAuthentication( $reqs );
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
static newFatal($message)
Factory function for fatal errors.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
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
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
static newGood($value=null)
Factory function for good results.
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
static idFromName($name, $flags=self::READ_NORMAL)
Get database id given a user name.
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