From c3cb4fbe752a5f346cc09e79dacdc5f889613fa9 Mon Sep 17 00:00:00 2001 From: bruno-ds Date: Tue, 23 Feb 2021 10:24:30 +0100 Subject: [PATCH] Fix merge wrongfully performed (thanks @molkobain & @piRGoif & @odain-cbd) --- setup/setuputils.class.inc.php | 7 +++++-- test/setup/SetupUtilsTest.php | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 46847d70b..d637006f2 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -617,8 +617,11 @@ class SetupUtils clearstatcache(); if (!is_file($sGraphvizPath) || !is_executable($sGraphvizPath)) { //N°3412 avoid shell injection - return new CheckResult(CheckResult::ERROR, - "$sGraphvizPath could not be executed: Please make sure it is installed and in the path"); + $aResult = []; + $aResult[] = new CheckResult(CheckResult::ERROR, + self::GetStringForJsonEncode("$sGraphvizPath could not be executed: Please make sure it is installed and in the path", 'Graphviz could not be executed') + ); + return $aResult; } if (!utils::IsWindowsEnvironment()){ diff --git a/test/setup/SetupUtilsTest.php b/test/setup/SetupUtilsTest.php index 47a996bb7..085f95237 100644 --- a/test/setup/SetupUtilsTest.php +++ b/test/setup/SetupUtilsTest.php @@ -21,6 +21,11 @@ use SetupUtils; */ class SetupUtilsTest extends ItopTestCase { + const ERROR = 0; + const WARNING = 1; + const INFO = 2; + const TRACE = 3; // for log purposes : replace old SetupLog::Log calls + protected function setUp() { parent::setUp(); @@ -34,9 +39,15 @@ class SetupUtilsTest extends ItopTestCase */ public function testCheckGraphviz($sScriptPath, $iSeverity, $sLabel){ /** @var \CheckResult $oCheck */ - $oCheck = SetupUtils::CheckGraphviz($sScriptPath); - $this->assertEquals($iSeverity, $oCheck->iSeverity); - $this->assertContains($sLabel, $oCheck->sLabel); + $aCheck = SetupUtils::CheckGraphviz($sScriptPath); + $bLabelFound = false; + foreach ($aCheck as $oCheck) { + $this->assertGreaterThanOrEqual($iSeverity, $oCheck->iSeverity); + if (!$bLabelFound && (empty($sLabel) || strpos($oCheck->sLabel, $sLabel) !== false)) { + $bLabelFound = true; + } + } + $this->assertTrue($bLabelFound, "label '$sLabel' not found"); } public function CheckGraphvizProvider(){ @@ -47,22 +58,22 @@ class SetupUtilsTest extends ItopTestCase return [ "bash injection" => [ "touch /tmp/toto", - 0, + self::ERROR, "could not be executed: Please make sure it is installed and in the path", ], "command ok" => [ "/usr/bin/whereis", - 2, + self::INFO, "", ], "empty command => dot by default" => [ "", - 2, + self::INFO, "", ], "command failed" => [ "/bin/ls", - 1, + self::WARNING, "dot could not be executed (retcode=2): Please make sure it is installed and in the path", ] ];