diff options
author | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-04-27 09:48:46 +0200 |
---|---|---|
committer | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-04-27 09:48:46 +0200 |
commit | 44709276c0dd681e021e3a6bb689beb55586e07f (patch) | |
tree | 234d3fd863970944de0c984c46b013899a58de7d /apps/encryption/tests/lib | |
parent | 20602ff36a091b928cd525eb131756e005836c22 (diff) | |
parent | d86f8ba5f8718329fb0742be3e18f229c1f56a34 (diff) | |
download | nextcloud-server-44709276c0dd681e021e3a6bb689beb55586e07f.tar.gz nextcloud-server-44709276c0dd681e021e3a6bb689beb55586e07f.zip |
Merge pull request #22777 from owncloud/encrypt_all_master_key
improved encrypt-all script
Diffstat (limited to 'apps/encryption/tests/lib')
-rw-r--r-- | apps/encryption/tests/lib/crypto/encryptalltest.php | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/apps/encryption/tests/lib/crypto/encryptalltest.php b/apps/encryption/tests/lib/crypto/encryptalltest.php index 04d931342a7..d31f58377c4 100644 --- a/apps/encryption/tests/lib/crypto/encryptalltest.php +++ b/apps/encryption/tests/lib/crypto/encryptalltest.php @@ -31,6 +31,9 @@ class EncryptAllTest extends TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject | \OCA\Encryption\KeyManager */ protected $keyManager; + /** @var \PHPUnit_Framework_MockObject_MockObject | \OCA\Encryption\Util */ + protected $util; + /** @var \PHPUnit_Framework_MockObject_MockObject | \OCP\IUserManager */ protected $userManager; @@ -73,6 +76,8 @@ class EncryptAllTest extends TestCase { ->disableOriginalConstructor()->getMock(); $this->keyManager = $this->getMockBuilder('OCA\Encryption\KeyManager') ->disableOriginalConstructor()->getMock(); + $this->util = $this->getMockBuilder('OCA\Encryption\Util') + ->disableOriginalConstructor()->getMock(); $this->userManager = $this->getMockBuilder('OCP\IUserManager') ->disableOriginalConstructor()->getMock(); $this->view = $this->getMockBuilder('OC\Files\View') @@ -110,6 +115,7 @@ class EncryptAllTest extends TestCase { $this->userManager, $this->view, $this->keyManager, + $this->util, $this->config, $this->mailer, $this->l, @@ -127,6 +133,7 @@ class EncryptAllTest extends TestCase { $this->userManager, $this->view, $this->keyManager, + $this->util, $this->config, $this->mailer, $this->l, @@ -137,6 +144,7 @@ class EncryptAllTest extends TestCase { ->setMethods(['createKeyPairs', 'encryptAllUsersFiles', 'outputPasswords']) ->getMock(); + $this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(false); $encryptAll->expects($this->at(0))->method('createKeyPairs')->with(); $encryptAll->expects($this->at(1))->method('encryptAllUsersFiles')->with(); $encryptAll->expects($this->at(2))->method('outputPasswords')->with(); @@ -145,6 +153,36 @@ class EncryptAllTest extends TestCase { } + public function testEncryptAllWithMasterKey() { + /** @var EncryptAll | \PHPUnit_Framework_MockObject_MockObject $encryptAll */ + $encryptAll = $this->getMockBuilder('OCA\Encryption\Crypto\EncryptAll') + ->setConstructorArgs( + [ + $this->setupUser, + $this->userManager, + $this->view, + $this->keyManager, + $this->util, + $this->config, + $this->mailer, + $this->l, + $this->questionHelper, + $this->secureRandom + ] + ) + ->setMethods(['createKeyPairs', 'encryptAllUsersFiles', 'outputPasswords']) + ->getMock(); + + $this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(true); + $encryptAll->expects($this->never())->method('createKeyPairs'); + $this->keyManager->expects($this->once())->method('validateMasterKey'); + $encryptAll->expects($this->at(0))->method('encryptAllUsersFiles')->with(); + $encryptAll->expects($this->never())->method('outputPasswords'); + + $encryptAll->encryptAll($this->inputInterface, $this->outputInterface); + + } + public function testCreateKeyPairs() { /** @var EncryptAll | \PHPUnit_Framework_MockObject_MockObject $encryptAll */ $encryptAll = $this->getMockBuilder('OCA\Encryption\Crypto\EncryptAll') @@ -154,6 +192,7 @@ class EncryptAllTest extends TestCase { $this->userManager, $this->view, $this->keyManager, + $this->util, $this->config, $this->mailer, $this->l, @@ -202,6 +241,7 @@ class EncryptAllTest extends TestCase { $this->userManager, $this->view, $this->keyManager, + $this->util, $this->config, $this->mailer, $this->l, @@ -212,6 +252,8 @@ class EncryptAllTest extends TestCase { ->setMethods(['encryptUsersFiles']) ->getMock(); + $this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(false); + // set protected property $output $this->invokePrivate($encryptAll, 'output', [$this->outputInterface]); $this->invokePrivate($encryptAll, 'userPasswords', [['user1' => 'pwd1', 'user2' => 'pwd2']]); @@ -232,6 +274,7 @@ class EncryptAllTest extends TestCase { $this->userManager, $this->view, $this->keyManager, + $this->util, $this->config, $this->mailer, $this->l, @@ -239,9 +282,10 @@ class EncryptAllTest extends TestCase { $this->secureRandom ] ) - ->setMethods(['encryptFile']) + ->setMethods(['encryptFile', 'setupUserFS']) ->getMock(); + $this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(false); $this->view->expects($this->at(0))->method('getDirectoryContent') ->with('/user1/files')->willReturn( @@ -268,8 +312,8 @@ class EncryptAllTest extends TestCase { } ); - $encryptAll->expects($this->at(0))->method('encryptFile')->with('/user1/files/bar'); - $encryptAll->expects($this->at(1))->method('encryptFile')->with('/user1/files/foo/subfile'); + $encryptAll->expects($this->at(1))->method('encryptFile')->with('/user1/files/bar'); + $encryptAll->expects($this->at(2))->method('encryptFile')->with('/user1/files/foo/subfile'); $progressBar = $this->getMockBuilder('Symfony\Component\Console\Helper\ProgressBar') ->disableOriginalConstructor()->getMock(); |