From 0fc46caedd690b05141a0b80bc5d7bca9b72b61b Mon Sep 17 00:00:00 2001 From: Heesung Ahn Date: Wed, 18 Mar 2015 18:49:22 -0400 Subject: Updated CI_Input unit test and fixed error "undefined offset" caused by using the same variable name, $i, twice for for loop inside for loop. Signed-off-by:Heesung Ahn --- tests/codeigniter/core/Input_test.php | 61 ++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 5 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 159a877dc..a632ee689 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -206,9 +206,23 @@ 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() { + //TODO: Find a way to test HTTP headers + $this->assertNull($this->input->get_request_header('test')); + } + + // -------------------------------------------------------------------- + + public function test_ip_address() + { + $this->input->ip_address = TRUE; + $this->assertTrue($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 +230,46 @@ 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.1/1'); + $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.2'; + $this->assertNotEquals('127.0.0.1', $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 -- cgit v1.2.3-24-g4f1b From c44a656649ca4d198f29ea1f07fe0174ce832ccc Mon Sep 17 00:00:00 2001 From: Heesung Ahn Date: Wed, 18 Mar 2015 19:12:27 -0400 Subject: minor update Signed-off-by:Heesung Ahn --- tests/codeigniter/core/Input_test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index a632ee689..e269b1762 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -250,9 +250,10 @@ class Input_test extends CI_TestCase { $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'); + $this->ci_set_config('proxy_ips', 'http://foo/bar/baz, 127.0.0.2'); $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.2'; - $this->assertNotEquals('127.0.0.1', $this->input->ip_address()); + $_SERVER['REMOTE_ADDR'] = '127.0.0.2'; + $this->assertEquals('127.0.0.2', $this->input->ip_address()); //IPv6 $this->input->ip_address = FALSE; -- cgit v1.2.3-24-g4f1b From 78978b2a53692ebf8070d1cb96ad4c1609e12329 Mon Sep 17 00:00:00 2001 From: Heesung Ahn Date: Thu, 19 Mar 2015 10:32:36 -0400 Subject: updated based on comment Signed-off-by:Heesung Ahn --- tests/codeigniter/core/Input_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index e269b1762..e6122cabc 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -210,8 +210,7 @@ class Input_test extends CI_TestCase { public function test_get_request_header() { - //TODO: Find a way to test HTTP headers - $this->assertNull($this->input->get_request_header('test')); + $this->markTestSkipped('TODO: Find a way to test HTTP headers'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 46a67d33388b4b79397f8f48ab39fcc2fdf8ea73 Mon Sep 17 00:00:00 2001 From: Heesung Ahn Date: Fri, 20 Mar 2015 09:22:01 -0400 Subject: updated based on comment Signed-off-by:Heesung Ahn --- tests/codeigniter/core/Input_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index e6122cabc..d644d7fc7 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -217,8 +217,8 @@ class Input_test extends CI_TestCase { public function test_ip_address() { - $this->input->ip_address = TRUE; - $this->assertTrue($this->input->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; -- cgit v1.2.3-24-g4f1b