diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2022-06-02 13:47:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-02 13:47:18 +0200 |
commit | 1d1b9d936b461ee9ae7242a692fce443e452e84b (patch) | |
tree | 4486a4760c163c89049e241adc901a917a8d562f | |
parent | 01bb642901996d2e9859f42c376b99178f2d94ef (diff) | |
parent | b212e8dcc937ee574e03131be8a3645fd5e0b9fa (diff) | |
download | nextcloud-server-1d1b9d936b461ee9ae7242a692fce443e452e84b.tar.gz nextcloud-server-1d1b9d936b461ee9ae7242a692fce443e452e84b.zip |
Merge pull request #32690 from nextcloud/bugfix/noid/fix-mountpoint-matching-encryption
Trim mount point before matching in encryption code
-rw-r--r-- | lib/private/Encryption/Util.php | 2 | ||||
-rw-r--r-- | tests/lib/Encryption/UtilTest.php | 41 |
2 files changed, 42 insertions, 1 deletions
diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php index 693e24c4721..174af2e8b89 100644 --- a/lib/private/Encryption/Util.php +++ b/lib/private/Encryption/Util.php @@ -304,7 +304,7 @@ class Util { $storageService = \OC::$server->get(GlobalStoragesService::class); $storages = $storageService->getAllStorages(); foreach ($storages as $storage) { - if (strpos($path, '/files/' . $storage->getMountPoint()) === 0) { + if (strpos($path, '/files/' . ltrim($storage->getMountPoint(), '/')) === 0) { if ($this->isMountPointApplicableToUser($storage, $uid)) { return true; } diff --git a/tests/lib/Encryption/UtilTest.php b/tests/lib/Encryption/UtilTest.php index 84d81dd1cbb..02155be11dd 100644 --- a/tests/lib/Encryption/UtilTest.php +++ b/tests/lib/Encryption/UtilTest.php @@ -4,6 +4,8 @@ namespace Test\Encryption; use OC\Encryption\Util; use OC\Files\View; +use OCA\Files_External\Lib\StorageConfig; +use OCA\Files_External\Service\GlobalStoragesService; use OCP\Encryption\IEncryptionModule; use OCP\IConfig; use Test\TestCase; @@ -188,4 +190,43 @@ class UtilTest extends TestCase { ['/foo/test.txt.ocTransferId7567.part', '/foo/test.txt'], ]; } + + public function dataTestIsSystemWideMountPoint() { + return [ + [false, 'non-matching mount point name', [], [], '/mp_another'], + [true, 'applicable to all', [], []], + [true, 'applicable to user directly', ['user1'], []], + [true, 'applicable to group directly', [], ['group1']], + [false, 'non-applicable to current user', ['user2'], []], + [false, 'non-applicable to current user\'s group', [], ['group2']], + [true, 'mount point without leading slash', [], [], 'mp'], + ]; + } + + /** + * @dataProvider dataTestIsSystemWideMountPoint + */ + public function testIsSystemWideMountPoint($expectedResult, $expectationText, $applicableUsers, $applicableGroups, $mountPointName = '/mp') { + $this->groupManager->method('isInGroup') + ->will($this->returnValueMap([ + ['user1', 'group1', true], // user is only in group1 + ['user1', 'group2', false], + ])); + + $storages = []; + + $storageConfig = $this->createMock(StorageConfig::class); + $storageConfig->method('getMountPoint')->willReturn($mountPointName); + $storageConfig->method('getApplicableUsers')->willReturn($applicableUsers); + $storageConfig->method('getApplicableGroups')->willReturn($applicableGroups); + $storages[] = $storageConfig; + + $storagesServiceMock = $this->createMock(GlobalStoragesService::class); + $storagesServiceMock->expects($this->atLeastOnce())->method('getAllStorages') + ->willReturn($storages); + + $this->overwriteService(GlobalStoragesService::class, $storagesServiceMock); + + $this->assertEquals($expectedResult, $this->util->isSystemWideMountPoint('/files/mp', 'user1'), 'Test case: ' . $expectationText); + } } |