mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-29 13:38:44 +02:00
N°931: Integrity controls
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@ env-*/*
|
||||
|
||||
# composer reserver directory, from sources, populate/update using "composer install"
|
||||
vendor/*
|
||||
test/vendor/*
|
||||
|
||||
# all datas but listing prevention
|
||||
data/*
|
||||
|
||||
5
.idea/codeStyles/Project.xml
generated
5
.idea/codeStyles/Project.xml
generated
@@ -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>
|
||||
4
.idea/inspectionProfiles/Combodo.xml
generated
4
.idea/inspectionProfiles/Combodo.xml
generated
@@ -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>
|
||||
|
||||
38
README.md
38
README.md
@@ -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/
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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.".");
|
||||
}
|
||||
|
||||
53
test/application/UtilsTest.php
Normal file
53
test/application/UtilsTest.php
Normal 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],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user