80 $user = \User::newFromName(
'UTSysop' );
82 $plugin = $this->createMock( \AuthPlugin::class );
83 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
84 $plugin->expects( $this->exactly( 2 ) )->method(
'updateUser' )
85 ->with( $this->identicalTo(
$user ) );
87 \Hooks::run(
'UserLoggedIn', [
$user ] );
89 $plugin = $this->createMock( \AuthPlugin::class );
90 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
91 $plugin->expects( $this->once() )->method(
'updateUser' )
92 ->will( $this->returnCallback(
function ( &
$user ) {
93 $user = \User::newFromName(
'UTSysop' );
97 \Hooks::run(
'UserLoggedIn', [
$user ] );
98 $this->fail(
'Expected exception not thrown' );
99 }
catch ( \UnexpectedValueException $ex ) {
101 get_class( $plugin ) .
'::updateUser() tried to replace $user!',
108 $user = \User::newFromName(
'UTSysop' );
110 $plugin = $this->createMock( \AuthPlugin::class );
111 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
112 $plugin->expects( $this->exactly( 2 ) )->method(
'initUser' )
113 ->with( $this->identicalTo(
$user ), $this->identicalTo(
false ) );
115 \Hooks::run(
'LocalUserCreated', [
$user,
false ] );
117 $plugin = $this->createMock( \AuthPlugin::class );
118 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
119 $plugin->expects( $this->once() )->method(
'initUser' )
120 ->will( $this->returnCallback(
function ( &
$user ) {
121 $user = \User::newFromName(
'UTSysop' );
125 \Hooks::run(
'LocalUserCreated', [
$user,
false ] );
126 $this->fail(
'Expected exception not thrown' );
127 }
catch ( \UnexpectedValueException $ex ) {
129 get_class( $plugin ) .
'::initUser() tried to replace $user!',
179 $reqs = [ PasswordAuthenticationRequest::class =>
$req ];
181 $plugin = $this->getMockBuilder( \AuthPlugin::class )
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::class )
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::class )
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::class )
236 ->setMethods( [
'isLocked' ] )
237 ->disableOriginalConstructor()
239 $pluginUser->expects( $this->once() )->method(
'isLocked' )
240 ->will( $this->returnValue(
true ) );
241 $plugin = $this->getMockBuilder( \AuthPlugin::class )
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::class )
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::class )
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::class )
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::class )
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::class );
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::class );
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::class );
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::class )
354 ->disableOriginalConstructor()
356 $pluginUser->expects( $this->once() )->method(
'isLocked' )
357 ->will( $this->returnValue(
true ) );
358 $plugin = $this->createMock( \AuthPlugin::class );
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::class,
$user );
366 $this->assertEquals(
'Foo',
$user->getName() );
369 ->will( $this->returnValue( $pluginUser ) );
371 $this->assertFalse( $provider->testUserCanAuthenticate(
'foo' ) );
373 $pluginUser = $this->getMockBuilder( \AuthPluginUser::class )
374 ->disableOriginalConstructor()
376 $pluginUser->expects( $this->once() )->method(
'isLocked' )
377 ->will( $this->returnValue(
false ) );
378 $plugin = $this->createMock( \AuthPlugin::class );
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::class,
$user );
386 $this->assertEquals(
'Foo',
$user->getName() );
389 ->will( $this->returnValue( $pluginUser ) );
391 $this->assertTrue( $provider->testUserCanAuthenticate(
'foo' ) );
395 $plugin = $this->getMockBuilder( \AuthPlugin::class )
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 ) {
401 return $u instanceof \User && $u->getName() ===
'Foo';
402 } ), $this->identicalTo(
null ) )
403 ->willReturn(
true );
405 $provider->providerRevokeAccessForUser(
'foo' );
407 $plugin = $this->getMockBuilder( \AuthPlugin::class )
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 ) {
417 return $u instanceof \User && $u->getName() ===
'Foo';
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',
505 $plugin = $this->createMock( \AuthPlugin::class );
506 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
507 $plugin->expects( $this->never() )->method(
'setPassword' );
509 $provider->providerChangeAuthenticationData(
510 $this->createMock( AuthenticationRequest::class )
515 $req->username =
'foo';
516 $req->password =
'bar';
518 $plugin = $this->createMock( \AuthPlugin::class );
519 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
520 $plugin->expects( $this->once() )->method(
'setPassword' )
521 ->with( $this->callback(
function ( $u ) {
522 return $u instanceof \User && $u->getName() ===
'Foo';
523 } ), $this->equalTo(
'bar' ) )
524 ->will( $this->returnValue(
true ) );
526 $provider->providerChangeAuthenticationData(
$req );
528 $plugin = $this->createMock( \AuthPlugin::class );
529 $plugin->expects( $this->any() )->method(
'domainList' )->willReturn( [] );
530 $plugin->expects( $this->once() )->method(
'setPassword' )
531 ->with( $this->callback(
function ( $u ) {
532 return $u instanceof \User && $u->getName() ===
'Foo';
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::class );
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 ) {
555 return $u instanceof \User && $u->getName() ===
'Foo';
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 );
601 $user = \User::newFromName(
'foo' );
602 $user->setEmail(
'email' );
603 $user->setRealName(
'realname' );
607 $reqs = [ PasswordAuthenticationRequest::class =>
$req ];
609 $plugin = $this->createMock( \AuthPlugin::class );
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::class );
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::class );
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 ) {
660 return $u instanceof \User && $u->getName() ===
'Foo';
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::class );
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 ) {
680 return $u instanceof \User && $u->getName() ===
'Foo';
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::class );
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 ) {
705 return $u instanceof \User && $u->getName() ===
'Foo';
706 } ), $this->equalTo(
'bar' ) )
707 ->
will( $this->returnValue(
true ) );
710 $req->username =
'foo';
711 $req->password =
'bar';
712 $req->domain =
'Domain2';