Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion core/simplecrypt.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,15 @@ function Encrypt($key, $sString)
*/
function Decrypt($key, $string)
{
return $this->oEngine->Decrypt($key,$string);
try{
return $this->oEngine->Decrypt($key,$string);
} catch(\Exception $e){
if (strlen($string)==0){
IssueLog::Error("Cannot decrypt empty/null value", null, ['msg' => $e->getMessage(), 'stack' => $e->getTraceAsString()]);
return $string;
}
throw $e;
}
}

/**
Expand Down
36 changes: 36 additions & 0 deletions tests/php-unit-tests/unitary-tests/core/SympleCryptTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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 testDecryptWithNullValue()
{
$oSimpleCrypt = new \SimpleCrypt("Sodium");
$this->assertEquals(null, $oSimpleCrypt->Decrypt("dd", null));
}

public function testDecryptWithEmptyValue()
{
$oSimpleCrypt = new \SimpleCrypt("Sodium");
$this->assertEquals('', $oSimpleCrypt->Decrypt("dd", ""));
}

public function testDecrypNonDecryptableValue()
{
$this->expectException(SodiumException::class);
$oSimpleCrypt = new \SimpleCrypt("Sodium");
$this->assertEquals('', $oSimpleCrypt->Decrypt("dd", "gabuzomeu"));
}

}