14 $this->fail(
'Expected exception not thrown' );
15 }
catch ( \InvalidArgumentException $ex ) {
17 'Trying to wrap AuthManagerAuthPlugin in AuthPluginPrimaryAuthenticationProvider ' .
23 $plugin = $this->createMock(
'AuthPlugin' );
24 $plugin->expects( $this->
any() )->method(
'domainList' )->willReturn( [] );
42 $this->fail(
'Expected exception not thrown' );
43 }
catch ( \InvalidArgumentException $ex ) {
45 "$reqType is not a MediaWiki\\Auth\\PasswordAuthenticationRequest",
54 $plugin = $this->createMock(
'AuthPlugin' );
55 $plugin->expects( $this->
any() )->method(
'domainList' )->willReturn( [] );
56 $plugin->expects( $this->once() )->method(
'updateExternalDB' )
57 ->with( $this->identicalTo(
$user ) );
66 $plugin = $this->createMock(
'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->createMock(
'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->createMock(
'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' );
99 }
catch ( \UnexpectedValueException $ex ) {
101 get_class( $plugin ) .
'::updateUser() tried to replace $user!',
110 $plugin = $this->createMock(
'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->createMock(
'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' );
127 }
catch ( \UnexpectedValueException $ex ) {
129 get_class( $plugin ) .
'::initUser() tried to replace $user!',
136 $plugin = $this->createMock(
'AuthPlugin' );
137 $plugin->expects( $this->
any() )->method(
'domainList' )->willReturn( [] );
140 'MediaWiki\\Auth\\AuthPluginPrimaryAuthenticationProvider:' . get_class( $plugin ),
141 $provider->getUniqueId()
152 $plugin = $this->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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' );
427 }
catch ( \UnexpectedValueException $ex ) {
429 'AuthPlugin failed to reset password for Foo in the following domains: D1',
436 $plugin = $this->createMock(
'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->createMock(
'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';
505 $plugin = $this->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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->createMock(
'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';