Skip to content

Commit

Permalink
add method_exists check, add test coverage for signalReceived
Browse files Browse the repository at this point in the history
  • Loading branch information
haltuf committed Nov 16, 2022
1 parent 8a80b9c commit 19d993d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/SecuredLinksControlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/SecuredLinksTest.php7.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

0 comments on commit 19d993d

Please sign in to comment.