Skip to content

Commit

Permalink
Merge pull request #34506 from owncloud/skip-shared-files-stable10
Browse files Browse the repository at this point in the history
[stable10] Backport of Skip shared files when adding recovery key
  • Loading branch information
phil-davis authored Feb 15, 2019
2 parents f438825 + c0be12c commit e2cd975
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
25 changes: 24 additions & 1 deletion apps/encryption/lib/Recovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace OCA\Encryption;


use OC\Files\FileInfo;
use OCA\Encryption\Crypto\Crypt;
use OCP\Encryption\Keys\IStorage;
use OCP\IConfig;
Expand Down Expand Up @@ -220,6 +221,9 @@ public function setRecoveryForUser($value) {
private function addRecoveryKeys($path) {
$dirContent = $this->view->getDirectoryContent($path);
foreach ($dirContent as $item) {
if ($this->isSharedStorage($item)) {
continue;
}
$filePath = $item->getPath();
if ($item['type'] === 'dir') {
$this->addRecoveryKeys($filePath . '/');
Expand Down Expand Up @@ -248,6 +252,9 @@ private function addRecoveryKeys($path) {
private function removeRecoveryKeys($path) {
$dirContent = $this->view->getDirectoryContent($path);
foreach ($dirContent as $item) {
if ($this->isSharedStorage($item)) {
continue;
}
$filePath = $item->getPath();
if ($item['type'] === 'dir') {
$this->removeRecoveryKeys($filePath . '/');
Expand Down Expand Up @@ -326,5 +333,21 @@ private function recoverFile($path, $privateKey, $uid) {

}


/**
* check if the item is on a shared storage
*
* @param FileInfo $item
* @return bool
*/
protected function isSharedStorage(FileInfo $item) {
/**
* hardcoded class to prevent dependency on files_sharing app and federated share
* TODO: add filter callback to view::getDirectoryContent() or its successor
* so we can filter by more than just mimetype
*/
if ($item->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) {
return true;
}
return false;
}
}
27 changes: 27 additions & 0 deletions apps/encryption/tests/RecoveryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
namespace OCA\Encryption\Tests;


use OC\Files\FileInfo;
use OC\Files\Mount\MountPoint;
use OCA\Encryption\Recovery;
use OCA\Files_Sharing\ISharedStorage;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
use Test\TestCase;

class RecoveryTest extends TestCase {
Expand Down Expand Up @@ -244,6 +250,27 @@ public function testRecoverFile() {
['/', 'testkey', 'admin']));
}

public function testNormalShareOrFedShareRecoveryKeySkipped() {
$storage = $this->createMock(IStorage::class);
$storage->method('instanceOfStorage')
->with(ISharedStorage::class)
->willReturn(true);

$cacheEntry = $this->createMock(ICacheEntry::class);
$mountPoint = $this->createMock(MountPoint::class);
$mountPoint->method('getStorage')
->willReturn($storage);

$user = $this->createMock(IUser::class);
$remoteUser = $this->createMock(IUser::class);
$normalShare = new FileInfo('test/files/foo', $storage, '', $cacheEntry, $mountPoint, $user);
$fedShare = new FileInfo('test/files/fedshare', $storage, '', $cacheEntry, $mountPoint, $remoteUser);

$this->viewMock->method('getDirectoryContent')
->willReturn([$normalShare, $fedShare]);
$this->assertEquals(true, $this->instance->setRecoveryForUser('1'));
}

protected function setUp() {
parent::setUp();

Expand Down

0 comments on commit e2cd975

Please sign in to comment.