<commit_before><?php

require_once dirname( __DIR__ ) . '/src/CEnv.php';
require_once dirname( __DIR__ ) . '/src/CLib.php';

use dekuan\delib;


/**
 * Created by PhpStorm.
 * User: xing
 * Date: 17/02/2017
 * Time: 12:49 AM
 */
class test extends PHPUnit_Framework_TestCase
{
	public function testGetClientIP()
	{
		$arrVarList	=
		[
			[ true,	true,	'HTTP_VDATA_FORWARDED_FOR', '172.16.31.10,172.16.31.10', '172.16.31.10' ],
			[ true,	false,	'HTTP_VDATA_FORWARDED_FOR', '172.16.31.10,172.16.31.10', '' ],
			[ false, true,	'HTTP_VDATA_FORWARDED_FOR', '172.16.31.10,172.16.31.10', '172.16.31.10' ],
			[ false, false,	'HTTP_VDATA_FORWARDED_FOR', '172.16.31.10,172.16.31.10', '' ],

			[ true,	true,	'REMOTE_ADDR', '172.16.58.3', '172.16.58.3' ],
			[ true,	false,	'REMOTE_ADDR', '172.16.58.3', '172.16.58.3' ],
			[ false, true,	'REMOTE_ADDR', '172.16.58.3', '172.16.58.3' ],
			[ false, false,	'REMOTE_ADDR', '172.16.58.3', '172.16.58.3' ],

			[ true,	true,	'HTTP_X_TRUE_IP', '192.168.127.12', '192.168.127.12' ],
			[ true,	false,	'HTTP_X_TRUE_IP', '192.168.127.12', '192.168.127.12' ],
			[ false, true,	'HTTP_X_TRUE_IP', '192.168.127.12', '192.168.127.12' ],
			[ false, false,	'HTTP_X_TRUE_IP', '192.168.127.12', '192.168.127.12' ],

			[ true,	true,	'HTTP_X_FORWARDED_FOR', '172.16.58.3,172.16.58.3', '172.16.58.3' ],
			[ true,	false,	'HTTP_X_FORWARDED_FOR', '172.16.58.3,172.16.58.3', '' ],
			[ false, true,	'HTTP_X_FORWARDED_FOR', '172.16.58.3,172.16.58.3', '172.16.58.3' ],
			[ false, false,	'HTTP_X_FORWARDED_FOR', '172.16.58.3,172.16.58.3', '' ],
		];

		foreach ( $arrVarList as $arrData )
		{
			$bMustBePublic	= $arrData[ 0 ];
			$bPlayWithProxy	= $arrData[ 1 ];
			$sKey		= $arrData[ 2 ];
			$sValue		= $arrData[ 3 ];
			$sExpect	= $arrData[ 4 ];

			$_SERVER	=
			[
				$sKey	=> $sValue,
			];

			echo "\r\n";
			echo "+ KEY:    " . $sKey . "\r\n  VALUE:  " . $sValue . "\r\n";

			echo "  PARAM:  MustBePublic=" . ( $bMustBePublic ? "true" : "false" ) . ", ";
			echo "PlayWithProxy=" . ( $bPlayWithProxy ? "true" : "false" ) . "\r\n";
			$sClientIP	= delib\CLib::GetClientIP( $bMustBePublic, $bPlayWithProxy );
			echo "  GOT IP: \"" . $sClientIP . "\"\r\n  EXPECT: \"" . $sExpect . "\"\r\n";

			$this->assertTrue( 0 == strcasecmp( $sExpect, $sClientIP ) );
		}

		//	...
		$_SERVER	= [];

		foreach ( $arrVarList as $arrData )
		{
			$sKey		= $arrData[ 2 ];
			$sValue		= $arrData[ 3 ];

			//	...
			$_SERVER[ $sKey ] = $sValue;
		}
		unset( $_SERVER['HTTP_VDATA_FORWARDED_FOR'] );

		//	...
		$sClientIP	= delib\CLib::GetClientIP( false, true );
		echo "\r\n+ Play With Proxy=true\r\n";
		print_r( $_SERVER );
		echo "\tRESULT:\t" . $sClientIP . "\r\n";
		$this->assertTrue( 0 == strcasecmp( '192.168.127.12', $sClientIP ) );
	}
}<commit_msg>Update CLib::GetClientIP for HTTP_X_TRUE_IP unit tests<commit_after><?php

require_once dirname( __DIR__ ) . '/src/CEnv.php';
require_once dirname( __DIR__ ) . '/src/CLib.php';

