1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Bouncer package. |
5
|
|
|
* |
6
|
|
|
* (c) François Hodierne <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Bouncer; |
13
|
|
|
|
14
|
|
|
use Bouncer\Request; |
15
|
|
|
|
16
|
|
|
class AddrTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
public function testGetAddr() |
20
|
|
|
{ |
21
|
|
|
$addr = '46.105.7.208'; |
22
|
|
|
|
23
|
|
|
$server = array(); |
24
|
|
|
$server['REMOTE_ADDR'] = $addr; |
25
|
|
|
|
26
|
|
|
$request = new Request; |
27
|
|
|
$request->initialize(array(), array(), array(), array(), array(), $server); |
28
|
|
|
|
29
|
|
|
$this->assertEquals($request->getAddr(), $addr); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetAddrForwarded() |
33
|
|
|
{ |
34
|
|
|
$addr = '46.105.7.208'; |
35
|
|
|
|
36
|
|
|
$server = array(); |
37
|
|
|
$server['REMOTE_ADDR'] = '127.0.0.1'; |
38
|
|
|
$server['HTTP_X_FORWARDED_FOR'] = $addr; |
39
|
|
|
|
40
|
|
|
Request::setTrustedProxies(array('127.0.0.1')); |
41
|
|
|
|
42
|
|
|
$request = new Request; |
43
|
|
|
$request->initialize(array(), array(), array(), array(), array(), $server); |
44
|
|
|
|
45
|
|
|
$this->assertEquals($request->getAddr(), $addr); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testGetAddrForwardedNotTrusted() |
49
|
|
|
{ |
50
|
|
|
$addr = '46.105.7.208'; |
51
|
|
|
|
52
|
|
|
$server = array(); |
53
|
|
|
$server['REMOTE_ADDR'] = '127.0.0.1'; |
54
|
|
|
$server['HTTP_X_FORWARDED_FOR'] = $addr; |
55
|
|
|
|
56
|
|
|
Request::setTrustedProxies(array()); |
57
|
|
|
|
58
|
|
|
$request = new Request; |
59
|
|
|
$request->initialize(array(), array(), array(), array(), array(), $server); |
60
|
|
|
|
61
|
|
|
$this->assertNotEquals($request->getAddr(), $addr); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|