Пример #1
0
 public function testOnException()
 {
     $driver = new FailDriver();
     $exception = AuthorizationException::from($driver);
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $request->expects($this->any())->method('getUri')->will($this->returnValue('/foo'));
     $request->expects($this->any())->method('getClientIp')->will($this->returnValue('127.0.0.1'));
     $msg = 'Blockade\\Driver\\FailDriver threw Blockade\\Exception\\AuthorizationException with message "Access denied" from ip 127.0.0.1 on page /foo';
     $this->logger->expects($this->once())->method('log')->with(LogLevel::NOTICE, $msg);
     $this->resolver->onException($exception, $request);
 }
 public function testOnKernelException()
 {
     $driver = new FailDriver();
     $exception = AuthorizationException::from($driver);
     $request = new Request();
     $response = new Response();
     $resolver = $this->newResolver();
     $this->listener->addResolver($resolver);
     $resolver->expects($this->once())->method('supportsDriver')->with($driver)->will($this->returnValue(true));
     $resolver->expects($this->once())->method('supportsException')->with($exception)->will($this->returnValue(true));
     $resolver->expects($this->once())->method('onException')->with($exception, $request)->will($this->returnValue($response));
     $kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')->disableOriginalConstructor()->getMock();
     $event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $exception);
     $this->assertFalse($event->hasResponse());
     $this->listener->onKernelException($event);
     $this->assertTrue($event->hasResponse());
 }
Пример #3
0
 protected function failAuthorization(Request $request, $permission)
 {
     $message = sprintf('Firewall %s blocked url %s - permission %s', $this->name, $request->getUri(), $permission);
     throw AuthorizationException::from($this->security, $message);
 }