aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
diff options
context:
space:
mode:
authorAurélien Tamisier <virtualtam+github@flibidi.net>2019-01-18 21:26:03 +0100
committerGitHub <noreply@github.com>2019-01-18 21:26:03 +0100
commitff3b5dc5542ec150f0d9b447394364a15e9156d0 (patch)
tree5e926e36816d510e3b3a10e20b94c23f43b55092 /tests/http/HttpUtils/GetIpAdressFromProxyTest.php
parent1826e383ecf501302974132fd443cf1ca06e10f6 (diff)
parentdea72c711ff740b3b829d238fcf85648465143a0 (diff)
downloadShaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.gz
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.zst
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.zip
Merge pull request #1248 from virtualtam/refactor/namespacing
Ensure all PHP classes are properly namespaced
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}