From 6564fb20c54acaa9debac46d2df4868790d6605b Mon Sep 17 00:00:00 2001 From: Alexander Popel Date: Mon, 24 Jul 2023 12:00:51 +0300 Subject: [PATCH 1/7] Merge changes from upstream --- Evidence.php | 15 +++++++++++---- ci/README.md | 6 +++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Evidence.php b/Evidence.php index fa77076..e0d225b 100644 --- a/Evidence.php +++ b/Evidence.php @@ -79,9 +79,11 @@ public function setArray($array) /** * Extract evidence from a web request - * No argument version automatically reads from current request - * @param $_SERVER - * @param $_COOKIE + * No argument version automatically reads from current request using the + * $_SERVER, $_COOKIE, $_GET and $_POST globals + * @param $server key value pairs for the HTTP headers + * @param $cookies key value pairs for the cookies + * @param $query key value pairs for the form parameters */ public function setFromWebRequest($server = null, $cookies = null, $query = null) { @@ -94,7 +96,9 @@ public function setFromWebRequest($server = null, $cookies = null, $query = null } if (!$query) { - $query = $_GET; + // Merge the GET and POST parameters favoring the GET keys if there + // are keys that conflict. + $query = array_merge($_POST, $_GET); } $evidence = array(); @@ -105,15 +109,18 @@ public function setFromWebRequest($server = null, $cookies = null, $query = null $key = strtolower($key); + error_log("header." . $key . ": " . $value, 0); $evidence["header." . $key] = $value; } } foreach ($cookies as $key => $value) { + error_log("cookie." . $key . ": " . $value, 0); $evidence["cookie." . $key] = $value; } foreach ($query as $key => $value) { + error_log("query." . $key . ": " . $value, 0); $evidence["query." . $key] = $value; } diff --git a/ci/README.md b/ci/README.md index d58d90d..2e9d94d 100644 --- a/ci/README.md +++ b/ci/README.md @@ -1,2 +1,6 @@ # API Specific CI/CD Approach -This API complies with the `common-ci` approach. \ No newline at end of file +This API complies with the `common-ci` approach. + +The following secrets are required: +* `ACCESS_TOKEN` - GitHub [access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#about-personal-access-tokens) for cloning repos, creating PRs, etc. + * Example: `github_pat_l0ng_r4nd0m_s7r1ng` From 51cedb9672b431e40fd4034e23da60e424361bf7 Mon Sep 17 00:00:00 2001 From: Alexander Popel Date: Thu, 27 Jul 2023 17:16:38 +0300 Subject: [PATCH 2/7] Merge branch '51Degrees:main' into main --- ...lish-main.yml => nightly-publish-main.yml} | 0 AspectPropertyValue.php | 19 +++++++++++++++++-- BasicListEvidenceKeyFilter.php | 6 ++---- ElementDataDictionary.php | 1 + EvidenceKeyFilter.php | 12 ++++++++++++ FlowData.php | 2 +- FlowElement.php | 11 +++-------- JavascriptBuilder.php | 3 +++ Logger.php | 2 ++ Pipeline.php | 2 ++ PipelineBuilder.php | 5 +++++ SetHeaderElement.php | 7 +++---- tests/JavaScriptBundlerTests.php | 2 ++ 13 files changed, 53 insertions(+), 19 deletions(-) rename .github/workflows/{nightky-publish-main.yml => nightly-publish-main.yml} (100%) diff --git a/.github/workflows/nightky-publish-main.yml b/.github/workflows/nightly-publish-main.yml similarity index 100% rename from .github/workflows/nightky-publish-main.yml rename to .github/workflows/nightly-publish-main.yml diff --git a/AspectPropertyValue.php b/AspectPropertyValue.php index 21d4b18..9df583f 100644 --- a/AspectPropertyValue.php +++ b/AspectPropertyValue.php @@ -32,6 +32,9 @@ */ class AspectPropertyValue { + private $_value; + public $noValueMessage = null; + public $hasValue = false; /** * Constructor for AspectPropertyValue @@ -59,8 +62,20 @@ public function __construct($noValueMessage = null, $value = "noValue") */ public function __get($key) { - if ($key === "value" && $this->noValueMessage) { - throw new \Exception($this->noValueMessage); + if ($key === "value") { + if ($this->hasValue) { + return $this->_value; + } else if (!empty($this->noValueMessage)) { + throw new \Exception($this->noValueMessage); + } + } + } + + public function __set($key, $value) + { + if ($key === "value") { + $this->_value = $value; + $this->hasValue = true; } } } diff --git a/BasicListEvidenceKeyFilter.php b/BasicListEvidenceKeyFilter.php index c7b6134..3204be6 100644 --- a/BasicListEvidenceKeyFilter.php +++ b/BasicListEvidenceKeyFilter.php @@ -49,15 +49,13 @@ public function __construct($list) */ public function filterEvidenceKey($key) { - $keep = false; - foreach ($this->list as $evidenceKey) { if (strtolower($key) === strtolower($evidenceKey)) { - $keep = true; + return true; } } - return $keep; + return false; } /** diff --git a/ElementDataDictionary.php b/ElementDataDictionary.php index f948da3..c9a0d88 100644 --- a/ElementDataDictionary.php +++ b/ElementDataDictionary.php @@ -30,6 +30,7 @@ **/ class ElementDataDictionary extends ElementData { + public $contents; /** * Constructor for element data dictionary diff --git a/EvidenceKeyFilter.php b/EvidenceKeyFilter.php index 889fa4e..025453e 100644 --- a/EvidenceKeyFilter.php +++ b/EvidenceKeyFilter.php @@ -32,6 +32,7 @@ */ class EvidenceKeyFilter { + private $_filterEvidenceKey = null; /** * filterevidence from an object @@ -58,6 +59,17 @@ public function filterEvidence($evidenceKeyObject) */ public function filterEvidenceKey($key) { + if ($this->_filterEvidenceKey) { + return call_user_func($this->_filterEvidenceKey, $key); + } + return true; } + + public function __set($name, $value) + { + if ($name === 'filterEvidenceKey') { + $this->_filterEvidenceKey = $value; + } + } } diff --git a/FlowData.php b/FlowData.php index 2dcb9ea..78ad4a1 100644 --- a/FlowData.php +++ b/FlowData.php @@ -171,7 +171,7 @@ public function getEvidenceDataKey() $requestedEvidence = array(); $evidence = $this->evidence->getAll(); - foreach ($this->Pipeline->flowElements as $flowElement) { + foreach ($this->pipeline->flowElements as $flowElement) { $requestedEvidence = array_merge($requestedEvidence, $flowElement->filterEvidence($this)); } diff --git a/FlowElement.php b/FlowElement.php index db8d50a..52e2268 100644 --- a/FlowElement.php +++ b/FlowElement.php @@ -32,16 +32,11 @@ **/ class FlowElement { - public function __construct() - { - - // List of Pipelines the FlowElement has been added to - $this->pipelines = []; - } - public $dataKey; public $properties = []; - + // List of Pipelines the FlowElement has been added to + public $pipelines = []; + /** * General wrapper function that calls a FlowElement's processInternal method * @param FlowData diff --git a/JavascriptBuilder.php b/JavascriptBuilder.php index 2337728..c47e00c 100644 --- a/JavascriptBuilder.php +++ b/JavascriptBuilder.php @@ -36,6 +36,9 @@ */ class JavascriptBuilderElement extends FlowElement { + public $settings; + public $minify; + public function __construct($settings = array()) { $this->settings = [ diff --git a/Logger.php b/Logger.php index ba606fe..8136b5b 100644 --- a/Logger.php +++ b/Logger.php @@ -32,6 +32,8 @@ class Logger private $levels = ["trace", "debug", "information", "warning", "error", "critical"]; + public $settings; + /** * Create a logger * @param string level ("trace", "debug", "information", "warning", "error", "critical") diff --git a/Pipeline.php b/Pipeline.php index 851a57e..fa1ad1a 100644 --- a/Pipeline.php +++ b/Pipeline.php @@ -35,6 +35,8 @@ class Pipeline public $flowElementsList = array(); public $logger; public $metaDataStore; + public $suppressProcessExceptions; + public $propertyDatabase; /** * Pipeline constructor diff --git a/PipelineBuilder.php b/PipelineBuilder.php index 77fe979..475e5e0 100644 --- a/PipelineBuilder.php +++ b/PipelineBuilder.php @@ -30,6 +30,11 @@ */ class PipelineBuilder { + public $pipelines; + public $addJavaScriptBuilder; + public $javascriptBuilderSettings; + public $useSetHeaderProperties; + public function __construct($settings = array()) { diff --git a/SetHeaderElement.php b/SetHeaderElement.php index 6567c53..e11befc 100644 --- a/SetHeaderElement.php +++ b/SetHeaderElement.php @@ -152,15 +152,14 @@ public function getPropertyValue($flowData, $elementKey, $propertyKey){ } $propertyKey = strtolower($propertyKey); - try { + if (isset($elementData->$propertyKey)) { $property = $elementData->$propertyKey; - } - catch (Exception $e) { + } else { echo sprintf(Messages::PROPERTY_NOT_FOUND, $propertyKey, $elementKey); return ""; } - if($property->hasValue && !in_array($property->value, ["Unknown", "noValue"])){ + if($property && $property->hasValue && !in_array($property->value, ["Unknown", "noValue"])){ $value = $property->value; } else{ diff --git a/tests/JavaScriptBundlerTests.php b/tests/JavaScriptBundlerTests.php index 5e05ed3..88035de 100644 --- a/tests/JavaScriptBundlerTests.php +++ b/tests/JavaScriptBundlerTests.php @@ -67,6 +67,8 @@ public function processInternal($FlowData) class TestPipeline { + public $Pipeline; + public function __construct($minify = NULL) { if (is_null($minify)) { From da40395a0c2b163649380a315228a58c40d35992 Mon Sep 17 00:00:00 2001 From: Alexander Popel Date: Tue, 1 Aug 2023 16:37:41 +0300 Subject: [PATCH 3/7] Pull upstream changes --- Evidence.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Evidence.php b/Evidence.php index e0d225b..937021d 100644 --- a/Evidence.php +++ b/Evidence.php @@ -43,7 +43,8 @@ public function __construct($flowData) } /** - * Set a single piece of evidence by its element and value + * If a flow element can use the key then add the key value pair to the + * evidence collection * @param string key * @param mixed value */ @@ -54,6 +55,7 @@ public function set($key, $value) foreach ($this->flowData->pipeline->flowElements as $flowElement) { if ($flowElement->filterEvidenceKey($key)) { $keep = true; + break; } } @@ -87,15 +89,15 @@ public function setArray($array) */ public function setFromWebRequest($server = null, $cookies = null, $query = null) { - if (!$server) { + if ($server === null) { $server = $_SERVER; } - if (!$cookies) { + if ($cookies === null) { $cookies = $_COOKIE; } - if (!$query) { + if ($query === null) { // Merge the GET and POST parameters favoring the GET keys if there // are keys that conflict. $query = array_merge($_POST, $_GET); @@ -134,7 +136,7 @@ public function setFromWebRequest($server = null, $cookies = null, $query = null // Protocol - if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { + if (isset($server['HTTPS']) && ($server['HTTPS'] == 'on' || $server['HTTPS'] == 1) || isset($server['HTTP_X_FORWARDED_PROTO']) && $server['HTTP_X_FORWARDED_PROTO'] == 'https') { $protocol = 'https'; } else { $protocol = 'http'; @@ -142,8 +144,8 @@ public function setFromWebRequest($server = null, $cookies = null, $query = null // Override protocol with referer header if set - if (isset($_SERVER["HTTP_REFERER"]) && $_SERVER["HTTP_REFERER"]) { - $protocol = parse_url($_SERVER["HTTP_REFERER"], PHP_URL_SCHEME); + if (isset($server["HTTP_REFERER"]) && $server["HTTP_REFERER"]) { + $protocol = parse_url($server["HTTP_REFERER"], PHP_URL_SCHEME); } $evidence["header.protocol"] = $protocol; @@ -151,7 +153,6 @@ public function setFromWebRequest($server = null, $cookies = null, $query = null $this->setArray($evidence); } - /** * Get a piece of evidence by key * @param string key From 228d58d419b9fb574a5035cc3c38cb5a19715529 Mon Sep 17 00:00:00 2001 From: Alexander Popel Date: Tue, 1 Aug 2023 17:02:58 +0300 Subject: [PATCH 4/7] options.json: add PHP 7.4 --- ci/options.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ci/options.json b/ci/options.json index 35e01c4..249b35e 100644 --- a/ci/options.json +++ b/ci/options.json @@ -46,5 +46,21 @@ "LanguageVersion": "8.0", "RunPerformance": true, "PackageRequirement": true + }, + { + "Name": "Ubuntu_PHP_7.4", + "Image": "ubuntu-latest", + "Language": "php", + "LanguageVersion": "7.4", + "RunPerformance": true, + "PackageRequirement": true + }, + { + "Name": "macOS_PHP_7.4", + "Image": "macos-latest", + "Language": "php", + "LanguageVersion": "7.4", + "RunPerformance": true, + "PackageRequirement": true } ] From d1d6d351d49fb6b3675622fde6e86e52b8bccefa Mon Sep 17 00:00:00 2001 From: lukareihl Date: Mon, 7 Aug 2023 09:41:14 +0200 Subject: [PATCH 5/7] Forbid method chaining after calling buildFromConfig() to prevent passing flow element duplicates to the Pipeline in build() --- PipelineBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PipelineBuilder.php b/PipelineBuilder.php index 475e5e0..7a432d6 100644 --- a/PipelineBuilder.php +++ b/PipelineBuilder.php @@ -148,6 +148,7 @@ public function addLogger($logger) * }` * @param string file name of the file to load config, or alternatively * pass a config object already read from file + * @return Pipeline */ public function buildFromConfig($fileOrConfig) { @@ -172,6 +173,6 @@ public function buildFromConfig($fileOrConfig) $this->flowElements[] = $flowElement; } - return $this; + return new Pipeline($this->flowElements, $this->settings); } } From f85e6b23cd7bc8a6e9142db10c3f8d261d471b6d Mon Sep 17 00:00:00 2001 From: lukareihl Date: Wed, 9 Aug 2023 14:01:12 +0200 Subject: [PATCH 6/7] Merge changes from upstream --- Evidence.php | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/Evidence.php b/Evidence.php index 7605705..178f9d7 100644 --- a/Evidence.php +++ b/Evidence.php @@ -1,24 +1,24 @@ - $value) { - error_log("cookie." . $key . ": " . $value, 0); $evidence["cookie." . $key] = $value; } foreach ($query as $key => $value) { - error_log("query." . $key . ": " . $value, 0); $evidence["query." . $key] = $value; } From 0639d45960131552a55cb9b44e0fcc6ac4e1eefe Mon Sep 17 00:00:00 2001 From: lukareihl Date: Thu, 10 Aug 2023 11:28:23 +0200 Subject: [PATCH 7/7] Revert "options.json: add PHP 7.4" This reverts commit 228d58d419b9fb574a5035cc3c38cb5a19715529. --- ci/options.json | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/ci/options.json b/ci/options.json index 249b35e..35e01c4 100644 --- a/ci/options.json +++ b/ci/options.json @@ -46,21 +46,5 @@ "LanguageVersion": "8.0", "RunPerformance": true, "PackageRequirement": true - }, - { - "Name": "Ubuntu_PHP_7.4", - "Image": "ubuntu-latest", - "Language": "php", - "LanguageVersion": "7.4", - "RunPerformance": true, - "PackageRequirement": true - }, - { - "Name": "macOS_PHP_7.4", - "Image": "macos-latest", - "Language": "php", - "LanguageVersion": "7.4", - "RunPerformance": true, - "PackageRequirement": true } ]