Skip to content

Commit

Permalink
Merge pull request #78 from prolic/message_as_context_for_route_guard
Browse files Browse the repository at this point in the history
route guard plugin adds message as context param
  • Loading branch information
codeliner committed Oct 20, 2015
2 parents a1b5f0b + 6410894 commit 3412339
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Plugin/Guard/RouteGuard.php
Expand Up @@ -43,7 +43,10 @@ public function __construct(AuthorizationService $authorizationService)
*/
public function onRoute(ActionEvent $actionEvent)
{
if ($this->authorizationService->isGranted($actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE_NAME))) {
if ($this->authorizationService->isGranted(
$actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE_NAME),
$actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE)
)) {
return;
}

Expand Down
6 changes: 4 additions & 2 deletions tests/Plugin/Guard/RouteGuardTest.php
Expand Up @@ -41,10 +41,11 @@ public function it_attaches_to_action_event_emitter()
public function it_allows_when_authorization_service_grants_access()
{
$authorizationService = $this->prophesize(AuthorizationService::class);
$authorizationService->isGranted('test_event')->willReturn(true);
$authorizationService->isGranted('test_event', new \stdClass())->willReturn(true);

$actionEvent = $this->prophesize(ActionEvent::class);
$actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE_NAME)->willReturn('test_event');
$actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE)->willReturn(new \stdClass());

$routeGuard = new RouteGuard($authorizationService->reveal());

Expand All @@ -58,10 +59,11 @@ public function it_allows_when_authorization_service_grants_access()
public function it_stops_propagation_and_throws_unauthorizedexception_when_authorization_service_denies_access()
{
$authorizationService = $this->prophesize(AuthorizationService::class);
$authorizationService->isGranted('test_event')->willReturn(false);
$authorizationService->isGranted('test_event', new \stdClass())->willReturn(false);

$actionEvent = $this->prophesize(ActionEvent::class);
$actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE_NAME)->willReturn('test_event');
$actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE)->willReturn(new \stdClass());
$actionEvent->stopPropagation(true)->willReturn(null);

$routeGuard = new RouteGuard($authorizationService->reveal());
Expand Down

0 comments on commit 3412339

Please sign in to comment.