|
@@ 37-48 (lines=12) @@
|
| 34 |
|
Assert::assertNull($middleware->getIpAddress()); |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
public function testXForwardedForIp() |
| 38 |
|
{ |
| 39 |
|
$middleware = new IpAddress(['192.168.1.1']); |
| 40 |
|
|
| 41 |
|
$request = ServerRequestFactory::fromGlobals([ |
| 42 |
|
'REMOTE_ADDR' => '192.168.1.1', |
| 43 |
|
'HTTP_X_FORWARDED_FOR' => '192.168.1.3, 192.168.1.2, 192.168.1.1' |
| 44 |
|
]); |
| 45 |
|
$this->runRequest($middleware, $request); |
| 46 |
|
|
| 47 |
|
Assert::assertSame('192.168.1.3', $middleware->getIpAddress()); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
public function testProxyIpIsIgnored() |
| 51 |
|
{ |
|
@@ 50-61 (lines=12) @@
|
| 47 |
|
Assert::assertSame('192.168.1.3', $middleware->getIpAddress()); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
public function testProxyIpIsIgnored() |
| 51 |
|
{ |
| 52 |
|
$middleware = new IpAddress(); |
| 53 |
|
|
| 54 |
|
$request = ServerRequestFactory::fromGlobals([ |
| 55 |
|
'REMOTE_ADDR' => '192.168.0.1', |
| 56 |
|
'HTTP_X_FORWARDED_FOR' => '192.168.1.3, 192.168.1.2, 192.168.1.1' |
| 57 |
|
]); |
| 58 |
|
$this->runRequest($middleware, $request); |
| 59 |
|
|
| 60 |
|
Assert::assertSame('192.168.0.1', $middleware->getIpAddress()); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
public function testHttpClientIp() |
| 64 |
|
{ |
|
@@ 63-74 (lines=12) @@
|
| 60 |
|
Assert::assertSame('192.168.0.1', $middleware->getIpAddress()); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
public function testHttpClientIp() |
| 64 |
|
{ |
| 65 |
|
$middleware = new IpAddress(['192.168.1.1']); |
| 66 |
|
|
| 67 |
|
$request = ServerRequestFactory::fromGlobals([ |
| 68 |
|
'REMOTE_ADDR' => '192.168.1.1', |
| 69 |
|
'HTTP_CLIENT_IP' => '192.168.1.3' |
| 70 |
|
]); |
| 71 |
|
$this->runRequest($middleware, $request); |
| 72 |
|
|
| 73 |
|
Assert::assertSame('192.168.1.3', $middleware->getIpAddress()); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
public function testXForwardedForIpV6() |
| 77 |
|
{ |
|
@@ 76-87 (lines=12) @@
|
| 73 |
|
Assert::assertSame('192.168.1.3', $middleware->getIpAddress()); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
public function testXForwardedForIpV6() |
| 77 |
|
{ |
| 78 |
|
$middleware = new IpAddress(['192.168.1.1']); |
| 79 |
|
|
| 80 |
|
$request = ServerRequestFactory::fromGlobals([ |
| 81 |
|
'REMOTE_ADDR' => '192.168.1.1', |
| 82 |
|
'HTTP_X_FORWARDED_FOR' => '001:DB8::21f:5bff:febf:ce22:8a2e' |
| 83 |
|
]); |
| 84 |
|
$this->runRequest($middleware, $request); |
| 85 |
|
|
| 86 |
|
Assert::assertSame('001:DB8::21f:5bff:febf:ce22:8a2e', $middleware->getIpAddress()); |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
public function testXForwardedForWithInvalidIp() |
| 90 |
|
{ |
|
@@ 89-100 (lines=12) @@
|
| 86 |
|
Assert::assertSame('001:DB8::21f:5bff:febf:ce22:8a2e', $middleware->getIpAddress()); |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
public function testXForwardedForWithInvalidIp() |
| 90 |
|
{ |
| 91 |
|
$middleware = new IpAddress(['192.168.1.1']); |
| 92 |
|
|
| 93 |
|
$request = ServerRequestFactory::fromGlobals([ |
| 94 |
|
'REMOTE_ADDR' => '192.168.1.1', |
| 95 |
|
'HTTP_X_FORWARDED_FOR' => 'foo-bar' |
| 96 |
|
]); |
| 97 |
|
$this->runRequest($middleware, $request); |
| 98 |
|
|
| 99 |
|
Assert::assertSame('192.168.1.1', $middleware->getIpAddress()); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
public function testXForwardedForIpWithTrustedProxy() |
| 103 |
|
{ |
|
@@ 102-113 (lines=12) @@
|
| 99 |
|
Assert::assertSame('192.168.1.1', $middleware->getIpAddress()); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
public function testXForwardedForIpWithTrustedProxy() |
| 103 |
|
{ |
| 104 |
|
$middleware = new IpAddress(['192.168.0.1', '192.168.0.2']); |
| 105 |
|
|
| 106 |
|
$request = ServerRequestFactory::fromGlobals([ |
| 107 |
|
'REMOTE_ADDR' => '192.168.0.2', |
| 108 |
|
'HTTP_X_FORWARDED_FOR' => '192.168.1.3, 192.168.1.2, 192.168.1.1' |
| 109 |
|
]); |
| 110 |
|
$this->runRequest($middleware, $request); |
| 111 |
|
|
| 112 |
|
Assert::assertSame('192.168.1.3', $middleware->getIpAddress()); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
public function testXForwardedForIpWithUntrustedProxy() |
| 116 |
|
{ |
|
@@ 115-126 (lines=12) @@
|
| 112 |
|
Assert::assertSame('192.168.1.3', $middleware->getIpAddress()); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
public function testXForwardedForIpWithUntrustedProxy() |
| 116 |
|
{ |
| 117 |
|
$middleware = new IpAddress(['192.168.0.1']); |
| 118 |
|
|
| 119 |
|
$request = ServerRequestFactory::fromGlobals([ |
| 120 |
|
'REMOTE_ADDR' => '192.168.0.2', |
| 121 |
|
'HTTP_X_FORWARDED_FOR' => '192.168.1.3, 192.168.1.2, 192.168.1.1' |
| 122 |
|
]); |
| 123 |
|
$this->runRequest($middleware, $request); |
| 124 |
|
|
| 125 |
|
Assert::assertSame('192.168.0.2', $middleware->getIpAddress()); |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
public function testForwardedWithMultipleFor() |
| 129 |
|
{ |
|
@@ 128-139 (lines=12) @@
|
| 125 |
|
Assert::assertSame('192.168.0.2', $middleware->getIpAddress()); |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
public function testForwardedWithMultipleFor() |
| 129 |
|
{ |
| 130 |
|
$middleware = new IpAddress(['192.168.1.1']); |
| 131 |
|
|
| 132 |
|
$request = ServerRequestFactory::fromGlobals([ |
| 133 |
|
'REMOTE_ADDR' => '192.168.1.1', |
| 134 |
|
'HTTP_FORWARDED' => 'for=192.0.2.43, for=198.51.100.17;by=203.0.113.60;proto=http;host=example.com', |
| 135 |
|
]); |
| 136 |
|
$this->runRequest($middleware, $request); |
| 137 |
|
|
| 138 |
|
Assert::assertSame('192.0.2.43', $middleware->getIpAddress()); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
public function testForwardedWithAllOptions() |
| 142 |
|
{ |
|
@@ 141-152 (lines=12) @@
|
| 138 |
|
Assert::assertSame('192.0.2.43', $middleware->getIpAddress()); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
public function testForwardedWithAllOptions() |
| 142 |
|
{ |
| 143 |
|
$middleware = new IpAddress(['192.168.1.1']); |
| 144 |
|
|
| 145 |
|
$request = ServerRequestFactory::fromGlobals([ |
| 146 |
|
'REMOTE_ADDR' => '192.168.1.1', |
| 147 |
|
'HTTP_FORWARDED' => 'for=192.0.2.60; proto=http;by=203.0.113.43; host=_hiddenProxy, for=192.0.2.61', |
| 148 |
|
]); |
| 149 |
|
$this->runRequest($middleware, $request); |
| 150 |
|
|
| 151 |
|
Assert::assertSame('192.0.2.60', $middleware->getIpAddress()); |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
public function testForwardedWithWithIpV6() |
| 155 |
|
{ |
|
@@ 154-165 (lines=12) @@
|
| 151 |
|
Assert::assertSame('192.0.2.60', $middleware->getIpAddress()); |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
public function testForwardedWithWithIpV6() |
| 155 |
|
{ |
| 156 |
|
$middleware = new IpAddress(['192.168.1.1']); |
| 157 |
|
|
| 158 |
|
$request = ServerRequestFactory::fromGlobals([ |
| 159 |
|
'REMOTE_ADDR' => '192.168.1.1', |
| 160 |
|
'HTTP_FORWARDED' => 'For="[2001:db8:cafe::17]:4711", for=_internalProxy', |
| 161 |
|
]); |
| 162 |
|
$this->runRequest($middleware, $request); |
| 163 |
|
|
| 164 |
|
Assert::assertSame('2001:db8:cafe::17', $middleware->getIpAddress()); |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
public function testCustomHeader() |
| 168 |
|
{ |