Skip to content

Commit 5ccc1fa

Browse files
authored
[9.x] Unqueue recaller cookie (#45305)
* Unqueue recaller cookie * update tests
1 parent 7f5daa5 commit 5ccc1fa

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Illuminate/Auth/SessionGuard.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ protected function clearUserDataFromStorage()
628628
{
629629
$this->session->remove($this->getName());
630630

631+
$this->getCookieJar()->unqueue($this->getRecallerName());
632+
631633
if (! is_null($this->recaller())) {
632634
$this->getCookieJar()->queue($this->getCookieJar()
633635
->forget($this->getRecallerName()));

tests/Auth/AuthGuardTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,14 @@ public function testLogoutRemovesSessionTokenAndRememberMeCookie()
334334
$user->shouldReceive('getRememberToken')->once()->andReturn('a');
335335
$user->shouldReceive('setRememberToken')->once();
336336
$mock->expects($this->once())->method('getName')->willReturn('foo');
337-
$mock->expects($this->once())->method('getRecallerName')->willReturn('bar');
337+
$mock->expects($this->exactly(2))->method('getRecallerName')->willReturn($recallerName = 'bar');
338338
$mock->expects($this->once())->method('recaller')->willReturn('non-null-cookie');
339339
$provider->shouldReceive('updateRememberToken')->once();
340340

341341
$cookie = m::mock(Cookie::class);
342342
$cookies->shouldReceive('forget')->once()->with('bar')->andReturn($cookie);
343343
$cookies->shouldReceive('queue')->once()->with($cookie);
344+
$cookies->shouldReceive('unqueue')->once()->with($recallerName);
344345
$mock->getSession()->shouldReceive('remove')->once()->with('foo');
345346
$mock->setUser($user);
346347
$mock->logout();
@@ -350,13 +351,16 @@ public function testLogoutRemovesSessionTokenAndRememberMeCookie()
350351
public function testLogoutDoesNotEnqueueRememberMeCookieForDeletionIfCookieDoesntExist()
351352
{
352353
[$session, $provider, $request, $cookie] = $this->getMocks();
353-
$mock = $this->getMockBuilder(SessionGuard::class)->onlyMethods(['getName', 'recaller'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
354+
$mock = $this->getMockBuilder(SessionGuard::class)->onlyMethods(['getName', 'getRecallerName', 'recaller'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
354355
$mock->setCookieJar($cookies = m::mock(CookieJar::class));
355356
$user = m::mock(Authenticatable::class);
356357
$user->shouldReceive('getRememberToken')->andReturn(null);
358+
$mock->expects($this->once())->method('getRecallerName')->willReturn($recallerName = 'bar');
357359
$mock->expects($this->once())->method('getName')->willReturn('foo');
358360
$mock->expects($this->once())->method('recaller')->willReturn(null);
359361

362+
$cookies->shouldReceive('unqueue')->with($recallerName);
363+
360364
$mock->getSession()->shouldReceive('remove')->once()->with('foo');
361365
$mock->setUser($user);
362366
$mock->logout();
@@ -398,12 +402,13 @@ public function testLogoutCurrentDeviceRemovesRememberMeCookie()
398402
$mock->setCookieJar($cookies = m::mock(CookieJar::class));
399403
$user = m::mock(Authenticatable::class);
400404
$mock->expects($this->once())->method('getName')->willReturn('foo');
401-
$mock->expects($this->once())->method('getRecallerName')->willReturn('bar');
405+
$mock->expects($this->exactly(2))->method('getRecallerName')->willReturn($recallerName = 'bar');
402406
$mock->expects($this->once())->method('recaller')->willReturn('non-null-cookie');
403407

404408
$cookie = m::mock(Cookie::class);
405409
$cookies->shouldReceive('forget')->once()->with('bar')->andReturn($cookie);
406410
$cookies->shouldReceive('queue')->once()->with($cookie);
411+
$cookies->shouldReceive('unqueue')->once()->with($recallerName);
407412
$mock->getSession()->shouldReceive('remove')->once()->with('foo');
408413
$mock->setUser($user);
409414
$mock->logoutCurrentDevice();
@@ -413,12 +418,14 @@ public function testLogoutCurrentDeviceRemovesRememberMeCookie()
413418
public function testLogoutCurrentDeviceDoesNotEnqueueRememberMeCookieForDeletionIfCookieDoesntExist()
414419
{
415420
[$session, $provider, $request, $cookie] = $this->getMocks();
416-
$mock = $this->getMockBuilder(SessionGuard::class)->onlyMethods(['getName', 'recaller'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
421+
$mock = $this->getMockBuilder(SessionGuard::class)->onlyMethods(['getName', 'getRecallerName', 'recaller'])->setConstructorArgs(['default', $provider, $session, $request])->getMock();
417422
$mock->setCookieJar($cookies = m::mock(CookieJar::class));
418423
$user = m::mock(Authenticatable::class);
419424
$user->shouldReceive('getRememberToken')->andReturn(null);
420425
$mock->expects($this->once())->method('getName')->willReturn('foo');
426+
$mock->expects($this->once())->method('getRecallerName')->willReturn($recallerName = 'bar');
421427
$mock->expects($this->once())->method('recaller')->willReturn(null);
428+
$cookies->shouldReceive('unqueue')->once()->with($recallerName);
422429

423430
$mock->getSession()->shouldReceive('remove')->once()->with('foo');
424431
$mock->setUser($user);

0 commit comments

Comments
 (0)