N°931: Integrity controls

This commit is contained in:
Eric
2018-09-11 12:25:01 +02:00
13 changed files with 2506 additions and 2344 deletions

1
.gitignore vendored
View File

@@ -4,6 +4,7 @@ env-*/*
# composer reserver directory, from sources, populate/update using "composer install"
vendor/*
test/vendor/*
# all datas but listing prevention
data/*

View File

@@ -34,5 +34,10 @@
<option name="SMART_TABS" value="true" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="XML">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>

View File

@@ -10,7 +10,11 @@
<inspection_tool class="PhpUndefinedClassInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="DONT_REPORT_MULTI_RESOLVE" value="true" />
</inspection_tool>
<inspection_tool class="PhpUndefinedMethodInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpUnhandledExceptionInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpUnusedLocalVariableInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="DONT_REPORT_INSIDE_LIST" value="true" />
</inspection_tool>
<inspection_tool class="PhpUnusedParameterInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="DONT_REPORT_ABSTRACT_CLASS" value="true" />
</inspection_tool>

View File

@@ -47,6 +47,44 @@ iTop also offers mass import tools and web services to integrate with your IT
iTop development is sponsored, led and supported by [Combodo][14].
# Contributors
We would like to give a special thank you to the people from the community who contributed to this project, including:
- Alves, David
- Beck, Pedro
- Bilger, Jean-François
- Cardoso, Anderson
- Cassaro, Bruno
- Casteleyn, Thomas
- Castro, Randall Badilla
- Colantoni, Maria Laura
- Dvořák, Lukáš
- Goethals, Stefan
- Gumble, David
- Hippler, Lars
- Khamit, Shamil
- Kunin, Vladimir
- Lassiter, Dennis
- Lucas, Jonathan
- Malik, Remie
- Rosenke, Stephan
- Seki, Shoji
- Shilov, Vladimir
- Tulio, Marco
- Turrubiates, Miguel
#### Aliases
- cprobst
- Karkoff1212
- Laura
- Schlobinux
- theBigOne
- ulmerspatz
#### Companies
- Hardis
- ITOMIG
[1]: https://sourceforge.net/p/itop/discussion/
[2]: https://sourceforge.net/p/itop/tickets/
[3]: https://sourceforge.net/projects/itop/files/itop/

View File

@@ -559,6 +559,18 @@ class utils
return $iReturn;
}
/**
* Checks if the memory limit is at least what is required
*
* @param int $memoryLimit set limit in bytes
* @param int $requiredLimit required limit in bytes
* @return bool
*/
public static function IsMemoryLimitOk($memoryLimit, $requiredLimit)
{
return ($memoryLimit >= $requiredLimit) || ($memoryLimit == -1);
}
/**
* Format a value into a more friendly format (KB, MB, GB, TB) instead a juste a Bytes amount.
*

View File

@@ -918,6 +918,10 @@ class ScalarExpression extends UnaryExpression
$aValue['label'] = $oObj->Get("friendlyname");
}
else
{
$aValue['label'] = Dict::S('Enum:Undefined');
}
}
catch (Exception $e)
{
@@ -934,6 +938,10 @@ class ScalarExpression extends UnaryExpression
$oObj = MetaModel::GetObject($sTarget, $this->GetValue(), true, true);
$aValue['label'] = $oObj->Get("friendlyname");
}
else
{
$aValue['label'] = Dict::S('Enum:Undefined');
}
}
catch (Exception $e)
{

View File

@@ -193,7 +193,7 @@
var result;
if( data && data.length ) {
for (var i=0; i < data.length; i++) {
if( data[i].result.toLowerCase() == q.toLowerCase() ) {
if( data[i].result.toLowerCase() === q.toLowerCase() ) {
result = data[i];
break;
}
@@ -386,6 +386,7 @@
$.ajax({
// try to leverage ajaxQueue plugin to abort previous requests
mode: "abort",
method: "POST",
// limit abortion to this input
port: "autocomplete" + input.name,
dataType: options.dataType,

View File

@@ -62,7 +62,7 @@ else
// Check that the limit will allow us to load the data
//
$iMemoryLimit = utils::ConvertToBytes($sMemoryLimit);
if ($iMemoryLimit < SAFE_MINIMUM_MEMORY)
if (!utils::IsMemoryLimitOk($iMemoryLimit, SAFE_MINIMUM_MEMORY))
{
if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === FALSE)
{

View File

@@ -274,7 +274,7 @@ class SetupUtils
// Check that the limit will allow us to load the data
//
$iMemoryLimit = utils::ConvertToBytes($sMemoryLimit);
if ($iMemoryLimit < self::MIN_MEMORY_LIMIT)
if (!utils::IsMemoryLimitOk($iMemoryLimit, self::MIN_MEMORY_LIMIT))
{
$aResult[] = new CheckResult(CheckResult::ERROR, "memory_limit ($iMemoryLimit) is too small, the minimum value to run the application is ".self::MIN_MEMORY_LIMIT.".");
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Copyright (C) 2018 Dennis Lassiter
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with iTop. If not, see <http://www.gnu.org/licenses/>
*
*/
class UtilsTest extends \Combodo\iTop\Test\UnitTest\ItopTestCase
{
public function setUp()
{
parent::setUp();
require_once(APPROOT . 'application/utils.inc.php');
}
/**
* @dataProvider memoryLimitDataProvider
*/
public function testIsMemoryLimit($expected, $memoryLimit, $requiredMemory)
{
$this->assertSame($expected, utils::IsMemoryLimitOk($memoryLimit, $requiredMemory));
}
/**
* DataProvider for testIsMemoryLimitOk
*
* @return array
*/
public function memoryLimitDataProvider()
{
return [
[true, '-1', 1024],
[true, -1, 1024],
[true, 1024, 1024],
[true, 2048, 1024],
[false, 1024, 2048],
];
}
}

