Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Backport of Skip shared files when adding recovery key #34506

Merged
merged 1 commit into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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