RKA\Middleware\Test\RendererTest::testXForwardedForIpWithUntrustedProxy PHP Метод

testXForwardedForIpWithUntrustedProxy() публичный Метод

    public function testXForwardedForIpWithUntrustedProxy()
    {
        $middleware = new IPAddress(true, ['192.168.0.1']);
        $request = ServerRequestFactory::fromGlobals(['REMOTE_ADDR' => '192.168.0.2', 'HTTP_X_FORWARDED_FOR' => '192.168.1.3, 192.168.1.2, 192.168.1.1']);
        $response = new Response();
        $ipAddress = '123';
        $response = $middleware($request, $response, function ($request, $response) use(&$ipAddress) {
            // simply store the "ip_address" attribute in to the referenced $ipAddress
            $ipAddress = $request->getAttribute('ip_address');
            return $response;
        });
        $this->assertSame('192.168.0.2', $ipAddress);
    }