]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/HttpUtils/GetIpAdressFromProxyTest.php
Merge pull request #1234 from virtualtam/lint
[github/shaarli/Shaarli.git] / tests / HttpUtils / GetIpAdressFromProxyTest.php
1 <?php
2
3 require_once 'application/HttpUtils.php';
4
5 /**
6 * Unitary tests for getIpAddressFromProxy()
7 */
8 class GetIpAdressFromProxyTest extends PHPUnit_Framework_TestCase
9 {
10
11 /**
12 * Test without proxy
13 */
14 public function testWithoutProxy()
15 {
16 $this->assertFalse(getIpAddressFromProxy(array(), array()));
17 }
18
19 /**
20 * Test with a single IP in proxy header.
21 */
22 public function testWithOneForwardedIp()
23 {
24 $ip = '1.1.1.1';
25 $server = array('HTTP_X_FORWARDED_FOR' => $ip);
26 $this->assertEquals($ip, getIpAddressFromProxy($server, array()));
27 }
28
29 /**
30 * Test with a multiple IPs in proxy header.
31 */
32 public function testWithMultipleForwardedIp()
33 {
34 $ip = '1.1.1.1';
35 $ip2 = '2.2.2.2';
36
37 $server = array('HTTP_X_FORWARDED_FOR' => $ip .','. $ip2);
38 $this->assertEquals($ip2, getIpAddressFromProxy($server, array()));
39
40 $server = array('HTTP_X_FORWARDED_FOR' => $ip .' , '. $ip2);
41 $this->assertEquals($ip2, getIpAddressFromProxy($server, array()));
42 }
43
44 /**
45 * Test with a trusted IP address.
46 */
47 public function testWithTrustedIp()
48 {
49 $ip = '1.1.1.1';
50 $ip2 = '2.2.2.2';
51
52 $server = array('HTTP_X_FORWARDED_FOR' => $ip);
53 $this->assertFalse(getIpAddressFromProxy($server, array($ip)));
54
55 $server = array('HTTP_X_FORWARDED_FOR' => $ip .','. $ip2);
56 $this->assertEquals($ip2, getIpAddressFromProxy($server, array($ip)));
57 $this->assertFalse(getIpAddressFromProxy($server, array($ip, $ip2)));
58 }
59 }