diff --git a/src/SecuredLinksControlTrait.php b/src/SecuredLinksControlTrait.php index 1371c89..72ece8d 100644 --- a/src/SecuredLinksControlTrait.php +++ b/src/SecuredLinksControlTrait.php @@ -41,7 +41,8 @@ public function signalReceived(string $signal): void if (method_exists($this, $method)) { $reflection = new \ReflectionMethod($this, $method); - $secured = Nette\Application\UI\ComponentReflection::parseAnnotation($reflection, 'secured') !== NULL || count($reflection->getAttributes(Secured::class)) > 0; + $secured = Nette\Application\UI\ComponentReflection::parseAnnotation($reflection, 'secured') !== NULL + || (method_exists($reflection, 'getAttributes') && count($reflection->getAttributes(Secured::class)) > 0); if ($secured) { $params = array($this->getUniqueId()); if ($this->params) { diff --git a/tests/cases/SecuredLinksTest.php7.phpt b/tests/cases/SecuredLinksTest.php7.phpt index aadc2ed..7f72df9 100644 --- a/tests/cases/SecuredLinksTest.php7.phpt +++ b/tests/cases/SecuredLinksTest.php7.phpt @@ -5,6 +5,7 @@ use Nette\Application\Request; use Nette\Application\Routers\SimpleRouter; +use Nette\Application\UI\BadSignalException; use Nette\Application\UI\Presenter; use Nette\Http\Request as HttpRequest; use Nette\Http\Response; @@ -64,4 +65,13 @@ $presenter->run(new Request('Test', 'GET', [ '_sec' => 'JqCasYHU', ])); +Assert::exception(function () use ($presenter) { + $presenter->run(new Request('Test', 'GET', [ + 'action' => 'default', + 'do' => 'pay', + 'value' => '0', + //'_sec' => 'JqCasYHU', + ])); +}, BadSignalException::class, "Invalid security token for signal 'pay' in class TestPresenter."); + Mockery::close();