]> BookStack Code Mirror - bookstack/commitdiff
Added google select_account test
authorDan Brown <redacted>
Sat, 10 Nov 2018 14:52:43 +0000 (14:52 +0000)
committerDan Brown <redacted>
Sat, 10 Nov 2018 14:52:43 +0000 (14:52 +0000)
Also cleaned the function naming a little to be more descriptive of the
work they do.

app/Auth/Access/SocialAuthService.php
phpunit.xml
tests/Auth/SocialAuthTest.php

index 66f567c98389ab2ed5bdecd19faa20761c7fd76c..0d46b9f882d5ebe6afe1d08fb0d7b4714c9eeb74 100644 (file)
@@ -40,7 +40,7 @@ class SocialAuthService
     public function startLogIn($socialDriver)
     {
         $driver = $this->validateDriver($socialDriver);
-        return $this->redirectToSocialProvider($driver)->redirect();
+        return $this->getSocialDriver($driver)->redirect();
     }
 
     /**
@@ -52,7 +52,7 @@ class SocialAuthService
     public function startRegister($socialDriver)
     {
         $driver = $this->validateDriver($socialDriver);
-        return $this->redirectToSocialProvider($driver)->redirect();
+        return $this->getSocialDriver($driver)->redirect();
     }
 
     /**
@@ -250,15 +250,17 @@ class SocialAuthService
 
     /**
      * Provide redirect options per service for the Laravel Socialite driver
-     * @param $driver
+     * @param $driverName
+     * @return \Laravel\Socialite\Contracts\Provider
      */
-    public function redirectToSocialProvider($driver)
+    public function getSocialDriver(string $driverName)
     {
-        if ($driver == 'google' && config('services.google.select_account'))
-        {
-            return $this->socialite->driver($driver)->with(['prompt' => 'select_account']);
+        $driver = $this->socialite->driver($driverName);
+
+        if ($driverName === 'google' && config('services.google.select_account')) {
+            $driver->with(['prompt' => 'select_account']);
         }
 
-        return $this->socialite->driver($driver);
+        return $driver;
     }
 }
index efed0070e234674fb793d03403f279e60d27caa6..3d18d9bbf2782ba7fdfa5b403099cf122251e0fd 100644 (file)
@@ -41,6 +41,7 @@
         <env name="GOOGLE_APP_SECRET" value="aaaaaaaaaaaaaa"/>
         <env name="GOOGLE_AUTO_REGISTER" value=""/>
         <env name="GOOGLE_AUTO_CONFIRM_EMAIL" value=""/>
+        <env name="GOOGLE_SELECT_ACCOUNT" value=""/>
         <env name="APP_URL" value="http://bookstack.dev"/>
         <env name="DEBUGBAR_ENABLED" value="false"/>
     </php>
index 572c32f4620ff23756b0f61867ce13c15338f863..b8ca81174c3911663c08e703266640ebd1abb212 100644 (file)
@@ -148,4 +148,12 @@ class SocialAuthTest extends TestCase
         $this->assertDatabaseHas('social_accounts', ['user_id' => $user->id]);
     }
 
+    public function test_google_select_account_option_changes_redirect_url()
+    {
+        config()->set('services.google.select_account', 'true');
+
+        $resp = $this->get('/login/service/google');
+        $this->assertContains('prompt=select_account', $resp->headers->get('Location'));
+    }
+
 }