5 use Wikimedia\TestingAccessWrapper;
20 $this->assertEquals(
$response, $provider->getAuthenticationRequests(
$action, [] ) );
38 ->setMethods( [
'beginLinkAttempt',
'continueLinkAttempt' ] )
40 $mock->expects( $this->once() )->method(
'beginLinkAttempt' )
41 ->with( $this->identicalTo(
$user ), $this->identicalTo(
'AuthManager::authnState' ) )
42 ->will( $this->returnValue( $obj ) );
43 $mock->expects( $this->never() )->method(
'continueLinkAttempt' );
45 $this->assertSame( $obj, $mock->beginSecondaryAuthentication(
$user, [] ) );
51 $reqs = [ new \stdClass ];
54 ->setMethods( [
'beginLinkAttempt',
'continueLinkAttempt' ] )
56 $mock->expects( $this->never() )->method(
'beginLinkAttempt' );
57 $mock->expects( $this->once() )->method(
'continueLinkAttempt' )
59 $this->identicalTo(
$user ),
60 $this->identicalTo(
'AuthManager::authnState' ),
61 $this->identicalTo( $reqs )
63 ->will( $this->returnValue( $obj ) );
65 $this->assertSame( $obj, $mock->continueSecondaryAuthentication(
$user, $reqs ) );
73 ->setMethods( [
'beginLinkAttempt',
'continueLinkAttempt' ] )
75 $mock->expects( $this->once() )->method(
'beginLinkAttempt' )
76 ->with( $this->identicalTo(
$user ), $this->identicalTo(
'AuthManager::accountCreationState' ) )
77 ->will( $this->returnValue( $obj ) );
78 $mock->expects( $this->never() )->method(
'continueLinkAttempt' );
80 $this->assertSame( $obj, $mock->beginSecondaryAccountCreation(
$user,
$user, [] ) );
86 $reqs = [ new \stdClass ];
89 ->setMethods( [
'beginLinkAttempt',
'continueLinkAttempt' ] )
91 $mock->expects( $this->never() )->method(
'beginLinkAttempt' );
92 $mock->expects( $this->once() )->method(
'continueLinkAttempt' )
94 $this->identicalTo(
$user ),
95 $this->identicalTo(
'AuthManager::accountCreationState' ),
96 $this->identicalTo( $reqs )
98 ->will( $this->returnValue( $obj ) );
100 $this->assertSame( $obj, $mock->continueSecondaryAccountCreation(
$user,
$user, $reqs ) );
111 ->setMethods( [
'getUniqueId' ] );
112 for ( $i = 1; $i <= 3; $i++ ) {
113 $req = $mb->getMockForAbstractClass();
114 $req->expects( $this->
any() )->method(
'getUniqueId' )
115 ->will( $this->returnValue(
"Request$i" ) );
125 ->setMethods( [
'getUniqueId' ] )
126 ->getMockForAbstractClass();
127 $badReq->expects( $this->
any() )->method(
'getUniqueId' )
128 ->will( $this->returnValue(
"BadReq" ) );
131 $provider = TestingAccessWrapper::newFromObject(
136 ->setMethods( [
'allowsAuthenticationDataChange' ] )
139 $manager->expects( $this->
any() )->method(
'allowsAuthenticationDataChange' )
140 ->will( $this->returnCallback(
function (
$req ) {
141 return $req->getUniqueId() !==
'BadReq'
145 $provider->setManager( $manager );
149 $provider->beginLinkAttempt(
$user,
'state' )
152 $request->getSession()->setSecret(
'state', [
157 $provider->beginLinkAttempt(
$user,
'state' )
161 $request->getSession()->setSecret(
'state', [
162 'maybeLink' => $reqs + [
'BadReq' => $badReq ]
164 $res = $provider->beginLinkAttempt(
$user,
'state' );
167 $this->assertSame(
'authprovider-confirmlink-message',
$res->message->getKey() );
168 $this->assertCount( 1,
$res->neededRequests );
172 foreach ( $expectReqs
as $r ) {
174 $r->username =
$user->getName();
176 $this->assertEquals( $expectReqs, TestingAccessWrapper::newFromObject(
$req )->linkRequests );
181 $obj = new \stdClass;
184 $done = [
false,
false,
false ];
188 ->setMethods( [
'beginLinkAttempt' ] )
190 $mock->expects( $this->once() )->method(
'beginLinkAttempt' )
191 ->with( $this->identicalTo(
$user ), $this->identicalTo(
'state' ) )
192 ->will( $this->returnValue( $obj ) );
195 TestingAccessWrapper::newFromObject( $mock )->continueLinkAttempt(
$user,
'state', $reqs )
201 'beginLinkAttempt',
'providerAllowsAuthenticationDataChange',
202 'providerChangeAuthenticationData'
205 $provider->expects( $this->never() )->method(
'beginLinkAttempt' );
206 $provider->expects( $this->
any() )->method(
'providerAllowsAuthenticationDataChange' )
207 ->will( $this->returnCallback(
function (
$req )
use ( $reqs ) {
208 return $req->getUniqueId() ===
'Request3'
211 $provider->expects( $this->
any() )->method(
'providerChangeAuthenticationData' )
212 ->will( $this->returnCallback(
function (
$req )
use ( &$done ) {
213 $done[
$req->id] =
true;
216 'AuthManagerConfig' => [
220 [
'factory' =>
function ()
use ( $provider ) {
228 $provider->setManager( $manager );
229 $provider = TestingAccessWrapper::newFromObject( $provider );
235 $provider->continueLinkAttempt(
$user,
'state', [
$req ] )
238 $request->getSession()->setSecret(
'state', [
243 $provider->continueLinkAttempt(
$user,
'state', [
$req ] )
246 $request->getSession()->setSecret(
'state', [
251 $res = $provider->continueLinkAttempt(
$user,
'state', [
$req ] )
253 $this->assertSame( [
false,
false,
false ], $done );
255 $request->getSession()->setSecret(
'state', [
256 'maybeLink' => [ $reqs[
'Request2'] ],
258 $req->confirmedLinkIDs = [
'Request1',
'Request2' ];
259 $res = $provider->continueLinkAttempt(
$user,
'state', [
$req ] );
261 $this->assertSame( [
false,
true,
false ], $done );
262 $done = [
false,
false,
false ];
264 $request->getSession()->setSecret(
'state', [
265 'maybeLink' => $reqs,
267 $req->confirmedLinkIDs = [
'Request1',
'Request2' ];
268 $res = $provider->continueLinkAttempt(
$user,
'state', [
$req ] );
270 $this->assertSame( [
true,
true,
false ], $done );
271 $done = [
false,
false,
false ];
273 $request->getSession()->setSecret(
'state', [
274 'maybeLink' => $reqs,
276 $req->confirmedLinkIDs = [
'Request1',
'Request3' ];
277 $res = $provider->continueLinkAttempt(
$user,
'state', [
$req ] );
279 $this->assertCount( 1,
$res->neededRequests );
281 $this->assertSame( [
true,
false,
false ], $done );
282 $done = [
false,
false,
false ];
284 $res = $provider->continueLinkAttempt(
$user,
'state', [
$res->neededRequests[0] ] );
286 $this->assertSame( [
false,
false,
false ], $done );