/** * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException */ public function testAccessDenied() { $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $token->expects($this->once())->method('getRoles')->will($this->returnValue(array())); $securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface'); $securityContext->expects($this->once())->method('isGranted')->will($this->throwException(new AccessDeniedException())); $securityContext->expects($this->once())->method('getToken')->will($this->returnValue($token)); $trustResolver = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationTrustResolverInterface'); $language = new ExpressionLanguage(); $listener = new SecurityListener($securityContext, $language, $trustResolver); $request = $this->createRequest(new Security(array('expression' => 'has_role("ROLE_ADMIN") and is_granted("FOO")'))); $event = new FilterControllerEvent($this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'), function () { return new Response(); }, $request, null); $listener->onKernelController($event); }
public function testNullSecurityContext() { $request = $this->prophesize(Request::class); $request->getMethod()->willReturn(null); $request->get('id')->willReturn('1'); $controller = $this->prophesize(SecuredControllerInterface::class); $controller->getSecurityContext()->willReturn(null); $controller->getLocale(Argument::any())->willReturn('de'); $this->filterControllerEvent->getRequest()->willReturn($request->reveal()); $this->filterControllerEvent->getController()->willReturn([$controller->reveal(), 'getAction']); $this->securityListener->onKernelController($this->filterControllerEvent->reveal()); $this->securityChecker->checkPermission(Argument::any(), Argument::any())->shouldNotBeCalled(); }