14 $this->fail(
'Expected exception not thrown' );
17 'Trying to wrap AuthManagerAuthPlugin in AuthPluginPrimaryAuthenticationProvider ' .
23 $plugin = $this->getMock(
'AuthPlugin' );
24 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
42 $this->fail(
'Expected exception not thrown' );
45 "$reqType is not a MediaWiki\\Auth\\PasswordAuthenticationRequest",
54 $plugin = $this->getMock(
'AuthPlugin' );
55 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
56 $plugin->expects( $this->once() )->method(
'updateExternalDB' )
57 ->with( $this->identicalTo(
$user ) );
66 $plugin = $this->getMock(
'AuthPlugin' );
67 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
68 $plugin->expects( $this->once() )->method(
'updateExternalDBGroups' )
70 $this->identicalTo(
$user ),
71 $this->identicalTo( [
'added' ] ),
72 $this->identicalTo( [
'removed' ] )
82 $plugin = $this->getMock(
'AuthPlugin' );
83 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
84 $plugin->expects( $this->exactly( 2 ) )->method(
'updateUser' )
85 ->with( $this->identicalTo(
$user ) );
89 $plugin = $this->getMock(
'AuthPlugin' );
90 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
91 $plugin->expects( $this->once() )->method(
'updateUser' )
92 ->will( $this->returnCallback(
function ( &
$user ) {
98 $this->fail(
'Expected exception not thrown' );
101 get_class( $plugin ) .
'::updateUser() tried to replace $user!',
110 $plugin = $this->getMock(
'AuthPlugin' );
111 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
112 $plugin->expects( $this->exactly( 2 ) )->method(
'initUser' )
113 ->with( $this->identicalTo(
$user ), $this->identicalTo(
false ) );
117 $plugin = $this->getMock(
'AuthPlugin' );
118 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
119 $plugin->expects( $this->once() )->method(
'initUser' )
120 ->will( $this->returnCallback(
function ( &
$user ) {
126 $this->fail(
'Expected exception not thrown' );
129 get_class( $plugin ) .
'::initUser() tried to replace $user!',
136 $plugin = $this->getMock(
'AuthPlugin' );
137 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
140 'MediaWiki\\Auth\\AuthPluginPrimaryAuthenticationProvider:' . get_class( $plugin ),
141 $provider->getUniqueId()
152 $plugin = $this->getMock(
'AuthPlugin' );
153 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
154 $plugin->expects( $this->any() )->method(
'allowPasswordChange' )
155 ->will( $this->returnValue( $allowPasswordChange ) );
157 $this->assertEquals(
$response, $provider->getAuthenticationRequests(
$action, [] ) );
181 $plugin = $this->getMockBuilder(
'AuthPlugin' )
182 ->setMethods( [
'authenticate' ] )
184 $plugin->expects( $this->never() )->method(
'authenticate' );
189 $provider->beginPrimaryAuthentication( [] )
192 $req->username =
'foo';
193 $req->password = null;
196 $provider->beginPrimaryAuthentication( $reqs )
199 $req->username = null;
200 $req->password =
'bar';
203 $provider->beginPrimaryAuthentication( $reqs )
206 $req->username =
'foo';
207 $req->password =
'bar';
209 $plugin = $this->getMockBuilder(
'AuthPlugin' )
210 ->setMethods( [
'userExists',
'authenticate' ] )
212 $plugin->expects( $this->once() )->method(
'userExists' )
213 ->will( $this->returnValue(
true ) );
214 $plugin->expects( $this->once() )->method(
'authenticate' )
215 ->with( $this->equalTo(
'Foo' ), $this->equalTo(
'bar' ) )
216 ->will( $this->returnValue(
true ) );
220 $provider->beginPrimaryAuthentication( $reqs )
223 $plugin = $this->getMockBuilder(
'AuthPlugin' )
224 ->setMethods( [
'userExists',
'authenticate' ] )
226 $plugin->expects( $this->once() )->method(
'userExists' )
227 ->will( $this->returnValue(
false ) );
228 $plugin->expects( $this->never() )->method(
'authenticate' );
232 $provider->beginPrimaryAuthentication( $reqs )
235 $pluginUser = $this->getMockBuilder(
'AuthPluginUser' )
236 ->setMethods( [
'isLocked' ] )
237 ->disableOriginalConstructor()
239 $pluginUser->expects( $this->once() )->method(
'isLocked' )
240 ->will( $this->returnValue(
true ) );
241 $plugin = $this->getMockBuilder(
'AuthPlugin' )
242 ->setMethods( [
'userExists',
'getUserInstance',
'authenticate' ] )
244 $plugin->expects( $this->once() )->method(
'userExists' )
245 ->will( $this->returnValue(
true ) );
246 $plugin->expects( $this->once() )->method(
'getUserInstance' )
247 ->will( $this->returnValue( $pluginUser ) );
248 $plugin->expects( $this->never() )->method(
'authenticate' );
252 $provider->beginPrimaryAuthentication( $reqs )
255 $plugin = $this->getMockBuilder(
'AuthPlugin' )
256 ->setMethods( [
'userExists',
'authenticate' ] )
258 $plugin->expects( $this->once() )->method(
'userExists' )
259 ->will( $this->returnValue(
true ) );
260 $plugin->expects( $this->once() )->method(
'authenticate' )
261 ->with( $this->equalTo(
'Foo' ), $this->equalTo(
'bar' ) )
262 ->will( $this->returnValue(
false ) );
266 $provider->beginPrimaryAuthentication( $reqs )
269 $plugin = $this->getMockBuilder(
'AuthPlugin' )
270 ->setMethods( [
'userExists',
'authenticate',
'strict' ] )
272 $plugin->expects( $this->once() )->method(
'userExists' )
273 ->will( $this->returnValue(
true ) );
274 $plugin->expects( $this->once() )->method(
'authenticate' )
275 ->with( $this->equalTo(
'Foo' ), $this->equalTo(
'bar' ) )
276 ->will( $this->returnValue(
false ) );
277 $plugin->expects( $this->any() )->method(
'strict' )->will( $this->returnValue(
true ) );
279 $ret = $provider->beginPrimaryAuthentication( $reqs );
281 $this->assertSame(
'wrongpassword',
$ret->message->getKey() );
283 $plugin = $this->getMockBuilder(
'AuthPlugin' )
284 ->setMethods( [
'userExists',
'authenticate',
'strictUserAuth' ] )
286 $plugin->expects( $this->once() )->method(
'userExists' )
287 ->will( $this->returnValue(
true ) );
288 $plugin->expects( $this->once() )->method(
'authenticate' )
289 ->with( $this->equalTo(
'Foo' ), $this->equalTo(
'bar' ) )
290 ->will( $this->returnValue(
false ) );
291 $plugin->expects( $this->any() )->method(
'strictUserAuth' )
292 ->with( $this->equalTo(
'Foo' ) )
293 ->will( $this->returnValue(
true ) );
295 $ret = $provider->beginPrimaryAuthentication( $reqs );
297 $this->assertSame(
'wrongpassword',
$ret->message->getKey() );
299 $plugin = $this->getMockBuilder(
'AuthPlugin' )
300 ->setMethods( [
'domainList',
'validDomain',
'setDomain',
'userExists',
'authenticate' ] )
302 $plugin->expects( $this->any() )->method(
'domainList' )
303 ->will( $this->returnValue( [
'Domain1',
'Domain2' ] ) );
304 $plugin->expects( $this->any() )->method(
'validDomain' )
305 ->will( $this->returnCallback(
function ( $domain ) {
306 return in_array( $domain, [
'Domain1',
'Domain2' ] );
308 $plugin->expects( $this->once() )->method(
'setDomain' )
309 ->with( $this->equalTo(
'Domain2' ) );
310 $plugin->expects( $this->once() )->method(
'userExists' )
311 ->will( $this->returnValue(
true ) );
312 $plugin->expects( $this->once() )->method(
'authenticate' )
313 ->with( $this->equalTo(
'Foo' ), $this->equalTo(
'bar' ) )
314 ->will( $this->returnValue(
true ) );
317 $req->username =
'foo';
318 $req->password =
'bar';
319 $req->domain =
'Domain2';
320 $provider->beginPrimaryAuthentication( [
$req ] );
324 $plugin = $this->getMock(
'AuthPlugin' );
325 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
326 $plugin->expects( $this->once() )->method(
'userExists' )
327 ->with( $this->equalTo(
'Foo' ) )
328 ->will( $this->returnValue(
true ) );
331 $this->assertTrue( $provider->testUserExists(
'foo' ) );
333 $plugin = $this->getMock(
'AuthPlugin' );
334 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
335 $plugin->expects( $this->once() )->method(
'userExists' )
336 ->with( $this->equalTo(
'Foo' ) )
337 ->will( $this->returnValue(
false ) );
340 $this->assertFalse( $provider->testUserExists(
'foo' ) );
344 $plugin = $this->getMock(
'AuthPlugin' );
345 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
346 $plugin->expects( $this->once() )->method(
'userExists' )
347 ->with( $this->equalTo(
'Foo' ) )
348 ->will( $this->returnValue(
false ) );
349 $plugin->expects( $this->never() )->method(
'getUserInstance' );
351 $this->assertFalse( $provider->testUserCanAuthenticate(
'foo' ) );
353 $pluginUser = $this->getMockBuilder(
'AuthPluginUser' )
354 ->disableOriginalConstructor()
356 $pluginUser->expects( $this->once() )->method(
'isLocked' )
357 ->will( $this->returnValue(
true ) );
358 $plugin = $this->getMock(
'AuthPlugin' );
359 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
360 $plugin->expects( $this->once() )->method(
'userExists' )
361 ->with( $this->equalTo(
'Foo' ) )
362 ->will( $this->returnValue(
true ) );
363 $plugin->expects( $this->once() )->method(
'getUserInstance' )
364 ->with( $this->callback(
function (
$user ) {
365 $this->assertInstanceOf(
'User',
$user );
366 $this->assertEquals(
'Foo',
$user->getName() );
369 ->will( $this->returnValue( $pluginUser ) );
371 $this->assertFalse( $provider->testUserCanAuthenticate(
'foo' ) );
373 $pluginUser = $this->getMockBuilder(
'AuthPluginUser' )
374 ->disableOriginalConstructor()
376 $pluginUser->expects( $this->once() )->method(
'isLocked' )
377 ->will( $this->returnValue(
false ) );
378 $plugin = $this->getMock(
'AuthPlugin' );
379 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
380 $plugin->expects( $this->once() )->method(
'userExists' )
381 ->with( $this->equalTo(
'Foo' ) )
382 ->will( $this->returnValue(
true ) );
383 $plugin->expects( $this->once() )->method(
'getUserInstance' )
384 ->with( $this->callback(
function (
$user ) {
385 $this->assertInstanceOf(
'User',
$user );
386 $this->assertEquals(
'Foo',
$user->getName() );
389 ->will( $this->returnValue( $pluginUser ) );
391 $this->assertTrue( $provider->testUserCanAuthenticate(
'foo' ) );
395 $plugin = $this->getMockBuilder(
'AuthPlugin' )
396 ->setMethods( [
'userExists',
'setPassword' ] )
398 $plugin->expects( $this->once() )->method(
'userExists' )->willReturn(
true );
399 $plugin->expects( $this->once() )->method(
'setPassword' )
400 ->with( $this->callback(
function ( $u ) {
402 } ), $this->identicalTo( null ) )
403 ->willReturn(
true );
405 $provider->providerRevokeAccessForUser(
'foo' );
407 $plugin = $this->getMockBuilder(
'AuthPlugin' )
408 ->setMethods( [
'domainList',
'userExists',
'setPassword' ] )
410 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [
'D1',
'D2',
'D3' ] );
411 $plugin->expects( $this->exactly( 3 ) )->method(
'userExists' )
412 ->willReturnCallback(
function ()
use ( $plugin ) {
413 return $plugin->getDomain() !==
'D2';
415 $plugin->expects( $this->exactly( 2 ) )->method(
'setPassword' )
416 ->with( $this->callback(
function ( $u ) {
418 } ), $this->identicalTo( null ) )
419 ->willReturnCallback(
function ()
use ( $plugin ) {
420 $this->assertNotEquals(
'D2', $plugin->getDomain() );
421 return $plugin->getDomain() !==
'D1';
425 $provider->providerRevokeAccessForUser(
'foo' );
426 $this->fail(
'Expected exception not thrown' );
429 'AuthPlugin failed to reset password for Foo in the following domains: D1',
436 $plugin = $this->getMock(
'AuthPlugin' );
437 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
438 $plugin->expects( $this->any() )->method(
'allowPropChange' )
439 ->will( $this->returnCallback(
function ( $prop ) {
440 return $prop ===
'allow';
444 $this->assertTrue( $provider->providerAllowsPropertyChange(
'allow' ) );
445 $this->assertFalse( $provider->providerAllowsPropertyChange(
'deny' ) );
456 $plugin = $this->getMock(
'AuthPlugin' );
457 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( $domains );
458 $plugin->expects( $allow === null ? $this->never() : $this->once() )
459 ->method(
'allowPasswordChange' )->will( $this->returnValue( $allow ) );
460 $plugin->expects( $this->any() )->method(
'validDomain' )
461 ->willReturnCallback(
function ( $d )
use ( $domains ) {
462 return in_array( $d, $domains,
true );
466 if ( is_object(
$type ) ) {
472 $req->username =
'UTSysop';
473 $req->password =
'Pa$$w0Rd!!!';
474 $req->retype =
'Pa$$w0Rd!!!';
475 $this->assertEquals( $expect, $provider->providerAllowsAuthenticationDataChange(
$req ) );
479 $domains = [
'foo',
'bar' ];
482 $reqValidDomain->domain =
'foo';
484 $reqInvalidDomain->domain =
'invalid';
490 new PasswordAuthenticationRequest,
505 $plugin = $this->getMock(
'AuthPlugin' );
506 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
507 $plugin->expects( $this->never() )->method(
'setPassword' );
509 $provider->providerChangeAuthenticationData(
515 $req->username =
'foo';
516 $req->password =
'bar';
518 $plugin = $this->getMock(
'AuthPlugin' );
519 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
520 $plugin->expects( $this->once() )->method(
'setPassword' )
521 ->with( $this->callback(
function ( $u ) {
523 } ), $this->equalTo(
'bar' ) )
524 ->
will( $this->returnValue(
true ) );
526 $provider->providerChangeAuthenticationData(
$req );
528 $plugin = $this->getMock(
'AuthPlugin' );
529 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
530 $plugin->expects( $this->once() )->method(
'setPassword' )
531 ->with( $this->callback(
function ( $u ) {
533 } ), $this->equalTo(
'bar' ) )
534 ->
will( $this->returnValue(
false ) );
537 $provider->providerChangeAuthenticationData(
$req );
538 $this->fail(
'Expected exception not thrown' );
540 $this->assertSame(
'authmanager-authplugin-setpass-failed-title', $e->title );
541 $this->assertSame(
'authmanager-authplugin-setpass-failed-message', $e->
msg );
544 $plugin = $this->getMock(
'AuthPlugin' );
545 $plugin->expects( $this->any() )->method(
'domainList' )
546 ->will( $this->returnValue( [
'Domain1',
'Domain2' ] ) );
547 $plugin->expects( $this->any() )->method(
'validDomain' )
548 ->will( $this->returnCallback(
function ( $domain ) {
549 return in_array( $domain, [
'Domain1',
'Domain2' ] );
551 $plugin->expects( $this->once() )->method(
'setDomain' )
552 ->with( $this->equalTo(
'Domain2' ) );
553 $plugin->expects( $this->once() )->method(
'setPassword' )
554 ->with( $this->callback(
function ( $u ) {
556 } ), $this->equalTo(
'bar' ) )
557 ->
will( $this->returnValue(
true ) );
560 $req->username =
'foo';
561 $req->password =
'bar';
562 $req->domain =
'Domain2';
563 $provider->providerChangeAuthenticationData(
$req );
572 $plugin = $this->getMock(
'AuthPlugin' );
573 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
574 $plugin->expects( $this->once() )
575 ->method(
'canCreateAccounts' )->will( $this->returnValue( $can ) );
578 $this->assertSame( $expect, $provider->accountCreationType() );
591 $plugin = $this->getMock(
'AuthPlugin' );
592 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
596 $provider->testForAccountCreation(
$user,
$user, [] )
602 $user->setEmail(
'email' );
603 $user->setRealName(
'realname' );
609 $plugin = $this->getMock(
'AuthPlugin' );
610 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
611 $plugin->expects( $this->any() )->method(
'canCreateAccounts' )
612 ->will( $this->returnValue(
false ) );
613 $plugin->expects( $this->never() )->method(
'addUser' );
616 $provider->beginPrimaryAccountCreation(
$user,
$user, [] );
617 $this->fail(
'Expected exception was not thrown' );
618 }
catch ( \BadMethodCallException $ex ) {
620 'Shouldn\'t call this when accountCreationType() is NONE', $ex->getMessage()
624 $plugin = $this->getMock(
'AuthPlugin' );
625 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
626 $plugin->expects( $this->any() )->method(
'canCreateAccounts' )
627 ->will( $this->returnValue(
true ) );
628 $plugin->expects( $this->never() )->method(
'addUser' );
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';
653 $plugin = $this->getMock(
'AuthPlugin' );
654 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
655 $plugin->expects( $this->any() )->method(
'canCreateAccounts' )
656 ->will( $this->returnValue(
true ) );
657 $plugin->expects( $this->once() )->method(
'addUser' )
659 $this->callback(
function ( $u ) {
662 $this->equalTo(
'bar' ),
663 $this->equalTo(
'email' ),
664 $this->equalTo(
'realname' )
666 ->
will( $this->returnValue(
true ) );
670 $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs )
673 $plugin = $this->getMock(
'AuthPlugin' );
674 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
675 $plugin->expects( $this->any() )->method(
'canCreateAccounts' )
676 ->will( $this->returnValue(
true ) );
677 $plugin->expects( $this->once() )->method(
'addUser' )
679 $this->callback(
function ( $u ) {
682 $this->equalTo(
'bar' ),
683 $this->equalTo(
'email' ),
684 $this->equalTo(
'realname' )
686 ->
will( $this->returnValue(
false ) );
688 $ret = $provider->beginPrimaryAccountCreation(
$user,
$user, $reqs );
690 $this->assertSame(
'authmanager-authplugin-create-fail',
$ret->message->getKey() );
692 $plugin = $this->getMock(
'AuthPlugin' );
693 $plugin->expects( $this->any() )->method(
'canCreateAccounts' )
694 ->will( $this->returnValue(
true ) );
695 $plugin->expects( $this->any() )->method(
'domainList' )
696 ->will( $this->returnValue( [
'Domain1',
'Domain2' ] ) );
697 $plugin->expects( $this->any() )->method(
'validDomain' )
698 ->will( $this->returnCallback(
function ( $domain ) {
699 return in_array( $domain, [
'Domain1',
'Domain2' ] );
701 $plugin->expects( $this->once() )->method(
'setDomain' )
702 ->with( $this->equalTo(
'Domain2' ) );
703 $plugin->expects( $this->once() )->method(
'addUser' )
704 ->with( $this->callback(
function ( $u ) {
706 } ), $this->equalTo(
'bar' ) )
707 ->
will( $this->returnValue(
true ) );
710 $req->username =
'foo';
711 $req->password =
'bar';
712 $req->domain =
'Domain2';
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
This is a value object for authentication requests with a username, password, and domain...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
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
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
static newFatal($message)
Factory function for fatal errors.
this hook is for auditing only $response
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
An error page which can definitely be safely rendered using the OutputPage.
static newGood($value=null)
Factory function for good results.
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
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
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
msg($key, $fallback)
Get a message from i18n.
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
</td >< td > &</td >< td > t want your writing to be edited mercilessly and redistributed at will
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