Merge remote-tracking branch 'origin/support/2.7' into develop

This commit is contained in:
Pierre Goiffon
2020-10-19 15:38:11 +02:00
9 changed files with 600 additions and 312 deletions

View File

@@ -321,7 +321,7 @@ ij_php_call_parameters_right_paren_on_new_line = false
ij_php_call_parameters_wrap = normal
ij_php_catch_on_new_line = true
ij_php_category_weight = 28
ij_php_class_brace_style = end_of_line
ij_php_class_brace_style = next_line
ij_php_comma_after_last_array_element = true
ij_php_concat_spaces = false
ij_php_copyright_weight = 28
@@ -361,7 +361,7 @@ ij_php_keep_control_statement_in_one_line = true
ij_php_keep_first_column_comment = true
ij_php_keep_indents_on_empty_lines = false
ij_php_keep_line_breaks = true
ij_php_keep_rparen_and_lbrace_on_one_line = true
ij_php_keep_rparen_and_lbrace_on_one_line = false
ij_php_keep_simple_classes_in_one_line = false
ij_php_keep_simple_methods_in_one_line = false
ij_php_lambda_brace_style = end_of_line
@@ -372,7 +372,7 @@ ij_php_link_weight = 28
ij_php_lower_case_boolean_const = true
ij_php_lower_case_keywords = true
ij_php_lower_case_null_const = true
ij_php_method_brace_style = end_of_line
ij_php_method_brace_style = next_line
ij_php_method_call_chain_wrap = off
ij_php_method_parameters_new_line_after_left_paren = true
ij_php_method_parameters_right_paren_on_new_line = true

View File

@@ -309,7 +309,7 @@ class BulkChange
$value = $oForeignAtt->MakeValueFromString($aRowData[$iCol], $this->m_bLocalizedValues);
}
$oReconFilter->AddCondition($sForeignAttCode, $value, '=');
$aResults[$iCol] = new CellStatus_Void($aRowData[$iCol]);
$aResults[$iCol] = new CellStatus_Void(htmlentities($aRowData[$iCol]));
}
$oExtObjects = new CMDBObjectSet($oReconFilter);
@@ -363,6 +363,7 @@ class BulkChange
foreach ($aKeyConfig as $sForeignAttCode => $iCol)
{
// Default reporting
// $aRowData[$iCol] is always null
$aResults[$iCol] = new CellStatus_Void($aRowData[$iCol]);
}
if ($oExtKey->IsNullAllowed())
@@ -395,7 +396,7 @@ class BulkChange
}
$aCacheKeys[] = $value;
$oReconFilter->AddCondition($sForeignAttCode, $value, '=');
$aResults[$iCol] = new CellStatus_Void($aRowData[$iCol]);
$aResults[$iCol] = new CellStatus_Void(htmlentities($aRowData[$iCol]));
}
$sCacheKey = implode('_|_', $aCacheKeys); // Unique key for this query...
$iForeignKey = null;
@@ -465,7 +466,7 @@ class BulkChange
foreach ($aKeyConfig as $sForeignAttCode => $iCol)
{
// Report the change on reconciliation values as well
$aResults[$iCol] = new CellStatus_Modify($aRowData[$iCol]);
$aResults[$iCol] = new CellStatus_Modify(htmlentities($aRowData[$iCol]));
}
}
}
@@ -538,7 +539,7 @@ class BulkChange
{
if ($sAttCode == 'id')
{
$aResults[$iCol]= new CellStatus_Void($aRowData[$iCol]);
$aResults[$iCol]= new CellStatus_Void(htmlentities($aRowData[$iCol]));
}
else
{
@@ -554,7 +555,7 @@ class BulkChange
}
if (isset($aErrors[$sAttCode]))
{
$aResults[$iCol]= new CellStatus_Issue($aRowData[$iCol], $sOrigValue, $aErrors[$sAttCode]);
$aResults[$iCol]= new CellStatus_Issue(htmlentities($aRowData[$iCol]), $sOrigValue, $aErrors[$sAttCode]);
}
elseif (array_key_exists($sAttCode, $aChangedFields))
{
@@ -577,7 +578,7 @@ class BulkChange
}
else
{
$aResults[$iCol]= new CellStatus_Void($aRowData[$iCol]);
$aResults[$iCol]= new CellStatus_Void(htmlentities($aRowData[$iCol]));
}
}
}
@@ -924,7 +925,7 @@ class BulkChange
{
// Leave the cell unchanged
$aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
$aResult[$iRow][$sAttCode] = new CellStatus_Issue(null, $this->m_aData[$iRow][$iCol], Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
$aResult[$iRow][$sAttCode] = new CellStatus_Issue(null, htmlentities($this->m_aData[$iRow][$iCol]), Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
}
}
}
@@ -1082,7 +1083,7 @@ class BulkChange
{
if (!array_key_exists($iCol, $aResult[$iRow]))
{
$aResult[$iRow][$iCol] = new CellStatus_Void($aRowData[$iCol]);
$aResult[$iRow][$iCol] = new CellStatus_Void(htmlentities($aRowData[$iCol]));
}
}
foreach($this->m_aExtKeys as $sAttCode => $aForeignAtts)
@@ -1096,7 +1097,7 @@ class BulkChange
if (!array_key_exists($iCol, $aResult[$iRow]))
{
// The foreign attribute is one of our reconciliation key
$aResult[$iRow][$iCol] = new CellStatus_Void($aRowData[$iCol]);
$aResult[$iRow][$iCol] = new CellStatus_Void(htmlentities($aRowData[$iCol]));
}
}
}

