Typo fix for AuthPluginPrimaryAuthenticationProvider::providerAllowsAuthenticationDat...
authorGergő Tisza <gtisza@wikimedia.org>
Sun, 29 May 2016 14:00:23 +0000 (14:00 +0000)
committerGergő Tisza <gtisza@wikimedia.org>
Sun, 29 May 2016 14:00:23 +0000 (14:00 +0000)
Change-Id: I7c05ea91009cdf765b06438e055de891e0edd1f4

includes/auth/AuthPluginPrimaryAuthenticationProvider.php
tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php

index 9746637..b8e36bc 100644 (file)
@@ -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' );
                                }
                        }
index b676d69..44f2743 100644 (file)
@@ -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' )
+                       ],
                ];
        }