Example #1
0
 /**
  * @dataProvider dataTestSetupUser
  *
  * @param bool $hasKeys
  * @param bool $expected
  */
 public function testSetupUser($hasKeys, $expected)
 {
     $this->keyManagerMock->expects($this->once())->method('userHasKeys')->with('uid')->willReturn($hasKeys);
     if ($hasKeys) {
         $this->keyManagerMock->expects($this->never())->method('storeKeyPair');
     } else {
         $this->cryptMock->expects($this->once())->method('createKeyPair')->willReturn('keyPair');
         $this->keyManagerMock->expects($this->once())->method('storeKeyPair')->with('uid', 'password', 'keyPair')->willReturn(true);
     }
     $this->assertSame($expected, $this->instance->setupUser('uid', 'password'));
 }
Example #2
0
 public function testRecoverFile()
 {
     $this->keyManagerMock->expects($this->once())->method('getEncryptedFileKey')->willReturn(true);
     $this->keyManagerMock->expects($this->once())->method('getShareKey')->willReturn(true);
     $this->cryptMock->expects($this->once())->method('multiKeyDecrypt')->willReturn(true);
     $this->fileMock->expects($this->once())->method('getAccessList')->willReturn(['users' => ['admin']]);
     $this->keyManagerMock->expects($this->once())->method('getPublicKey')->willReturn('publicKey');
     $this->keyManagerMock->expects($this->once())->method('addSystemKeys')->with($this->anything(), $this->anything(), $this->equalTo('admin'))->willReturn(['admin' => 'publicKey']);
     $this->cryptMock->expects($this->once())->method('multiKeyEncrypt');
     $this->keyManagerMock->expects($this->once())->method('setAllFileKeys');
     $this->assertNull(self::invokePrivate($this->instance, 'recoverFile', ['/', 'testkey', 'admin']));
 }
Example #3
0
 /**
  * Test case if the public key is missing. ownCloud should still encrypt
  * the file for the remaining users
  */
 public function testUpdateMissingPublicKey()
 {
     $this->keyManagerMock->expects($this->once())->method('getFileKey')->willReturn('fileKey');
     $this->keyManagerMock->expects($this->any())->method('getPublicKey')->willReturnCallback(function ($user) {
         throw new PublicKeyMissingException($user);
     });
     $this->keyManagerMock->expects($this->any())->method('addSystemKeys')->willReturnCallback(function ($accessList, $publicKeys) {
         return $publicKeys;
     });
     $this->cryptMock->expects($this->once())->method('multiKeyEncrypt')->willReturnCallback(function ($fileKey, $publicKeys) {
         $this->assertEmpty($publicKeys);
         $this->assertSame('fileKey', $fileKey);
     });
     $this->keyManagerMock->expects($this->never())->method('getVersion');
     $this->keyManagerMock->expects($this->never())->method('setVersion');
     $this->assertTrue($this->instance->update('path', 'user1', ['users' => ['user1']]));
 }
 /**
  * test updatePrivateKeyPassword() with the correct old and new password
  */
 public function testUpdatePrivateKeyPassword()
 {
     $oldPassword = '******';
     $newPassword = '******';
     $this->ocSessionMock->expects($this->once())->method('get')->with('loginname')->willReturn('testUser');
     $this->userManagerMock->expects($this->at(0))->method('checkPassword')->with('testUserUid', 'new')->willReturn(false);
     $this->userManagerMock->expects($this->at(1))->method('checkPassword')->with('testUser', 'new')->willReturn(true);
     $this->cryptMock->expects($this->once())->method('decryptPrivateKey')->willReturn('decryptedKey');
     $this->cryptMock->expects($this->once())->method('encryptPrivateKey')->willReturn('encryptedKey');
     $this->cryptMock->expects($this->once())->method('generateHeader')->willReturn('header.');
     // methods which must be called after successful changing the key password
     $this->keyManagerMock->expects($this->once())->method('setPrivateKey')->with($this->equalTo('testUserUid'), $this->equalTo('header.encryptedKey'));
     $this->sessionMock->expects($this->once())->method('setPrivateKey')->with($this->equalTo('decryptedKey'));
     $this->sessionMock->expects($this->once())->method('setStatus')->with($this->equalTo(Session::INIT_SUCCESSFUL));
     $result = $this->controller->updatePrivateKeyPassword($oldPassword, $newPassword);
     $data = $result->getData();
     $this->assertSame(Http::STATUS_OK, $result->getStatus());
     $this->assertSame('Private key password successfully updated.', $data['message']);
 }