diff options
author | Björn Schießle <bjoern@schiessle.org> | 2016-01-05 19:01:03 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2016-02-09 23:43:26 +0100 |
commit | 9bb97c714bb2158fd019ba9efc24a8bc8595b499 (patch) | |
tree | 0b448eee0d30aa194cbc887c08f7c44728a9e109 /apps/encryption | |
parent | b9ff16498befe211205ea3c20c2eb341f97919fa (diff) | |
download | nextcloud-server-9bb97c714bb2158fd019ba9efc24a8bc8595b499.tar.gz nextcloud-server-9bb97c714bb2158fd019ba9efc24a8bc8595b499.zip |
fixing unit tests
Diffstat (limited to 'apps/encryption')
-rw-r--r-- | apps/encryption/lib/crypto/crypt.php | 2 | ||||
-rw-r--r-- | apps/encryption/tests/lib/crypto/cryptTest.php | 63 | ||||
-rw-r--r-- | apps/encryption/tests/lib/crypto/encryptionTest.php | 2 |
3 files changed, 56 insertions, 11 deletions
diff --git a/apps/encryption/lib/crypto/crypt.php b/apps/encryption/lib/crypto/crypt.php index d5a41c29009..f27f55619af 100644 --- a/apps/encryption/lib/crypto/crypt.php +++ b/apps/encryption/lib/crypto/crypt.php @@ -442,7 +442,7 @@ class Crypt { $catFile = $this->splitMetaData($keyFileContents, $cipher); - if ($catFile['signature']) { + if ($catFile['signature'] !== false) { $this->checkSignature($catFile['encrypted'], $passPhrase, $catFile['signature']); } diff --git a/apps/encryption/tests/lib/crypto/cryptTest.php b/apps/encryption/tests/lib/crypto/cryptTest.php index c774da1836c..d94aea463cf 100644 --- a/apps/encryption/tests/lib/crypto/cryptTest.php +++ b/apps/encryption/tests/lib/crypto/cryptTest.php @@ -204,17 +204,61 @@ class cryptTest extends TestCase { } /** - * test splitIV() + * @dataProvider dataTestSplitMetaData */ - public function testSplitIV() { - $data = 'encryptedContent00iv001234567890123456'; - $result = self::invokePrivate($this->crypt, 'splitIV', array($data)); + public function testSplitMetaData($data, $expected) { + $result = self::invokePrivate($this->crypt, 'splitMetaData', array($data, 'AES-256-CFB')); $this->assertTrue(is_array($result)); - $this->assertSame(2, count($result)); + $this->assertSame(3, count($result)); $this->assertArrayHasKey('encrypted', $result); $this->assertArrayHasKey('iv', $result); - $this->assertSame('encryptedContent', $result['encrypted']); - $this->assertSame('1234567890123456', $result['iv']); + $this->assertArrayHasKey('signature', $result); + $this->assertSame($expected['encrypted'], $result['encrypted']); + $this->assertSame($expected['iv'], $result['iv']); + $this->assertSame($expected['signature'], $result['signature']); + } + + public function dataTestSplitMetaData() { + return [ + ['encryptedContent00iv001234567890123456xx', + ['encrypted' => 'encryptedContent', 'iv' => '1234567890123456', 'signature' => false]], + ['encryptedContent00iv00123456789012345600sig00e1992521e437f6915f9173b190a512cfc38a00ac24502db44e0ba10c2bb0cc86xxx', + ['encrypted' => 'encryptedContent', 'iv' => '1234567890123456', 'signature' => 'e1992521e437f6915f9173b190a512cfc38a00ac24502db44e0ba10c2bb0cc86']], + ]; + } + + /** + * @dataProvider dataTestHasSignature + */ + public function testHasSignature($data, $expected) { + $this->assertSame($expected, + $this->invokePrivate($this->crypt, 'hasSignature', array($data, 'AES-256-CFB')) + ); + } + + public function dataTestHasSignature() { + return [ + ['encryptedContent00iv001234567890123456xx', false], + ['encryptedContent00iv00123456789012345600sig00e1992521e437f6915f9173b190a512cfc38a00ac24502db44e0ba10c2bb0cc86xxx', true] + ]; + } + + /** + * @dataProvider dataTestHasSignatureFail + * @expectedException \OC\HintException + */ + public function testHasSignatureFail($cipher) { + $data = 'encryptedContent00iv001234567890123456xx'; + $this->invokePrivate($this->crypt, 'hasSignature', array($data, $cipher)); + } + + public function dataTestHasSignatureFail() { + return [ + ['AES-256-CTR'], + ['aes-256-ctr'], + ['AES-128-CTR'], + ['ctr-256-ctr'] + ]; } /** @@ -222,7 +266,7 @@ class cryptTest extends TestCase { */ public function testAddPadding() { $result = self::invokePrivate($this->crypt, 'addPadding', array('data')); - $this->assertSame('dataxx', $result); + $this->assertSame('dataxxx', $result); } /** @@ -348,7 +392,8 @@ class cryptTest extends TestCase { [ $this->logger, $this->userSession, - $this->config + $this->config, + $this->l ] ) ->setMethods( diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php index 62e77c742d8..ad943ab6e49 100644 --- a/apps/encryption/tests/lib/crypto/encryptionTest.php +++ b/apps/encryption/tests/lib/crypto/encryptionTest.php @@ -229,7 +229,7 @@ class EncryptionTest extends TestCase { public function dataTestBegin() { return array( - array('w', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'fileKey', 'myCipher'), + array('w', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'fileKey', 'defaultCipher'), array('r', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'fileKey', 'myCipher'), array('w', [], 'legacyCipher', 'defaultCipher', '', 'defaultCipher'), array('r', [], 'legacyCipher', 'defaultCipher', 'file_key', 'legacyCipher'), |