Skip to content

Commit

Permalink
Merge branch 'batumibiz-master'
Browse files Browse the repository at this point in the history
Closes #9
  • Loading branch information
akrabat committed Feb 18, 2018
2 parents 832687b + e2f7e5d commit 558ae43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
12 changes: 4 additions & 8 deletions src/IpAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,10 @@ protected function determineClientIpAddress($request)
$ipAddress = $serverParams['REMOTE_ADDR'];
}

$checkProxyHeaders = $this->checkProxyHeaders;
if ($checkProxyHeaders && !empty($this->trustedProxies)) {
if (!in_array($ipAddress, $this->trustedProxies)) {
$checkProxyHeaders = false;
}
}

if ($checkProxyHeaders) {
if ($this->checkProxyHeaders
&& !empty($this->trustedProxies)
&& in_array($ipAddress, $this->trustedProxies)
) {
foreach ($this->headersToInspect as $header) {
if ($request->hasHeader($header)) {
$ip = $this->getFirstIpAddressFromHeader($request, $header);
Expand Down
16 changes: 8 additions & 8 deletions tests/IpAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testIpIsNullIfMissing()

public function testXForwardedForIp()
{
$middleware = new IPAddress(true);
$middleware = new IPAddress(true, ['192.168.1.1']);

$request = ServerRequestFactory::fromGlobals([
'REMOTE_ADDR' => '192.168.1.1',
Expand Down Expand Up @@ -88,7 +88,7 @@ public function testProxyIpIsIgnored()

public function testHttpClientIp()
{
$middleware = new IPAddress(true);
$middleware = new IPAddress(true, ['192.168.1.1']);

$request = ServerRequestFactory::fromGlobals([
'REMOTE_ADDR' => '192.168.1.1',
Expand All @@ -108,7 +108,7 @@ public function testHttpClientIp()

public function testXForwardedForIpV6()
{
$middleware = new IPAddress(true);
$middleware = new IPAddress(true, ['192.168.1.1']);

$request = ServerRequestFactory::fromGlobals([
'REMOTE_ADDR' => '192.168.1.1',
Expand All @@ -128,7 +128,7 @@ public function testXForwardedForIpV6()

public function testXForwardedForWithInvalidIp()
{
$middleware = new IPAddress(true);
$middleware = new IPAddress(true, ['192.168.1.1']);

$request = ServerRequestFactory::fromGlobals([
'REMOTE_ADDR' => '192.168.1.1',
Expand Down Expand Up @@ -188,7 +188,7 @@ public function testXForwardedForIpWithUntrustedProxy()

public function testForwardedWithMultipleFor()
{
$middleware = new IPAddress(true);
$middleware = new IPAddress(true, ['192.168.1.1']);

$request = ServerRequestFactory::fromGlobals([
'REMOTE_ADDR' => '192.168.1.1',
Expand All @@ -208,7 +208,7 @@ public function testForwardedWithMultipleFor()

public function testForwardedWithAllOptions()
{
$middleware = new IPAddress(true);
$middleware = new IPAddress(true, ['192.168.1.1']);

$request = ServerRequestFactory::fromGlobals([
'REMOTE_ADDR' => '192.168.1.1',
Expand All @@ -228,7 +228,7 @@ public function testForwardedWithAllOptions()

public function testForwardedWithWithIpV6()
{
$middleware = new IPAddress(true);
$middleware = new IPAddress(true, ['192.168.1.1']);

$request = ServerRequestFactory::fromGlobals([
'REMOTE_ADDR' => '192.168.1.1',
Expand All @@ -251,7 +251,7 @@ public function testCustomHeader()
$headersToInspect = [
'Foo-Bar'
];
$middleware = new IPAddress(true, [], null, $headersToInspect);
$middleware = new IPAddress(true, ['192.168.0.1'], null, $headersToInspect);

$request = ServerRequestFactory::fromGlobals([
'REMOTE_ADDR' => '192.168.0.1',
Expand Down

0 comments on commit 558ae43

Please sign in to comment.