public matchRequest ( Neos\Flow\Mvc\RequestInterface $request ) : boolean | ||
$request | Neos\Flow\Mvc\RequestInterface | The request that should be matched |
return | boolean | TRUE if the pattern matched, FALSE otherwise |
public function matchRequest(RequestInterface $request)
{
if (!isset($this->options['cidrPattern'])) {
throw new InvalidRequestPatternException('Missing option "cidrPattern" in the Ip request pattern configuration', 1446224520);
}
if (!$request instanceof ActionRequest) {
return false;
}
return (bool) IpUtility::cidrMatch($request->getHttpRequest()->getClientIpAddress(), $this->options['cidrPattern']);
}
/** * @dataProvider validAndInvalidIpPatterns * @test */ public function requestMatchingBasicallyWorks($pattern, $ip, $expected) { $requestMock = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->setMethods(array('getClientIpAddress'))->getMock(); $requestMock->expects($this->once())->method('getClientIpAddress')->will($this->returnValue($ip)); $actionRequestMock = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); $actionRequestMock->expects($this->any())->method('getHttpRequest')->will($this->returnValue($requestMock)); $requestPattern = new Ip(['cidrPattern' => $pattern]); $this->assertEquals($expected, $requestPattern->matchRequest($actionRequestMock)); }