summaryrefslogtreecommitdiff
path: root/_test/cases/inc/common_clientip.test.php
diff options
context:
space:
mode:
authorchris <chris@jalakai.co.uk>2006-08-04 16:22:43 +0200
committerchris <chris@jalakai.co.uk>2006-08-04 16:22:43 +0200
commit03c4aec3c817c51eda2cf5c241f76e3bef585799 (patch)
treedf6e92a9b73f0ff360fc3c44c0e0c8426809ee97 /_test/cases/inc/common_clientip.test.php
parentac900efc10a9139823163ed90870a7595d726f9f (diff)
downloadrpg-03c4aec3c817c51eda2cf5c241f76e3bef585799.tar.gz
rpg-03c4aec3c817c51eda2cf5c241f76e3bef585799.tar.bz2
unittest fixes
darcs-hash:20060804142243-9b6ab-d208f7f1a67a9958fda05c519c8407ad5e733cea.gz
Diffstat (limited to '_test/cases/inc/common_clientip.test.php')
-rw-r--r--_test/cases/inc/common_clientip.test.php147
1 files changed, 147 insertions, 0 deletions
diff --git a/_test/cases/inc/common_clientip.test.php b/_test/cases/inc/common_clientip.test.php
new file mode 100644
index 000000000..257229811
--- /dev/null
+++ b/_test/cases/inc/common_clientip.test.php
@@ -0,0 +1,147 @@
+<?php
+
+require_once DOKU_INC.'inc/init.php';
+require_once DOKU_INC.'inc/common.php';
+
+class common_clientIP_test extends UnitTestCase {
+
+ function test_simple_all(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '';
+ $out = '123.123.123.123';
+ $this->assertEqual(clientIP(),$out);
+ }
+
+ function test_proxy1_all(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '77.77.77.77';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '';
+ $out = '123.123.123.123,77.77.77.77';
+ $this->assertEqual(clientIP(),$out);
+ }
+
+ function test_proxy2_all(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77';
+ $out = '123.123.123.123,77.77.77.77';
+ $this->assertEqual(clientIP(),$out);
+ }
+
+ function test_proxyhops_all(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77,66.66.66.66';
+ $out = '123.123.123.123,77.77.77.77,66.66.66.66';
+ $this->assertEqual(clientIP(),$out);
+ }
+
+ function test_simple_single(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '';
+ $out = '123.123.123.123';
+ $this->assertEqual(clientIP(true),$out);
+ }
+
+ function test_proxy1_single(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '77.77.77.77';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '';
+ $out = '77.77.77.77';
+ $this->assertEqual(clientIP(true),$out);
+ }
+
+ function test_proxy2_single(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77';
+ $out = '77.77.77.77';
+ $this->assertEqual(clientIP(true),$out);
+ }
+
+ function test_proxyhops_single(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '77.77.77.77,66.66.66.66';
+ $out = '66.66.66.66';
+ $this->assertEqual(clientIP(true),$out);
+ }
+
+ function test_local_all(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1';
+ $out = '123.123.123.123,127.0.0.1';
+ $this->assertEqual(clientIP(),$out);
+ }
+
+ function test_local1_single(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1';
+ $out = '123.123.123.123';
+ $this->assertEqual(clientIP(true),$out);
+ }
+
+ function test_local2_single(){
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '123.123.123.123';
+ $out = '123.123.123.123';
+ $this->assertEqual(clientIP(true),$out);
+ }
+
+ function test_local3_single(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,10.0.0.1,192.168.0.2,172.17.1.1,172.21.1.1,172.31.1.1';
+ $out = '123.123.123.123';
+ $this->assertEqual(clientIP(true),$out);
+ }
+
+ function test_local4_single(){
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.0.5';
+ $out = '192.168.0.5';
+ $this->assertEqual(clientIP(true),$out);
+ }
+
+ function test_garbage_all(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222';
+ $out = '123.123.123.123';
+ $this->assertEqual(clientIP(),$out);
+ }
+
+ function test_garbage_single(){
+ $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222';
+ $out = '123.123.123.123';
+ $this->assertEqual(clientIP(true),$out);
+ }
+
+ function test_garbageonly_all(){
+ $_SERVER['REMOTE_ADDR'] = 'argh';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222';
+ $out = '0.0.0.0';
+ $this->assertEqual(clientIP(),$out);
+ }
+
+ function test_garbageonly_single(){
+ $_SERVER['REMOTE_ADDR'] = 'argh';
+ $_SERVER['HTTP_X_REAL_IP'] = '';
+ $_SERVER['HTTP_X_FORWARDED_FOR'] = 'some garbage, or something, 222';
+ $out = '0.0.0.0';
+ $this->assertEqual(clientIP(true),$out);
+ }
+
+
+}
+
+//Setup VIM: ex: et ts=4 enc=utf-8 :