Skip to content

Commit b212e8d

Browse files
committed
Add unit tests for encryption's isSystemWideMountPoint
Signed-off-by: Vincent Petry <[email protected]>
1 parent a704bcf commit b212e8d

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

tests/lib/Encryption/UtilTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use OC\Encryption\Util;
66
use OC\Files\View;
7+
use OCA\Files_External\Lib\StorageConfig;
8+
use OCA\Files_External\Service\GlobalStoragesService;
79
use OCP\Encryption\IEncryptionModule;
810
use OCP\IConfig;
911
use Test\TestCase;
@@ -188,4 +190,43 @@ public function dataTestStripPartialFileExtension() {
188190
['/foo/test.txt.ocTransferId7567.part', '/foo/test.txt'],
189191
];
190192
}
193+
194+
public function dataTestIsSystemWideMountPoint() {
195+
return [
196+
[false, 'non-matching mount point name', [], [], '/mp_another'],
197+
[true, 'applicable to all', [], []],
198+
[true, 'applicable to user directly', ['user1'], []],
199+
[true, 'applicable to group directly', [], ['group1']],
200+
[false, 'non-applicable to current user', ['user2'], []],
201+
[false, 'non-applicable to current user\'s group', [], ['group2']],
202+
[true, 'mount point without leading slash', [], [], 'mp'],
203+
];
204+
}
205+
206+
/**
207+
* @dataProvider dataTestIsSystemWideMountPoint
208+
*/
209+
public function testIsSystemWideMountPoint($expectedResult, $expectationText, $applicableUsers, $applicableGroups, $mountPointName = '/mp') {
210+
$this->groupManager->method('isInGroup')
211+
->will($this->returnValueMap([
212+
['user1', 'group1', true], // user is only in group1
213+
['user1', 'group2', false],
214+
]));
215+
216+
$storages = [];
217+
218+
$storageConfig = $this->createMock(StorageConfig::class);
219+
$storageConfig->method('getMountPoint')->willReturn($mountPointName);
220+
$storageConfig->method('getApplicableUsers')->willReturn($applicableUsers);
221+
$storageConfig->method('getApplicableGroups')->willReturn($applicableGroups);
222+
$storages[] = $storageConfig;
223+
224+
$storagesServiceMock = $this->createMock(GlobalStoragesService::class);
225+
$storagesServiceMock->expects($this->atLeastOnce())->method('getAllStorages')
226+
->willReturn($storages);
227+
228+
$this->overwriteService(GlobalStoragesService::class, $storagesServiceMock);
229+
230+
$this->assertEquals($expectedResult, $this->util->isSystemWideMountPoint('/files/mp', 'user1'), 'Test case: ' . $expectationText);
231+
}
191232
}

0 commit comments

Comments
 (0)