AuthManager: Fix ConfirmLink validation
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 9 Jun 2016 15:06:38 +0000 (11:06 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Thu, 9 Jun 2016 15:20:23 +0000 (11:20 -0400)
I726d79de added validation of the incoming requests to
ConfirmLinkSecondaryAuthenticationProvider, but forgot to fill in the
username and action fields before doing so meaning the confirmation
would probably fail.

Change-Id: I75cb65c24538a1e60e3b47a3b9ecfbd3a79ce8bf

includes/auth/ConfirmLinkSecondaryAuthenticationProvider.php
tests/phpunit/includes/auth/ConfirmLinkSecondaryAuthenticationProviderTest.php

index 57f1e6b..32c8fd5 100644 (file)
@@ -51,7 +51,11 @@ class ConfirmLinkSecondaryAuthenticationProvider extends AbstractSecondaryAuthen
                        return AuthenticationResponse::newAbstain();
                }
 
-               $maybeLink = array_filter( $state['maybeLink'], function ( $req ) {
+               $maybeLink = array_filter( $state['maybeLink'], function ( $req ) use ( $user ) {
+                       if ( !$req->action ) {
+                               $req->action = AuthManager::ACTION_CHANGE;
+                       }
+                       $req->username = $user->getName();
                        return $this->manager->allowsAuthenticationDataChange( $req )->isGood();
                } );
                if ( !$maybeLink ) {
index d254e81..580ef6c 100644 (file)
@@ -175,7 +175,12 @@ class ConfirmLinkSecondaryAuthenticationProviderTest extends \MediaWikiTestCase
                $this->assertCount( 1, $res->neededRequests );
                $req = $res->neededRequests[0];
                $this->assertInstanceOf( ConfirmLinkAuthenticationRequest::class, $req );
-               $this->assertEquals( $reqs, \TestingAccessWrapper::newFromObject( $req )->linkRequests );
+               $expectReqs = $this->getLinkRequests();
+               foreach ( $expectReqs as $r ) {
+                       $r->action = AuthManager::ACTION_CHANGE;
+                       $r->username = $user->getName();
+               }
+               $this->assertEquals( $expectReqs, \TestingAccessWrapper::newFromObject( $req )->linkRequests );
        }
 
        public function testContinueLinkAttempt() {