Skip to content

Commit

Permalink
Fix failing tests.
Browse files Browse the repository at this point in the history
I cocked up the tests the first time around.
  • Loading branch information
markstory committed Dec 25, 2014
1 parent 3578d92 commit a72b567
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
28 changes: 8 additions & 20 deletions tests/TestCase/Utility/Crypto/McryptTest.php
Expand Up @@ -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.
*
Expand All @@ -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);
}

Expand Down
16 changes: 0 additions & 16 deletions tests/TestCase/Utility/Crypto/OpenSslTest.php
Expand Up @@ -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.');
}

}

0 comments on commit a72b567

Please sign in to comment.