aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2018-12-03 00:34:53 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-01-12 22:47:48 +0100
commit51753e403fa69c0ce124ede27d300477e3e799ca (patch)
tree0afe2a84598648b49cc53bb3e8640569ac370240 /tests/http/HttpUtils/GetIpAdressFromProxyTest.php
parentfb1b182fbf0ee5afed586f77eec84d7a906831ef (diff)
downloadShaarli-51753e403fa69c0ce124ede27d300477e3e799ca.tar.gz
Shaarli-51753e403fa69c0ce124ede27d300477e3e799ca.tar.zst
Shaarli-51753e403fa69c0ce124ede27d300477e3e799ca.zip
namespacing: move HTTP utilities along \Shaarli\Http\ classes
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/http/HttpUtils/GetIpAdressFromProxyTest.php')
-rw-r--r--tests/http/HttpUtils/GetIpAdressFromProxyTest.php61
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
3namespace Shaarli\Http;
4
5require_once 'application/http/HttpUtils.php';
6
7/**
8 * Unitary tests for getIpAddressFromProxy()
9 */
10class 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}