Merge branch 'support/3.2' into develop

# Conflicts:
#	core/simplecrypt.class.inc.php
#	tests/php-unit-tests/unitary-tests/core/SympleCryptTest.php
This commit is contained in:
Stephen Abello
2025-11-06 10:27:03 +01:00
8 changed files with 122 additions and 38 deletions

View File

@@ -14,23 +14,66 @@ use SodiumException;
*/
class SympleCryptTest extends ItopDataTestCase
{
public function testDecryptWithNullValue()
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 \SimpleCrypt("Sodium");
$oSimpleCrypt = new $sClass();
$this->assertEquals(null, $oSimpleCrypt->Decrypt("dd", null));
}
public function testDecryptWithEmptyValue()
/**
* @param $sClass
* @dataProvider DecryptClassProvider
**/
public function testDecryptWithEmptyValue($sClass)
{
$oSimpleCrypt = new \SimpleCrypt("Sodium");
$oSimpleCrypt = new $sClass();
$this->assertEquals('', $oSimpleCrypt->Decrypt("dd", ""));
}
public function testDecrypNonDecryptableValue()
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)
{
$this->expectException(SodiumException::class);
$oSimpleCrypt = new \SimpleCrypt("Sodium");
$this->assertEquals('', $oSimpleCrypt->Decrypt("dd", "gabuzomeu"));
if($sExpectedException !== null) {
$this->expectException($sExpectedException);
}
$oSimpleCrypt = new $sClass();
$result=$oSimpleCrypt->Decrypt("dd", "gabuzomeuuofteod");
$this->assertEquals($sExpectedValue, $result,'');
}
}