From 318b792b312381d3d9ea775d439e20c39444a4a2 Mon Sep 17 00:00:00 2001 From: odain-cbd <56586767+odain-cbd@users.noreply.github.com> Date: Fri, 10 Oct 2025 14:25:39 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B04058=20-=20Setup=20failed=20when=20added?= =?UTF-8?q?=20an=20encrypted=20field=20due=20to=20default=20value=20NULL?= =?UTF-8?q?=20non=20SODIUM=20compatible=20(#754)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * N°4058 - Setup failed when added an encrypted field due to default value NULL non SODIUM compatible * N°4058 - Setup failed when added an encrypted field due to default value NULL non SODIUM compatible * change log level to warning --- core/simplecrypt.class.inc.php | 12 +++++-- .../unitary-tests/core/SympleCryptTest.php | 36 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/php-unit-tests/unitary-tests/core/SympleCryptTest.php diff --git a/core/simplecrypt.class.inc.php b/core/simplecrypt.class.inc.php index b49d0c2d1..0be60cf20 100644 --- a/core/simplecrypt.class.inc.php +++ b/core/simplecrypt.class.inc.php @@ -130,7 +130,15 @@ class SimpleCrypt */ 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::Warning("Cannot decrypt empty/null value", null, ['msg' => $e->getMessage(), 'stack' => $e->getTraceAsString()]); + return $string; + } + throw $e; + } } /** @@ -422,4 +430,4 @@ class SimpleCryptOpenSSLMcryptCompatibilityEngine implements CryptEngine return trim($plaintext); } -} +} \ No newline at end of file diff --git a/tests/php-unit-tests/unitary-tests/core/SympleCryptTest.php b/tests/php-unit-tests/unitary-tests/core/SympleCryptTest.php new file mode 100644 index 000000000..e38f1d745 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/SympleCryptTest.php @@ -0,0 +1,36 @@ +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")); + } + +}