View File

@@ -28,31 +28,39 @@
class CoreException extends Exception
{
/**
* CoreException constructor.
*
* @param string $sIssue error message
* @param array|null $aContextData key/value array, value MUST implements _toString
* @param string $sImpact
* @param Exception|null $oPrevious
*/
public function __construct($sIssue, $aContextData = null, $sImpact = '', $oPrevious = null)
{
$this->m_sIssue = $sIssue;
$this->m_sImpact = $sImpact;
$this->m_aContextData = $aContextData ? $aContextData : array();
if (is_array($aContextData)) {
$this->m_aContextData = $aContextData;
} else {
$this->m_aContextData = [];
}
$sMessage = $sIssue;
if (!empty($sImpact)) $sMessage .= "($sImpact)";
if (count($this->m_aContextData) > 0)
{
if (!empty($sImpact)) {
$sMessage .= "($sImpact)";
}
if (count($this->m_aContextData) > 0) {
$sMessage .= ": ";
$aContextItems = array();
foreach($this->m_aContextData as $sKey => $value)
{
if (is_array($value))
{
foreach ($this->m_aContextData as $sKey => $value) {
if (is_array($value)) {
$aPairs = array();
foreach($value as $key => $val)
{
if (is_array($val))
{
foreach ($value as $key => $val) {
if (is_array($val)) {
$aPairs[] = $key.'=>('.implode(', ', $val).')';
}
else
{
} else {
$aPairs[] = $key.'=>'.$val;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1069,7 +1069,7 @@ class MatchExpression extends BinaryExpression
public function __construct(FieldExpression $oLeftExpr, Expression $oRightExpr)
{
if (!$oRightExpr instanceof ScalarExpression && !$oRightExpr instanceof VariableExpression) {
throw new CoreException('Only instance of ScalarExpression or VariableExpression are allowed in MATCHES '.get_class( $oRightExpr).' found', $oRightExpr);
throw new CoreException('Only instance of ScalarExpression or VariableExpression are allowed in MATCHES '.get_class($oRightExpr).' found');
}
parent::__construct($oLeftExpr, 'MATCHES', $oRightExpr);
}

View File

@@ -69,8 +69,8 @@ $(function()
if (sTitle.length == 0) {
sTitle = oEntry['label'];
}
sTitle = SanitizeHtml(sTitle, false);
sLabel = SanitizeHtml(sLabel, false);
sTitle = EncodeHtml(sTitle, false);
sLabel = EncodeHtml(sLabel, false);
if ((this.options.new_entry !== null) && (iEntry == aBreadCrumb.length-1)) {
// Last entry is the current page

View File

@@ -681,16 +681,16 @@ function DisplayHistory(sSelector, sFilter, iCount, iStart) {
/**
* @param sValue value to escape
* @param bReplaceAmp if false don't replace "&" (can be useful when dealing with html entities)
* @returns {string} sanitized value, ready to insert in the DOM without XSS risk
* @param bReplaceAmp if false don't replace "&" (can be useful when sValue contrains html entities we want to keep)
* @returns {string} escaped value, ready to insert in the DOM without XSS risk
*
* @since 2.6.5, 2.7.2, 3.0.0 N°3332
* @see https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#rule-1-html-encode-before-inserting-untrusted-data-into-html-element-content
* @see https://stackoverflow.com/questions/295566/sanitize-rewrite-html-on-the-client-side/430240#430240 why inserting in the DOM (for
* example the text() JQuery way) isn't safe
*/
function SanitizeHtml(sValue, bReplaceAmp) {
var sSanitizedValue = (sValue+'')
function EncodeHtml(sValue, bReplaceAmp) {
var sEncodedValue = (sValue+'')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
@@ -698,10 +698,10 @@ function SanitizeHtml(sValue, bReplaceAmp) {
.replace(/\//g, '&#x2F;');
if (bReplaceAmp) {
sSanitizedValue = sSanitizedValue.replace(/&/g, '&amp;');
sEncodedValue = sEncodedValue.replace(/&/g, '&amp;');
}
return sSanitizedValue;
return sEncodedValue;
}
// Very simple equivalent to format: placeholders are %1$s %2$d ...

View File

@@ -454,7 +454,7 @@ try
// Do nothing
}
}
$sHtmlValue = utils::HtmlEntities(utils::HtmlEntityDecode($oCellStatus->GetDisplayableValue()));
$sHtmlValue = $oCellStatus->GetDisplayableValue();
switch(get_class($oCellStatus))
{
case 'CellStatus_Issue':

View File

@@ -1,18 +1,20 @@
<?php
namespace Combodo\iTop\Test\UnitTest\Core;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use CMDBSource;
use MetaModel;
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @backupGlobals disabled
*/
class BulkChangeTest extends ItopDataTestCase
{
class BulkChangeTest extends ItopDataTestCase {
const CREATE_TEST_ORG = true;
protected function setUp()
{
protected function setUp() {
parent::setUp();
require_once(APPROOT.'core/coreexception.class.inc.php');
require_once(APPROOT.'core/bulkchange.class.inc.php');
@@ -20,8 +22,7 @@ class BulkChangeTest extends ItopDataTestCase
}
//bug 2888: csv import / data synchro issue with password validation
public function testPasswordBulkChangeIssue()
{
public function testPasswordBulkChangeIssue() {
/** @var Personn $oPerson */
$oPerson = $this->createObject('Person', array(
'first_name' => 'isaac',
@@ -31,18 +32,21 @@ class BulkChangeTest extends ItopDataTestCase
));
$aData = array(
array($oPerson->Get("first_name"),
array(
$oPerson->Get("first_name"),
$oPerson->Get("name"),
$oPerson->Get("email"),
"EN US",
"iasimov",
"harryseldon",
"profileid->name:Administrator"
)
"profileid->name:Administrator",
),
);
$aAttributes = array("language" => 3, "login" => 4, "password" => 5, "profile_list" => 6);
$aExtKeys = array("contactid" =>
array("first_name" => 0, "name" => 1, "email" => 2));
$aExtKeys = array(
"contactid" =>
array("first_name" => 0, "name" => 1, "email" => 2),
);
$oBulk = new \BulkChange(
"UserLocal",
$aData,
@@ -59,14 +63,343 @@ class BulkChangeTest extends ItopDataTestCase
$aRes = $oBulk->Process($oChange);
static::assertNotNull($aRes);
foreach ($aRes as $aRow)
{
if (array_key_exists('__STATUS__', $aRow))
{
foreach ($aRes as $aRow) {
if (array_key_exists('__STATUS__', $aRow)) {
$sStatus = $aRow['__STATUS__'];
$this->assertFalse(strstr($sStatus->GetDescription(), "CoreCannotSaveObjectException"), "CSVimport/Datasynchro: Password validation failed with: " . $sStatus->GetDescription());
$this->assertFalse(strstr($sStatus->GetDescription(), "CoreCannotSaveObjectException"),
"CSVimport/Datasynchro: Password validation failed with: ".$sStatus->GetDescription());
}
}
}
/**
* test $oBulk->Process with server 1 from demo datas
* @dataProvider BulkChangeProvider
*
* @param $aData
* @param $aAttributes
* @param $aExtKeys
* @param $aReconcilKeys
*/
public function testBulkChangeIssue($aData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult) {
$this->debug("aReconcilKeys:".$aReconcilKeys[0]);
$oBulk = new \BulkChange(
"Server",
$aData,
$aAttributes,
$aExtKeys,
$aReconcilKeys,
null,
null,
"Y-m-d H:i:s", // date format
true // localize
);
$oChange = \CMDBObject::GetCurrentChange();
$aRes = $oBulk->Process($oChange);
static::assertNotNull($aRes);
foreach ($aRes as $aRow) {
if (array_key_exists('__STATUS__', $aRow)) {
$sStatus = $aRow['__STATUS__'];
//$this->debug("sStatus:".$sStatus->GetDescription());
$this->assertEquals($sStatus->GetDescription(), $aResult["__STATUS__"]);
foreach ($aRow as $i => $oCell) {
if ($i != "finalclass" && $i != "__STATUS__") {
$this->debug("i:".$i);
$this->debug('GetDisplayableValue:'.$oCell->GetDisplayableValue());
$this->debug("aResult:".$aResult[$i]);
$this->assertEquals($oCell->GetDisplayableValue(), $aResult[$i]);
}
}
}
}
}
public function BulkChangeProvider() {
return [
"Case 3, 5 et 8 : unchanged" => [
[["Demo", "Server1", "1", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[0 => "Demo", "org_id" => "3", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
],
"Case 9 : wrong date format" => [
[["Demo", "Server1", "1", "production", "date"]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[ 0 => "Demo", "org_id" => "n/a", 1 => "Server1", 2 => "1", 3 => "production", 4 => "date", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
],
"Case 1 : no match" => [
[["Bad", "Server1", "1", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
["org_id" => "",1 => "Server1",2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
],
"Case 10 : Missing mandatory value" => [
[["", "Server1", "1", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[ "org_id" => "", 1 => "Server1", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
],
"Case 6 : Unexpected value" => [
[["Demo", "Server1", "1", "<svg onclick\"alert(1)\">", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[0 => "Demo", "org_id" => "3", 1 => "Server1", 2 => "1", 3 => "&lt;svg onclick&quot;alert(1)&quot;&gt;", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
],
];
}
/**
* test $oBulk->Process with new server datas
* @dataProvider CSVImportProvider
*
* @param $aInitData
* @param $aCsvData
* @param $aAttributes
* @param $aExtKeys
* @param $aReconcilKeys
*/
public function testCas1BulkChangeIssue($aInitData, $aCsvData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult) {
CMDBSource::Query('START TRANSACTION');
//change value during the test
$db_core_transactions_enabled=MetaModel::GetConfig()->Get('db_core_transactions_enabled');
MetaModel::GetConfig()->Set('db_core_transactions_enabled',false);
/** @var Server $oServer */
$oServer = $this->createObject('Server', array(
'name' => $aInitData[1],
'status' => $aInitData[2],
'org_id' => $aInitData[0],
'purchase_date' => $aInitData[3],
));
$aCsvData[0][2]=$oServer->GetKey();
$aResult[2]=$oServer->GetKey();
$aResult["id"]=$oServer->GetKey();
$this->debug("oServer->GetKey():".$oServer->GetKey());
$this->debug("aCsvData:".json_encode($aCsvData[0]));
$this->debug("aReconcilKeys:".$aReconcilKeys[0]);
$oBulk = new \BulkChange(
"Server",
$aCsvData,
$aAttributes,
$aExtKeys,
$aReconcilKeys,
null,
null,
"Y-m-d H:i:s", // date format
true // localize
);
$this->debug("BulkChange:");
$oChange = \CMDBObject::GetCurrentChange();
$this->debug("GetCurrentChange:");
$aRes = $oBulk->Process($oChange);
$this->debug("Process:");
static::assertNotNull($aRes);
$this->debug("assertNotNull:");
foreach ($aRes as $aRow) {
if (array_key_exists('__STATUS__', $aRow)) {
$sStatus = $aRow['__STATUS__'];
$this->debug("sStatus:".$sStatus->GetDescription());
$this->assertEquals($sStatus->GetDescription(), $aResult["__STATUS__"]);
foreach ($aRow as $i => $oCell) {
if ($i != "finalclass" && $i != "__STATUS__") {
$this->debug("i:".$i);
$this->debug('GetDisplayableValue:'.$oCell->GetDisplayableValue());
$this->debug("aResult:".$aResult[$i]);
$this->assertEquals( $aResult[$i], $oCell->GetDisplayableValue());
}
}
$this->assertEquals( $aResult[0], $aRow[0]->GetDisplayableValue());
}
}
CMDBSource::Query('ROLLBACK');
MetaModel::GetConfig()->Set('db_core_transactions_enabled',$db_core_transactions_enabled);
}
public function CSVImportProvider() {
return [
"Case 6 - 1 : Unexpected value" => [
["1", "ServerTest", "production", ""],
[["Demo", "ServerTest", "key", "BadValue", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[0 => "Demo", "org_id" => "3", 1 => "ServerTest", 2 => "1", 3 => "BadValue", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
],
"Case 6 - 2 : Unexpected value" => [
["1", "ServerTest", "production", ""],
[["Demo", "ServerTest", "key", "<svg onclick\"alert(1)\">", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[0 => "Demo", "org_id" => "3", 1 => "ServerTest", 2 => "1", 3 => "&lt;svg onclick&quot;alert(1)&quot;&gt;", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
],
"Case 8 : unchanged name" => [
["1", "<svg onclick\"alert(1)\">", "production", ""],
[["Demo", "<svg onclick\"alert(1)\">", "key", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[0 => "Demo", "org_id" => "3", 1 => "&lt;svg onclick&quot;alert(1)&quot;&gt;", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "updated 1 cols"],
],
"Case 3, 5 et 8 : unchanged 2" => [
["1", "ServerTest", "production", ""],
[["Demo", "ServerTest", "1", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[0 => "Demo", "org_id" => "3", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "updated 1 cols"],
],
"Case 9 - 1: wrong date format" => [
["1", "ServerTest", "production", ""],
[["Demo", "ServerTest", "1", "production", "date"]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[ 0 => "Demo", "org_id" => "n/a", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "date", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
],
"Case 9 - 2: wrong date format" => [
["1", "ServerTest", "production", ""],
[["Demo", "ServerTest", "1", "production", "<svg onclick\"alert(1)\">"]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[ 0 => "Demo", "org_id" => "n/a", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "&lt;svg onclick&quot;alert(1)&quot;&gt;", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
],
"Case 1 - 1 : no match" => [
["1", "ServerTest", "production", ""],
[["Bad", "ServerTest", "1", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[ 0 => "Bad", "org_id" => "",1 => "ServerTest",2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
],
"Case 1 - 2 : no match" => [
["1", "ServerTest", "production", ""],
[["<svg fonclick\"alert(1)\">", "ServerTest", "1", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[ 0 => "&lt;svg fonclick&quot;alert(1)&quot;&gt;", "org_id" => "",1 => "ServerTest",2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
],
"Case 10 : Missing mandatory value" => [
["1", "ServerTest", "production", ""],
[["", "ServerTest", "1", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[ 0 => "", "org_id" => "", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "Issue: Unexpected attribute value(s)"],
],
"Case 0 : Date format" => [
["1", "ServerTest", "production", "2020-02-01"],
[["Demo", "ServerTest", "1", "production", "2020-20-03"]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[ 0 => "Demo", "org_id" => "n/a", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "2020-20-03", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
],
];
}
/**
* test $oBulk->Process with new server and new organization datas
* @dataProvider CSVImportProvider2
*
* @param $aInitData
* @param $aCsvData
* @param $aAttributes
* @param $aExtKeys
* @param $aReconcilKeys
*/
public function testCas2BulkChangeIssue($aInitData, $aCsvData, $aAttributes, $aExtKeys, $aReconcilKeys, $aResult) {
CMDBSource::Query('START TRANSACTION');
//change value during the test
$db_core_transactions_enabled=MetaModel::GetConfig()->Get('db_core_transactions_enabled');
MetaModel::GetConfig()->Set('db_core_transactions_enabled',false);
/** @var Server $oServer */
$oOrganisation = $this->createObject('Organization', array(
'name' =>$aInitData[0]
));
$aResult["org_id"]=$oOrganisation->GetKey();
$oServer = $this->createObject('Server', array(
'name' => $aInitData[1],
'status' => $aInitData[2],
'org_id' => $oOrganisation->GetKey(),
'purchase_date' => $aInitData[3],
));
$aCsvData[0][2]=$oServer->GetKey();
$aResult[2]=$oServer->GetKey();
$aResult["id"]=$oServer->GetKey();
$oBulk = new \BulkChange(
"Server",
$aCsvData,
$aAttributes,
$aExtKeys,
$aReconcilKeys,
null,
null,
"Y-m-d H:i:s", // date format
true // localize
);
$oChange = \CMDBObject::GetCurrentChange();
$aRes = $oBulk->Process($oChange);
static::assertNotNull($aRes);
foreach ($aRes as $aRow) {
foreach ($aRow as $i => $oCell) {
if ($i != "finalclass" && $i != "__STATUS__") {
$this->debug("i:".$i);
$this->debug('GetDisplayableValue:'.$oCell->GetDisplayableValue());
$this->debug("aResult:".$aResult[$i]);
$this->assertEquals($aResult[$i], $oCell->GetDisplayableValue());
}
elseif ($i == "__STATUS__") {
$sStatus = $aRow['__STATUS__'];
$this->assertEquals($aResult["__STATUS__"], $sStatus->GetDescription());
}
}
$this->assertEquals($aResult[0], $aRow[0]->GetDisplayableValue());
}
CMDBSource::Query('ROLLBACK');
MetaModel::GetConfig()->Set('db_core_transactions_enabled',$db_core_transactions_enabled);
}
public function CSVImportProvider2() {
return [
"Case 3 : unchanged name" => [
["dodo","ServerYO", "production", ""],
[["dodo", "ServerYO", "key", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[0 => "dodo", "org_id" => "3", 1 => "ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
],
"Case 3 bis : unchanged name" => [
["<svg >","ServerYO", "production", ""],
[["<svg >", "ServerYO", "key", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[0 => "&lt;svg &gt;", "org_id" => "3", 1 => "ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
],
"Case 3 ter : unchanged name" => [
["<svg onclick\"alert(1)\" >","ServerYO", "production", ""],
[["<svg onclick\"alert(1)\" >", "ServerYO", "key", "production", ""]],
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
["org_id" => ["name" => 0]],
["id"],
[0 => "&lt;svg onclick&quot;alert(1)&quot; &gt;", "org_id" => "3", 1 => "ServerYO", 2 => "1", 3 => "production", 4 => "", "id" => 1, "__STATUS__" => "unchanged"],
],
];
}
}