N°4250 - Problem with unencryption when the attribute is empty

N°4058 - Setup failed when added an encrypted field due to default value NULL non SODIUM compatible
This commit is contained in:
Anne-Cath
2025-11-04 15:25:53 +01:00
parent adfa800063
commit 26f21ee6eb
2 changed files with 100 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
<?php
/*!
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Test\UnitTest\Core;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use SodiumException;
/**
* Tests of the ormPassword class
*/
class SympleCryptTest extends ItopDataTestCase
{
public function DecryptClassProvider()
{
$aClassProvider = ['SimpleCrypt'=>['SimpleCrypt'],
'SimpleCryptSimpleEngine'=>['SimpleCryptSimpleEngine']];
if(function_exists('sodium_crypto_secretbox_open')){
$aClassProvider['SimpleCryptSodiumEngine'] = ['SimpleCryptSodiumEngine'] ;
}
if(function_exists('openssl_decrypt')){
$aClassProvider['SimpleCryptOpenSSLEngine'] = ['SimpleCryptOpenSSLEngine'];
$aClassProvider['SimpleCryptOpenSSLMcryptCompatibilityEngine'] = ['SimpleCryptOpenSSLMcryptCompatibilityEngine'];
}
return$aClassProvider;
}
/**
* @param $sClass
* @dataProvider DecryptClassProvider
**/
public function testDecryptWithNullValue($sClass)
{
$oSimpleCrypt = new $sClass();
$this->assertEquals(null, $oSimpleCrypt->Decrypt("dd", null));
}
/**
* @param $sClass
* @dataProvider DecryptClassProvider
**/
public function testDecryptWithEmptyValue($sClass)
{
$oSimpleCrypt = new $sClass();
$this->assertEquals('', $oSimpleCrypt->Decrypt("dd", ""));
}
public function DecryptClassWithNonDecryptableValueProvider()
{
$aClassProvider = ['SimpleCrypt'=>['SimpleCrypt', '** decryption error **'],
// 'SimpleCryptSimpleEngine'=>['SimpleCryptSimpleEngine', ' ']
];
if(function_exists('sodium_crypto_secretbox_open')){
$aClassProvider['SimpleCryptSodiumEngine'] = ['SimpleCryptSodiumEngine', '', 'SodiumException'] ;
}
if(function_exists('openssl_decrypt')){
$aClassProvider['SimpleCryptOpenSSLEngine'] = ['SimpleCryptOpenSSLEngine', '** decryption error **'];
$aClassProvider['SimpleCryptOpenSSLMcryptCompatibilityEngine'] = ['SimpleCryptOpenSSLMcryptCompatibilityEngine', '** decryption error **'];
}
return$aClassProvider;
}
/**
* @param $sClass
* @param $sExpectedValue
* @dataProvider DecryptClassWithNonDecryptableValueProvider
**/
public function testDecrypWithNonDecryptableValue($sClass, $sExpectedValue = '', $sExpectedException = null)
{
if($sExpectedException !== null) {
$this->expectException($sExpectedException);
}
$oSimpleCrypt = new $sClass();
$result=$oSimpleCrypt->Decrypt("dd", "gabuzomeuuofteod");
$this->assertEquals($sExpectedValue, $result,'');
}
}