Skip to content

Commit f37d7da

Browse files
fix(auth): update getRecallerId to cast ID to int
also add test for returning integer ID from remember cookie
1 parent fda6610 commit f37d7da

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/Illuminate/Auth/Guard.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public function user()
149149
// pull the user data on that cookie which serves as a remember cookie on
150150
// the application. Once we have a user we can return it to the caller.
151151
$recaller = $this->getRecaller();
152-
153152
if (is_null($user) && ! is_null($recaller))
154153
{
155154
$user = $this->getUserByRecaller($recaller);
@@ -210,15 +209,14 @@ protected function getRecaller()
210209
/**
211210
* Get the user ID from the recaller cookie.
212211
*
213-
* @return string
212+
* @return int
214213
*/
215-
protected function getRecallerId()
216-
{
217-
if ($this->validRecaller($recaller = $this->getRecaller()))
218-
{
219-
return head(explode('|', $recaller));
220-
}
221-
}
214+
protected function getRecallerId()
215+
{
216+
if ($this->validRecaller($recaller = $this->getRecaller())) {
217+
return (int) head(explode('|', $recaller));
218+
}
219+
}
222220

223221
/**
224222
* Determine if the recaller cookie is in a valid format.

tests/Auth/AuthGuardTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,25 @@ public function testUserUsesRememberCookieIfItExists()
374374
$this->assertEquals($user->reveal(), $guard->user());
375375
$this->assertTrue($guard->viaRemember());
376376
}
377+
378+
public function testGetIdWhenRememberCookieExistsWillReturnIntegerIdFromCookieValue()
379+
{
380+
$request = Request::create('/', 'GET', [], [
381+
'remember_82e5d2c56bdd0811318f0cf078b78bfc' => '123|recaller'
382+
]);
383+
384+
$this->session->get('login_82e5d2c56bdd0811318f0cf078b78bfc', Argument::any())->will(function ($args) {
385+
return $args[1];
386+
});
387+
388+
$guard = new Guard(
389+
$this->userProvider->reveal(),
390+
$this->session->reveal(),
391+
$request
392+
);
393+
394+
$this->assertNotNull($guard->id());
395+
$this->assertIsInt($guard->id());
396+
$this->assertSame(123, $guard->id());
397+
}
377398
}

0 commit comments

Comments
 (0)