| @@ 184-204 (lines=21) @@ | ||
| 181 | * Tests that we accept proxy method based on a whitelisted IP using the |
|
| 182 | * dashed range notation. |
|
| 183 | */ |
|
| 184 | public function testValidWhitelistedProxyMethodWithDashNotation() |
|
| 185 | { |
|
| 186 | $lookup = new Whip( |
|
| 187 | Whip::PROXY_HEADERS, |
|
| 188 | array( |
|
| 189 | Whip::PROXY_HEADERS => array( |
|
| 190 | IpWhitelist::IPV4 => array( |
|
| 191 | '127.0.0.0-127.0.255.255', |
|
| 192 | ), |
|
| 193 | IpWhitelist::IPV6 => array( |
|
| 194 | '::1' |
|
| 195 | ) |
|
| 196 | ) |
|
| 197 | ), |
|
| 198 | array( |
|
| 199 | 'REMOTE_ADDR' => '127.0.0.1', |
|
| 200 | 'HTTP_X_FORWARDED_FOR' => '32.32.32.32' |
|
| 201 | ) |
|
| 202 | ); |
|
| 203 | $this->assertEquals('32.32.32.32', $lookup->getIpAddress()); |
|
| 204 | } |
|
| 205 | ||
| 206 | /** |
|
| 207 | * Tests that we accept proxy method based on a whitelisted IP using the |
|
| @@ 210-230 (lines=21) @@ | ||
| 207 | * Tests that we accept proxy method based on a whitelisted IP using the |
|
| 208 | * wildcard asterix notation. |
|
| 209 | */ |
|
| 210 | public function testValidWhitelistedProxyMethodWithWildcardNotation() |
|
| 211 | { |
|
| 212 | $lookup = new Whip( |
|
| 213 | Whip::PROXY_HEADERS, |
|
| 214 | array( |
|
| 215 | Whip::PROXY_HEADERS => array( |
|
| 216 | IpWhitelist::IPV4 => array( |
|
| 217 | '127.0.*' |
|
| 218 | ), |
|
| 219 | IpWhitelist::IPV6 => array( |
|
| 220 | '::1' |
|
| 221 | ) |
|
| 222 | ) |
|
| 223 | ), |
|
| 224 | array( |
|
| 225 | 'REMOTE_ADDR' => '127.0.0.1', |
|
| 226 | 'HTTP_X_FORWARDED_FOR' => '32.32.32.32' |
|
| 227 | ) |
|
| 228 | ); |
|
| 229 | $this->assertEquals('32.32.32.32', $lookup->getIpAddress()); |
|
| 230 | } |
|
| 231 | ||
| 232 | /** |
|
| 233 | * Tests that we accept proxy method based on a whitelisted IP using the |
|
| @@ 236-256 (lines=21) @@ | ||
| 233 | * Tests that we accept proxy method based on a whitelisted IP using the |
|
| 234 | * CIDR address notation. |
|
| 235 | */ |
|
| 236 | public function testValidWhitelistedProxyMethodWithCIDRdNotation() |
|
| 237 | { |
|
| 238 | $lookup = new Whip( |
|
| 239 | Whip::PROXY_HEADERS, |
|
| 240 | array( |
|
| 241 | Whip::PROXY_HEADERS => array( |
|
| 242 | IpWhitelist::IPV4 => array( |
|
| 243 | '127.0.0.0/24' |
|
| 244 | ), |
|
| 245 | IpWhitelist::IPV6 => array( |
|
| 246 | '::1' |
|
| 247 | ) |
|
| 248 | ) |
|
| 249 | ), |
|
| 250 | array( |
|
| 251 | 'REMOTE_ADDR' => '127.0.0.1', |
|
| 252 | 'HTTP_X_FORWARDED_FOR' => '32.32.32.32' |
|
| 253 | ) |
|
| 254 | ); |
|
| 255 | $this->assertEquals('32.32.32.32', $lookup->getIpAddress()); |
|
| 256 | } |
|
| 257 | ||
| 258 | /** |
|
| 259 | * Tests that we get false if there is a valid IP in a proxy header but |
|
| @@ 262-282 (lines=21) @@ | ||
| 259 | * Tests that we get false if there is a valid IP in a proxy header but |
|
| 260 | * we reject it due to REMOTE_ADDR not being in the whitelist. |
|
| 261 | */ |
|
| 262 | public function testValidIpRejectedDueToWhitelist() |
|
| 263 | { |
|
| 264 | $lookup = new Whip( |
|
| 265 | Whip::PROXY_HEADERS, |
|
| 266 | array( |
|
| 267 | Whip::PROXY_HEADERS => array( |
|
| 268 | IpWhitelist::IPV4 => array( |
|
| 269 | '127.0.0.1/24' |
|
| 270 | ), |
|
| 271 | IpWhitelist::IPV6 => array( |
|
| 272 | '::1' |
|
| 273 | ) |
|
| 274 | ) |
|
| 275 | ), |
|
| 276 | array( |
|
| 277 | 'REMOTE_ADDR' => '24.24.24.24', |
|
| 278 | 'HTTP_X_FORWARDED_FOR' => '32.32.32.32' |
|
| 279 | ) |
|
| 280 | ); |
|
| 281 | $this->assertFalse($lookup->getIpAddress()); |
|
| 282 | } |
|
| 283 | ||
| 284 | /** |
|
| 285 | * Tests that we reject a proxy listed IPv6 address that does not fall within |
|
| @@ 379-400 (lines=22) @@ | ||
| 376 | /** |
|
| 377 | * Test a custom header with a whitelisted IP. |
|
| 378 | */ |
|
| 379 | public function testCustomHeader() |
|
| 380 | { |
|
| 381 | $lookup = new Whip( |
|
| 382 | Whip::CUSTOM_HEADERS | Whip::REMOTE_ADDR, |
|
| 383 | array( |
|
| 384 | Whip::CUSTOM_HEADERS => array( |
|
| 385 | IpWhitelist::IPV4 => array( |
|
| 386 | '127.0.0.1', |
|
| 387 | '::1' |
|
| 388 | ) |
|
| 389 | ) |
|
| 390 | ), |
|
| 391 | array( |
|
| 392 | 'REMOTE_ADDR' => '127.0.0.1', |
|
| 393 | 'HTTP_CUSTOM_SECRET_HEADER' => '32.32.32.32' |
|
| 394 | ) |
|
| 395 | ); |
|
| 396 | $this->assertEquals( |
|
| 397 | '32.32.32.32', |
|
| 398 | $lookup->addCustomHeader('HTTP_CUSTOM_SECRET_HEADER')->getIpAddress() |
|
| 399 | ); |
|
| 400 | } |
|
| 401 | ||
| 402 | /** |
|
| 403 | * Test HTTP_X_REAL_IP header. |
|