]>
Commit | Line | Data |
---|---|---|
88110550 V |
1 | <?php |
2 | /** | |
3 | * HttpUtils' tests | |
4 | */ | |
5 | ||
51753e40 V |
6 | namespace Shaarli\Http; |
7 | ||
8 | require_once 'application/http/HttpUtils.php'; | |
88110550 V |
9 | |
10 | /** | |
11 | * Unitary tests for client_ip_id() | |
12 | */ | |
a5a9cf23 | 13 | class ClientIpIdTest extends \Shaarli\TestCase |
88110550 V |
14 | { |
15 | /** | |
16 | * Get a remote client ID based on its IP | |
17 | */ | |
18 | public function testClientIpIdRemote() | |
19 | { | |
20 | $this->assertEquals( | |
21 | '10.1.167.42', | |
22 | client_ip_id(['REMOTE_ADDR' => '10.1.167.42']) | |
23 | ); | |
24 | } | |
25 | ||
26 | /** | |
27 | * Get a remote client ID based on its IP and proxy information (1) | |
28 | */ | |
29 | public function testClientIpIdRemoteForwarded() | |
30 | { | |
31 | $this->assertEquals( | |
32 | '10.1.167.42_127.0.1.47', | |
33 | client_ip_id([ | |
34 | 'REMOTE_ADDR' => '10.1.167.42', | |
35 | 'HTTP_X_FORWARDED_FOR' => '127.0.1.47' | |
36 | ]) | |
37 | ); | |
38 | } | |
39 | ||
40 | /** | |
41 | * Get a remote client ID based on its IP and proxy information (2) | |
42 | */ | |
43 | public function testClientIpIdRemoteForwardedClient() | |
44 | { | |
45 | $this->assertEquals( | |
46 | '10.1.167.42_10.1.167.56_127.0.1.47', | |
47 | client_ip_id([ | |
48 | 'REMOTE_ADDR' => '10.1.167.42', | |
49 | 'HTTP_X_FORWARDED_FOR' => '10.1.167.56', | |
50 | 'HTTP_CLIENT_IP' => '127.0.1.47' | |
51 | ]) | |
52 | ); | |
53 | } | |
54 | } |