summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-03-20 12:27:38 +0100
committerGitHub <noreply@github.com>2017-03-20 12:27:38 +0100
commit35f6b8716e0f4f851e6c5df19b24a1fa76cca5c0 (patch)
tree5cffd99f112f9b3a949e1a4aafd611f1060d2530 /apps/files_sharing
parent25f772d592172c40ecbb97db71e9590678eab2a4 (diff)
parent80d2717e5cb80615c2e75885398c26289fad463c (diff)
downloadnextcloud-server-35f6b8716e0f4f851e6c5df19b24a1fa76cca5c0.tar.gz
nextcloud-server-35f6b8716e0f4f851e6c5df19b24a1fa76cca5c0.zip
Merge pull request #3884 from nextcloud/downstream-26956
Skip null groups in group manager
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php2
-rw-r--r--apps/files_sharing/lib/MountProvider.php18
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php7
-rw-r--r--apps/files_sharing/tests/MountProviderTest.php22
4 files changed, 45 insertions, 4 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 711970d0c84..78eef6c26bb 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -804,7 +804,7 @@ class ShareAPIController extends OCSController {
if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$sharedWith = $this->groupManager->get($share->getSharedWith());
$user = $this->userManager->get($this->currentUser);
- if ($user !== null && $sharedWith->inGroup($user)) {
+ if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) {
return true;
}
}
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php
index f474190fc98..a02d6350499 100644
--- a/apps/files_sharing/lib/MountProvider.php
+++ b/apps/files_sharing/lib/MountProvider.php
@@ -173,7 +173,23 @@ class MountProvider implements IMountProvider {
if ($share->getTarget() !== $superShare->getTarget()) {
// adjust target, for database consistency
$share->setTarget($superShare->getTarget());
- $this->shareManager->moveShare($share, $user->getUID());
+ try {
+ $this->shareManager->moveShare($share, $user->getUID());
+ } catch (\InvalidArgumentException $e) {
+ // ignore as it is not important and we don't want to
+ // block FS setup
+
+ // the subsequent code anyway only uses the target of the
+ // super share
+
+ // such issue can usually happen when dealing with
+ // null groups which usually appear with group backend
+ // caching inconsistencies
+ $this->logger->debug(
+ 'Could not adjust share target for share ' . $share->getId() . ' to make it consistent: ' . $e->getMessage(),
+ ['app' => 'files_sharing']
+ );
+ }
}
if (!is_null($share->getNodeCacheEntry())) {
$superShare->setNodeCacheEntry($share->getNodeCacheEntry());
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index 97774081b6a..2bf9a40b2cc 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -544,14 +544,19 @@ class ShareAPIControllerTest extends \Test\TestCase {
$this->groupManager->method('get')->will($this->returnValueMap([
['group', $group],
['group2', $group2],
+ ['groupnull', null],
]));
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMockBuilder('OCP\Share\IShare')->getMock();
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
$share->method('getSharedWith')->willReturn('group2');
+ $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
- $this->groupManager->method('get')->with('group2')->willReturn($group);
+ // null group
+ $share = $this->getMock('OCP\Share\IShare');
+ $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
+ $share->method('getSharedWith')->willReturn('groupnull');
$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMockBuilder('OCP\Share\IShare')->getMock();
diff --git a/apps/files_sharing/tests/MountProviderTest.php b/apps/files_sharing/tests/MountProviderTest.php
index 1c83d91d08f..b700d417ad4 100644
--- a/apps/files_sharing/tests/MountProviderTest.php
+++ b/apps/files_sharing/tests/MountProviderTest.php
@@ -269,6 +269,20 @@ class MountProviderTest extends \Test\TestCase {
['1', 100, 'user2', '/share2-renamed', 31],
],
],
+ // #9: share as outsider with "nullgroup" and "user1" where recipient renamed in between
+ [
+ [
+ [2, 100, 'user2', '/share2', 31],
+ ],
+ [
+ [1, 100, 'nullgroup', '/share2-renamed', 31],
+ ],
+ [
+ // use target of least recent share
+ ['1', 100, 'nullgroup', '/share2-renamed', 31],
+ ],
+ true
+ ],
];
}
@@ -284,7 +298,7 @@ class MountProviderTest extends \Test\TestCase {
* @param array $groupShares array of group share specs
* @param array $expectedShares array of expected supershare specs
*/
- public function testMergeShares($userShares, $groupShares, $expectedShares) {
+ public function testMergeShares($userShares, $groupShares, $expectedShares, $moveFails = false) {
$rootFolder = $this->createMock(IRootFolder::class);
$userManager = $this->createMock(IUserManager::class);
@@ -319,6 +333,12 @@ class MountProviderTest extends \Test\TestCase {
return new \OC\Share20\Share($rootFolder, $userManager);
}));
+ if ($moveFails) {
+ $this->shareManager->expects($this->any())
+ ->method('moveShare')
+ ->will($this->throwException(new \InvalidArgumentException()));
+ }
+
$mounts = $this->provider->getMountsForUser($this->user, $this->loader);
$this->assertCount(count($expectedShares), $mounts);