View File

@@ -412,6 +412,11 @@ class CriterionConversionTest extends ItopDataTestCase
'ExpectedOQL' => "SELECT `Contact` FROM Contact AS `Contact` JOIN Organization AS `Organization` ON `Contact`.org_id = `Organization`.id JOIN Organization AS `Organization1` ON `Organization`.parent_id BELOW `Organization1`.id WHERE (`Organization1`.`id` = '1')",
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key', 'operator' => 'IN')),
),
'key IN 2' => array(
'OQL' => "SELECT Contact WHERE org_id IN ('1', '999999')",
'ExpectedOQL' => "SELECT `Contact` FROM Contact AS `Contact` JOIN Organization AS `Organization` ON `Contact`.org_id = `Organization`.id JOIN Organization AS `Organization1` ON `Organization`.parent_id BELOW `Organization1`.id WHERE (`Organization1`.`id` = '1')",
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key', 'operator' => 'IN')),
),
'key empty' => array(
'OQL' => "SELECT Person WHERE location_id = '0'",
'ExpectedOQL' => "SELECT `Person` FROM Person AS `Person` WHERE (`Person`.`location_id` = '0')",
@@ -438,8 +443,8 @@ class CriterionConversionTest extends ItopDataTestCase
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key')),
),
'Hierarchical below 2' => array(
'OQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('2', '4')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'ExpectedOQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('2', '4')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'OQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('1', '2')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'ExpectedOQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('1', '2')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key')),
),
'IP range' => array(

View File

@@ -19,6 +19,28 @@ class TagSetFieldDataTest extends ItopDataTestCase
// Need commit to create the FULLTEXT INDEX of MySQL
const USE_TRANSACTION = false;
public function testGetAllowedValues()
{
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iInitialCount = count($aAllowedValues);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(1, $iCurrCount - $iInitialCount);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag2', 'Second');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(2, $iCurrCount - $iInitialCount);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag3', 'Third');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(3, $iCurrCount - $iInitialCount);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag4', 'Fourth');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(4, $iCurrCount - $iInitialCount);
}
public function testDoCheckToWrite()
{
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
@@ -67,8 +89,6 @@ class TagSetFieldDataTest extends ItopDataTestCase
}
/**
* @expectedException \CoreException
*
* @throws \CoreException
* @throws \CoreUnexpectedValue
*/
@@ -76,19 +96,34 @@ class TagSetFieldDataTest extends ItopDataTestCase
{
$oTagData = $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$oTagData->DBDelete();
$oTagData = $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$oTicket = $this->CreateTicket(1);
$oTicket->Set(TAG_ATTCODE, 'tag1');
$oTicket->DBWrite();
$oTagData->DBDelete($oDeletionPlan);
try
{
$oTagData->DBDelete();
}
catch (\CoreException $e)
{
static::assertTrue(true);
return;
}
static::assertFalse(true);
}
public function testComputeValues()
{
$sTagClass = \MetaModel::GetTagDataClass(TAG_CLASS, TAG_ATTCODE);
$oTagData = $this->createObject($sTagClass, array(
'tag_code' => 'tag1',
'tag_label' => 'First',
));
$this->debug("Created {$oTagData->Get('tag_class')}::{$oTagData->Get('tag_attcode')}");
static::assertEquals(TAG_CLASS, $oTagData->Get('tag_class'));
static::assertEquals(TAG_ATTCODE, $oTagData->Get('tag_attcode'));
}
public function testGetAllowedValues()
{
}
}

View File

@@ -59,7 +59,7 @@ function SetMemoryLimit($oP)
// Check that the limit will allow us to load the data
//
$iMemoryLimit = utils::ConvertToBytes($sMemoryLimit);
if ($iMemoryLimit < SAFE_MINIMUM_MEMORY)
if (!utils::IsMemoryLimitOk($iMemoryLimit, SAFE_MINIMUM_MEMORY))
{
if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === FALSE)
{