|
4 | 4 |
|
5 | 5 | use OC\Encryption\Util; |
6 | 6 | use OC\Files\View; |
| 7 | +use OCA\Files_External\Lib\StorageConfig; |
| 8 | +use OCA\Files_External\Service\GlobalStoragesService; |
7 | 9 | use OCP\Encryption\IEncryptionModule; |
8 | 10 | use OCP\IConfig; |
9 | 11 | use Test\TestCase; |
@@ -188,4 +190,43 @@ public function dataTestStripPartialFileExtension() { |
188 | 190 | ['/foo/test.txt.ocTransferId7567.part', '/foo/test.txt'], |
189 | 191 | ]; |
190 | 192 | } |
| 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 | + } |
191 | 232 | } |
0 commit comments