From a72b567a6a8fde7ca1df6a24d94be193ef23df57 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 24 Dec 2014 23:32:47 -0500 Subject: [PATCH] Fix failing tests. I cocked up the tests the first time around. --- tests/TestCase/Utility/Crypto/McryptTest.php | 28 ++++++------------- tests/TestCase/Utility/Crypto/OpenSslTest.php | 16 ----------- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/tests/TestCase/Utility/Crypto/McryptTest.php b/tests/TestCase/Utility/Crypto/McryptTest.php index ef89e283b5a..413d40bcdad 100644 --- a/tests/TestCase/Utility/Crypto/McryptTest.php +++ b/tests/TestCase/Utility/Crypto/McryptTest.php @@ -77,29 +77,14 @@ public function testEncryptDecrypt() { */ public function testDecryptKeyFailure() { $txt = 'The quick brown fox'; - $key = 'This key is enough bytes'; + + $key = substr(hash('sha256', 'This key is enough bytes'), 0, 32); $result = $this->crypt->encrypt($txt, $key); - $key = 'Not the same key.'; + $key = substr(hash('sha256', 'Not the same key.'), 0, 32); $this->assertFalse($this->crypt->decrypt($txt, $key), 'Modified key will fail.'); } -/** - * Test that decrypt fails when there is an hmac error. - * - * @return void - */ - public function testDecryptHmacFailure() { - $txt = 'The quick brown fox'; - $key = 'This key is long enough'; - $salt = 'this is a delicious salt!'; - $result = $this->crypt->encrypt($txt, $key, $salt); - - // Change one of the bytes in the hmac. - $result[10] = 'x'; - $this->assertFalse($this->crypt->decrypt($result, $key, $salt), 'Modified hmac causes failure.'); - } - /** * Ensure that data encrypted with 2.x encrypt() function can be decrypted with mcrypt engine. * @@ -109,11 +94,14 @@ public function testDecryptHmacFailure() { */ public function testDecryptOldData() { $key = 'My password is nice and long really it is'; + $key = substr(hash('sha256', $key), 0, 32); + $cipher = 'ZmFkMjdmY2U2NjgzOTkwMGZmMWJiMzY0ZDA5ZDUwZmNjYTdjNWVkZThkMzhmNzdiY' . 'Tg3ZDFjMzNjNmViMDljMnk9k0LmYpwSZH5eq7GmDozMwHxzh37YaXFQ2TK5gXb5OfTKXv83K+NjAS9lIo/Zvw=='; - $salt = ''; + $data = base64_decode($cipher); + $cipher = substr($data, 64); - $result = $this->crypt->encrypt($txt, $key, $salt); + $result = $this->crypt->decrypt($cipher, $key); $this->assertEquals('This is a secret message', $result); } diff --git a/tests/TestCase/Utility/Crypto/OpenSslTest.php b/tests/TestCase/Utility/Crypto/OpenSslTest.php index 928f933b91d..2a2c1f22223 100644 --- a/tests/TestCase/Utility/Crypto/OpenSslTest.php +++ b/tests/TestCase/Utility/Crypto/OpenSslTest.php @@ -74,20 +74,4 @@ public function testDecryptKeyFailure() { $this->assertFalse($this->crypt->decrypt($txt, $key), 'Modified key will fail.'); } -/** - * Test that decrypt fails when there is an hmac error. - * - * @return void - */ - public function testDecryptHmacFailure() { - $txt = 'The quick brown fox'; - $key = 'This key is long enough'; - $salt = 'this is a delicious salt!'; - $result = $this->crypt->encrypt($txt, $key, $salt); - - // Change one of the bytes in the hmac. - $result[10] = 'x'; - $this->assertFalse($this->crypt->decrypt($result, $key, $salt), 'Modified hmac causes failure.'); - } - }