32 $user = \User::newFromName(
'UTSysop' );
35 $mock = $this->getMockBuilder( ConfirmLinkSecondaryAuthenticationProvider::class )
36 ->setMethods( [
'beginLinkAttempt',
'continueLinkAttempt' ] )
38 $mock->expects( $this->once() )->method(
'beginLinkAttempt' )
39 ->with( $this->identicalTo(
$user ), $this->identicalTo(
'AuthManager::authnState' ) )
40 ->will( $this->returnValue( $obj ) );
41 $mock->expects( $this->never() )->method(
'continueLinkAttempt' );
43 $this->assertSame( $obj, $mock->beginSecondaryAuthentication(
$user, [] ) );
47 $user = \User::newFromName(
'UTSysop' );
49 $reqs = [ new \stdClass ];
51 $mock = $this->getMockBuilder( ConfirmLinkSecondaryAuthenticationProvider::class )
52 ->setMethods( [
'beginLinkAttempt',
'continueLinkAttempt' ] )
54 $mock->expects( $this->never() )->method(
'beginLinkAttempt' );
55 $mock->expects( $this->once() )->method(
'continueLinkAttempt' )
57 $this->identicalTo(
$user ),
58 $this->identicalTo(
'AuthManager::authnState' ),
59 $this->identicalTo( $reqs )
61 ->will( $this->returnValue( $obj ) );
63 $this->assertSame( $obj, $mock->continueSecondaryAuthentication(
$user, $reqs ) );
67 $user = \User::newFromName(
'UTSysop' );
70 $mock = $this->getMockBuilder( ConfirmLinkSecondaryAuthenticationProvider::class )
71 ->setMethods( [
'beginLinkAttempt',
'continueLinkAttempt' ] )
73 $mock->expects( $this->once() )->method(
'beginLinkAttempt' )
74 ->with( $this->identicalTo(
$user ), $this->identicalTo(
'AuthManager::accountCreationState' ) )
75 ->will( $this->returnValue( $obj ) );
76 $mock->expects( $this->never() )->method(
'continueLinkAttempt' );
78 $this->assertSame( $obj, $mock->beginSecondaryAccountCreation(
$user,
$user, [] ) );
82 $user = \User::newFromName(
'UTSysop' );
84 $reqs = [ new \stdClass ];
86 $mock = $this->getMockBuilder( ConfirmLinkSecondaryAuthenticationProvider::class )
87 ->setMethods( [
'beginLinkAttempt',
'continueLinkAttempt' ] )
89 $mock->expects( $this->never() )->method(
'beginLinkAttempt' );
90 $mock->expects( $this->once() )->method(
'continueLinkAttempt' )
92 $this->identicalTo(
$user ),
93 $this->identicalTo(
'AuthManager::accountCreationState' ),
94 $this->identicalTo( $reqs )
96 ->will( $this->returnValue( $obj ) );
98 $this->assertSame( $obj, $mock->continueSecondaryAccountCreation(
$user,
$user, $reqs ) );
122 $badReq = $this->getMockBuilder( AuthenticationRequest::class )
123 ->setMethods( [
'getUniqueId' ] )
124 ->getMockForAbstractClass();
125 $badReq->expects( $this->any() )->method(
'getUniqueId' )
126 ->will( $this->returnValue(
"BadReq" ) );
128 $user = \User::newFromName(
'UTSysop' );
129 $provider = \TestingAccessWrapper::newFromObject(
133 $manager = $this->getMockBuilder( AuthManager::class )
134 ->setMethods( [
'allowsAuthenticationDataChange' ] )
137 $manager->expects( $this->any() )->method(
'allowsAuthenticationDataChange' )
138 ->will( $this->returnCallback(
function (
$req ) {
139 return $req->getUniqueId() !==
'BadReq'
140 ? \StatusValue::newGood()
141 : \StatusValue::newFatal(
'no' );
143 $provider->setManager( $manager );
147 $provider->beginLinkAttempt(
$user,
'state' )
150 $request->getSession()->setSecret(
'state', [
155 $provider->beginLinkAttempt(
$user,
'state' )
159 $request->getSession()->setSecret(
'state', [
160 'maybeLink' => $reqs + [
'BadReq' => $badReq ]
162 $res = $provider->beginLinkAttempt(
$user,
'state' );
163 $this->assertInstanceOf( AuthenticationResponse::class,
$res );
165 $this->assertSame(
'authprovider-confirmlink-message',
$res->message->getKey() );
166 $this->assertCount( 1,
$res->neededRequests );
168 $this->assertInstanceOf( ConfirmLinkAuthenticationRequest::class,
$req );
170 foreach ( $expectReqs
as $r ) {
172 $r->username =
$user->getName();
174 $this->assertEquals( $expectReqs, \TestingAccessWrapper::newFromObject(
$req )->linkRequests );
178 $user = \User::newFromName(
'UTSysop' );
179 $obj = new \stdClass;
182 $done = [
false,
false,
false ];
185 $mock = $this->getMockBuilder( ConfirmLinkSecondaryAuthenticationProvider::class )
186 ->setMethods( [
'beginLinkAttempt' ] )
188 $mock->expects( $this->once() )->method(
'beginLinkAttempt' )
189 ->with( $this->identicalTo(
$user ), $this->identicalTo(
'state' ) )
190 ->will( $this->returnValue( $obj ) );
193 \TestingAccessWrapper::newFromObject( $mock )->continueLinkAttempt(
$user,
'state', $reqs )
197 $provider = $this->getMockBuilder( ConfirmLinkSecondaryAuthenticationProvider::class )
199 'beginLinkAttempt',
'providerAllowsAuthenticationDataChange',
200 'providerChangeAuthenticationData'
203 $provider->expects( $this->never() )->method(
'beginLinkAttempt' );
204 $provider->expects( $this->any() )->method(
'providerAllowsAuthenticationDataChange' )
205 ->will( $this->returnCallback(
function (
$req )
use ( $reqs ) {
206 return $req->getUniqueId() ===
'Request3'
207 ? \StatusValue::newFatal(
'foo' ) : \StatusValue::newGood();
209 $provider->expects( $this->any() )->method(
'providerChangeAuthenticationData' )
210 ->will( $this->returnCallback(
function (
$req )
use ( &$done ) {
211 $done[
$req->id] =
true;
213 $config = new \HashConfig( [
214 'AuthManagerConfig' => [
218 [
'factory' =>
function ()
use ( $provider ) {
226 $provider->setManager( $manager );
227 $provider = \TestingAccessWrapper::newFromObject( $provider );
233 $provider->continueLinkAttempt(
$user,
'state', [
$req ] )
236 $request->getSession()->setSecret(
'state', [
241 $provider->continueLinkAttempt(
$user,
'state', [
$req ] )
244 $request->getSession()->setSecret(
'state', [
249 $res = $provider->continueLinkAttempt(
$user,
'state', [
$req ] )
251 $this->assertSame( [
false,
false,
false ], $done );
253 $request->getSession()->setSecret(
'state', [
254 'maybeLink' => [ $reqs[
'Request2'] ],
256 $req->confirmedLinkIDs = [
'Request1',
'Request2' ];
257 $res = $provider->continueLinkAttempt(
$user,
'state', [
$req ] );
259 $this->assertSame( [
false,
true,
false ], $done );
260 $done = [
false,
false,
false ];
262 $request->getSession()->setSecret(
'state', [
263 'maybeLink' => $reqs,
265 $req->confirmedLinkIDs = [
'Request1',
'Request2' ];
266 $res = $provider->continueLinkAttempt(
$user,
'state', [
$req ] );
268 $this->assertSame( [
true,
true,
false ], $done );
269 $done = [
false,
false,
false ];
271 $request->getSession()->setSecret(
'state', [
272 'maybeLink' => $reqs,
274 $req->confirmedLinkIDs = [
'Request1',
'Request3' ];
275 $res = $provider->continueLinkAttempt(
$user,
'state', [
$req ] );
277 $this->assertCount( 1,
$res->neededRequests );
278 $this->assertInstanceOf( ButtonAuthenticationRequest::class,
$res->neededRequests[0] );
279 $this->assertSame( [
true,
false,
false ], $done );
280 $done = [
false,
false,
false ];
282 $res = $provider->continueLinkAttempt(
$user,
'state', [
$res->neededRequests[0] ] );
284 $this->assertSame( [
false,
false,
false ], $done );