use dekuan\delib;


/**
 * Created by PhpStorm.
 * User: xing
 * Date: 17/02/2017
 * Time: 12:49 AM
 */
class test extends PHPUnit_Framework_TestCase
{
	public function testGetClientIP()
	{
		$arrVarList	=
		[
			[ true,	true,	'HTTP_VDATA_FORWARDED_FOR', '172.16.31.10,172.16.31.10', '172.16.31.10' ],
			[ true,	false,	'HTTP_VDATA_FORWARDED_FOR', '172.16.31.10,172.16.31.10', '' ],
			[ false, true,	'HTTP_VDATA_FORWARDED_FOR', '172.16.31.10,172.16.31.10', '172.16.31.10' ],
			[ false, false,	'HTTP_VDATA_FORWARDED_FOR', '172.16.31.10,172.16.31.10', '' ],

			[ true,	true,	'REMOTE_ADDR', '172.16.58.3', '172.16.58.3' ],
			[ true,	false,	'REMOTE_ADDR', '172.16.58.3', '172.16.58.3' ],
			[ false, true,	'REMOTE_ADDR', '172.16.58.3', '172.16.58.3' ],
			[ false, false,	'REMOTE_ADDR', '172.16.58.3', '172.16.58.3' ],

			[ true,	true,	'HTTP_X_TRUE_IP', '172.16.31.10, 172.16.58.3', '172.16.31.10' ],
			[ true,	false,	'HTTP_X_TRUE_IP', '172.16.31.10, 172.16.58.3', '172.16.31.10' ],
			[ false, true,	'HTTP_X_TRUE_IP', '172.16.31.10, 172.16.58.3', '172.16.31.10' ],
			[ false, false,	'HTTP_X_TRUE_IP', '172.16.31.10, 172.16.58.3', '172.16.31.10' ],

			[ true,	true,	'HTTP_X_FORWARDED_FOR', '172.16.58.3,172.16.58.3', '172.16.58.3' ],
			[ true,	false,	'HTTP_X_FORWARDED_FOR', '172.16.58.3,172.16.58.3', '' ],
			[ false, true,	'HTTP_X_FORWARDED_FOR', '172.16.58.3,172.16.58.3', '172.16.58.3' ],
			[ false, false,	'HTTP_X_FORWARDED_FOR', '172.16.58.3,172.16.58.3', '' ],
		];

		foreach ( $arrVarList as $arrData )
		{
			$bMustBePublic	= $arrData[ 0 ];
			$bPlayWithProxy	= $arrData[ 1 ];
			$sKey		= $arrData[ 2 ];
			$sValue		= $arrData[ 3 ];
			$sExpect	= $arrData[ 4 ];

			$_SERVER	=
			[
				$sKey	=> $sValue,
			];

			echo "\r\n";
			echo "+ KEY:    " . $sKey . "\r\n  VALUE:  " . $sValue . "\r\n";

			echo "  PARAM:  MustBePublic=" . ( $bMustBePublic ? "true" : "false" ) . ", ";
			echo "PlayWithProxy=" . ( $bPlayWithProxy ? "true" : "false" ) . "\r\n";
			$sClientIP	= delib\CLib::GetClientIP( $bMustBePublic, $bPlayWithProxy );
			echo "  GOT IP: \"" . $sClientIP . "\"\r\n  EXPECT: \"" . $sExpect . "\"\r\n";

			$this->assertTrue( 0 == strcasecmp( $sExpect, $sClientIP ) );
		}

		//	...
		$_SERVER	= [];

		foreach ( $arrVarList as $arrData )
		{
			$sKey		= $arrData[ 2 ];
			$sValue		= $arrData[ 3 ];

			//	...
			$_SERVER[ $sKey ] = $sValue;
		}
		unset( $_SERVER['HTTP_VDATA_FORWARDED_FOR'] );

		//	...
		$sClientIP	= delib\CLib::GetClientIP( false, true );
		echo "\r\n+ Play With Proxy=true\r\n";
		print_r( $_SERVER );
		echo "\tRESULT:\t" . $sClientIP . "\r\n";
		$this->assertTrue( 0 == strcasecmp( '172.16.31.10', $sClientIP ) );
	}
}
{'fraction_non_alphanumeric': 0.23144027060708564, 'fraction_numerical': 0.12853836567562757, 'mean_word_length': 2.973125884016973, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 78, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '68238', 'n_tokens_mistral': 3229, 'n_tokens_neox': 2595, 'n_words': 411}