Skip to content

Commit 2b6143e

Browse files
committed
Fix PHP error when checking for impersonation without authentication.
1 parent 5d4885b commit 2b6143e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Controller/Component/AuthenticationComponent.php

+4
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ public function stopImpersonating()
445445
*/
446446
public function isImpersonating(): bool
447447
{
448+
if (!$this->getIdentity()) {
449+
return false;
450+
}
451+
448452
$service = $this->getImpersonationAuthenticationService();
449453
$controller = $this->getController();
450454

tests/TestCase/Controller/Component/AuthenticationComponentTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -731,13 +731,17 @@ public function testIsImpersonating()
731731
$this->request->getSession()->write('AuthImpersonate', $impersonator);
732732
$this->service->authenticate($this->request);
733733
$request = $this->request
734-
->withAttribute('authentication', $this->service);
734+
->withAttribute('authentication', $this->service)
735+
->withAttribute('identity', new Identity($impersonated));
735736
$controller = new Controller($request, $this->response);
736737
$registry = new ComponentRegistry($controller);
737738
$component = new AuthenticationComponent($registry);
738739

739740
$result = $component->isImpersonating();
740741
$this->assertTrue($result);
742+
743+
$component->logout();
744+
$this->assertFalse($component->isImpersonating());
741745
}
742746

743747
/**

0 commit comments

Comments
 (0)