Completed
Push — master ( 6a6e14...e9047f )
by Julián
02:21
created

IPTest::testBadProxyIp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Effortless maintenance management (http://juliangut.com/janitor)
4
 *
5
 * @link https://github.com/juliangut/janitor for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/janitor/blob/master/LICENSE
8
 */
9
10
namespace Janitor\Test\Excluder;
11
12
use Janitor\Excluder\IP;
13
use Zend\Diactoros\ServerRequestFactory;
14
15
/**
16
 * Class IPTest
17
 */
18
class IPTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @var array
22
     */
23
    protected $excludedIPs = [
24
        '98.139.183.24',
25
        '74.125.230.5',
26
        '204.79.197.200',
27
    ];
28
29
    public function testCreation()
30
    {
31
        $excluder = new IP;
32
        self::assertFalse($excluder->isExcluded(ServerRequestFactory::fromGlobals()));
33
    }
34
35
    /**
36
     * @expectedException \InvalidArgumentException
37
     */
38
    public function testBadIp()
39
    {
40
        new IP(['invalidIP']);
41
    }
42
43
    /**
44
     * @expectedException \InvalidArgumentException
45
     */
46
    public function testBadProxyIp()
47
    {
48
        new IP(null, 'badIp');
49
    }
50
51
    public function testIsExcluded()
52
    {
53
        $request = ServerRequestFactory::fromGlobals(['REMOTE_ADDR' => '74.125.230.5']);
54
        $request = $request->withHeader('Client-Ip', '74.125.230.5');
55
        $excluder = new IP($this->excludedIPs);
56
57
        self::assertTrue($excluder->isExcluded($request));
58
    }
59
60
    public function testIsNotExcluded()
61
    {
62
        $request = ServerRequestFactory::fromGlobals();
63
        $request = $request->withHeader('X-Forwarded', '80.80.80.80');
64
        $excluder = new IP($this->excludedIPs, ['10.10.10.10']);
65
66
        self::assertFalse($excluder->isExcluded($request));
67
    }
68
}
69