summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2015-03-20 14:56:05 +0100
committerAndrey Andreev <narf@devilix.net>2015-03-20 14:56:05 +0100
commita375c354432b87405671a52fdb053b48ad72313b (patch)
treec5db91b1a5a278faa656fb9299ceb509ba49ec3f /tests
parentf4cb8f9590c9d02d228b0ab67be6ac0ca51e0087 (diff)
parent46a67d33388b4b79397f8f48ab39fcc2fdf8ea73 (diff)
Merge pull request #3682 from ahnh/UnitTest_ipaddress
Updated CI_Input unit tests and fixed undefined offset error in CI_Input::ip_address()
Diffstat (limited to 'tests')
-rw-r--r--tests/codeigniter/core/Input_test.php61
1 files changed, 56 insertions, 5 deletions
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
index 159a877dc..d644d7fc7 100644
--- a/tests/codeigniter/core/Input_test.php
+++ b/tests/codeigniter/core/Input_test.php
@@ -206,9 +206,22 @@ class Input_test extends CI_TestCase {
$this->markTestSkipped('TODO: Find a way to test HTTP headers');
}
- public function test_ip_address()
+ // --------------------------------------------------------------------
+
+ public function test_get_request_header()
{
+ $this->markTestSkipped('TODO: Find a way to test HTTP headers');
+ }
+
+ // --------------------------------------------------------------------
+
+ public function test_ip_address()
+ {
+ $this->input->ip_address = '127.0.0.1';
+ $this->assertEquals('127.0.0.1', $this->input->ip_address());
+
// 127.0.0.1 is set in our Bootstrap file
+ $this->input->ip_address = FALSE;
$this->assertEquals('127.0.0.1', $this->input->ip_address());
// Invalid
@@ -216,9 +229,47 @@ class Input_test extends CI_TestCase {
$this->input->ip_address = FALSE; // reset cached value
$this->assertEquals('0.0.0.0', $this->input->ip_address());
- // TODO: Add proxy_ips tests
-
- // Back to reality
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
+
+ // Proxy_ips tests
+ $this->input->ip_address = FALSE;
+ $this->ci_set_config('proxy_ips', '127.0.0.3, 127.0.0.4, 127.0.0.2');
+ $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.2';
+ $this->assertEquals('127.0.0.1', $this->input->ip_address());
+
+ // Invalid spoof
+ $this->input->ip_address = FALSE;
+ $this->ci_set_config('proxy_ips', 'invalid_ip_address');
+ $_SERVER['HTTP_CLIENT_IP'] = 'invalid_ip_address';
+ $this->assertEquals('127.0.0.1', $this->input->ip_address());
+
+ $this->input->ip_address = FALSE;
+ $this->ci_set_config('proxy_ips', 'http://foo/bar/baz, 127.0.0.1/1');
+ $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.1';
+ $this->assertEquals('127.0.0.1', $this->input->ip_address());
+
+ $this->input->ip_address = FALSE;
+ $this->ci_set_config('proxy_ips', 'http://foo/bar/baz, 127.0.0.2');
+ $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.2';
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.2';
+ $this->assertEquals('127.0.0.2', $this->input->ip_address());
+
+ //IPv6
+ $this->input->ip_address = FALSE;
+ $this->ci_set_config('proxy_ips', 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329/1, FE80:0000:0000:0000:0202:B3FF:FE1E:8300/2');
+ $_SERVER['HTTP_CLIENT_IP'] = 'FE80:0000:0000:0000:0202:B3FF:FE1E:8300';
+ $_SERVER['REMOTE_ADDR'] = 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329';
+ $this->assertEquals('FE80:0000:0000:0000:0202:B3FF:FE1E:8300', $this->input->ip_address());
+
+ $this->input->ip_address = FALSE;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // back to reality
}
-}
+
+ // --------------------------------------------------------------------
+
+ public function test_user_agent()
+ {
+ $_SERVER['HTTP_USER_AGENT'] = 'test';
+ $this->assertEquals('test', $this->input->user_agent());
+ }
+} \ No newline at end of file