diff --git a/src/Panel/AuthPanel.php b/src/Panel/AuthPanel.php index 9cd92340..2f58482f 100644 --- a/src/Panel/AuthPanel.php +++ b/src/Panel/AuthPanel.php @@ -5,6 +5,7 @@ use Cake\Core\InstanceConfigTrait; use Cake\Event\EventInterface; use DebugKit\DebugPanel; +use RuntimeException; use TinyAuth\Auth\AclTrait; use TinyAuth\Auth\AllowTrait; use TinyAuth\Utility\Config; @@ -74,7 +75,10 @@ public function shutdown(EventInterface $event): void { $rule = $this->_getAllowRule($params); $this->isPublic = $this->_isActionAllowed($rule, $params['action']); - $controller->loadComponent('TinyAuth.AuthUser'); + if (!$controller->components()->has('AuthUser')) { + throw new RuntimeException('You must have TinyAuth.AuthUser component installed'); + } + /** @var \TinyAuth\Controller\Component\AuthUserComponent $authUserComponent */ $authUserComponent = $controller->components()->get('AuthUser'); $user = $authUserComponent->user(); diff --git a/tests/TestCase/Panel/AuthPanelTest.php b/tests/TestCase/Panel/AuthPanelTest.php index 501627bb..c095ba7a 100644 --- a/tests/TestCase/Panel/AuthPanelTest.php +++ b/tests/TestCase/Panel/AuthPanelTest.php @@ -61,6 +61,7 @@ public function tearDown(): void { */ public function testPanelRestrictedAction() { $controller = new Controller(new ServerRequest()); + $controller->loadComponent('TinyAuth.AuthUser'); $event = new Event('event', $controller); $this->panel->shutdown($event); @@ -86,6 +87,7 @@ public function testPanelPublicAction() { $request = new ServerRequest(['url' => '/users']); $request = $request->withAttribute('params', $url); $controller = new Controller($request); + $controller->loadComponent('TinyAuth.AuthUser'); $event = new Event('event', $controller); $this->panel->shutdown($event); @@ -115,6 +117,7 @@ public function testPanelAclRestricted() { $request = new ServerRequest(['url' => '/tags']); $request = $request->withAttribute('params', $url); $controller = new Controller($request); + $controller->loadComponent('TinyAuth.AuthUser'); $event = new Event('event', $controller); $this->panel->shutdown($event); @@ -147,6 +150,7 @@ public function testPanelAclAllowed() { 'role_id' => 1, ]); $controller = new Controller($request); + $controller->loadComponent('TinyAuth.AuthUser'); $event = new Event('event', $controller); $this->panel->shutdown($event);