diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-07-16 14:03:21 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-07-16 14:03:21 +0200 |
commit | d6f02eb703ec69b98f8fecf3ded8bf9f1556cb06 (patch) | |
tree | 4f1a19c547425d3b405d9417d0d30e3985a29ade /apps/encryption/tests | |
parent | bfb90d10edfc863213522c704f7d0b8bad8c8646 (diff) | |
parent | 1e284b15ff07b7a90067c5166ee7f85547095a34 (diff) | |
download | nextcloud-server-d6f02eb703ec69b98f8fecf3ded8bf9f1556cb06.tar.gz nextcloud-server-d6f02eb703ec69b98f8fecf3ded8bf9f1556cb06.zip |
Merge pull request #17500 from owncloud/encryption_migration_improvements
Only clean up if migration finished succesfully
Diffstat (limited to 'apps/encryption/tests')
-rw-r--r-- | apps/encryption/tests/lib/KeyManagerTest.php | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/apps/encryption/tests/lib/KeyManagerTest.php b/apps/encryption/tests/lib/KeyManagerTest.php index 2561b29462f..0bac5e0341b 100644 --- a/apps/encryption/tests/lib/KeyManagerTest.php +++ b/apps/encryption/tests/lib/KeyManagerTest.php @@ -182,18 +182,62 @@ class KeyManagerTest extends TestCase { ); } - public function testUserHasKeys() { + /** + * @dataProvider dataTestUserHasKeys + */ + public function testUserHasKeys($key, $expected) { $this->keyStorageMock->expects($this->exactly(2)) ->method('getUserKey') ->with($this->equalTo($this->userId), $this->anything()) - ->willReturn('key'); + ->willReturn($key); - $this->assertTrue( + $this->assertSame($expected, $this->instance->userHasKeys($this->userId) ); } + public function dataTestUserHasKeys() { + return [ + ['key', true], + ['', false] + ]; + } + + /** + * @expectedException \OCA\Encryption\Exceptions\PrivateKeyMissingException + */ + public function testUserHasKeysMissingPrivateKey() { + $this->keyStorageMock->expects($this->exactly(2)) + ->method('getUserKey') + ->willReturnCallback(function ($uid, $keyID, $encryptionModuleId) { + if ($keyID=== 'privateKey') { + return ''; + } + return 'key'; + }); + + $this->instance->userHasKeys($this->userId); + } + + /** + * @expectedException \OCA\Encryption\Exceptions\PublicKeyMissingException + */ + public function testUserHasKeysMissingPublicKey() { + $this->keyStorageMock->expects($this->exactly(2)) + ->method('getUserKey') + ->willReturnCallback(function ($uid, $keyID, $encryptionModuleId){ + if ($keyID === 'publicKey') { + return ''; + } + return 'key'; + }); + + $this->instance->userHasKeys($this->userId); + + } + + public function testInit() { $this->keyStorageMock->expects($this->any()) ->method('getUserKey') |