A free open source IT asset/license management system
Fixed #19562 - log last_login on google workspace login
snipe066a028db391
diff --git a/app/Http/Controllers/GoogleAuthController.php b/app/Http/Controllers/GoogleAuthController.phpindex f6ab95d59c..115ee4ae35 100644--- a/app/Http/Controllers/GoogleAuthController.php+++ b/app/Http/Controllers/GoogleAuthController.php@@ -63,10 +63,10 @@ class GoogleAuthController extends Controller}Log::debug('Google user '.$socialUser->getEmail().' found in Snipe-IT');- $user->update([- 'avatar' => $socialUser->avatar,- 'last_login' => \Carbon::now(),- ]);++ $user->avatar = $socialUser->avatar;+ $user->last_login = \Carbon::now();+ $user->save();Auth::login($user, true);diff --git a/tests/Feature/Auth/GoogleLoginTest.php b/tests/Feature/Auth/GoogleLoginTest.phpnew file mode 100644index 0000000000..7a401939e6--- /dev/null+++ b/tests/Feature/Auth/GoogleLoginTest.php@@ -0,0 +1,37 @@+<?php++namespace Tests\Feature\Auth;++use App\Models\User;+use Illuminate\Support\Facades\Auth;+use Laravel\Socialite\Facades\Socialite;+use Laravel\Socialite\Two\User as SocialiteUser;+use Mockery;+use PHPUnit\Framework\Attributes\Test;+use Tests\TestCase;++class GoogleLoginTest extends TestCase+{+ #[Test]+ public function successful_google_callback_updates_the_last_login_timestamp(): void+ {++ $user = User::factory()->create([+ 'username' => '[email protected]',+ 'last_login' => null,+ ]);++ $socialUser = Mockery::mock(SocialiteUser::class);+ $socialUser->shouldReceive('getEmail')->andReturn('[email protected]');+ $socialUser->avatar = 'https://lh3.googleusercontent.com/a/sample-avatar';++ $driver = Mockery::mock();+ $driver->shouldReceive('user')->andReturn($socialUser);+ Socialite::shouldReceive('driver')->with('google')->andReturn($driver);++ $this->get(route('google.callback'))->assertRedirect(route('home'));++ $this->assertNotNull($user->fresh()->last_login, 'last_login must be stamped after a successful Google callback.');+ $this->assertTrue(Auth::check(), 'User must be authenticated after a successful Google callback.');+ }+}