Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Controller/Component/AuthenticationComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ public function setIdentity(ArrayAccess $identity)
$controller = $this->getController();
$service = $this->getAuthenticationService();

$service->clearIdentity($controller->getRequest(), $controller->getResponse());
/** @psalm-var array{request: \Cake\Http\ServerRequest, response: \Cake\Http\Response} $result */
$result = $service->clearIdentity($controller->getRequest(), $controller->getResponse());

$controller->setRequest($result['request']);
$controller->setResponse($result['response']);

/** @psalm-var array{request: \Cake\Http\ServerRequest, response: \Cake\Http\Response} $result */
$result = $service->persistIdentity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,63 @@ public function testSetIdentityOverwrite()
);
}

public function testSetIdentityWithCookieAuthDoNotRememberMe()
{
$service = new AuthenticationService([
'identifiers' => [
'Authentication.Password',
],
'authenticators' => [
'Authentication.Session',
'Authentication.Form',
'Authentication.Cookie',
],
]);
$request = $this->request->withAttribute('authentication', $service)
->withData('remember_me', 0);

$controller = new Controller($request, $this->response);
$registry = new ComponentRegistry($controller);
$component = new AuthenticationComponent($registry);

$component->setIdentity($this->identityData);
$result = $component->getIdentity();
$this->assertSame($this->identityData, $result->getOriginalData());
$expectedCookieHeader = [
'CookieAuth=; expires=Thu, 01-Jan-1970 00:00:01 GMT+0000; path=/',
];
$actualCookieHeader = $controller->getResponse()->getHeader('Set-Cookie');
$this->assertSame($expectedCookieHeader, $actualCookieHeader);
}

public function testSetIdentityWithCookieAuthRememberMe()
{
$service = new AuthenticationService([
'identifiers' => [
'Authentication.Password',
],
'authenticators' => [
'Authentication.Session',
'Authentication.Form',
'Authentication.Cookie',
],
]);
$request = $this->request->withAttribute('authentication', $service)
->withData('remember_me', 1);

$controller = new Controller($request, $this->response);
$registry = new ComponentRegistry($controller);
$component = new AuthenticationComponent($registry);

$component->setIdentity($this->identityData);
$result = $component->getIdentity();
$this->assertSame($this->identityData, $result->getOriginalData());
$actualCookieHeader = $controller->getResponse()->getHeader('Set-Cookie');
$this->assertCount(2, $actualCookieHeader);
$this->assertStringContainsString('CookieAuth=', $actualCookieHeader[1]);
$this->assertStringNotContainsString('expires=Thu, 01-Jan-1970 00:00:01 GMT+0000;', $actualCookieHeader[1]);
}

/**
* testGetIdentity
*
Expand Down
Loading