3 require_once 'application/HttpUtils.php';
6 * Unitary tests for getIpAddressFromProxy()
8 class GetIpAdressFromProxyTest
extends PHPUnit_Framework_TestCase
14 public function testWithoutProxy()
16 $this->assertFalse(getIpAddressFromProxy(array(), array()));
20 * Test with a single IP in proxy header.
22 public function testWithOneForwardedIp()
25 $server = array('HTTP_X_FORWARDED_FOR' => $ip);
26 $this->assertEquals($ip, getIpAddressFromProxy($server, array()));
30 * Test with a multiple IPs in proxy header.
32 public function testWithMultipleForwardedIp()
37 $server = array('HTTP_X_FORWARDED_FOR' => $ip .','. $ip2);
38 $this->assertEquals($ip2, getIpAddressFromProxy($server, array()));
40 $server = array('HTTP_X_FORWARDED_FOR' => $ip .' , '. $ip2);
41 $this->assertEquals($ip2, getIpAddressFromProxy($server, array()));
45 * Test with a trusted IP address.
47 public function testWithTrustedIp()
52 $server = array('HTTP_X_FORWARDED_FOR' => $ip);
53 $this->assertFalse(getIpAddressFromProxy($server, array($ip)));
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)));