mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
fix: remove login marker cookie on logout
Apply suggestions from code review Co-authored-by: Michal Kleiner <mk@011.nz>
This commit is contained in:
parent
08028d3969
commit
31668e8acf
@ -113,5 +113,9 @@ class SessionAuthenticationHandler implements AuthenticationHandler
|
||||
{
|
||||
$request = $request ?: Controller::curr()->getRequest();
|
||||
$request->getSession()->destroy(true, $request);
|
||||
|
||||
if (Member::config()->get('login_marker_cookie')) {
|
||||
Cookie::force_expiry(Member::config()->get('login_marker_cookie'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,15 @@ namespace SilverStripe\Security\Tests\MemberAuthenticator;
|
||||
use SilverStripe\Control\Cookie;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Security\MemberAuthenticator\SessionAuthenticationHandler;
|
||||
|
||||
class SessionAuthenticationHandlerTest extends SapphireTest
|
||||
{
|
||||
protected static $fixture_file = 'SessionAuthenticationHandlerTest.yml';
|
||||
|
||||
protected $usesDatabase = true;
|
||||
|
||||
/**
|
||||
@ -58,4 +60,20 @@ class SessionAuthenticationHandlerTest extends SapphireTest
|
||||
$this->assertNotNull($matchedMember);
|
||||
$this->assertEquals($matchedMember->Email, $member->Email);
|
||||
}
|
||||
|
||||
public function testLoginMarkerCookie()
|
||||
{
|
||||
Config::modify()->set(Member::class, 'login_marker_cookie', 'sslogin');
|
||||
|
||||
/** @var Member $member */
|
||||
$member = $this->objFromFixture(Member::class, 'test');
|
||||
|
||||
$this->logInAs($member);
|
||||
|
||||
$this->assertNotNull(Cookie::get('sslogin'), 'Login marker cookie is set after logging in');
|
||||
|
||||
$this->logOut();
|
||||
|
||||
$this->assertNull(Cookie::get('sslogin'), 'Login marker cookie is deleted after logging out');
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
'SilverStripe\Security\Group':
|
||||
usergroup:
|
||||
Title: usergroup
|
||||
Code: usergroup
|
||||
'SilverStripe\Security\Member':
|
||||
test:
|
||||
FirstName: Test
|
||||
Surname: User
|
||||
Email: testuser@example.com
|
||||
Password: 1nitialPassword
|
||||
Groups: '=>SilverStripe\Security\Group.usergroup'
|
Loading…
Reference in New Issue
Block a user