-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX Better handling of remember me token when login across devices is…
… disabled (#9895) * BUG Make sure remember me tokens are not invalidated when logging out without the logout_across_devices flag * Remove unneeded comment
- Loading branch information
Maxime Rainville
authored
Mar 30, 2021
1 parent
504e203
commit 66fa597
Showing
3 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Security\Tests; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Security\Member; | ||
use SilverStripe\Security\RememberLoginHash; | ||
|
||
class RememberLoginHashTest extends SapphireTest | ||
{ | ||
protected static $fixture_file = 'RememberLoginHashTest.yml'; | ||
|
||
/** @var RememberLoginHash[] */ | ||
private $loginHash = []; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
/** @var Member $main */ | ||
$main = $this->objFromFixture(Member::class, 'main'); | ||
|
||
/** @var Member $secondary */ | ||
$secondary = $this->objFromFixture(Member::class, 'secondary'); | ||
|
||
$this->loginHash = [ | ||
'current' => RememberLoginHash::generate($main), | ||
'other' => RememberLoginHash::generate($main), | ||
'secondary' => RememberLoginHash::generate($secondary), | ||
]; | ||
} | ||
|
||
public function clearScenarios() | ||
{ | ||
return [ | ||
'logout across devices' => [true, 'current', ['secondary'], ['current', 'other']], | ||
'logout across devices on non-persistent session' => [true, false, ['secondary'], ['current', 'other']], | ||
'logout single device' => [false, 'current', ['secondary', 'other'], ['current']], | ||
'logout single device on non-persistent session' => [false, false, ['secondary', 'current', 'other'], []], | ||
]; | ||
} | ||
|
||
/** | ||
* @param bool $logoutAcrossDevices | ||
* @param string $deviceId | ||
* @param array $expected | ||
* @param array $unexpected | ||
* @dataProvider clearScenarios | ||
*/ | ||
public function testClear(bool $logoutAcrossDevices, string $deviceId, array $expected, array $unexpected) | ||
{ | ||
RememberLoginHash::config()->set('logout_across_devices', $logoutAcrossDevices); | ||
|
||
RememberLoginHash::clear( | ||
$this->objFromFixture(Member::class, 'main'), | ||
$deviceId ? $this->loginHash[$deviceId]->DeviceID : null | ||
); | ||
|
||
foreach ($expected as $key) { | ||
$ID = $this->loginHash[$key]->ID; | ||
$this->assertNotEmpty( | ||
RememberLoginHash::get()->byID($ID), | ||
"$key $ID RememberLoginHash is found" | ||
); | ||
} | ||
|
||
foreach ($unexpected as $key) { | ||
$ID = $this->loginHash[$key]->ID; | ||
$this->assertEmpty( | ||
RememberLoginHash::get()->byID($ID), | ||
"$key RememberLoginHash has been removed" | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'SilverStripe\Security\Member': | ||
main: | ||
FirstName: Main | ||
Surname: Test Subject | ||
secondary: | ||
FirstName: Secondary | ||
Surname: Test Subject |