Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-07-15 18:11:54 +0300
committerCarl Schwan <carl@carlschwan.eu>2022-08-03 14:24:38 +0300
commitaafaa3951550347f47e53b44675cd66c77916535 (patch)
tree2637c86b65726b7704681dc0a6019096265a9974 /apps/files_sharing
parent146dda4266e8b5252a4c0eff1ad3552e2dd651f5 (diff)
Multiple fixes
- Fix tests - Use non deprecated event stuff - Add a bit of type hinting to the new stuff - More safe handling of instanceOfStorage (share might not be the first wrapper) - Fix resharing Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/AppInfo/Application.php53
-rw-r--r--apps/files_sharing/lib/Controller/PublicPreviewController.php2
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php67
-rw-r--r--apps/files_sharing/lib/MountProvider.php5
-rw-r--r--apps/files_sharing/src/components/SharingEntry.vue33
-rw-r--r--apps/files_sharing/src/components/SharingEntryLink.vue9
-rw-r--r--apps/files_sharing/tests/ApplicationTest.php47
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php187
8 files changed, 276 insertions, 127 deletions
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php
index 79952c053b1..4bf1ef5a843 100644
--- a/apps/files_sharing/lib/AppInfo/Application.php
+++ b/apps/files_sharing/lib/AppInfo/Application.php
@@ -50,6 +50,7 @@ use OCA\Files_Sharing\Notification\Listener;
use OCA\Files_Sharing\Notification\Notifier;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
+use OCP\Files\Event\BeforeDirectGetEvent;
use OCA\Files_Sharing\ShareBackend\File;
use OCA\Files_Sharing\ShareBackend\Folder;
use OCA\Files_Sharing\ViewOnly;
@@ -61,6 +62,8 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\EventDispatcher\GenericEvent;
use OCP\Federation\ICloudIdManager;
use OCP\Files\Config\IMountProviderCollection;
+use OCP\Files\Events\BeforeDirectFileDownloadEvent;
+use OCP\Files\Events\BeforeZipCreatedEvent;
use OCP\Files\IRootFolder;
use OCP\Group\Events\UserAddedEvent;
use OCP\IDBConnection;
@@ -156,59 +159,53 @@ class Application extends App implements IBootstrap {
public function registerDownloadEvents(
IEventDispatcher $dispatcher,
- ?IUserSession $userSession,
+ IUserSession $userSession,
IRootFolder $rootFolder
): void {
$dispatcher->addListener(
- 'file.beforeGetDirect',
- function (GenericEvent $event) use ($userSession, $rootFolder) {
- $pathsToCheck = [$event->getArgument('path')];
- $event->setArgument('run', true);
-
+ BeforeDirectFileDownloadEvent::class,
+ function (BeforeDirectFileDownloadEvent $event) use ($userSession, $rootFolder): void {
+ $pathsToCheck = [$event->getPath()];
// Check only for user/group shares. Don't restrict e.g. share links
- if ($userSession && $userSession->isLoggedIn()) {
- $uid = $userSession->getUser()->getUID();
+ $user = $userSession->getUser();
+ if ($user) {
$viewOnlyHandler = new ViewOnly(
- $rootFolder->getUserFolder($uid)
+ $rootFolder->getUserFolder($user->getUID())
);
if (!$viewOnlyHandler->check($pathsToCheck)) {
- $event->setArgument('run', false);
- $event->setArgument('errorMessage', 'Access to this resource or one of its sub-items has been denied.');
+ $event->setSuccessful(false);
+ $event->setErrorMessage('Access to this resource or one of its sub-items has been denied.');
}
}
}
);
$dispatcher->addListener(
- 'file.beforeCreateZip',
- function (GenericEvent $event) use ($userSession, $rootFolder) {
- $dir = $event->getArgument('dir');
- $files = $event->getArgument('files');
+ BeforeZipCreatedEvent::class,
+ function (BeforeZipCreatedEvent $event) use ($userSession, $rootFolder): void {
+ $dir = $event->getDirectory();
+ $files = $event->getFiles();
$pathsToCheck = [];
- if (\is_array($files)) {
- foreach ($files as $file) {
- $pathsToCheck[] = $dir . '/' . $file;
- }
- } elseif (\is_string($files)) {
- $pathsToCheck[] = $dir . '/' . $files;
+ foreach ($files as $file) {
+ $pathsToCheck[] = $dir . '/' . $file;
}
// Check only for user/group shares. Don't restrict e.g. share links
- if ($userSession && $userSession->isLoggedIn()) {
- $uid = $userSession->getUser()->getUID();
+ $user = $userSession->getUser();
+ if ($user) {
$viewOnlyHandler = new ViewOnly(
- $rootFolder->getUserFolder($uid)
+ $rootFolder->getUserFolder($user->getUID())
);
if (!$viewOnlyHandler->check($pathsToCheck)) {
- $event->setArgument('errorMessage', 'Access to this resource or one of its sub-items has been denied.');
- $event->setArgument('run', false);
+ $event->setErrorMessage('Access to this resource or one of its sub-items has been denied.');
+ $event->setSuccessful(false);
} else {
- $event->setArgument('run', true);
+ $event->setSuccessful(true);
}
} else {
- $event->setArgument('run', true);
+ $event->setSuccessful(true);
}
}
);
diff --git a/apps/files_sharing/lib/Controller/PublicPreviewController.php b/apps/files_sharing/lib/Controller/PublicPreviewController.php
index 4a16afa7ac0..98c4d8cafb4 100644
--- a/apps/files_sharing/lib/Controller/PublicPreviewController.php
+++ b/apps/files_sharing/lib/Controller/PublicPreviewController.php
@@ -136,7 +136,7 @@ class PublicPreviewController extends PublicShareController {
* @param $token
* @return DataResponse|FileDisplayResponse
*/
- public function directLink($token) {
+ public function directLink(string $token) {
// No token no image
if ($token === '') {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index df160217bea..66b3153f099 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -45,6 +45,7 @@ declare(strict_types=1);
namespace OCA\Files_Sharing\Controller;
use OC\Files\FileInfo;
+use OC\Files\Storage\Wrapper\Wrapper;
use OCA\Files_Sharing\Exceptions\SharingRightsException;
use OCA\Files_Sharing\External\Storage;
use OCA\Files_Sharing\SharedStorage;
@@ -524,14 +525,7 @@ class ShareAPIController extends OCSController {
$permissions &= ~($permissions & ~$node->getPermissions());
}
- if ($share->getNode()->getStorage()->instanceOfStorage(SharedStorage::class)) {
- /** @var \OCA\Files_Sharing\SharedStorage $storage */
- $inheritedAttributes = $share->getNode()->getStorage()->getShare()->getAttributes();
- if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) {
- $share->setHideDownload(true);
- }
- }
-
+ $this->checkInheritedAttributes($share);
if ($shareType === IShare::TYPE_USER) {
// Valid user is required to share
@@ -1110,6 +1104,25 @@ class ShareAPIController extends OCSController {
$share->setNote($note);
}
+ $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
+
+ // get the node with the point of view of the current user
+ $nodes = $userFolder->getById($share->getNode()->getId());
+ if (count($nodes) > 0) {
+ $node = $nodes[0];
+ $storage = $node->getStorage();
+ if ($storage && $storage->instanceOfStorage(SharedStorage::class)) {
+ /** @var \OCA\Files_Sharing\SharedStorage $storage */
+ $inheritedAttributes = $storage->getShare()->getAttributes();
+ if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) {
+ if ($hideDownload === 'false') {
+ throw new OCSBadRequestException($this->l->t('Cannot increase permissions'));
+ }
+ $share->setHideDownload(true);
+ }
+ }
+ }
+
/**
* expirationdate, password and publicUpload only make sense for link shares
*/
@@ -1135,24 +1148,6 @@ class ShareAPIController extends OCSController {
$share->setHideDownload(false);
}
- $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
- // get the node with the point of view of the current user
- $nodes = $userFolder->getById($share->getNode()->getId());
- if (count($nodes) > 0) {
- $node = $nodes[0];
- $storage = $node->getStorage();
- if ($storage->instanceOfStorage(SharedStorage::class)) {
- /** @var \OCA\Files_Sharing\SharedStorage $storage */
- $inheritedAttributes = $storage->getShare()->getAttributes();
- if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) {
- if ($hideDownload === 'false') {
- throw new OCSBadRequestException($this->l->t('Cannot increate permissions'));
- }
- $share->setHideDownload(true);
- }
- }
- }
-
$newPermissions = null;
if ($publicUpload === 'true') {
$newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE;
@@ -1905,4 +1900,24 @@ class ShareAPIController extends OCSController {
return $share;
}
+
+ private function checkInheritedAttributes(IShare $share): void {
+ if ($share->getNode()->getStorage()->instanceOfStorage(SharedStorage::class)) {
+ $storage = $share->getNode()->getStorage();
+ if ($storage instanceof Wrapper) {
+ $storage = $storage->getInstanceOfStorage(SharedStorage::class);
+ if ($storage === null) {
+ throw new \RuntimeException('Should not happen, instanceOfStorage but getInstanceOfStorage return null');
+ }
+ } else {
+ throw new \RuntimeException('Should not happen, instanceOfStorage but not a wrapper');
+ }
+ /** @var \OCA\Files_Sharing\SharedStorage $storage */
+ $inheritedAttributes = $storage->getShare()->getAttributes();
+ if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) {
+ $share->setHideDownload(true);
+ }
+ }
+
+ }
}
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php
index 46e7617edfc..d85d796c722 100644
--- a/apps/files_sharing/lib/MountProvider.php
+++ b/apps/files_sharing/lib/MountProvider.php
@@ -241,8 +241,9 @@ class MountProvider implements IMountProvider {
$superPermissions |= $share->getPermissions();
// update share permission attributes
- if ($share->getAttributes() !== null) {
- foreach ($share->getAttributes()->toArray() as $attribute) {
+ $attributes = $share->getAttributes();
+ if ($attributes !== null) {
+ foreach ($attributes->toArray() as $attribute) {
if ($superAttributes->getAttribute($attribute['scope'], $attribute['key']) === true) {
// if super share attribute is already enabled, it is most permissive
continue;
diff --git a/apps/files_sharing/src/components/SharingEntry.vue b/apps/files_sharing/src/components/SharingEntry.vue
index d8bf5bcccc9..ad4147f0c9b 100644
--- a/apps/files_sharing/src/components/SharingEntry.vue
+++ b/apps/files_sharing/src/components/SharingEntry.vue
@@ -80,8 +80,9 @@
<ActionCheckbox ref="canDownload"
:checked.sync="canDownload"
+ v-if="isSetDownloadButtonVisible"
:disabled="saving || !canSetDownload">
- {{ t('files_sharing', 'Allow download') }}
+ {{ allowDownloadText }}
</ActionCheckbox>
<!-- expiration date -->
@@ -407,6 +408,36 @@ export default {
return (typeof this.share.status === 'object' && !Array.isArray(this.share.status))
},
+ /**
+ * @return {string}
+ */
+ allowDownloadText() {
+ if (this.isFolder) {
+ return t('files_sharing', 'Allow download of office files')
+ } else {
+ return t('files_sharing', 'Allow download')
+ }
+ },
+
+ /**
+ * @return {boolean}
+ */
+ isSetDownloadButtonVisible() {
+ const allowedMimetypes = [
+ // Office documents
+ 'application/msword',
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+ 'application/vnd.ms-powerpoint',
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
+ 'application/vnd.ms-excel',
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+ 'application/vnd.oasis.opendocument.text',
+ 'application/vnd.oasis.opendocument.spreadsheet',
+ 'application/vnd.oasis.opendocument.presentation',
+ ]
+
+ return this.isFolder || allowedMimetypes.includes(this.fileInfo.mimetype)
+ },
},
methods: {
diff --git a/apps/files_sharing/src/components/SharingEntryLink.vue b/apps/files_sharing/src/components/SharingEntryLink.vue
index d5acf64c202..2dc10de5484 100644
--- a/apps/files_sharing/src/components/SharingEntryLink.vue
+++ b/apps/files_sharing/src/components/SharingEntryLink.vue
@@ -158,7 +158,7 @@
<ActionSeparator />
<ActionCheckbox :checked.sync="share.hideDownload"
- :disabled="saving"
+ :disabled="saving || canChangeHideDownload"
@change="queueUpdate('hideDownload')">
{{ t('files_sharing', 'Hide download') }}
</ActionCheckbox>
@@ -606,6 +606,12 @@ export default {
isPasswordPolicyEnabled() {
return typeof this.config.passwordPolicy === 'object'
},
+
+ canChangeHideDownload() {
+ const hasDisabledDownload = (shareAttribute) => shareAttribute.key === 'download' && shareAttribute.scope === 'permissions' && shareAttribute.enabled === false
+
+ return this.fileInfo.shareAttributes.some(hasDisabledDownload)
+ },
},
methods: {
@@ -867,7 +873,6 @@ export default {
this.$emit('remove:share', this.share)
},
},
-
}
</script>
diff --git a/apps/files_sharing/tests/ApplicationTest.php b/apps/files_sharing/tests/ApplicationTest.php
index ee04996ac15..11c8137c398 100644
--- a/apps/files_sharing/tests/ApplicationTest.php
+++ b/apps/files_sharing/tests/ApplicationTest.php
@@ -22,6 +22,8 @@
*/
namespace OCA\Files_Sharing\Tests;
+use OCP\Files\Events\BeforeDirectFileDownloadEvent;
+use OCP\Files\Events\BeforeZipCreatedEvent;
use Psr\Log\LoggerInterface;
use OC\Share20\LegacyHooks;
use OC\Share20\Manager;
@@ -32,6 +34,7 @@ use OCP\Constants;
use OCP\EventDispatcher\GenericEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICacheEntry;
+use OCP\Files\Event\BeforeDirectGetEvent;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@@ -45,12 +48,8 @@ use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
use Test\TestCase;
class ApplicationTest extends TestCase {
-
- /** @var Application */
- private $application;
-
- /** @var IEventDispatcher */
- private $eventDispatcher;
+ private Application $application;
+ private IEventDispatcher $eventDispatcher;
/** @var IUserSession */
private $userSession;
@@ -81,7 +80,7 @@ class ApplicationTest extends TestCase {
);
}
- public function providesDataForCanGet() {
+ public function providesDataForCanGet(): array {
// normal file (sender) - can download directly
$senderFileStorage = $this->createMock(IStorage::class);
$senderFileStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(false);
@@ -130,7 +129,7 @@ class ApplicationTest extends TestCase {
/**
* @dataProvider providesDataForCanGet
*/
- public function testCheckDirectCanBeDownloaded($path, $userFolder, $run) {
+ public function testCheckDirectCanBeDownloaded(string $path, Folder $userFolder, bool $run): void {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('test');
$this->userSession->method('getUser')->willReturn($user);
@@ -138,13 +137,13 @@ class ApplicationTest extends TestCase {
$this->rootFolder->method('getUserFolder')->willReturn($userFolder);
// Simulate direct download of file
- $event = new GenericEvent(null, [ 'path' => $path ]);
- $this->eventDispatcher->dispatch('file.beforeGetDirect', $event);
+ $event = new BeforeDirectFileDownloadEvent($path);
+ $this->eventDispatcher->dispatchTyped($event);
- $this->assertEquals($run, !$event->hasArgument('errorMessage'));
+ $this->assertEquals($run, $event->isSuccessful());
}
- public function providesDataForCanZip() {
+ public function providesDataForCanZip(): array {
// Mock: Normal file/folder storage
$nonSharedStorage = $this->createMock(IStorage::class);
$nonSharedStorage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(false);
@@ -172,7 +171,7 @@ class ApplicationTest extends TestCase {
$sender1UserFolder->method('get')->willReturn($sender1RootFolder);
$return[] = [ '/folder', ['bar1.txt', 'bar2.txt'], $sender1UserFolder, true ];
- $return[] = [ '/', 'folder', $sender1UserFolder, true ];
+ $return[] = [ '/', ['folder'], $sender1UserFolder, true ];
// 3. cannot download zipped 1 non-shared file and 1 secure-shared inside non-shared folder
$receiver1File = $this->createMock(File::class);
@@ -199,7 +198,7 @@ class ApplicationTest extends TestCase {
$receiver2UserFolder = $this->createMock(Folder::class);
$receiver2UserFolder->method('get')->willReturn($receiver2RootFolder);
- $return[] = [ '/', 'secured-folder', $receiver2UserFolder, false ];
+ $return[] = [ '/', ['secured-folder'], $receiver2UserFolder, false ];
return $return;
}
@@ -207,7 +206,7 @@ class ApplicationTest extends TestCase {
/**
* @dataProvider providesDataForCanZip
*/
- public function testCheckZipCanBeDownloaded($dir, $files, $userFolder, $run) {
+ public function testCheckZipCanBeDownloaded(string $dir, array $files, Folder $userFolder, bool $run): void {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('test');
$this->userSession->method('getUser')->willReturn($user);
@@ -216,22 +215,22 @@ class ApplicationTest extends TestCase {
$this->rootFolder->method('getUserFolder')->with('test')->willReturn($userFolder);
// Simulate zip download of folder folder
- $event = new GenericEvent(null, ['dir' => $dir, 'files' => $files, 'run' => true]);
- $this->eventDispatcher->dispatch('file.beforeCreateZip', $event);
+ $event = new BeforeZipCreatedEvent($dir, $files);
+ $this->eventDispatcher->dispatchTyped($event);
- $this->assertEquals($run, $event->getArgument('run'));
- $this->assertEquals($run, !$event->hasArgument('errorMessage'));
+ $this->assertEquals($run, $event->isSuccessful());
+ $this->assertEquals($run, $event->getErrorMessage() === null);
}
- public function testCheckFileUserNotFound() {
+ public function testCheckFileUserNotFound(): void {
$this->userSession->method('isLoggedIn')->willReturn(false);
// Simulate zip download of folder folder
- $event = new GenericEvent(null, ['dir' => '/test', 'files' => ['test.txt'], 'run' => true]);
- $this->eventDispatcher->dispatch('file.beforeCreateZip', $event);
+ $event = new BeforeZipCreatedEvent('/test', ['test.txt']);
+ $this->eventDispatcher->dispatchTyped($event);
// It should run as this would restrict e.g. share links otherwise
- $this->assertTrue($event->getArgument('run'));
- $this->assertFalse($event->hasArgument('errorMessage'));
+ $this->assertTrue($event->isSuccessful());
+ $this->assertEquals(null, $event->getErrorMessage());
}
}
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index 581781a203d..8665d649aad 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -46,6 +46,7 @@ use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\Storage;
+use OCP\Files\Storage\IStorage;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
@@ -1675,8 +1676,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(File::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
->method('get')
@@ -1709,8 +1712,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(File::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
->method('get')
@@ -1761,8 +1766,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(File::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
->method('get')
@@ -1817,8 +1824,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(File::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
->method('get')
@@ -1876,8 +1885,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
->method('get')
@@ -1930,8 +1941,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
->method('get')
@@ -1964,8 +1977,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
@@ -1985,8 +2000,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
@@ -2007,8 +2024,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(File::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
@@ -2028,8 +2047,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
@@ -2064,8 +2085,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
@@ -2100,8 +2123,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
@@ -2143,8 +2168,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$path->method('getPath')->willReturn('valid-path');
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
@@ -2179,8 +2206,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
@@ -2222,8 +2251,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($path);
@@ -2270,8 +2301,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(File::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
->method('get')
@@ -2342,8 +2375,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(File::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
->method('get')
@@ -2396,8 +2431,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(File::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
->method('get')
@@ -2480,8 +2517,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(File::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$path->method('getPath')->willReturn('valid-path');
$userFolder->expects($this->once())
@@ -2523,8 +2562,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(File::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(false);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', false],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$userFolder->expects($this->once())
->method('get')
@@ -2604,8 +2645,10 @@ class ShareAPIControllerTest extends TestCase {
$path = $this->getMockBuilder(Folder::class)->getMock();
$storage = $this->createMock(Storage::class);
$storage->method('instanceOfStorage')
- ->with('OCA\Files_Sharing\External\Storage')
- ->willReturn(true);
+ ->willReturnMap([
+ ['OCA\Files_Sharing\External\Storage', true],
+ ['OCA\Files_Sharing\SharedStorage', false],
+ ]);
$path->method('getStorage')->willReturn($storage);
$path->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
$userFolder->expects($this->once())
@@ -2964,8 +3007,17 @@ class ShareAPIControllerTest extends TestCase {
$this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD');
$ocs = $this->mockFormatShare();
+ $userFolder = $this->createMock(Folder::class);
+ $userFolder->method('getById')
+ ->with(42)
+ ->willReturn([]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$folder = $this->getMockBuilder(Folder::class)->getMock();
+ $folder->method('getId')
+ ->willReturn(42);
$share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL)
@@ -3003,8 +3055,16 @@ class ShareAPIControllerTest extends TestCase {
$this->expectExceptionMessage('Public upload disabled by the administrator');
$ocs = $this->mockFormatShare();
+ $userFolder = $this->createMock(Folder::class);
+ $userFolder->method('getById')
+ ->with(42)
+ ->willReturn([]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$folder = $this->getMockBuilder(Folder::class)->getMock();
+ $folder->method('getId')->willReturn(42);
$share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL)
@@ -3026,6 +3086,15 @@ class ShareAPIControllerTest extends TestCase {
$ocs = $this->mockFormatShare();
$file = $this->getMockBuilder(File::class)->getMock();
+ $file->method('getId')
+ ->willReturn(42);
+ $userFolder = $this->createMock(Folder::class);
+ $userFolder->method('getById')
+ ->with(42)
+ ->willReturn([]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL)
@@ -3039,13 +3108,21 @@ class ShareAPIControllerTest extends TestCase {
$ocs->updateShare(42, null, 'password', null, 'true', '');
}
- public function testUpdateLinkSharePasswordDoesNotChangeOther() {
+ public function testUpdateLinkSharePasswordDoesNotChangeOther(): void {
$ocs = $this->mockFormatShare();
$date = new \DateTime('2000-01-01');
$date->setTime(0,0,0);
$node = $this->getMockBuilder(File::class)->getMock();
+ $node->method('getId')->willReturn(42);
+ $userFolder = $this->createMock(Folder::class);
+ $userFolder->method('getById')
+ ->with(42)
+ ->willReturn([]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$share = $this->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
@@ -3090,7 +3167,15 @@ class ShareAPIControllerTest extends TestCase {
$date = new \DateTime('2000-01-01');
$date->setTime(0,0,0);
+ $userFolder = $this->createMock(Folder::class);
+ $userFolder->method('getById')
+ ->with(42)
+ ->willReturn([]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$node = $this->getMockBuilder(File::class)->getMock();
+ $node->method('getId')->willReturn(42);
$share = $this->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
@@ -3141,7 +3226,15 @@ class ShareAPIControllerTest extends TestCase {
$date = new \DateTime('2000-01-01');
$date->setTime(0,0,0);
+ $userFolder = $this->createMock(Folder::class);
+ $userFolder->method('getById')
+ ->with(42)
+ ->willReturn([]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$node = $this->getMockBuilder(File::class)->getMock();
+ $node->method('getId')->willReturn(42);
$share = $this->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)
@@ -3174,7 +3267,15 @@ class ShareAPIControllerTest extends TestCase {
$date = new \DateTime('2000-01-01');
$date->setTime(0,0,0);
+ $userFolder = $this->createMock(Folder::class);
+ $userFolder->method('getById')
+ ->with(42)
+ ->willReturn([]);
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser)
+ ->willReturn($userFolder);
$node = $this->getMockBuilder(File::class)->getMock();
+ $node->method('getId')->willReturn(42);
$share = $this->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setSharedBy($this->currentUser)