/** * @dataProvider dataTestUpdate * * @param string $fileKey * @param boolean $expected */ public function testUpdate($fileKey, $expected) { $this->keyManagerMock->expects($this->once())->method('getFileKey')->willReturn($fileKey); $this->keyManagerMock->expects($this->any())->method('getPublicKey')->willReturn('publicKey'); $this->keyManagerMock->expects($this->any())->method('addSystemKeys')->willReturnCallback(function ($accessList, $publicKeys) { return $publicKeys; }); $this->assertSame($expected, $this->instance->update('path', 'user1', ['users' => ['user1']])); }
public function testUpdateNoUsers() { $this->invokePrivate($this->instance, 'rememberVersion', [['path' => 2]]); $this->keyManagerMock->expects($this->never())->method('getFileKey'); $this->keyManagerMock->expects($this->never())->method('getPublicKey'); $this->keyManagerMock->expects($this->never())->method('addSystemKeys'); $this->keyManagerMock->expects($this->once())->method('setVersion')->willReturnCallback(function ($path, $version, $view) { $this->assertSame('path', $path); $this->assertSame(2, $version); $this->assertTrue($view instanceof \OC\Files\View); }); $this->instance->update('path', 'user1', []); }
/** * 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']])); }