mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°4459 Make sure that every test will pass even if the CI provides an invalid configuration file. Also allow encryption mecanism to be fully controlled by the tests
This commit is contained in:
@@ -4272,43 +4272,6 @@ class AttributeEncryptedString extends AttributeString implements iAttributeNoGr
|
|||||||
{
|
{
|
||||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW;
|
||||||
|
|
||||||
static $sKey = null; // Encryption key used for all encrypted fields
|
|
||||||
static $sLibrary = null; // Encryption library used for all encrypted fields
|
|
||||||
|
|
||||||
public function __construct($sCode, $aParams)
|
|
||||||
{
|
|
||||||
parent::__construct($sCode, $aParams);
|
|
||||||
if (self::$sKey == null)
|
|
||||||
{
|
|
||||||
self::$sKey = MetaModel::GetConfig()->GetEncryptionKey();
|
|
||||||
}
|
|
||||||
if (self::$sLibrary == null)
|
|
||||||
{
|
|
||||||
self::$sLibrary = MetaModel::GetConfig()->GetEncryptionLibrary();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When the attribute definitions are stored in APC cache:
|
|
||||||
* 1) The static class variable $sKey is NOT serialized
|
|
||||||
* 2) The object's constructor is NOT called upon wakeup
|
|
||||||
* 3) mcrypt may crash the server if passed an empty key !!
|
|
||||||
*
|
|
||||||
* So let's restore the key (if needed) when waking up
|
|
||||||
**/
|
|
||||||
public function __wakeup()
|
|
||||||
{
|
|
||||||
if (self::$sKey == null)
|
|
||||||
{
|
|
||||||
self::$sKey = MetaModel::GetConfig()->GetEncryptionKey();
|
|
||||||
}
|
|
||||||
if (self::$sLibrary == null)
|
|
||||||
{
|
|
||||||
self::$sLibrary = MetaModel::GetConfig()->GetEncryptionLibrary();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected function GetSQLCol($bFullSpec = false)
|
protected function GetSQLCol($bFullSpec = false)
|
||||||
{
|
{
|
||||||
return "TINYBLOB";
|
return "TINYBLOB";
|
||||||
@@ -4347,8 +4310,8 @@ class AttributeEncryptedString extends AttributeString implements iAttributeNoGr
|
|||||||
*/
|
*/
|
||||||
public function FromSQLToValue($aCols, $sPrefix = '')
|
public function FromSQLToValue($aCols, $sPrefix = '')
|
||||||
{
|
{
|
||||||
$oSimpleCrypt = new SimpleCrypt(self::$sLibrary);
|
$oSimpleCrypt = new SimpleCrypt(MetaModel::GetConfig()->GetEncryptionLibrary());
|
||||||
$sValue = $oSimpleCrypt->Decrypt(self::$sKey, $aCols[$sPrefix]);
|
$sValue = $oSimpleCrypt->Decrypt(MetaModel::GetConfig()->GetEncryptionKey(), $aCols[$sPrefix]);
|
||||||
|
|
||||||
return $sValue;
|
return $sValue;
|
||||||
}
|
}
|
||||||
@@ -4363,8 +4326,8 @@ class AttributeEncryptedString extends AttributeString implements iAttributeNoGr
|
|||||||
*/
|
*/
|
||||||
public function GetSQLValues($value)
|
public function GetSQLValues($value)
|
||||||
{
|
{
|
||||||
$oSimpleCrypt = new SimpleCrypt(self::$sLibrary);
|
$oSimpleCrypt = new SimpleCrypt(MetaModel::GetConfig()->GetEncryptionLibrary());
|
||||||
$encryptedValue = $oSimpleCrypt->Encrypt(self::$sKey, $value);
|
$encryptedValue = $oSimpleCrypt->Encrypt(MetaModel::GetConfig()->GetEncryptionKey(), $value);
|
||||||
|
|
||||||
$aValues = array();
|
$aValues = array();
|
||||||
$aValues[$this->Get("sql")] = $encryptedValue;
|
$aValues[$this->Get("sql")] = $encryptedValue;
|
||||||
|
|||||||
@@ -129,6 +129,13 @@ abstract class ItopDataTestCase extends ItopTestCase
|
|||||||
{
|
{
|
||||||
$this->CreateTestOrganization();
|
$this->CreateTestOrganization();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oConfig = MetaModel::GetConfig();
|
||||||
|
if ($oConfig->GetEncryptionLibrary() != DEFAULT_ENCRYPTION_LIB
|
||||||
|
&& $oConfig->GetEncryptionKey() == DEFAULT_ENCRYPTION_KEY) {
|
||||||
|
// Config file is corrupted, let's fix it
|
||||||
|
$oConfig->SetEncryptionKey("6eb9d9afa3ee0fbcebe622a33bf57aaeafb7c37998fd24c403c2522c2d60117f");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,14 +14,6 @@ class QueryBuilderExpressionsTest extends \Combodo\iTop\Test\UnitTest\ItopCustom
|
|||||||
return __DIR__."/Delta/all-attributes.xml";
|
return __DIR__."/Delta/all-attributes.xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
// Workaround to cope with inconsistent settings in itop-config files from the CI
|
|
||||||
\AttributeEncryptedString::$sKey = "6eb9d9afa3ee0fbcebe622a33bf57aaeafb7c37998fd24c403c2522c2d60117f";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testICanWriteAndReadAnyTypeOfAttribute()
|
public function testICanWriteAndReadAnyTypeOfAttribute()
|
||||||
{
|
{
|
||||||
$oTagA = \MetaModel::NewObject(\TagSetFieldData::GetTagDataClassName('TestObject', 'tagset'), [
|
$oTagA = \MetaModel::NewObject(\TagSetFieldData::GetTagDataClassName('TestObject', 'tagset'), [
|
||||||
|
|||||||
Reference in New Issue
Block a user