56 $user = \User::newFromName(
'UTSysop' );
58 $provider = $this->getMockBuilder(
59 ResetPasswordSecondaryAuthenticationProvider::class
62 'providerAllowsAuthenticationDataChange',
'providerChangeAuthenticationData'
65 $provider->expects( $this->any() )->method(
'providerAllowsAuthenticationDataChange' )
66 ->will( $this->returnCallback(
function (
$req ) {
67 $this->assertSame(
'UTSysop',
$req->username );
70 $provider->expects( $this->any() )->method(
'providerChangeAuthenticationData' )
71 ->will( $this->returnCallback(
function (
$req ) {
72 $this->assertSame(
'UTSysop',
$req->username );
75 $config = new \HashConfig( [
76 'AuthManagerConfig' => [
80 [
'factory' =>
function ()
use ( $provider ) {
87 $provider->setManager( $manager );
88 $provider = \TestingAccessWrapper::newFromObject( $provider );
93 wfMessage(
'authprovider-resetpass-skip-label' ),
94 wfMessage(
'authprovider-resetpass-skip-help' )
98 $passReq->password =
'Foo';
99 $passReq->retype =
'Bar';
100 $passReq->allow = \StatusValue::newGood();
101 $passReq->done =
false;
103 $passReq2 = $this->getMockBuilder( PasswordAuthenticationRequest::class )
104 ->enableProxyingToOriginalMethods()
107 $passReq2->password =
'Foo';
108 $passReq2->retype =
'Foo';
109 $passReq2->allow = \StatusValue::newGood();
110 $passReq2->done =
false;
114 $passReq3->password =
'Foo';
115 $passReq3->retype =
'Foo';
116 $passReq3->allow = \StatusValue::newGood();
117 $passReq3->done =
false;
121 $provider->tryReset(
$user, [] )
124 $manager->setAuthenticationSessionData(
'reset-pass',
'foo' );
126 $provider->tryReset(
$user, [] );
127 $this->fail(
'Expected exception not thrown' );
128 }
catch ( \UnexpectedValueException $ex ) {
129 $this->assertSame(
'reset-pass is not valid', $ex->getMessage() );
132 $manager->setAuthenticationSessionData(
'reset-pass', (
object)[] );
134 $provider->tryReset(
$user, [] );
135 $this->fail(
'Expected exception not thrown' );
136 }
catch ( \UnexpectedValueException $ex ) {
137 $this->assertSame(
'reset-pass msg is missing', $ex->getMessage() );
140 $manager->setAuthenticationSessionData(
'reset-pass', [
144 $provider->tryReset(
$user, [] );
145 $this->fail(
'Expected exception not thrown' );
146 }
catch ( \UnexpectedValueException $ex ) {
147 $this->assertSame(
'reset-pass msg is not valid', $ex->getMessage() );
150 $manager->setAuthenticationSessionData(
'reset-pass', [
154 $provider->tryReset(
$user, [] );
155 $this->fail(
'Expected exception not thrown' );
156 }
catch ( \UnexpectedValueException $ex ) {
157 $this->assertSame(
'reset-pass hard is missing', $ex->getMessage() );
160 $manager->setAuthenticationSessionData(
'reset-pass', [
166 $provider->tryReset(
$user, [] );
167 $this->fail(
'Expected exception not thrown' );
168 }
catch ( \UnexpectedValueException $ex ) {
169 $this->assertSame(
'reset-pass req is not valid', $ex->getMessage() );
172 $manager->setAuthenticationSessionData(
'reset-pass', [
178 $provider->tryReset(
$user, [ $passReq ] );
179 $this->fail(
'Expected exception not thrown' );
180 }
catch ( \UnexpectedValueException $ex ) {
181 $this->assertSame(
'reset-pass req is not valid', $ex->getMessage() );
184 $manager->setAuthenticationSessionData(
'reset-pass', [
189 $this->assertInstanceOf( AuthenticationResponse::class,
$res );
191 $this->assertEquals( $msg,
$res->message );
192 $this->assertCount( 1,
$res->neededRequests );
193 $this->assertInstanceOf(
194 PasswordAuthenticationRequest::class,
195 $res->neededRequests[0]
197 $this->assertNotNull( $manager->getAuthenticationSessionData(
'reset-pass' ) );
198 $this->assertFalse( $passReq->done );
200 $manager->setAuthenticationSessionData(
'reset-pass', [
206 $this->assertInstanceOf( AuthenticationResponse::class,
$res );
208 $this->assertEquals( $msg,
$res->message );
209 $this->assertCount( 2,
$res->neededRequests );
210 $expectedPassReq = clone $passReq;
212 $this->assertEquals( $expectedPassReq,
$res->neededRequests[0] );
213 $this->assertEquals( $skipReq,
$res->neededRequests[1] );
214 $this->assertNotNull( $manager->getAuthenticationSessionData(
'reset-pass' ) );
215 $this->assertFalse( $passReq->done );
217 $passReq->retype =
'Bad';
218 $manager->setAuthenticationSessionData(
'reset-pass', [
223 $res = $provider->tryReset(
$user, [ $skipReq, $passReq ] );
225 $this->assertNull( $manager->getAuthenticationSessionData(
'reset-pass' ) );
226 $this->assertFalse( $passReq->done );
228 $passReq->retype =
'Bad';
229 $manager->setAuthenticationSessionData(
'reset-pass', [
233 $res = $provider->tryReset(
$user, [ $skipReq, $passReq ] );
235 $this->assertSame(
'badretype',
$res->message->getKey() );
236 $this->assertCount( 1,
$res->neededRequests );
237 $this->assertInstanceOf(
238 PasswordAuthenticationRequest::class,
239 $res->neededRequests[0]
241 $this->assertNotNull( $manager->getAuthenticationSessionData(
'reset-pass' ) );
242 $this->assertFalse( $passReq->done );
244 $manager->setAuthenticationSessionData(
'reset-pass', [
248 $res = $provider->tryReset(
$user, [ $skipReq, $passReq3 ] );
250 $this->assertEquals( $msg,
$res->message );
251 $this->assertCount( 1,
$res->neededRequests );
252 $this->assertInstanceOf(
253 PasswordAuthenticationRequest::class,
254 $res->neededRequests[0]
256 $this->assertNotNull( $manager->getAuthenticationSessionData(
'reset-pass' ) );
257 $this->assertFalse( $passReq->done );
259 $passReq->retype = $passReq->password;
260 $passReq->allow = \StatusValue::newFatal(
'arbitrary-fail' );
261 $res = $provider->tryReset(
$user, [ $skipReq, $passReq ] );
263 $this->assertSame(
'arbitrary-fail',
$res->message->getKey() );
264 $this->assertCount( 1,
$res->neededRequests );
265 $this->assertInstanceOf(
266 PasswordAuthenticationRequest::class,
267 $res->neededRequests[0]
269 $this->assertNotNull( $manager->getAuthenticationSessionData(
'reset-pass' ) );
270 $this->assertFalse( $passReq->done );
272 $passReq->allow = \StatusValue::newGood();
273 $res = $provider->tryReset(
$user, [ $skipReq, $passReq ] );
275 $this->assertNull( $manager->getAuthenticationSessionData(
'reset-pass' ) );
276 $this->assertTrue( $passReq->done );
278 $manager->setAuthenticationSessionData(
'reset-pass', [
283 $res = $provider->tryReset(
$user, [ $passReq2 ] );
285 $this->assertNull( $manager->getAuthenticationSessionData(
'reset-pass' ) );
286 $this->assertTrue( $passReq2->done );
288 $passReq->done =
false;
289 $passReq2->done =
false;
290 $manager->setAuthenticationSessionData(
'reset-pass', [
295 $res = $provider->tryReset(
$user, [ $passReq ] );
296 $this->assertInstanceOf( AuthenticationResponse::class,
$res );
298 $this->assertEquals( $msg,
$res->message );
299 $this->assertCount( 2,
$res->neededRequests );
300 $expectedPassReq = clone $passReq2;
302 $this->assertEquals( $expectedPassReq,
$res->neededRequests[0] );
303 $this->assertEquals( $skipReq,
$res->neededRequests[1] );
304 $this->assertNotNull( $manager->getAuthenticationSessionData(
'reset-pass' ) );
305 $this->assertFalse( $passReq->done );
306 $this->assertFalse( $passReq2->done );