diff options
author | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:30:33 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:30:33 +0200 |
commit | 1b8ed48a0d3964186f4d66d443783f4d250e7147 (patch) | |
tree | 23597f312507ba0c1b461755b9aa086106374a4d /tests/http/HttpUtils/GetIpAdressFromProxyTest.php | |
parent | 1aa24ed8d2974cda98733f74b36844b02942cc11 (diff) | |
parent | ed3365325d231e044dedc32608fde87b1b39fa34 (diff) | |
download | Shaarli-1b8ed48a0d3964186f4d66d443783f4d250e7147.tar.gz Shaarli-1b8ed48a0d3964186f4d66d443783f4d250e7147.tar.zst Shaarli-1b8ed48a0d3964186f4d66d443783f4d250e7147.zip |
Merge tag 'v0.11.0' into latest
Release v0.11.0
Diffstat (limited to 'tests/http/HttpUtils/GetIpAdressFromProxyTest.php')
-rw-r--r-- | tests/http/HttpUtils/GetIpAdressFromProxyTest.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/http/HttpUtils/GetIpAdressFromProxyTest.php b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php new file mode 100644 index 00000000..fe3a639e --- /dev/null +++ b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php | |||
@@ -0,0 +1,61 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Shaarli\Http; | ||
4 | |||
5 | require_once 'application/http/HttpUtils.php'; | ||
6 | |||
7 | /** | ||
8 | * Unitary tests for getIpAddressFromProxy() | ||
9 | */ | ||
10 | class GetIpAdressFromProxyTest extends \PHPUnit\Framework\TestCase | ||
11 | { | ||
12 | |||
13 | /** | ||
14 | * Test without proxy | ||
15 | */ | ||
16 | public function testWithoutProxy() | ||
17 | { | ||
18 | $this->assertFalse(getIpAddressFromProxy(array(), array())); | ||
19 | } | ||
20 | |||
21 | /** | ||
22 | * Test with a single IP in proxy header. | ||
23 | */ | ||
24 | public function testWithOneForwardedIp() | ||
25 | { | ||
26 | $ip = '1.1.1.1'; | ||
27 | $server = array('HTTP_X_FORWARDED_FOR' => $ip); | ||
28 | $this->assertEquals($ip, getIpAddressFromProxy($server, array())); | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * Test with a multiple IPs in proxy header. | ||
33 | */ | ||
34 | public function testWithMultipleForwardedIp() | ||
35 | { | ||
36 | $ip = '1.1.1.1'; | ||
37 | $ip2 = '2.2.2.2'; | ||
38 | |||
39 | $server = array('HTTP_X_FORWARDED_FOR' => $ip .','. $ip2); | ||
40 | $this->assertEquals($ip2, getIpAddressFromProxy($server, array())); | ||
41 | |||
42 | $server = array('HTTP_X_FORWARDED_FOR' => $ip .' , '. $ip2); | ||
43 | $this->assertEquals($ip2, getIpAddressFromProxy($server, array())); | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Test with a trusted IP address. | ||
48 | */ | ||
49 | public function testWithTrustedIp() | ||
50 | { | ||
51 | $ip = '1.1.1.1'; | ||
52 | $ip2 = '2.2.2.2'; | ||
53 | |||
54 | $server = array('HTTP_X_FORWARDED_FOR' => $ip); | ||
55 | $this->assertFalse(getIpAddressFromProxy($server, array($ip))); | ||
56 | |||
57 | $server = array('HTTP_X_FORWARDED_FOR' => $ip .','. $ip2); | ||
58 | $this->assertEquals($ip2, getIpAddressFromProxy($server, array($ip))); | ||
59 | $this->assertFalse(getIpAddressFromProxy($server, array($ip, $ip2))); | ||
60 | } | ||
61 | } | ||