aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-13 12:07:13 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-13 12:07:13 +0200
commitd9f6275ebca035fec8331652c677981056793ccc (patch)
tree37a64baf4f0eba6b781040605965383d8aded2cc /tests/http/HttpUtils/GetIpAdressFromProxyTest.php
parent38672ba0d1c722e5d6d33a58255ceb55e9410e46 (diff)
parentd63ff87a009313141ae684ec447b902562ff6ee7 (diff)
downloadShaarli-d9f6275ebca035fec8331652c677981056793ccc.tar.gz
Shaarli-d9f6275ebca035fec8331652c677981056793ccc.tar.zst
Shaarli-d9f6275ebca035fec8331652c677981056793ccc.zip
Merge branch 'v0.11' into stablestable
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}