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] Don't try decrypting federated shares in decrypt-all command #30155

Merged
merged 1 commit into from
Feb 13, 2018
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
4 changes: 2 additions & 2 deletions lib/private/Encryption/DecryptAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ protected function decryptUsersFiles($uid, ProgressBar $progress, $userCount) {
while ($root = array_pop($directories)) {
$content = $this->rootView->getDirectoryContent($root);
foreach ($content as $file) {
// only decrypt files owned by the user
if($file->getStorage()->instanceOfStorage('OCA\Files_Sharing\SharedStorage')) {
// only decrypt files owned by the user, exclude incoming local shares, and incoming federated shares
if ($file->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) {
continue;
}
$path = $root . '/' . $file['name'];
Expand Down
35 changes: 24 additions & 11 deletions tests/lib/Encryption/DecryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
use OCP\Files\Storage\IStorage;

/**
* Class DecryptAllTest
Expand Down Expand Up @@ -260,16 +261,23 @@ public function dataTestDecryptAllUsersFiles() {

public function providesData() {
return[
[true],
[false]
['called', \OC\Files\Storage\Local::class],
['exception', \OC\Files\Storage\Local::class],
['skip', SharedStorage::class],
['skip', \OCA\Files_Sharing\External\Storage::class],
];
}
/**
* @param $throwsExceptionInDecrypt
* @dataProvider providesData
*/
public function testDecryptUsersFiles($throwsExceptionInDecrypt) {
$storage = $this->createMock(SharedStorage::class);
public function testDecryptUsersFiles($decryptBehavior, $storageClass) {
$storage = $this->createMock($storageClass);
$storage->expects($this->any())
->method('instanceOfStorage')
->will($this->returnCallback(function($className) use ($storage) {
return ($storage instanceof $className);
}));

/** @var DecryptAll | \PHPUnit_Framework_MockObject_MockObject $instance */
$instance = $this->getMockBuilder(DecryptAll::class)
Expand All @@ -292,12 +300,14 @@ public function testDecryptUsersFiles($throwsExceptionInDecrypt) {
]
);

$this->view->expects($this->at(3))->method('getDirectoryContent')
->with('/user1/files/foo')->willReturn(
[
new FileInfo('path', $storage, 'intPath', ['name' => 'subfile', 'type'=>'file', 'encrypted'=>true], null)
]
);
if ($decryptBehavior !== 'skip') {
$this->view->expects($this->at(3))->method('getDirectoryContent')
->with('/user1/files/foo')->willReturn(
[
new FileInfo('path', $storage, 'intPath', ['name' => 'subfile', 'type'=>'file', 'encrypted'=>true], null)
]
);
}

$this->view->expects($this->any())->method('is_dir')
->willReturnCallback(
Expand All @@ -309,11 +319,14 @@ function($path) {
}
);

if ($throwsExceptionInDecrypt) {
if ($decryptBehavior === 'exception') {
$instance->expects($this->at(0))
->method('decryptFile')
->with('/user1/files/bar')
->willThrowException(new \Exception());
} else if ($decryptBehavior === 'skip') {
$instance->expects($this->never())
->method('decryptFile');
} else {
$instance->expects($this->at(0))
->method('decryptFile')
Expand Down