From: Gergő Tisza Date: Sun, 29 May 2016 14:00:23 +0000 (+0000) Subject: Typo fix for AuthPluginPrimaryAuthenticationProvider::providerAllowsAuthenticationDat... X-Git-Tag: 1.31.0-rc.0~6765^2 X-Git-Url: http://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=32673970aac21ee7b5fbec71a8c71207f9eba025 Typo fix for AuthPluginPrimaryAuthenticationProvider::providerAllowsAuthenticationDataChange Change-Id: I7c05ea91009cdf765b06438e055de891e0edd1f4 --- diff --git a/includes/auth/AuthPluginPrimaryAuthenticationProvider.php b/includes/auth/AuthPluginPrimaryAuthenticationProvider.php index 9746637b00..b8e36bc4f3 100644 --- a/includes/auth/AuthPluginPrimaryAuthenticationProvider.php +++ b/includes/auth/AuthPluginPrimaryAuthenticationProvider.php @@ -329,7 +329,7 @@ class AuthPluginPrimaryAuthenticationProvider if ( $req->domain === null ) { return \StatusValue::newGood( 'ignored' ); } - if ( !$this->auth->validDomain( $domain ) ) { + if ( !$this->auth->validDomain( $req->domain ) ) { return \StatusValue::newFatal( 'authmanager-authplugin-setpass-bad-domain' ); } } diff --git a/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php index b676d69a48..44f2743d35 100644 --- a/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php @@ -461,14 +461,19 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { * @param StatusValue $expect */ public function testProviderAllowsAuthenticationDataChange( $type, $allow, $expect ) { + $domains = $type instanceof PasswordDomainAuthenticationRequest ? [ 'foo', 'bar' ] : []; $plugin = $this->getMock( 'AuthPlugin' ); - $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); + $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( $domains ); $plugin->expects( $allow === null ? $this->never() : $this->once() ) ->method( 'allowPasswordChange' )->will( $this->returnValue( $allow ) ); + $plugin->expects( $this->any() )->method( 'validDomain' ) + ->willReturnCallback( function ( $d ) use ( $domains ) { + return in_array( $d, $domains, true ); + } ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); - if ( $type === PasswordAuthenticationRequest::class ) { - $req = new $type(); + if ( is_object( $type ) ) { + $req = $type; } else { $req = $this->getMock( $type ); } @@ -480,14 +485,28 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public static function provideProviderAllowsAuthenticationDataChange() { + $domains = [ 'foo', 'bar' ]; + $reqNoDomain = new PasswordDomainAuthenticationRequest( $domains ); + $reqValidDomain = new PasswordDomainAuthenticationRequest( $domains ); + $reqValidDomain->domain = 'foo'; + $reqInvalidDomain = new PasswordDomainAuthenticationRequest( $domains ); + $reqInvalidDomain->domain = 'invalid'; + return [ [ AuthenticationRequest::class, null, \StatusValue::newGood( 'ignored' ) ], - [ PasswordAuthenticationRequest::class, true, \StatusValue::newGood() ], + [ new PasswordAuthenticationRequest, true, \StatusValue::newGood() ], [ - PasswordAuthenticationRequest::class, + new PasswordAuthenticationRequest, false, \StatusValue::newFatal( 'authmanager-authplugin-setpass-denied' ) ], + [ $reqNoDomain, true, \StatusValue::newGood( 'ignored' ) ], + [ $reqValidDomain, true, \StatusValue::newGood() ], + [ + $reqInvalidDomain, + true, + \StatusValue::newFatal( 'authmanager-authplugin-setpass-bad-domain' ) + ], ]; }