]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/http/HttpUtils/GetIpAdressFromProxyTest.php
3 namespace Shaarli\Http
;
5 require_once 'application/http/HttpUtils.php';
8 * Unitary tests for getIpAddressFromProxy()
10 class GetIpAdressFromProxyTest
extends \Shaarli\TestCase
16 public function testWithoutProxy()
18 $this->assertFalse(getIpAddressFromProxy(array(), array()));
22 * Test with a single IP in proxy header.
24 public function testWithOneForwardedIp()
27 $server = array('HTTP_X_FORWARDED_FOR' => $ip);
28 $this->assertEquals($ip, getIpAddressFromProxy($server, array()));
32 * Test with a multiple IPs in proxy header.
34 public function testWithMultipleForwardedIp()
39 $server = array('HTTP_X_FORWARDED_FOR' => $ip .','. $ip2);
40 $this->assertEquals($ip2, getIpAddressFromProxy($server, array()));
42 $server = array('HTTP_X_FORWARDED_FOR' => $ip .' , '. $ip2);
43 $this->assertEquals($ip2, getIpAddressFromProxy($server, array()));
47 * Test with a trusted IP address.
49 public function testWithTrustedIp()
54 $server = array('HTTP_X_FORWARDED_FOR' => $ip);
55 $this->assertFalse(getIpAddressFromProxy($server, array($ip)));
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)));