diff --git a/app/Services/SocialAuthService.php b/app/Services/SocialAuthService.php
index fe554b8d7..5edd4cad7 100644
--- a/app/Services/SocialAuthService.php
+++ b/app/Services/SocialAuthService.php
@@ -98,7 +98,6 @@ class SocialAuthService
// Get any attached social accounts or users
$socialAccount = $this->socialAccount->where('driver_id', '=', $socialId)->first();
- $user = $this->userRepo->getByEmail($socialUser->getEmail());
$isLoggedIn = auth()->check();
$currentUser = user();
diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php
index 295d1a801..928565156 100644
--- a/resources/views/auth/login.blade.php
+++ b/resources/views/auth/login.blade.php
@@ -34,10 +34,10 @@
{{ trans('auth.social_login') }}
@if(isset($socialDrivers['google']))
-
+
@endif
@if(isset($socialDrivers['github']))
-
+
@endif
@endif
diff --git a/tests/Auth/SocialAuthTest.php b/tests/Auth/SocialAuthTest.php
index d5a7e6921..5739f9a7d 100644
--- a/tests/Auth/SocialAuthTest.php
+++ b/tests/Auth/SocialAuthTest.php
@@ -32,4 +32,48 @@ class SocialAuthTest extends TestCase
$this->seeInDatabase('social_accounts', ['user_id' => $user->id]);
}
+ public function test_social_login()
+ {
+ $user = factory(\BookStack\User::class)->make();
+
+ config([
+ 'GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc',
+ 'GITHUB_APP_ID' => 'abc123', 'GITHUB_APP_SECRET' => '123abc',
+ 'APP_URL' => 'http://localhost'
+ ]);
+
+ $mockSocialite = Mockery::mock('Laravel\Socialite\Contracts\Factory');
+ $this->app['Laravel\Socialite\Contracts\Factory'] = $mockSocialite;
+ $mockSocialDriver = Mockery::mock('Laravel\Socialite\Contracts\Provider');
+ $mockSocialUser = Mockery::mock('\Laravel\Socialite\Contracts\User');
+
+ $mockSocialUser->shouldReceive('getId')->twice()->andReturn('logintest123');
+
+ $mockSocialDriver->shouldReceive('user')->twice()->andReturn($mockSocialUser);
+ $mockSocialite->shouldReceive('driver')->twice()->with('google')->andReturn($mockSocialDriver);
+ $mockSocialite->shouldReceive('driver')->twice()->with('github')->andReturn($mockSocialDriver);
+ $mockSocialDriver->shouldReceive('redirect')->twice()->andReturn(redirect('/'));
+
+ // Test login routes
+ $this->visit('/login')->seeElement('#social-login-google')
+ ->click('#social-login-google')
+ ->seePageIs('/login');
+
+ // Test social callback
+ $this->visit('/login/service/google/callback')->seePageIs('/login')
+ ->see(trans('errors.social_account_not_used', ['socialAccount' => 'Google']));
+
+ $this->visit('/login')->seeElement('#social-login-github')
+ ->click('#social-login-github')
+ ->seePageIs('/login');
+
+ // Test social callback with matching social account
+ DB::table('social_accounts')->insert([
+ 'user_id' => $this->getAdmin()->id,
+ 'driver' => 'github',
+ 'driver_id' => 'logintest123'
+ ]);
+ $this->visit('/login/service/github/callback')->seePageIs('/');
+ }
+
}