diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-06-01 18:01:59 +0200 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2022-06-01 18:10:59 +0200 |
commit | b212e8dcc937ee574e03131be8a3645fd5e0b9fa (patch) | |
tree | c9e79a17ea2d07ccaa8280f97a70daad317e8290 | |
parent | a704bcf97f9c1baadd3a6f8497bcc9f9c2f4f195 (diff) | |
download | nextcloud-server-b212e8dcc937ee574e03131be8a3645fd5e0b9fa.tar.gz nextcloud-server-b212e8dcc937ee574e03131be8a3645fd5e0b9fa.zip |
Add unit tests for encryption's isSystemWideMountPoint
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
-rw-r--r-- | tests/lib/Encryption/UtilTest.php | 41 |
1 files changed, 41 insertions, 0 deletions
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); + } } |