|
28 | 28 | use OCP\Files\NotFoundException; |
29 | 29 | use OCP\Files\Storage\IStorage; |
30 | 30 | use OCP\HintException; |
| 31 | +use OCP\IAppConfig; |
31 | 32 | use OCP\IConfig; |
32 | 33 | use OCP\IDateTimeZone; |
33 | 34 | use OCP\IGroup; |
@@ -72,6 +73,8 @@ class ManagerTest extends \Test\TestCase { |
72 | 73 | protected $logger; |
73 | 74 | /** @var IConfig|MockObject */ |
74 | 75 | protected $config; |
| 76 | + /** @var IAppConfig|MockObject */ |
| 77 | + protected $appConfig; |
75 | 78 | /** @var ISecureRandom|MockObject */ |
76 | 79 | protected $secureRandom; |
77 | 80 | /** @var IHasher|MockObject */ |
@@ -113,6 +116,7 @@ class ManagerTest extends \Test\TestCase { |
113 | 116 | protected function setUp(): void { |
114 | 117 | $this->logger = $this->createMock(LoggerInterface::class); |
115 | 118 | $this->config = $this->createMock(IConfig::class); |
| 119 | + $this->appConfig = $this->createMock(IAppConfig::class); |
116 | 120 | $this->secureRandom = $this->createMock(ISecureRandom::class); |
117 | 121 | $this->hasher = $this->createMock(IHasher::class); |
118 | 122 | $this->mountManager = $this->createMock(IMountManager::class); |
@@ -156,6 +160,7 @@ private function createManager(IProviderFactory $factory): Manager { |
156 | 160 | return new Manager( |
157 | 161 | $this->logger, |
158 | 162 | $this->config, |
| 163 | + $this->appConfig, |
159 | 164 | $this->secureRandom, |
160 | 165 | $this->hasher, |
161 | 166 | $this->mountManager, |
@@ -183,6 +188,7 @@ private function createManagerMock() { |
183 | 188 | ->setConstructorArgs([ |
184 | 189 | $this->logger, |
185 | 190 | $this->config, |
| 191 | + $this->appConfig, |
186 | 192 | $this->secureRandom, |
187 | 193 | $this->hasher, |
188 | 194 | $this->mountManager, |
@@ -2472,6 +2478,74 @@ public function testCreateShareUser(): void { |
2472 | 2478 | $manager->createShare($share); |
2473 | 2479 | } |
2474 | 2480 |
|
| 2481 | + public function testCreateShareBlockedGroups() { |
| 2482 | + /** setup blocked groups list */ |
| 2483 | + $appConfig = $this->createMock(IAppConfig::class); |
| 2484 | + $appConfig->method('getValueArray') |
| 2485 | + ->with('files_sharing', 'groups_block_list') |
| 2486 | + ->willReturn(['blocked-group-1', 'blocked-group-2']); |
| 2487 | + $this->appConfig = $appConfig; |
| 2488 | + |
| 2489 | + $shareProvider = $this->createMock(IShareProvider::class); |
| 2490 | + $shareProvider->method('getSharesByPath')->willReturn([]); |
| 2491 | + $this->factory->setProvider($shareProvider); |
| 2492 | + |
| 2493 | + $manager = $this->createManagerMock() |
| 2494 | + ->setMethods(['allowGroupSharing', 'canShare', 'generalCreateChecks', 'pathCreateChecks']) |
| 2495 | + ->getMock(); |
| 2496 | + |
| 2497 | + $shareOwner = $this->createMock(IUser::class); |
| 2498 | + $shareOwner->method('getUID')->willReturn('shareOwner'); |
| 2499 | + |
| 2500 | + $storage = $this->createMock(IStorage::class); |
| 2501 | + $path = $this->createMock(File::class); |
| 2502 | + $path->method('getOwner')->willReturn($shareOwner); |
| 2503 | + $path->method('getName')->willReturn('target'); |
| 2504 | + $path->method('getStorage')->willReturn($storage); |
| 2505 | + |
| 2506 | + /** test create share with 'blocked-group-2': should throw exception */ |
| 2507 | + $this->expectException(\InvalidArgumentException::class); |
| 2508 | + $share = $this->createShare( |
| 2509 | + null, |
| 2510 | + IShare::TYPE_GROUP, |
| 2511 | + $path, |
| 2512 | + 'blocked-group-1', |
| 2513 | + 'sharedBy', |
| 2514 | + null, |
| 2515 | + \OCP\Constants::PERMISSION_ALL); |
| 2516 | + |
| 2517 | + $manager->expects($this->any()) |
| 2518 | + ->method('allowGroupSharing') |
| 2519 | + ->willReturn(true); |
| 2520 | + $manager->expects($this->once()) |
| 2521 | + ->method('canShare') |
| 2522 | + ->with($share) |
| 2523 | + ->willReturn(true); |
| 2524 | + $manager->expects($this->once()) |
| 2525 | + ->method('generalCreateChecks') |
| 2526 | + ->with($share); |
| 2527 | + ; |
| 2528 | + $manager->expects($this->once()) |
| 2529 | + ->method('pathCreateChecks') |
| 2530 | + ->with($path); |
| 2531 | + |
| 2532 | + $this->defaultProvider |
| 2533 | + ->expects($this->any()) |
| 2534 | + ->method('create') |
| 2535 | + ->with($share) |
| 2536 | + ->willReturnArgument(0); |
| 2537 | + |
| 2538 | + $share->expects($this->any()) |
| 2539 | + ->method('setShareOwner') |
| 2540 | + ->with('shareOwner'); |
| 2541 | + $share->expects($this->any()) |
| 2542 | + ->method('setTarget') |
| 2543 | + ->with('/target'); |
| 2544 | + |
| 2545 | + $manager->createShare($share); |
| 2546 | + |
| 2547 | + } |
| 2548 | + |
2475 | 2549 | public function testCreateShareGroup(): void { |
2476 | 2550 | $manager = $this->createManagerMock() |
2477 | 2551 | ->setMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks']) |
|
0 commit comments