namespace Tests\Auth;
-use BookStack\Actions\ActivityType;
-use BookStack\Auth\SocialAccount;
-use BookStack\Auth\User;
+use BookStack\Access\SocialAccount;
+use BookStack\Activity\ActivityType;
+use BookStack\Users\Models\User;
use Illuminate\Support\Facades\DB;
use Laravel\Socialite\Contracts\Factory;
use Laravel\Socialite\Contracts\Provider;
$user = User::factory()->make();
$this->setSettings(['registration-enabled' => 'true']);
- config(['GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc', 'APP_URL' => 'http://localhost']);
+ config(['GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc']);
$mockSocialite = $this->mock(Factory::class);
$mockSocialDriver = Mockery::mock(Provider::class);
config([
'GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc',
'GITHUB_APP_ID' => 'abc123', 'GITHUB_APP_SECRET' => '123abc',
- 'APP_URL' => 'http://localhost',
]);
$mockSocialite = $this->mock(Factory::class);
$this->assertActivityExists(ActivityType::AUTH_LOGIN, null, 'github; (' . $this->users->admin()->id . ') ' . $this->users->admin()->name);
}
+ public function test_social_account_attach()
+ {
+ config([
+ 'GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc',
+ ]);
+ $editor = $this->users->editor();
+
+ $mockSocialite = $this->mock(Factory::class);
+ $mockSocialDriver = Mockery::mock(Provider::class);
+ $mockSocialUser = Mockery::mock(\Laravel\Socialite\Contracts\User::class);
+
+ $mockSocialUser->shouldReceive('getId')->twice()->andReturn('logintest123');
+ $mockSocialUser->shouldReceive('getAvatar')->andReturn(null);
+
+ $mockSocialite->shouldReceive('driver')->twice()->with('google')->andReturn($mockSocialDriver);
+ $mockSocialDriver->shouldReceive('redirect')->once()->andReturn(redirect('/login/service/google/callback'));
+ $mockSocialDriver->shouldReceive('user')->once()->andReturn($mockSocialUser);
+
+ // Test login routes
+ $resp = $this->actingAs($editor)->followingRedirects()->get('/login/service/google');
+ $resp->assertSee('Access & Security');
+
+ // Test social callback with matching social account
+ $this->assertDatabaseHas('social_accounts', [
+ 'user_id' => $editor->id,
+ 'driver' => 'google',
+ 'driver_id' => 'logintest123',
+ ]);
+ }
+
public function test_social_account_detach()
{
$editor = $this->users->editor();
config([
'GITHUB_APP_ID' => 'abc123', 'GITHUB_APP_SECRET' => '123abc',
- 'APP_URL' => 'http://localhost',
]);
$socialAccount = SocialAccount::query()->forceCreate([
'driver_id' => 'logintest123',
]);
- $resp = $this->actingAs($editor)->get($editor->getEditUrl());
+ $resp = $this->actingAs($editor)->get('/my-account/auth');
$this->withHtml($resp)->assertElementContains('form[action$="/login/service/github/detach"]', 'Disconnect Account');
$resp = $this->post('/login/service/github/detach');
- $resp->assertRedirect($editor->getEditUrl());
+ $resp->assertRedirect('/my-account/auth#social-accounts');
$resp = $this->followRedirects($resp);
$resp->assertSee('Github account was successfully disconnected from your profile.');
{
config([
'services.google.client_id' => 'abc123', 'services.google.client_secret' => '123abc',
- 'APP_URL' => 'http://localhost',
]);
$user = User::factory()->make();
{
config([
'services.google.client_id' => 'abc123', 'services.google.client_secret' => '123abc',
- 'APP_URL' => 'http://localhost', 'services.google.auto_register' => true, 'services.google.auto_confirm' => true,
+ 'services.google.auto_register' => true, 'services.google.auto_confirm' => true,
]);
$user = User::factory()->make();
$this->setSettings(['registration-enabled' => 'true']);
- config(['GITHUB_APP_ID' => 'abc123', 'GITHUB_APP_SECRET' => '123abc', 'APP_URL' => 'http://localhost']);
+ config(['GITHUB_APP_ID' => 'abc123', 'GITHUB_APP_SECRET' => '123abc']);
$mockSocialite = $this->mock(Factory::class);
$mockSocialDriver = Mockery::mock(Provider::class);