From 32e6fb1fd24cadf3464ef7ee9537d35a607acd30 Mon Sep 17 00:00:00 2001 From: alexivsn Date: Sun, 30 Aug 2020 22:00:16 +0300 Subject: [PATCH 01/24] Fix client ip extraction --- src/Utils.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Utils.php b/src/Utils.php index 18998f7..e3b8318 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -8,19 +8,18 @@ abstract class Utils { - public static function clientIpFromRequest() { - if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { - $parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); - return $parts[0]; - } - if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) { - return $_SERVER['HTTP_X_REAL_IP']; - } - if (array_key_exists('REMOTE_ADDR', $_SERVER)) { - return $_SERVER['REMOTE_ADDR']; + foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) { + if (array_key_exists($key, $_SERVER) === true) { + foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { + if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) { + return $ip; + } + } + } } + return null; } From 4f0358d7d53ad9cf04a65e6426b9c1c928d7f4a7 Mon Sep 17 00:00:00 2001 From: Amit Bourmad Date: Mon, 21 Sep 2020 16:46:19 +0300 Subject: [PATCH 02/24] Update build.yml --- .github/workflows/build.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ee50755..2a5103b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,14 +25,12 @@ jobs: status: STARTING color: warning + - uses: actions/checkout@v2 - uses: php-actions/composer@v1 - uses: nanasess/setup-php@master - uses: php-actions/phpunit@v9 - - name: Run tests - run: phpunit test/AgentTest.php && php test/SecureNativeTest.php - - name: Publish to codecov run: bash <(curl -s https://codecov.io/bash) @@ -56,4 +54,4 @@ jobs: message_id: ${{ steps.slack.outputs.message_id }} channel: github-actions status: FAILED - color: danger \ No newline at end of file + color: danger From c8f3ed0dfc9fbed2388de65eb8a3b4a6bb6c0caf Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Tue, 3 Nov 2020 11:34:12 +0200 Subject: [PATCH 03/24] Add basic structure of proxy headers --- composer.json | 2 +- src/ConfigurationManager.php | 2 ++ src/SecureNativeOptions.php | 24 +++++++++++++++++++++++- tests/ConfigurationManagerTest.php | 3 +++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8377580..b02fd4c 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ ] }, "require": { - "php": ">=7.2.0", + "php": ">=7.4", "guzzlehttp/guzzle": "^6.0", "antecedent/patchwork": "~2.0", "monolog/monolog": "2.0.2", diff --git a/src/ConfigurationManager.php b/src/ConfigurationManager.php index 1510265..c32f4ac 100644 --- a/src/ConfigurationManager.php +++ b/src/ConfigurationManager.php @@ -15,6 +15,7 @@ function getConfigMap() 'SECURENATIVE_DISABLE' => (object)['name' => 'disable', 'type' => 'boolean'], 'SECURENATIVE_LOG_LEVEL' => (object)['name' => 'logLevel', 'type' => 'string'], 'SECURENATIVE_FAILOVER_STRATEGY' => (object)['name' => 'failoverStrategy', 'type' => 'string'], + 'SECURENATIVE_PROXY_HEADERS' => (object)['name' => 'proxyHeaders', 'type' => 'array'], ]; } @@ -104,6 +105,7 @@ private static function loadConfig($configFilePath = null) $getConfigOrEnv('disable', 'SECURENATIVE_DISABLE'), $getConfigOrEnv('logLevel', 'SECURENATIVE_LOG_LEVEL'), $getConfigOrEnv('failoverStrategy', 'SECURENATIVE_FAILOVER_STRATEGY'), + $getConfigOrEnv('proxyHeaders', 'SECURENATIVE_PROXY_HEADERS'), ); } diff --git a/src/SecureNativeOptions.php b/src/SecureNativeOptions.php index 4e9da63..742fce7 100644 --- a/src/SecureNativeOptions.php +++ b/src/SecureNativeOptions.php @@ -14,6 +14,7 @@ class SecureNativeOptions private $disable; private $logLevel; private $failoverStrategy; + private $proxyHeaders; // Needed for option merging private $default = array( @@ -26,9 +27,10 @@ class SecureNativeOptions "disable" => false, "logLevel" => 'fatal', "failoverStrategy" => 'fail-open', + "proxyHeaders" => array(), ); - public function __construct($apiKey = null, $apiUrl = null, $interval = null, $maxEvents = null, $timeout = null, $autoSend = null, $disable = null, $logLevel = null, $failoverStrategy = null) + public function __construct($apiKey = null, $apiUrl = null, $interval = null, $maxEvents = null, $timeout = null, $autoSend = null, $disable = null, $logLevel = null, $failoverStrategy = null, $proxyHeaders = null) { $this->apiKey = isset($apiKey) ? $apiKey : $this->default["apiKey"]; $this->apiUrl = isset($apiUrl) ? $apiUrl : $this->default["apiUrl"]; @@ -39,6 +41,7 @@ public function __construct($apiKey = null, $apiUrl = null, $interval = null, $m $this->disable = isset($disable) ? $disable : $this->default["disable"]; $this->logLevel = isset($logLevel) ? $logLevel : $this->default["logLevel"]; $this->failoverStrategy = isset($failoverStrategy) ? $failoverStrategy : $this->default["failoverStrategy"]; + $this->proxyHeaders = isset($proxyHeaders) ? $proxyHeaders : $this->default["proxyHeaders"]; } /** @@ -203,6 +206,24 @@ public function setFailoverStrategy(string $failoverStrategy): SecureNativeOptio return $this; } + /** + * @return array + */ + public function getProxyHeaders(): array + { + return $this->proxyHeaders; + } + + /** + * @param array $proxyHeaders + * @return SecureNativeOptions + */ + public function setProxyHeaders(array $proxyHeaders): SecureNativeOptions + { + $this->proxyHeaders = $proxyHeaders; + return $this; + } + /** * Merge an existing `SecureNativeOptions` object into an existing one * @param SecureNativeOptions $options @@ -217,5 +238,6 @@ public function mergeOptions(SecureNativeOptions $options) { $options->isDisable() != $this->default["disable"] ? $this->setDisable($options->isDisable()) : null; $options->getLogLevel() != $this->default["logLevel"] ? $this->setLogLevel($options->getLogLevel()) : null; $options->getFailoverStrategy() != $this->default["failoverStrategy"] ? $this->setFailoverStrategy($options->getFailoverStrategy()) : null; + $options->getProxyHeaders() != $this->default["proxyHeaders"] ? $this->setProxyHeaders($options->getProxyHeaders()) : null; } } diff --git a/tests/ConfigurationManagerTest.php b/tests/ConfigurationManagerTest.php index c6a6d3b..b3a2278 100644 --- a/tests/ConfigurationManagerTest.php +++ b/tests/ConfigurationManagerTest.php @@ -33,6 +33,7 @@ public function testReadConfigFile() $this->assertArrayHasKey('autoSend', $arr); $this->assertArrayHasKey('disable', $arr); $this->assertArrayHasKey('logLevel', $arr); + $this->assertArrayHasKey('proxyHeaders', $arr); } public function testUnknownKeys() @@ -83,6 +84,7 @@ private function getConfigTestKeys() 'SECURENATIVE_DISABLE' => (object)['name' => 'isDisable', 'value' => false], 'SECURENATIVE_LOG_LEVEL' => (object)['name' => 'getLogLevel', 'value' => 'log'], 'SECURENATIVE_FAILOVER_STRATEGY' => (object)['name' => 'getFailoverStrategy', 'value' => 'failush'], + 'SECURENATIVE_PROXY_HEADERS' => (object)['name' => 'getProxyHeaders', 'value' => 'CF-Connecting-Ip,Some-Random-IP'], ]; } @@ -142,6 +144,7 @@ public function testEnvironmentVariablesOverride() $this->assertEquals(true, $options->isAutoSend()); $this->assertEquals(false, $options->isDisable()); $this->assertEquals("fatal", $options->getLogLevel()); + $this->assertEquals(['CF-Connecting-Ip", "Some-Random-IP'], $options->getProxyHeaders()); foreach ($testKeys as $key => $item) { // Clear env variables after test From 450efd6245844f298794f011ea01a9ea15744d68 Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Tue, 3 Nov 2020 11:36:41 +0200 Subject: [PATCH 04/24] Add basic structure of proxy headers --- src/Utils.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Utils.php b/src/Utils.php index e3b8318..8d0ecc5 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -8,18 +8,19 @@ abstract class Utils { + public static function clientIpFromRequest() { - foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) { - if (array_key_exists($key, $_SERVER) === true) { - foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { - if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) { - return $ip; - } - } - } + if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { + $parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); + return $parts[0]; + } + if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) { + return $_SERVER['HTTP_X_REAL_IP']; + } + if (array_key_exists('REMOTE_ADDR', $_SERVER)) { + return $_SERVER['REMOTE_ADDR']; } - return null; } @@ -121,4 +122,4 @@ public static function encrypt($plainText, $cipherKey) { } } -} +} \ No newline at end of file From a4e05c96a29dc58ea916d28f5ecec3f033b8b60f Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Tue, 3 Nov 2020 16:57:52 +0200 Subject: [PATCH 05/24] Wrap client from request --- .phpunit.result.cache | 1 + composer.json | 4 +++- src/SecureNative.php | 22 ++++++++-------------- src/SecureNativeContext.php | 6 +++--- src/Utils.php | 11 ++++++++++- tests/AgentTest.php | 3 ++- tests/MockUtils.php | 4 +++- 7 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..5b16f0d --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +C:37:"PHPUnit\Runner\DefaultTestResultCache":1589:{a:2:{s:7:"defects";a:13:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:4;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;}s:5:"times";a:18:{s:30:"AgentTest::testApiKeyException";d:0.007;s:18:"ApiTest::testTrack";d:0.007;s:31:"ApiTest::testTrackCustomContext";d:0.001;s:19:"ApiTest::testVerify";d:0.002;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.001;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0;s:41:"ConfigurationManagerTest::testInvalidFile";d:0;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.002;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.001;s:43:"ConfigurationManagerTest::testDefaultParams";d:0;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0;s:34:"EventManagerTest::testEventOptions";d:0;s:32:"EventManagerTest::testBuildEvent";d:0;s:30:"EventManagerTest::testSendSync";d:0.001;s:34:"EventManagerTest::testSendFailSync";d:0.003;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.001;s:31:"EventManagerTest::testSendAsync";d:0.002;}}} \ No newline at end of file diff --git a/composer.json b/composer.json index b02fd4c..c609027 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,9 @@ "guzzlehttp/guzzle": "^6.0", "antecedent/patchwork": "~2.0", "monolog/monolog": "2.0.2", - "phpunit/phpunit": "^9" + "phpunit/phpunit": "^9", + "ext-openssl": "*", + "ext-json": "*" }, "require-dev": { "php-coveralls/php-coveralls": "*" diff --git a/src/SecureNative.php b/src/SecureNative.php index 3a195bd..fc9ddfb 100644 --- a/src/SecureNative.php +++ b/src/SecureNative.php @@ -95,20 +95,6 @@ public static function flow($flowId, Array $attributes) return self::$eventManager->sendSync($event, $requestUrl); } - public static function getRequestContext() - { - return SecureNativeContext::fromRequest(); - } - - /** - * @deprecated use `getRequestContext()` instead - * @return SecureNativeContext - */ - public static function contextFromContext() - { - return SecureNativeContext::fromRequest(); - } - public static function getMiddleware() { return self::$middleware; @@ -122,6 +108,14 @@ public static function getApiKey() return self::$apiKey; } + /** + * @return SecureNativeContext + */ + public static function fromRequest() + { + return SecureNativeContext::fromRequest(self::$options); + } + /** * Destroy object after use */ diff --git a/src/SecureNativeContext.php b/src/SecureNativeContext.php index fe7ea94..47bf7e5 100644 --- a/src/SecureNativeContext.php +++ b/src/SecureNativeContext.php @@ -35,11 +35,11 @@ public function __construct($clientToken, $ip = null, $remoteIp = null, $headers $this->body = $body; } - public static function fromRequest() : SecureNativeContext + public static function fromRequest($options) : SecureNativeContext { $clientToken = Utils::cookieIdFromRequest() ? Utils::cookieIdFromRequest() : Utils::securHeaderFromRequest(); - $ip = Utils::clientIpFromRequest(); - $remoteIp = Utils::clientIpFromRequest(); + $ip = Utils::clientIpFromRequest($options); + $remoteIp = Utils::clientIpFromRequest($options); $headers = Utils::headersFromRequest(); $url = Utils::urlFromRequest(); $method = Utils::methodFromRequest(); diff --git a/src/Utils.php b/src/Utils.php index 8d0ecc5..f278368 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -9,8 +9,17 @@ abstract class Utils { - public static function clientIpFromRequest() + public static function clientIpFromRequest($options) { + if (!empty($options) && count($options->getProxyHeaders()) > 0) { + foreach ($options->getProxyHeaders() as $header) { + if (array_key_exists($header, $_SERVER)) { + $parts = explode(',', $_SERVER[$header]); + return $parts[0]; + } + } + } + if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { $parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); return $parts[0]; diff --git a/tests/AgentTest.php b/tests/AgentTest.php index ff38425..fbdaeaf 100644 --- a/tests/AgentTest.php +++ b/tests/AgentTest.php @@ -18,7 +18,8 @@ public static function initSDK() public function testApiKeyException() { - $context = SecureNativeContext::fromRequest(); + $options = new SecureNativeOptions(); + $context = SecureNative::fromRequest($options); // SecureNative::track(array( // 'event' => EventTypes::LOG_IN, diff --git a/tests/MockUtils.php b/tests/MockUtils.php index da25df9..25782f9 100644 --- a/tests/MockUtils.php +++ b/tests/MockUtils.php @@ -6,6 +6,7 @@ use GuzzleHttp\Psr7\Response; use SecureNative\sdk\EventTypes; use SecureNative\sdk\SecureNative; +use SecureNative\sdk\SecureNativeOptions; function getClient($fail = false) { @@ -27,9 +28,10 @@ function getClient($fail = false) function mock_track_object($context = null) { + $options = new SecureNativeOptions(); return array( 'event' => EventTypes::LOG_IN, - 'context' => isset($context) ? $context : SecureNative::getRequestContext(), + 'context' => isset($context) ? $context : SecureNative::fromRequest($options), 'userId' => '556595', 'userTraits' => (object)[ 'name' => 'Your name', From 880177bb27d4aaaf23a1b44b5eaca55625852552 Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Wed, 4 Nov 2020 13:10:18 +0200 Subject: [PATCH 06/24] Fix tests --- .phpunit.result.cache | 2 +- src/ConfigurationManager.php | 2 ++ tests/ConfigurationManagerTest.php | 4 ++-- tests/assets/securenative.json | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 5b16f0d..3ccdd36 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":1589:{a:2:{s:7:"defects";a:13:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:4;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;}s:5:"times";a:18:{s:30:"AgentTest::testApiKeyException";d:0.007;s:18:"ApiTest::testTrack";d:0.007;s:31:"ApiTest::testTrackCustomContext";d:0.001;s:19:"ApiTest::testVerify";d:0.002;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.001;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0;s:41:"ConfigurationManagerTest::testInvalidFile";d:0;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.002;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.001;s:43:"ConfigurationManagerTest::testDefaultParams";d:0;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0;s:34:"EventManagerTest::testEventOptions";d:0;s:32:"EventManagerTest::testBuildEvent";d:0;s:30:"EventManagerTest::testSendSync";d:0.001;s:34:"EventManagerTest::testSendFailSync";d:0.003;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.001;s:31:"EventManagerTest::testSendAsync";d:0.002;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":1593:{a:2:{s:7:"defects";a:13:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:3;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;}s:5:"times";a:18:{s:30:"AgentTest::testApiKeyException";d:0.022;s:18:"ApiTest::testTrack";d:0.013;s:31:"ApiTest::testTrackCustomContext";d:0.001;s:19:"ApiTest::testVerify";d:0.001;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.001;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0;s:40:"ConfigurationManagerTest::testLoadConfig";d:0;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.002;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.001;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0;s:34:"EventManagerTest::testEventOptions";d:0;s:32:"EventManagerTest::testBuildEvent";d:0.001;s:30:"EventManagerTest::testSendSync";d:0.002;s:34:"EventManagerTest::testSendFailSync";d:0.003;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.001;s:31:"EventManagerTest::testSendAsync";d:0.001;}}} \ No newline at end of file diff --git a/src/ConfigurationManager.php b/src/ConfigurationManager.php index c32f4ac..f3d9b55 100644 --- a/src/ConfigurationManager.php +++ b/src/ConfigurationManager.php @@ -89,6 +89,8 @@ private static function loadConfig($configFilePath = null) $envVal = intval($envVal); } else if ($type == "boolean") { $envVal = boolval($envVal); + } else if ($type == "array") { + $envVal = explode(',', $envVal); } } diff --git a/tests/ConfigurationManagerTest.php b/tests/ConfigurationManagerTest.php index b3a2278..64a0403 100644 --- a/tests/ConfigurationManagerTest.php +++ b/tests/ConfigurationManagerTest.php @@ -84,7 +84,7 @@ private function getConfigTestKeys() 'SECURENATIVE_DISABLE' => (object)['name' => 'isDisable', 'value' => false], 'SECURENATIVE_LOG_LEVEL' => (object)['name' => 'getLogLevel', 'value' => 'log'], 'SECURENATIVE_FAILOVER_STRATEGY' => (object)['name' => 'getFailoverStrategy', 'value' => 'failush'], - 'SECURENATIVE_PROXY_HEADERS' => (object)['name' => 'getProxyHeaders', 'value' => 'CF-Connecting-Ip,Some-Random-IP'], + 'SECURENATIVE_PROXY_HEADERS' => (object)['name' => 'getProxyHeaders', 'value' => 'CF-Connecting-IP,Some-Random-IP'], ]; } @@ -144,7 +144,7 @@ public function testEnvironmentVariablesOverride() $this->assertEquals(true, $options->isAutoSend()); $this->assertEquals(false, $options->isDisable()); $this->assertEquals("fatal", $options->getLogLevel()); - $this->assertEquals(['CF-Connecting-Ip", "Some-Random-IP'], $options->getProxyHeaders()); + $this->assertEquals(["CF-Connecting-IP", "Some-Random-IP"], $options->getProxyHeaders()); foreach ($testKeys as $key => $item) { // Clear env variables after test diff --git a/tests/assets/securenative.json b/tests/assets/securenative.json index ae61b07..f5559c9 100644 --- a/tests/assets/securenative.json +++ b/tests/assets/securenative.json @@ -7,5 +7,6 @@ "SECURENATIVE_TIMEOUT": 1500, "SECURENATIVE_AUTO_SEND": true, "SECURENATIVE_DISABLE": false, - "SECURENATIVE_LOG_LEVEL": "fatal" + "SECURENATIVE_LOG_LEVEL": "fatal", + "SECURENATIVE_PROXY_HEADERS": ["CF-Connecting-IP", "Some-Random-IP"] } \ No newline at end of file From dcb0bb0e5f0da9d292ea2e490bebd7e1916d8bda Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Wed, 4 Nov 2020 13:14:00 +0200 Subject: [PATCH 07/24] Update readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e27378..48fa5fb 100644 --- a/README.md +++ b/README.md @@ -161,10 +161,12 @@ SecureNative::track(array( **Example** ```php +$options = new SecureNativeOptions(); + $ver = SecureNative::verify(array( 'event' => EventTypes::VERIFY, 'userId' => '1234', - 'context' => SecureNativeContext::fromRequest(), + 'context' => SecureNative::fromRequest($options), 'userTraits' => (object)[ 'name' => 'Your Name', 'email' => 'name@gmail.com' From 1a46db4c7a8bec8c1464166470b2d3b27ad85c27 Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Wed, 4 Nov 2020 14:53:22 +0200 Subject: [PATCH 08/24] Fix tests --- .phpunit.result.cache | 2 +- build/logs/clover.xml | 658 +++++++++++++++++++++++++++++ tests/ConfigurationManagerTest.php | 1 - 3 files changed, 659 insertions(+), 2 deletions(-) create mode 100644 build/logs/clover.xml diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 3ccdd36..2abf2ed 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":1593:{a:2:{s:7:"defects";a:13:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:3;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;}s:5:"times";a:18:{s:30:"AgentTest::testApiKeyException";d:0.022;s:18:"ApiTest::testTrack";d:0.013;s:31:"ApiTest::testTrackCustomContext";d:0.001;s:19:"ApiTest::testVerify";d:0.001;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.001;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0;s:40:"ConfigurationManagerTest::testLoadConfig";d:0;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.002;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.001;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0;s:34:"EventManagerTest::testEventOptions";d:0;s:32:"EventManagerTest::testBuildEvent";d:0.001;s:30:"EventManagerTest::testSendSync";d:0.002;s:34:"EventManagerTest::testSendFailSync";d:0.003;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.001;s:31:"EventManagerTest::testSendAsync";d:0.001;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":1612:{a:2:{s:7:"defects";a:13:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;}s:5:"times";a:18:{s:30:"AgentTest::testApiKeyException";d:0.012;s:18:"ApiTest::testTrack";d:0.021;s:31:"ApiTest::testTrackCustomContext";d:0.013;s:19:"ApiTest::testVerify";d:0.013;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.002;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.001;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.003;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.004;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.004;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.008;s:30:"EventManagerTest::testSendSync";d:0.011;s:34:"EventManagerTest::testSendFailSync";d:0.012;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.011;s:31:"EventManagerTest::testSendAsync";d:0.01;}}} \ No newline at end of file diff --git a/build/logs/clover.xml b/build/logs/clover.xml new file mode 100644 index 0000000..cd74c4c --- /dev/null +++ b/build/logs/clover.xml @@ -0,0 +1,658 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/ConfigurationManagerTest.php b/tests/ConfigurationManagerTest.php index 64a0403..8006799 100644 --- a/tests/ConfigurationManagerTest.php +++ b/tests/ConfigurationManagerTest.php @@ -84,7 +84,6 @@ private function getConfigTestKeys() 'SECURENATIVE_DISABLE' => (object)['name' => 'isDisable', 'value' => false], 'SECURENATIVE_LOG_LEVEL' => (object)['name' => 'getLogLevel', 'value' => 'log'], 'SECURENATIVE_FAILOVER_STRATEGY' => (object)['name' => 'getFailoverStrategy', 'value' => 'failush'], - 'SECURENATIVE_PROXY_HEADERS' => (object)['name' => 'getProxyHeaders', 'value' => 'CF-Connecting-IP,Some-Random-IP'], ]; } From f21791436786deb63e6679dfab12fa794159ad30 Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Wed, 4 Nov 2020 14:56:19 +0200 Subject: [PATCH 09/24] Update php version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c609027..36bfc8c 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ ] }, "require": { - "php": ">=7.4", + "php": ">=7.2.0", "guzzlehttp/guzzle": "^6.0", "antecedent/patchwork": "~2.0", "monolog/monolog": "2.0.2", From cb1cf97a0187e67ffb2d3c59d70923b2a7bbba73 Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Sun, 8 Nov 2020 09:55:38 +0200 Subject: [PATCH 10/24] Add proxy headers tests --- .phpunit.result.cache | 2 +- build/logs/clover.xml | 60 ++++++++++++++++++------------------- src/SecureNativeContext.php | 2 +- src/Utils.php | 2 +- tests/RequestUtilsTest.php | 41 +++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 33 deletions(-) create mode 100644 tests/RequestUtilsTest.php diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 2abf2ed..516ac4d 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":1612:{a:2:{s:7:"defects";a:13:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;}s:5:"times";a:18:{s:30:"AgentTest::testApiKeyException";d:0.012;s:18:"ApiTest::testTrack";d:0.021;s:31:"ApiTest::testTrackCustomContext";d:0.013;s:19:"ApiTest::testVerify";d:0.013;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.002;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.001;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.003;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.004;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.004;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.008;s:30:"EventManagerTest::testSendSync";d:0.011;s:34:"EventManagerTest::testSendFailSync";d:0.012;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.011;s:31:"EventManagerTest::testSendAsync";d:0.01;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":1798:{a:2:{s:7:"defects";a:13:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;}s:5:"times";a:21:{s:30:"AgentTest::testApiKeyException";d:0.029;s:18:"ApiTest::testTrack";d:0.027;s:31:"ApiTest::testTrackCustomContext";d:0.012;s:19:"ApiTest::testVerify";d:0.014;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.003;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.002;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.002;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.003;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.004;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.003;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.007;s:30:"EventManagerTest::testSendSync";d:0.013;s:34:"EventManagerTest::testSendFailSync";d:0.014;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.011;s:31:"EventManagerTest::testSendAsync";d:0.012;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0.001;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0.001;}}} \ No newline at end of file diff --git a/build/logs/clover.xml b/build/logs/clover.xml index cd74c4c..94ad282 100644 --- a/build/logs/clover.xml +++ b/build/logs/clover.xml @@ -1,6 +1,6 @@ - - + + @@ -501,20 +501,20 @@ - + - - - - - - - - - - - - + + + + + + + + + + + + @@ -560,11 +560,11 @@ - - - - - + + + + + @@ -577,21 +577,21 @@ - + - + - - - - - - + + + + + + @@ -650,9 +650,9 @@ - + - + diff --git a/src/SecureNativeContext.php b/src/SecureNativeContext.php index 47bf7e5..57db7e4 100644 --- a/src/SecureNativeContext.php +++ b/src/SecureNativeContext.php @@ -37,7 +37,7 @@ public function __construct($clientToken, $ip = null, $remoteIp = null, $headers public static function fromRequest($options) : SecureNativeContext { - $clientToken = Utils::cookieIdFromRequest() ? Utils::cookieIdFromRequest() : Utils::securHeaderFromRequest(); + $clientToken = Utils::cookieIdFromRequest() ? Utils::cookieIdFromRequest() : Utils::secureHeaderFromRequest(); $ip = Utils::clientIpFromRequest($options); $remoteIp = Utils::clientIpFromRequest($options); $headers = Utils::headersFromRequest(); diff --git a/src/Utils.php b/src/Utils.php index f278368..c27e1f4 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -72,7 +72,7 @@ public static function methodFromRequest() return ''; } - public static function securHeaderFromRequest() + public static function secureHeaderFromRequest() { if (array_key_exists('HTTP_X_SECURENATIVE', $_SERVER)) { return $_SERVER['HTTP_X_SECURENATIVE']; diff --git a/tests/RequestUtilsTest.php b/tests/RequestUtilsTest.php new file mode 100644 index 0000000..e64695b --- /dev/null +++ b/tests/RequestUtilsTest.php @@ -0,0 +1,41 @@ +setProxyHeaders(["CF-Connecting-IP"]); + + $_SERVER["CF-Connecting-IP"] = "203.0.113.1"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("203.0.113.1", $client_ip); + } + + public function testProxyHeadersWithIpv6() + { + $options = new SecureNativeOptions(); + $options->setProxyHeaders(["CF-Connecting-IP"]); + + $_SERVER["CF-Connecting-IP"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testProxyHeadersWithMultipleHeaders() + { + $options = new SecureNativeOptions(); + $options->setProxyHeaders(["CF-Connecting-IP"]); + + $_SERVER["CF-Connecting-IP"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } +} \ No newline at end of file From 6235095675397914d6446c1d9ff638f73bea4b1a Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Tue, 10 Nov 2020 10:18:56 +0200 Subject: [PATCH 11/24] Fix tests --- .github/workflows/build.yml | 2 +- .github/workflows/publish.yml | 2 +- tests/AgentTest.php | 2 -- tests/ApiTest.php | 6 ------ tests/SecureNativeTest.php | 2 -- 5 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2a5103b..d7ad439 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,4 +54,4 @@ jobs: message_id: ${{ steps.slack.outputs.message_id }} channel: github-actions status: FAILED - color: danger + color: danger \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index edf036a..eea167e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,7 +3,7 @@ name: Publish on: release: types: [created] - + jobs: release: runs-on: ubuntu-latest diff --git a/tests/AgentTest.php b/tests/AgentTest.php index fbdaeaf..efdf717 100644 --- a/tests/AgentTest.php +++ b/tests/AgentTest.php @@ -1,8 +1,6 @@ Date: Tue, 10 Nov 2020 13:43:26 +0200 Subject: [PATCH 12/24] Update readme --- .phpunit.result.cache | 2 +- README.md | 30 +++++++++++++++++++++++++++--- build/logs/clover.xml | 6 +++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 516ac4d..505469c 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":1798:{a:2:{s:7:"defects";a:13:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;}s:5:"times";a:21:{s:30:"AgentTest::testApiKeyException";d:0.029;s:18:"ApiTest::testTrack";d:0.027;s:31:"ApiTest::testTrackCustomContext";d:0.012;s:19:"ApiTest::testVerify";d:0.014;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.003;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.002;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.002;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.003;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.004;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.003;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.007;s:30:"EventManagerTest::testSendSync";d:0.013;s:34:"EventManagerTest::testSendFailSync";d:0.014;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.011;s:31:"EventManagerTest::testSendAsync";d:0.012;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0.001;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0.001;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":1798:{a:2:{s:7:"defects";a:13:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;}s:5:"times";a:21:{s:30:"AgentTest::testApiKeyException";d:0.013;s:18:"ApiTest::testTrack";d:0.019;s:31:"ApiTest::testTrackCustomContext";d:0.012;s:19:"ApiTest::testVerify";d:0.013;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.002;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.002;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.003;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.004;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.003;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.007;s:30:"EventManagerTest::testSendSync";d:0.011;s:34:"EventManagerTest::testSendFailSync";d:0.012;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.011;s:31:"EventManagerTest::testSendAsync";d:0.011;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0.001;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0.001;}}} \ No newline at end of file diff --git a/README.md b/README.md index 48fa5fb..cba5c5c 100644 --- a/README.md +++ b/README.md @@ -68,9 +68,9 @@ Attach `securenative.json` file to your root folder: ```json { - "SECURENATIVE_API_KEY": "SOME_API_KEY", - "SECURENATIVE_APP_NAME": "SOME_APP_NAME", - "SECURENATIVE_API_URL": "SOME_API_URL", + "SECURENATIVE_API_KEY": "YOUR_API_KEY", + "SECURENATIVE_APP_NAME": "APP_NAME", + "SECURENATIVE_API_URL": "API_URL", "SECURENATIVE_INTERVAL": 1000, "SECURENATIVE_MAX_EVENTS": 100, "SECURENATIVE_TIMEOUT": 1500, @@ -189,3 +189,27 @@ if ($verified) { // Request is trusted (coming from SecureNative) } ``` + +## Extract proxy headers + +You can specify custom header keys to allow extraction of client ip from different providers. +This example demonstrates the usage of proxy headers for ip extraction from Cloudflare. + +### Option 1: Using config file +```json +{ + "SECURENATIVE_API_KEY": "YOUR_API_KEY", + "SECURENATIVE_PROXY_HEADERS": ["CF-Connecting-IP"] +} +``` + +Initialize sdk as shown above. + +### Options 2: Using ConfigurationBuilder + +```php +$options = new SecureNativeOptions(); +$options->setProxyHeaders(["CF-Connecting-IP"]); + +SecureNative::init(); +``` \ No newline at end of file diff --git a/build/logs/clover.xml b/build/logs/clover.xml index 94ad282..69601aa 100644 --- a/build/logs/clover.xml +++ b/build/logs/clover.xml @@ -1,6 +1,6 @@ - - + + @@ -620,7 +620,7 @@ - + From 13cfc98e1ef1c82be4449804e0eda02b3af3fb5f Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Tue, 10 Nov 2020 13:46:38 +0200 Subject: [PATCH 13/24] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cba5c5c..32edc46 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ if ($verified) { } ``` -## Extract proxy headers +## Extract proxy headers from cloud providers You can specify custom header keys to allow extraction of client ip from different providers. This example demonstrates the usage of proxy headers for ip extraction from Cloudflare. From 4bce01ecf6b8efa13f61b2c559ca385b53b97dfe Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Tue, 17 Nov 2020 10:50:49 +0200 Subject: [PATCH 14/24] Add ip extraction tests --- .phpunit.result.cache | 2 +- build/logs/clover.xml | 139 +++++++++++------------ src/Utils.php | 1 + tests/RequestUtilsTest.php | 219 +++++++++++++++++++++++++++++++++++++ 4 files changed, 291 insertions(+), 70 deletions(-) diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 505469c..07cc51e 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":1798:{a:2:{s:7:"defects";a:13:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;}s:5:"times";a:21:{s:30:"AgentTest::testApiKeyException";d:0.013;s:18:"ApiTest::testTrack";d:0.019;s:31:"ApiTest::testTrackCustomContext";d:0.012;s:19:"ApiTest::testVerify";d:0.013;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.002;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.002;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.003;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.004;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.003;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.007;s:30:"EventManagerTest::testSendSync";d:0.011;s:34:"EventManagerTest::testSendFailSync";d:0.012;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.011;s:31:"EventManagerTest::testSendAsync";d:0.011;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0.001;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0.001;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":5275:{a:2:{s:7:"defects";a:34:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";i:3;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";i:3;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";i:3;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";i:3;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";i:3;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";i:3;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";i:3;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";i:3;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";i:3;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";i:3;}s:5:"times";a:45:{s:30:"AgentTest::testApiKeyException";d:0.028;s:18:"ApiTest::testTrack";d:0.027;s:31:"ApiTest::testTrackCustomContext";d:0.012;s:19:"ApiTest::testVerify";d:0.013;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.003;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.002;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.002;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.002;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.003;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.005;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.003;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.007;s:30:"EventManagerTest::testSendSync";d:0.013;s:34:"EventManagerTest::testSendFailSync";d:0.016;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.012;s:31:"EventManagerTest::testSendAsync";d:0.012;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0.001;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0.001;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";d:0.005;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";d:0.002;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";d:0.001;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";d:0.002;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";d:0.002;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";d:0.002;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";d:0.003;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";d:0.003;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";d:0.002;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";d:0.002;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";d:0.002;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";d:0.003;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";d:0.003;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";d:0.002;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";d:0.002;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";d:0.003;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";d:0.003;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";d:0.002;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";d:0.002;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";d:0.002;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";d:0.003;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";d:0.002;s:57:"RequestUtilsTest::testExtractionPriorityWithXForwardedFor";d:0.001;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";d:0.001;}}} \ No newline at end of file diff --git a/build/logs/clover.xml b/build/logs/clover.xml index 69601aa..8d69c56 100644 --- a/build/logs/clover.xml +++ b/build/logs/clover.xml @@ -1,6 +1,6 @@ - - + + @@ -503,18 +503,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + @@ -560,8 +560,8 @@ - - + + @@ -581,78 +581,79 @@ - + - - - + + + - - - - - - - - - - + + + + + + + + + + - - - + + + - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - + - - - + + + - - - + + + - + - + + - + diff --git a/src/Utils.php b/src/Utils.php index c27e1f4..906745c 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -5,6 +5,7 @@ const ALGORITHM = "AES-256-CBC"; const BLOCK_SIZE = 16; const AES_KEY_SIZE = 32; +const IP_HEADERS = ["HTTP_X_FORWARDED_FOR", "X_FORWARDED_FOR", "HTTP_X_REAL_IP", "HTTP_X_CLIENT_IP", "REMOTE_ADDR", "x-forwarded-for", "x-client-ip", "x-real-ip", "x-forwarded", "x-cluster-client-ip", "forwarded-for", "forwarded", "via"]; abstract class Utils { diff --git a/tests/RequestUtilsTest.php b/tests/RequestUtilsTest.php index e64695b..90e65e5 100644 --- a/tests/RequestUtilsTest.php +++ b/tests/RequestUtilsTest.php @@ -38,4 +38,223 @@ public function testProxyHeadersWithMultipleHeaders() $client_ip = Utils::clientIpFromRequest($options); $this->assertEquals("141.246.115.116", $client_ip); } + + public function testIpExtractionUsingXFORWARDEDFORHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["X_FORWARDED_FOR"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["X_FORWARDED_FOR"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testIpExtractionUsingHTTPXREALIPHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["HTTP_X_REAL_IP"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["HTTP_X_REAL_IP"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testIpExtractionUsingREMOTEADDRHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["REMOTE_ADDR"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["REMOTE_ADDR"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testIpExtractionUsingXClientIpHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["x-client-ip"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingXClientIpHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["x-client-ip"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testIpExtractionUsingXRealIpHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["x-real-ip"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingXRealIpHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["x-real-ip"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testIpExtractionUsingForwardedForHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["forwarded-for"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingForwardedForHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["forwarded-for"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testIpExtractionUsingXClusterClientIpHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["x-cluster-client-ip"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["x-cluster-client-ip"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testIpExtractionUsingXForwardedHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["x-forwarded"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingXForwardedHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["x-forwarded"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testIpExtractionUsingForwardedHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["forwarded"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingForwardedHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["forwarded"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testIpExtractionUsingViaHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["via"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingViaHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["via"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6() + { + $options = new SecureNativeOptions(); + $_SERVER["HTTP_X_CLIENT_IP"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); + } + + public function testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4() + { + $options = new SecureNativeOptions(); + $_SERVER["HTTP_X_CLIENT_IP"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("141.246.115.116", $client_ip); + } + + public function testExtractionPriorityWithXForwardedFor() + { + $options = new SecureNativeOptions(); + $_SERVER["HTTP_X_FORWARDED_FOR"] = "203.0.113.1"; + $_SERVER["HTTP_X_REAL_IP"] = "198.51.100.101"; + $_SERVER["HTTP_X_CLIENT_IP"] = "198.51.100.102"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("203.0.113.1", $client_ip); + } + + public function testExtractionPriorityWithoutXForwardedFor() + { + $options = new SecureNativeOptions(); + $_SERVER["HTTP_X_REAL_IP"] = "198.51.100.101"; + $_SERVER["HTTP_X_CLIENT_IP"] = "203.0.113.1, 141.246.115.116, 12.34.56.3"; + + $client_ip = Utils::clientIpFromRequest($options); + $this->assertEquals("203.0.113.1", $client_ip); + } } \ No newline at end of file From 0b921d9d6ce3cac5774ad6b2c9273b58798107ba Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Tue, 17 Nov 2020 14:08:22 +0200 Subject: [PATCH 15/24] Fix ip extraction function --- .phpunit.result.cache | 2 +- build/logs/clover.xml | 113 +++++++++++++++++++------------------ src/Utils.php | 27 +++++---- tests/RequestUtilsTest.php | 30 ++++++++++ 4 files changed, 104 insertions(+), 68 deletions(-) diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 07cc51e..8481731 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":5275:{a:2:{s:7:"defects";a:34:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";i:3;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";i:3;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";i:3;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";i:3;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";i:3;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";i:3;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";i:3;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";i:3;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";i:3;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";i:3;}s:5:"times";a:45:{s:30:"AgentTest::testApiKeyException";d:0.028;s:18:"ApiTest::testTrack";d:0.027;s:31:"ApiTest::testTrackCustomContext";d:0.012;s:19:"ApiTest::testVerify";d:0.013;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.003;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.002;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.002;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.002;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.003;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.005;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.003;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.007;s:30:"EventManagerTest::testSendSync";d:0.013;s:34:"EventManagerTest::testSendFailSync";d:0.016;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.012;s:31:"EventManagerTest::testSendAsync";d:0.012;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0.001;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0.001;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";d:0.005;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";d:0.002;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";d:0.001;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";d:0.002;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";d:0.002;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";d:0.002;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";d:0.003;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";d:0.003;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";d:0.002;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";d:0.002;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";d:0.002;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";d:0.003;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";d:0.003;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";d:0.002;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";d:0.002;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";d:0.003;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";d:0.003;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";d:0.002;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";d:0.002;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";d:0.002;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";d:0.003;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";d:0.002;s:57:"RequestUtilsTest::testExtractionPriorityWithXForwardedFor";d:0.001;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";d:0.001;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":5417:{a:2:{s:7:"defects";a:36:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";i:3;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";i:3;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";i:3;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";i:3;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";i:3;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";i:3;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";i:3;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";i:3;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";i:3;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";i:3;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";i:3;}s:5:"times";a:45:{s:30:"AgentTest::testApiKeyException";d:0.021;s:18:"ApiTest::testTrack";d:0.02;s:31:"ApiTest::testTrackCustomContext";d:0.012;s:19:"ApiTest::testVerify";d:0.013;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.002;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.001;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.003;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.004;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.004;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.008;s:30:"EventManagerTest::testSendSync";d:0.012;s:34:"EventManagerTest::testSendFailSync";d:0.012;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.012;s:31:"EventManagerTest::testSendAsync";d:0.01;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0.001;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0.001;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";d:0.001;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";d:0.001;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";d:0.001;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";d:0.002;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";d:0.001;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";d:0.002;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";d:0.002;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";d:0.001;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";d:0.001;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";d:0.002;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";d:0.002;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";d:0.002;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";d:0.002;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";d:0.002;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";d:0.001;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";d:0.001;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";d:0.001;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";d:0.001;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";d:0.001;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";d:0.001;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";d:0.001;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";d:0.001;s:57:"RequestUtilsTest::testExtractionPriorityWithXForwardedFor";d:0.001;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";d:0.001;}}} \ No newline at end of file diff --git a/build/logs/clover.xml b/build/logs/clover.xml index 8d69c56..a0f8ae9 100644 --- a/build/logs/clover.xml +++ b/build/logs/clover.xml @@ -1,6 +1,6 @@ - - + + @@ -581,79 +581,80 @@ - + - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - + + + - - - - - - + + + + + - - - - - - - + + + + + + + - + - - - - - + + + + + - - + + + + + - + diff --git a/src/Utils.php b/src/Utils.php index 906745c..617a8de 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -5,7 +5,7 @@ const ALGORITHM = "AES-256-CBC"; const BLOCK_SIZE = 16; const AES_KEY_SIZE = 32; -const IP_HEADERS = ["HTTP_X_FORWARDED_FOR", "X_FORWARDED_FOR", "HTTP_X_REAL_IP", "HTTP_X_CLIENT_IP", "REMOTE_ADDR", "x-forwarded-for", "x-client-ip", "x-real-ip", "x-forwarded", "x-cluster-client-ip", "forwarded-for", "forwarded", "via"]; +const IP_HEADERS = ["HTTP_X_FORWARDED_FOR", "X_FORWARDED_FOR", "HTTP_X_CLIENT_IP", "HTTP_X_REAL_IP", "REMOTE_ADDR", "x-forwarded-for", "x-client-ip", "x-real-ip", "x-forwarded", "x-cluster-client-ip", "forwarded-for", "forwarded", "via"]; abstract class Utils { @@ -16,21 +16,26 @@ public static function clientIpFromRequest($options) foreach ($options->getProxyHeaders() as $header) { if (array_key_exists($header, $_SERVER)) { $parts = explode(',', $_SERVER[$header]); - return $parts[0]; + foreach ($parts as $ip) { + if (filter_var($ip, FILTER_VALIDATE_IP)) { + return $ip; + } + } } } } - if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { - $parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); - return $parts[0]; - } - if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) { - return $_SERVER['HTTP_X_REAL_IP']; - } - if (array_key_exists('REMOTE_ADDR', $_SERVER)) { - return $_SERVER['REMOTE_ADDR']; + foreach (IP_HEADERS as $header) { + if (array_key_exists($header, $_SERVER)) { + $parts = explode(',', $_SERVER[$header]); + foreach ($parts as $ip) { + if (filter_var($ip, FILTER_VALIDATE_IP)) { + return $ip; + } + } + } } + return null; } diff --git a/tests/RequestUtilsTest.php b/tests/RequestUtilsTest.php index 90e65e5..a899e80 100644 --- a/tests/RequestUtilsTest.php +++ b/tests/RequestUtilsTest.php @@ -14,6 +14,7 @@ public function testProxyHeadersWithIpv4() $_SERVER["CF-Connecting-IP"] = "203.0.113.1"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["CF-Connecting-IP"]); $this->assertEquals("203.0.113.1", $client_ip); } @@ -25,6 +26,7 @@ public function testProxyHeadersWithIpv6() $_SERVER["CF-Connecting-IP"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["CF-Connecting-IP"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -36,6 +38,7 @@ public function testProxyHeadersWithMultipleHeaders() $_SERVER["CF-Connecting-IP"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["CF-Connecting-IP"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -45,6 +48,7 @@ public function testIpExtractionUsingXFORWARDEDFORHeaderIpv6() $_SERVER["X_FORWARDED_FOR"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["X_FORWARDED_FOR"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -54,6 +58,7 @@ public function testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4() $_SERVER["X_FORWARDED_FOR"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["X_FORWARDED_FOR"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -63,6 +68,7 @@ public function testIpExtractionUsingHTTPXREALIPHeaderIpv6() $_SERVER["HTTP_X_REAL_IP"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["HTTP_X_REAL_IP"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -72,6 +78,7 @@ public function testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4() $_SERVER["HTTP_X_REAL_IP"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["HTTP_X_REAL_IP"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -81,6 +88,7 @@ public function testIpExtractionUsingREMOTEADDRHeaderIpv6() $_SERVER["REMOTE_ADDR"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["REMOTE_ADDR"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -90,6 +98,7 @@ public function testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4() $_SERVER["REMOTE_ADDR"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["REMOTE_ADDR"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -99,6 +108,7 @@ public function testIpExtractionUsingXClientIpHeaderIpv6() $_SERVER["x-client-ip"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["x-client-ip"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -108,6 +118,7 @@ public function testIpExtractionUsingXClientIpHeaderMultipleIpv4() $_SERVER["x-client-ip"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["x-client-ip"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -117,6 +128,7 @@ public function testIpExtractionUsingXRealIpHeaderIpv6() $_SERVER["x-real-ip"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["x-real-ip"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -126,6 +138,7 @@ public function testIpExtractionUsingXRealIpHeaderMultipleIpv4() $_SERVER["x-real-ip"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["x-real-ip"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -135,6 +148,7 @@ public function testIpExtractionUsingForwardedForHeaderIpv6() $_SERVER["forwarded-for"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["forwarded-for"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -144,6 +158,7 @@ public function testIpExtractionUsingForwardedForHeaderMultipleIpv4() $_SERVER["forwarded-for"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["forwarded-for"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -153,6 +168,7 @@ public function testIpExtractionUsingXClusterClientIpHeaderIpv6() $_SERVER["x-cluster-client-ip"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["x-cluster-client-ip"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -162,6 +178,7 @@ public function testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4() $_SERVER["x-cluster-client-ip"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["x-cluster-client-ip"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -171,6 +188,7 @@ public function testIpExtractionUsingXForwardedHeaderIpv6() $_SERVER["x-forwarded"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["x-forwarded"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -180,6 +198,7 @@ public function testIpExtractionUsingXForwardedHeaderMultipleIpv4() $_SERVER["x-forwarded"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["x-forwarded"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -189,6 +208,7 @@ public function testIpExtractionUsingForwardedHeaderIpv6() $_SERVER["forwarded"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["forwarded"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -198,6 +218,7 @@ public function testIpExtractionUsingForwardedHeaderMultipleIpv4() $_SERVER["forwarded"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["forwarded"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -207,6 +228,7 @@ public function testIpExtractionUsingViaHeaderIpv6() $_SERVER["via"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["via"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -216,6 +238,7 @@ public function testIpExtractionUsingViaHeaderMultipleIpv4() $_SERVER["via"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["via"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -225,6 +248,7 @@ public function testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6() $_SERVER["HTTP_X_CLIENT_IP"] = "f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["HTTP_X_CLIENT_IP"]); $this->assertEquals("f71f:5bf9:25ff:1883:a8c4:eeff:7b80:aa2d", $client_ip); } @@ -234,6 +258,7 @@ public function testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4() $_SERVER["HTTP_X_CLIENT_IP"] = "141.246.115.116, 203.0.113.1, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["HTTP_X_CLIENT_IP"]); $this->assertEquals("141.246.115.116", $client_ip); } @@ -245,6 +270,9 @@ public function testExtractionPriorityWithXForwardedFor() $_SERVER["HTTP_X_CLIENT_IP"] = "198.51.100.102"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["HTTP_X_FORWARDED_FOR"]); + unset($_SERVER["HTTP_X_REAL_IP"]); + unset($_SERVER["HTTP_X_CLIENT_IP"]); $this->assertEquals("203.0.113.1", $client_ip); } @@ -255,6 +283,8 @@ public function testExtractionPriorityWithoutXForwardedFor() $_SERVER["HTTP_X_CLIENT_IP"] = "203.0.113.1, 141.246.115.116, 12.34.56.3"; $client_ip = Utils::clientIpFromRequest($options); + unset($_SERVER["HTTP_X_REAL_IP"]); + unset($_SERVER["HTTP_X_CLIENT_IP"]); $this->assertEquals("203.0.113.1", $client_ip); } } \ No newline at end of file From ec3c657fab7fb2bbe4621956e571456e24499248 Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Tue, 17 Nov 2020 16:19:30 +0200 Subject: [PATCH 16/24] Fix ip extraction function --- .phpunit.result.cache | 2 +- build/logs/clover.xml | 4 ++-- tests/ApiTest.php | 1 - tests/ConfigurationManagerTest.php | 4 ++-- tests/EventManagerTest.php | 2 -- tests/SecureNativeTest.php | 1 - 6 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 8481731..e2b11dd 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":5417:{a:2:{s:7:"defects";a:36:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";i:3;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";i:3;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";i:3;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";i:3;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";i:3;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";i:3;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";i:3;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";i:3;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";i:3;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";i:3;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";i:3;}s:5:"times";a:45:{s:30:"AgentTest::testApiKeyException";d:0.021;s:18:"ApiTest::testTrack";d:0.02;s:31:"ApiTest::testTrackCustomContext";d:0.012;s:19:"ApiTest::testVerify";d:0.013;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.002;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.001;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.003;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.004;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.004;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.008;s:30:"EventManagerTest::testSendSync";d:0.012;s:34:"EventManagerTest::testSendFailSync";d:0.012;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.012;s:31:"EventManagerTest::testSendAsync";d:0.01;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0.001;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0.001;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";d:0.001;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";d:0.001;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";d:0.001;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";d:0.002;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";d:0.001;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";d:0.002;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";d:0.002;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";d:0.001;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";d:0.001;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";d:0.002;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";d:0.002;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";d:0.002;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";d:0.002;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";d:0.002;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";d:0.001;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";d:0.001;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";d:0.001;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";d:0.001;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";d:0.001;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";d:0.001;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";d:0.001;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";d:0.001;s:57:"RequestUtilsTest::testExtractionPriorityWithXForwardedFor";d:0.001;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";d:0.001;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":5419:{a:2:{s:7:"defects";a:36:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";i:3;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";i:3;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";i:3;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";i:3;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";i:3;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";i:3;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";i:3;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";i:3;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";i:3;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";i:3;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";i:3;}s:5:"times";a:45:{s:30:"AgentTest::testApiKeyException";d:0.026;s:18:"ApiTest::testTrack";d:0.025;s:31:"ApiTest::testTrackCustomContext";d:0.011;s:19:"ApiTest::testVerify";d:0.013;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.003;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.002;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.002;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.003;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.004;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.008;s:30:"EventManagerTest::testSendSync";d:0.013;s:34:"EventManagerTest::testSendFailSync";d:0.014;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.013;s:31:"EventManagerTest::testSendAsync";d:0.012;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0.001;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0.001;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";d:0.001;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";d:0.001;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";d:0.001;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";d:0.001;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";d:0.001;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";d:0.002;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";d:0.001;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";d:0.001;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";d:0.001;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";d:0.001;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";d:0.001;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";d:0.001;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";d:0.002;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";d:0.002;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";d:0.001;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";d:0.001;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";d:0.001;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";d:0.002;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";d:0.002;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";d:0.002;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";d:0.001;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";d:0.001;s:57:"RequestUtilsTest::testExtractionPriorityWithXForwardedFor";d:0.001;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";d:0.001;}}} \ No newline at end of file diff --git a/build/logs/clover.xml b/build/logs/clover.xml index a0f8ae9..10aa9d4 100644 --- a/build/logs/clover.xml +++ b/build/logs/clover.xml @@ -1,6 +1,6 @@ - - + + diff --git a/tests/ApiTest.php b/tests/ApiTest.php index ffaad33..0dc38d7 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -26,7 +26,6 @@ public function testTrack() SecureNative::init(self::TEST_API_KEY, $options, $eventManager); $trackObject = mock_track_object(); - $callbackRes = null; SecureNative::track($trackObject, function ($params) use (&$callbackRes) { $callbackRes = $params; diff --git a/tests/ConfigurationManagerTest.php b/tests/ConfigurationManagerTest.php index 8006799..6503058 100644 --- a/tests/ConfigurationManagerTest.php +++ b/tests/ConfigurationManagerTest.php @@ -92,7 +92,7 @@ public function testEnvironmentVariables() { $testKeys = $this->getConfigTestKeys(); - // Set env for each ovject item + // Set env for each object item foreach ($testKeys as $key => $item) { putenv("$key=" . $item->value); } @@ -126,7 +126,7 @@ public function testEnvironmentVariablesOverride() { $testKeys = $this->getConfigTestKeys(); - // Set env for each ovject item + // Set env for each object item foreach ($testKeys as $key => $item) { putenv("$key=" . $item->value); } diff --git a/tests/EventManagerTest.php b/tests/EventManagerTest.php index 0dafafd..1e78417 100644 --- a/tests/EventManagerTest.php +++ b/tests/EventManagerTest.php @@ -105,7 +105,6 @@ public function testAsyncShouldRetry() { $this->assertNull($callbackRes, 'Track callback should not be called'); } - public function testSendAsync() { $options = new SecureNativeOptions(self::TEST_API_KEY, "http://testushim.com"); @@ -133,5 +132,4 @@ public function testSendAsync() $this->assertObjectHasAttribute('prop1', $callbackRes->{'properties'}); $this->assertObjectHasAttribute('prop2', $callbackRes->{'properties'}); } - } diff --git a/tests/SecureNativeTest.php b/tests/SecureNativeTest.php index 57e9c3f..dce2bc6 100644 --- a/tests/SecureNativeTest.php +++ b/tests/SecureNativeTest.php @@ -73,7 +73,6 @@ public function testMaxTrackParamsException() )); } - public function testBasicVerify() { SecureNative::init(TEST_API_KEY); From 239cc45970dca9e19c70d5387b358b14b3975f09 Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Wed, 18 Nov 2020 17:56:37 +0200 Subject: [PATCH 17/24] Fix github actions --- .github/workflows/build.yml | 3 +++ .github/workflows/ci.yml | 3 +++ .github/workflows/publish.yml | 4 ---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d7ad439..2ff2a3d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,6 +30,9 @@ jobs: - uses: php-actions/composer@v1 - uses: nanasess/setup-php@master - uses: php-actions/phpunit@v9 + with: + configuration: tests/phpunit.xml + args: --coverage-text - name: Publish to codecov run: bash <(curl -s https://codecov.io/bash) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d7d1b4..6fd00e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,9 @@ jobs: - uses: php-actions/composer@v1 - uses: nanasess/setup-php@master - uses: php-actions/phpunit@v9 + with: + configuration: tests/phpunit.xml + args: --coverage-text - name: Publish to codecov run: bash <(curl -s https://codecov.io/bash) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eea167e..b7e6f7f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -22,10 +22,6 @@ jobs: - uses: actions/checkout@v2 - uses: php-actions/composer@v1 - uses: nanasess/setup-php@master - - uses: php-actions/phpunit@v9 - - - name: Publish to codecov - run: bash <(curl -s https://codecov.io/bash) - name: Publish uses: musps/action-deployer-php@master From 8ab1b0e5a113707423ba72d6dc19898f2f3e70cc Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Wed, 18 Nov 2020 18:00:09 +0200 Subject: [PATCH 18/24] Fix github actions --- .github/workflows/build.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ff2a3d..d3311e2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,7 +31,7 @@ jobs: - uses: nanasess/setup-php@master - uses: php-actions/phpunit@v9 with: - configuration: tests/phpunit.xml + configuration: ./phpunit.xml args: --coverage-text - name: Publish to codecov diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fd00e6..a64778a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: - uses: nanasess/setup-php@master - uses: php-actions/phpunit@v9 with: - configuration: tests/phpunit.xml + configuration: ./phpunit.xml args: --coverage-text - name: Publish to codecov From 91e37a1736ae96062a0928162dad79bfa5046077 Mon Sep 17 00:00:00 2001 From: Amit Bourmad Date: Thu, 19 Nov 2020 14:03:37 +0200 Subject: [PATCH 19/24] Testing github build --- .github/workflows/build.yml | 6 +++--- .github/workflows/ci.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d3311e2..28df403 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,9 +30,9 @@ jobs: - uses: php-actions/composer@v1 - uses: nanasess/setup-php@master - uses: php-actions/phpunit@v9 - with: - configuration: ./phpunit.xml - args: --coverage-text +# with: +# configuration: ./phpunit.xml +# args: --coverage-text - name: Publish to codecov run: bash <(curl -s https://codecov.io/bash) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a64778a..d40a04f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,9 +26,9 @@ jobs: - uses: php-actions/composer@v1 - uses: nanasess/setup-php@master - uses: php-actions/phpunit@v9 - with: - configuration: ./phpunit.xml - args: --coverage-text +# with: +# configuration: ./phpunit.xml +# args: --coverage-text - name: Publish to codecov run: bash <(curl -s https://codecov.io/bash) From 0a357d05722276e8c19e31a0ff2f5a3ba661a33f Mon Sep 17 00:00:00 2001 From: Amit Bourmad Date: Thu, 19 Nov 2020 14:08:52 +0200 Subject: [PATCH 20/24] Testing github build --- .github/workflows/build.yml | 6 +++--- .github/workflows/ci.yml | 6 +++--- tests/phpunit.xml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 28df403..d3311e2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,9 +30,9 @@ jobs: - uses: php-actions/composer@v1 - uses: nanasess/setup-php@master - uses: php-actions/phpunit@v9 -# with: -# configuration: ./phpunit.xml -# args: --coverage-text + with: + configuration: ./phpunit.xml + args: --coverage-text - name: Publish to codecov run: bash <(curl -s https://codecov.io/bash) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d40a04f..a64778a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,9 +26,9 @@ jobs: - uses: php-actions/composer@v1 - uses: nanasess/setup-php@master - uses: php-actions/phpunit@v9 -# with: -# configuration: ./phpunit.xml -# args: --coverage-text + with: + configuration: ./phpunit.xml + args: --coverage-text - name: Publish to codecov run: bash <(curl -s https://codecov.io/bash) diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 920d833..ea57bdc 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,5 +1,5 @@ - + . From cc307d9811cfe0d6110977ae371f376256d42f8a Mon Sep 17 00:00:00 2001 From: Amit Bourmad Date: Thu, 19 Nov 2020 14:13:01 +0200 Subject: [PATCH 21/24] Testing github build again --- .phpunit.result.cache | 2 +- tests/phpunit.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.phpunit.result.cache b/.phpunit.result.cache index e2b11dd..c39587a 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":5419:{a:2:{s:7:"defects";a:36:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";i:3;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";i:3;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";i:3;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";i:3;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";i:3;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";i:3;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";i:3;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";i:3;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";i:3;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";i:3;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";i:3;}s:5:"times";a:45:{s:30:"AgentTest::testApiKeyException";d:0.026;s:18:"ApiTest::testTrack";d:0.025;s:31:"ApiTest::testTrackCustomContext";d:0.011;s:19:"ApiTest::testVerify";d:0.013;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.003;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.002;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0.002;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0.003;s:43:"ConfigurationManagerTest::testDefaultParams";d:0.004;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0.003;s:34:"EventManagerTest::testEventOptions";d:0.003;s:32:"EventManagerTest::testBuildEvent";d:0.008;s:30:"EventManagerTest::testSendSync";d:0.013;s:34:"EventManagerTest::testSendFailSync";d:0.014;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.013;s:31:"EventManagerTest::testSendAsync";d:0.012;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0.001;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0.001;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";d:0.001;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";d:0.001;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";d:0.001;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";d:0.001;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";d:0.001;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";d:0.002;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";d:0.001;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";d:0.001;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";d:0.001;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";d:0.001;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";d:0.001;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";d:0.001;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";d:0.002;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";d:0.002;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";d:0.001;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";d:0.001;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";d:0.001;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";d:0.002;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";d:0.002;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";d:0.002;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";d:0.001;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";d:0.001;s:57:"RequestUtilsTest::testExtractionPriorityWithXForwardedFor";d:0.001;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";d:0.001;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":5287:{a:2:{s:7:"defects";a:36:{s:30:"AgentTest::testApiKeyException";i:4;s:18:"ApiTest::testTrack";i:4;s:19:"ApiTest::testVerify";i:4;s:44:"ConfigurationManagerTest::testReadConfigFile";i:3;s:50:"ConfigurationManagerTest::testEnvironmentVariables";i:4;s:43:"ConfigurationManagerTest::testDefaultParams";i:3;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";i:4;s:34:"EventManagerTest::testEventOptions";i:4;s:32:"EventManagerTest::testBuildEvent";i:4;s:30:"EventManagerTest::testSendSync";i:4;s:34:"EventManagerTest::testSendFailSync";i:4;s:38:"EventManagerTest::testAsyncShouldRetry";i:4;s:31:"EventManagerTest::testSendAsync";i:4;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";i:3;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";i:3;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";i:3;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";i:3;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";i:3;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";i:3;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";i:3;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";i:3;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";i:3;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";i:3;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";i:3;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";i:3;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";i:3;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";i:3;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";i:3;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";i:3;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";i:3;}s:5:"times";a:45:{s:30:"AgentTest::testApiKeyException";d:0.023;s:18:"ApiTest::testTrack";d:0.015;s:31:"ApiTest::testTrackCustomContext";d:0.001;s:19:"ApiTest::testVerify";d:0.001;s:44:"ConfigurationManagerTest::testReadConfigFile";d:0.001;s:41:"ConfigurationManagerTest::testUnknownKeys";d:0.001;s:41:"ConfigurationManagerTest::testInvalidFile";d:0.001;s:48:"ConfigurationManagerTest::testInvalidFileEntries";d:0.001;s:40:"ConfigurationManagerTest::testLoadConfig";d:0;s:50:"ConfigurationManagerTest::testEnvironmentVariables";d:0;s:43:"ConfigurationManagerTest::testDefaultParams";d:0;s:58:"ConfigurationManagerTest::testEnvironmentVariablesOverride";d:0;s:34:"EventManagerTest::testEventOptions";d:0;s:32:"EventManagerTest::testBuildEvent";d:0;s:30:"EventManagerTest::testSendSync";d:0.002;s:34:"EventManagerTest::testSendFailSync";d:0.002;s:38:"EventManagerTest::testAsyncShouldRetry";d:0.002;s:31:"EventManagerTest::testSendAsync";d:0.001;s:42:"RequestUtilsTest::testProxyHeadersWithIpv4";d:0;s:42:"RequestUtilsTest::testProxyHeadersWithIpv6";d:0;s:53:"RequestUtilsTest::testProxyHeadersWithMultipleHeaders";d:0;s:62:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderIpv6";d:0;s:70:"RequestUtilsTest::testIpExtractionUsingXFORWARDEDFORHeaderMultipleIpv4";d:0;s:60:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderIpv6";d:0;s:68:"RequestUtilsTest::testIpExtractionUsingHTTPXREALIPHeaderMultipleIpv4";d:0;s:59:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderIpv6";d:0;s:67:"RequestUtilsTest::testIpExtractionUsingREMOTEADDRHeaderMultipleIpv4";d:0;s:58:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderIpv6";d:0;s:66:"RequestUtilsTest::testIpExtractionUsingXClientIpHeaderMultipleIpv4";d:0;s:56:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderIpv6";d:0;s:64:"RequestUtilsTest::testIpExtractionUsingXRealIpHeaderMultipleIpv4";d:0;s:61:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderIpv6";d:0;s:69:"RequestUtilsTest::testIpExtractionUsingForwardedForHeaderMultipleIpv4";d:0;s:65:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderIpv6";d:0;s:73:"RequestUtilsTest::testIpExtractionUsingXClusterClientIpHeaderMultipleIpv4";d:0;s:59:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderIpv6";d:0;s:67:"RequestUtilsTest::testIpExtractionUsingXForwardedHeaderMultipleIpv4";d:0;s:58:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderIpv6";d:0;s:66:"RequestUtilsTest::testIpExtractionUsingForwardedHeaderMultipleIpv4";d:0;s:52:"RequestUtilsTest::testIpExtractionUsingViaHeaderIpv6";d:0;s:60:"RequestUtilsTest::testIpExtractionUsingViaHeaderMultipleIpv4";d:0;s:62:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderIpv6";d:0;s:70:"RequestUtilsTest::testIpExtractionUsingHTTPXCLIENTIPHeaderMultipleIpv4";d:0;s:57:"RequestUtilsTest::testExtractionPriorityWithXForwardedFor";d:0;s:60:"RequestUtilsTest::testExtractionPriorityWithoutXForwardedFor";d:0;}}} \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml index ea57bdc..934604d 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,5 +1,5 @@ - + . From 4b383eb381d502639ba2ad95952c451fbb2114f8 Mon Sep 17 00:00:00 2001 From: Amit Bourmad Date: Thu, 19 Nov 2020 14:16:17 +0200 Subject: [PATCH 22/24] Testing github build again 2 --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index cc955a1..31788df 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,5 @@ - + ./tests From 125bc03026b702cc788bbe815f9b4900b017d8ec Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Sun, 22 Nov 2020 10:37:37 +0200 Subject: [PATCH 23/24] Add changelog to github actions --- .github/workflows/publish.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b7e6f7f..728c02e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -29,6 +29,11 @@ jobs: env: SSH_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} + - name: Create changelog + uses: heinrichreimer/github-changelog-generator-action@v2.1.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Notify slack success if: success() env: From 68e4321b2254edec482c7cd012019202a240a223 Mon Sep 17 00:00:00 2001 From: Inbal Tako Date: Sun, 22 Nov 2020 10:40:22 +0200 Subject: [PATCH 24/24] Fix readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32edc46..6f3f21c 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ $options = new SecureNativeOptions(); $ver = SecureNative::verify(array( 'event' => EventTypes::VERIFY, 'userId' => '1234', - 'context' => SecureNative::fromRequest($options), + 'context' => SecureNative::fromRequest(), 'userTraits' => (object)[ 'name' => 'Your Name', 'email' => 'name@gmail.com'