Skip to content

Commit 3e0f75a

Browse files
committed
Fix issue 404labfr#162
1 parent 7c1f9c5 commit 3e0f75a

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

phpunit.xml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<file>tests/BladeDirectivesTest.php</file>
1818
<file>tests/RoutesTest.php</file>
1919
<file>tests/MiddlewareProtectFromImpersonationTest.php</file>
20+
<file>tests/SessionGuardTest.php</file>
2021
</testsuite>
2122
</testsuites>
2223
<filter>

src/Guard/SessionGuard.php

+19
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,27 @@ public function quietLogout()
3131
{
3232
$this->clearUserDataFromStorage();
3333

34+
$this->clearPasswordHashes();
35+
3436
$this->user = null;
3537

3638
$this->loggedOut = true;
3739
}
40+
41+
/**
42+
* Removes the stored password hashes from the session.
43+
*
44+
* @param void
45+
* @return void
46+
*/
47+
protected function clearPasswordHashes()
48+
{
49+
// Sort out password hashes stored in session
50+
foreach (array_keys(config('auth.guards')) as $guard) {
51+
$hashName = 'password_hash_' . $guard;
52+
if ($this->session->has($hashName)) {
53+
$this->session->remove($hashName);
54+
}
55+
}
56+
}
3857
}

tests/SessionGuardTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Lab404\Tests;
4+
5+
use Lab404\Tests\Stubs\Models\User;
6+
7+
class SessionGuardTest extends TestCase
8+
{
9+
/** @var String $guard */
10+
private $guard;
11+
12+
public function setUp(): void
13+
{
14+
parent::setUp();
15+
$this->guard = 'web';
16+
}
17+
18+
/** @test */
19+
public function it_removes_password_hash_from_session()
20+
{
21+
$hashName = 'password_hash_' . $this->guard;
22+
$this->app['auth']->guard($this->guard)->loginUsingId('[email protected]');
23+
$this->app['auth']->guard($this->guard)->getSession()->put($hashName, 'test_hash');
24+
$this->app['auth']->guard($this->guard)->quietLogout();
25+
$this->assertFalse($this->app['auth']->guard($this->guard)->check());
26+
$this->assertFalse($this->app['auth']->guard($this->guard)->getSession()->has($hashName));
27+
}
28+
}

0 commit comments

Comments
 (0)