| 1 | <?php |
||
| 18 | * Class IPTest. |
||
| 19 | */ |
||
| 20 | class IPTest extends \PHPUnit_Framework_TestCase |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var array |
||
| 24 | */ |
||
| 25 | protected $excludedIPs = [ |
||
| 26 | '98.139.183.24', |
||
| 27 | '74.125.230.5', |
||
| 28 | '204.79.197.200', |
||
| 29 | ]; |
||
| 30 | |||
| 31 | public function testCreation() |
||
| 32 | { |
||
| 33 | $excluder = new IP; |
||
| 34 | self::assertFalse($excluder->isExcluded(ServerRequestFactory::fromGlobals())); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @expectedException \InvalidArgumentException |
||
| 39 | */ |
||
| 40 | public function testBadIp() |
||
| 41 | { |
||
| 42 | new IP(['invalidIP']); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @expectedException \InvalidArgumentException |
||
| 47 | */ |
||
| 48 | public function testBadProxyIp() |
||
| 49 | { |
||
| 50 | new IP(null, 'badIp'); |
||
| 51 | } |
||
| 52 | |||
| 53 | public function testIsExcluded() |
||
| 54 | { |
||
| 55 | $request = ServerRequestFactory::fromGlobals(['REMOTE_ADDR' => '74.125.230.5']); |
||
| 56 | $request = $request->withHeader('Client-Ip', '74.125.230.5'); |
||
| 57 | $excluder = new IP($this->excludedIPs); |
||
| 58 | |||
| 59 | self::assertTrue($excluder->isExcluded($request)); |
||
| 60 | } |
||
| 61 | |||
| 62 | public function testIsNotExcluded() |
||
| 63 | { |
||
| 64 | $request = ServerRequestFactory::fromGlobals(); |
||
| 65 | $request = $request->withHeader('X-Forwarded', '80.80.80.80'); |
||
| 66 | $excluder = new IP($this->excludedIPs, ['10.10.10.10']); |
||
| 67 | |||
| 68 | self::assertFalse($excluder->isExcluded($request)); |
||
| 69 | } |
||
| 71 |