From 8fe2f6585c29f9c8477b3fffde34bdddebc00da1 Mon Sep 17 00:00:00 2001 From: Boorinio Date: Mon, 22 May 2023 15:58:18 +0200 Subject: [PATCH] [10.x] Remove session on authenticatable deletion v2 (#47141) * Clear session from storage if no recaller can be found * Update SessionGuard.php * Fixed tests to expect new behavior. --------- Co-authored-by: Taylor Otwell --- src/Illuminate/Auth/SessionGuard.php | 4 ++++ tests/Auth/AuthGuardTest.php | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/Illuminate/Auth/SessionGuard.php b/src/Illuminate/Auth/SessionGuard.php index 769edb204330..9187315db207 100644 --- a/src/Illuminate/Auth/SessionGuard.php +++ b/src/Illuminate/Auth/SessionGuard.php @@ -173,6 +173,10 @@ public function user() } } + if (is_null($this->user)) { + $this->clearUserDataFromStorage(); + } + return $this->user; } diff --git a/tests/Auth/AuthGuardTest.php b/tests/Auth/AuthGuardTest.php index 52c4cfe7d1c8..0a99502a6157 100755 --- a/tests/Auth/AuthGuardTest.php +++ b/tests/Auth/AuthGuardTest.php @@ -262,6 +262,9 @@ public function testAuthenticateThrowsWhenUserIsNull() $this->expectExceptionMessage('Unauthenticated.'); $guard = $this->getGuard(); + $guard->setCookieJar($cookies = m::mock(CookieJar::class)); + $cookies->shouldReceive('unqueue')->once(); + $guard->getSession()->shouldReceive('remove')->once(); $guard->getSession()->shouldReceive('get')->once()->andReturn(null); $guard->authenticate(); @@ -313,6 +316,9 @@ public function testUserMethodReturnsCachedUser() public function testNullIsReturnedForUserIfNoUserFound() { $mock = $this->getGuard(); + $mock->setCookieJar($cookies = m::mock(CookieJar::class)); + $cookies->shouldReceive('unqueue')->once(); + $mock->getSession()->shouldReceive('remove')->once(); $mock->getSession()->shouldReceive('get')->once()->andReturn(null); $this->assertNull($mock->user()); }