@@ -46,268 +46,268 @@ |
||
| 46 | 46 | * @package OCA\Files\Tests\Controller |
| 47 | 47 | */ |
| 48 | 48 | class ViewControllerTest extends TestCase { |
| 49 | - private ContainerInterface&MockObject $container; |
|
| 50 | - private IAppManager&MockObject $appManager; |
|
| 51 | - private ICacheFactory&MockObject $cacheFactory; |
|
| 52 | - private IConfig&MockObject $config; |
|
| 53 | - private IEventDispatcher $eventDispatcher; |
|
| 54 | - private IEventLogger&MockObject $eventLogger; |
|
| 55 | - private IInitialState&MockObject $initialState; |
|
| 56 | - private IL10N&MockObject $l10n; |
|
| 57 | - private IRequest&MockObject $request; |
|
| 58 | - private IRootFolder&MockObject $rootFolder; |
|
| 59 | - private ITemplateManager&MockObject $templateManager; |
|
| 60 | - private IURLGenerator $urlGenerator; |
|
| 61 | - private IUser&MockObject $user; |
|
| 62 | - private IUserSession&MockObject $userSession; |
|
| 63 | - private LoggerInterface&MockObject $logger; |
|
| 64 | - private UserConfig&MockObject $userConfig; |
|
| 65 | - private ViewConfig&MockObject $viewConfig; |
|
| 66 | - private Router $router; |
|
| 67 | - private IRegistry&MockObject $twoFactorRegistry; |
|
| 68 | - |
|
| 69 | - private ViewController&MockObject $viewController; |
|
| 70 | - |
|
| 71 | - protected function setUp(): void { |
|
| 72 | - parent::setUp(); |
|
| 73 | - $this->appManager = $this->createMock(IAppManager::class); |
|
| 74 | - $this->config = $this->createMock(IConfig::class); |
|
| 75 | - $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
| 76 | - $this->initialState = $this->createMock(IInitialState::class); |
|
| 77 | - $this->l10n = $this->createMock(IL10N::class); |
|
| 78 | - $this->request = $this->createMock(IRequest::class); |
|
| 79 | - $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 80 | - $this->templateManager = $this->createMock(ITemplateManager::class); |
|
| 81 | - $this->userConfig = $this->createMock(UserConfig::class); |
|
| 82 | - $this->userSession = $this->createMock(IUserSession::class); |
|
| 83 | - $this->viewConfig = $this->createMock(ViewConfig::class); |
|
| 84 | - $this->twoFactorRegistry = $this->createMock(IRegistry::class); |
|
| 85 | - |
|
| 86 | - $this->user = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 87 | - $this->user->expects($this->any()) |
|
| 88 | - ->method('getUID') |
|
| 89 | - ->willReturn('testuser1'); |
|
| 90 | - $this->userSession->expects($this->any()) |
|
| 91 | - ->method('getUser') |
|
| 92 | - ->willReturn($this->user); |
|
| 93 | - |
|
| 94 | - // Make sure we know the app is enabled |
|
| 95 | - $this->appManager->expects($this->any()) |
|
| 96 | - ->method('cleanAppId') |
|
| 97 | - ->willReturnArgument(0); |
|
| 98 | - $this->appManager->expects($this->any()) |
|
| 99 | - ->method('getAppPath') |
|
| 100 | - ->willReturnCallback(fn (string $appid): string => \OC::$SERVERROOT . '/apps/' . $appid); |
|
| 101 | - $this->appManager->expects($this->any()) |
|
| 102 | - ->method('isAppLoaded') |
|
| 103 | - ->willReturn(true); |
|
| 104 | - |
|
| 105 | - $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
| 106 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 107 | - $this->eventLogger = $this->createMock(IEventLogger::class); |
|
| 108 | - $this->container = $this->createMock(ContainerInterface::class); |
|
| 109 | - $this->router = new Router( |
|
| 110 | - $this->logger, |
|
| 111 | - $this->request, |
|
| 112 | - $this->config, |
|
| 113 | - $this->eventLogger, |
|
| 114 | - $this->container, |
|
| 115 | - $this->appManager, |
|
| 116 | - ); |
|
| 117 | - |
|
| 118 | - // Create a real URLGenerator instance to generate URLs |
|
| 119 | - $this->urlGenerator = new URLGenerator( |
|
| 120 | - $this->config, |
|
| 121 | - $this->userSession, |
|
| 122 | - $this->cacheFactory, |
|
| 123 | - $this->request, |
|
| 124 | - $this->router |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - $filenameValidator = $this->createMock(FilenameValidator::class); |
|
| 128 | - $this->viewController = $this->getMockBuilder(ViewController::class) |
|
| 129 | - ->setConstructorArgs([ |
|
| 130 | - 'files', |
|
| 131 | - $this->request, |
|
| 132 | - $this->urlGenerator, |
|
| 133 | - $this->l10n, |
|
| 134 | - $this->config, |
|
| 135 | - $this->eventDispatcher, |
|
| 136 | - $this->userSession, |
|
| 137 | - $this->appManager, |
|
| 138 | - $this->rootFolder, |
|
| 139 | - $this->initialState, |
|
| 140 | - $this->templateManager, |
|
| 141 | - $this->userConfig, |
|
| 142 | - $this->viewConfig, |
|
| 143 | - $filenameValidator, |
|
| 144 | - $this->twoFactorRegistry, |
|
| 145 | - ]) |
|
| 146 | - ->onlyMethods([ |
|
| 147 | - 'getStorageInfo', |
|
| 148 | - ]) |
|
| 149 | - ->getMock(); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function testIndexWithRegularBrowser(): void { |
|
| 153 | - $this->viewController |
|
| 154 | - ->expects($this->any()) |
|
| 155 | - ->method('getStorageInfo') |
|
| 156 | - ->willReturn([ |
|
| 157 | - 'used' => 123, |
|
| 158 | - 'quota' => 100, |
|
| 159 | - 'total' => 100, |
|
| 160 | - 'relative' => 123, |
|
| 161 | - 'owner' => 'MyName', |
|
| 162 | - 'ownerDisplayName' => 'MyDisplayName', |
|
| 163 | - ]); |
|
| 164 | - |
|
| 165 | - $this->config |
|
| 166 | - ->method('getUserValue') |
|
| 167 | - ->willReturnMap([ |
|
| 168 | - [$this->user->getUID(), 'files', 'file_sorting', 'name', 'name'], |
|
| 169 | - [$this->user->getUID(), 'files', 'file_sorting_direction', 'asc', 'asc'], |
|
| 170 | - [$this->user->getUID(), 'files', 'files_sorting_configs', '{}', '{}'], |
|
| 171 | - [$this->user->getUID(), 'files', 'show_hidden', false, false], |
|
| 172 | - [$this->user->getUID(), 'files', 'crop_image_previews', true, true], |
|
| 173 | - [$this->user->getUID(), 'files', 'show_grid', true], |
|
| 174 | - ]); |
|
| 175 | - |
|
| 176 | - $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 177 | - |
|
| 178 | - $this->rootFolder->expects($this->any()) |
|
| 179 | - ->method('getUserFolder') |
|
| 180 | - ->with('testuser1') |
|
| 181 | - ->willReturn($baseFolderFiles); |
|
| 182 | - |
|
| 183 | - $this->config |
|
| 184 | - ->expects($this->any()) |
|
| 185 | - ->method('getAppValue') |
|
| 186 | - ->willReturnArgument(2); |
|
| 187 | - |
|
| 188 | - $expected = new TemplateResponse( |
|
| 189 | - 'files', |
|
| 190 | - 'index', |
|
| 191 | - ); |
|
| 192 | - $policy = new ContentSecurityPolicy(); |
|
| 193 | - $policy->addAllowedWorkerSrcDomain('\'self\''); |
|
| 194 | - $policy->addAllowedFrameDomain('\'self\''); |
|
| 195 | - $expected->setContentSecurityPolicy($policy); |
|
| 196 | - |
|
| 197 | - $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView')); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - public static function dataTestShortRedirect(): array { |
|
| 201 | - // openfile is true by default |
|
| 202 | - // opendetails is undefined by default |
|
| 203 | - // both will be evaluated as truthy |
|
| 204 | - return [ |
|
| 205 | - [null, null, '/index.php/apps/files/files/123456?openfile=true'], |
|
| 206 | - ['', null, '/index.php/apps/files/files/123456?openfile=true'], |
|
| 207 | - [null, '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
| 208 | - ['', '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
| 209 | - ['false', '', '/index.php/apps/files/files/123456?openfile=false'], |
|
| 210 | - [null, 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
| 211 | - ['true', 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
| 212 | - ['false', 'true', '/index.php/apps/files/files/123456?openfile=false&opendetails=true'], |
|
| 213 | - ['false', 'false', '/index.php/apps/files/files/123456?openfile=false&opendetails=false'], |
|
| 214 | - ]; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestShortRedirect')] |
|
| 218 | - public function testShortRedirect(?string $openfile, ?string $opendetails, string $result): void { |
|
| 219 | - $this->appManager->expects($this->any()) |
|
| 220 | - ->method('isEnabledForUser') |
|
| 221 | - ->with('files') |
|
| 222 | - ->willReturn(true); |
|
| 223 | - |
|
| 224 | - $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 225 | - $this->rootFolder->expects($this->any()) |
|
| 226 | - ->method('getUserFolder') |
|
| 227 | - ->with('testuser1') |
|
| 228 | - ->willReturn($baseFolderFiles); |
|
| 229 | - |
|
| 230 | - $parentNode = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 231 | - $parentNode->expects($this->once()) |
|
| 232 | - ->method('getPath') |
|
| 233 | - ->willReturn('testuser1/files/Folder'); |
|
| 234 | - |
|
| 235 | - $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 236 | - $node->expects($this->once()) |
|
| 237 | - ->method('getParent') |
|
| 238 | - ->willReturn($parentNode); |
|
| 239 | - |
|
| 240 | - $baseFolderFiles->expects($this->any()) |
|
| 241 | - ->method('getFirstNodeById') |
|
| 242 | - ->with(123456) |
|
| 243 | - ->willReturn($node); |
|
| 244 | - |
|
| 245 | - $response = $this->viewController->showFile('123456', $opendetails, $openfile); |
|
| 246 | - $this->assertStringContainsString($result, $response->getHeaders()['Location']); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - public function testShowFileRouteWithTrashedFile(): void { |
|
| 250 | - $this->appManager->expects($this->exactly(2)) |
|
| 251 | - ->method('isEnabledForUser') |
|
| 252 | - ->willReturn(true); |
|
| 253 | - |
|
| 254 | - $parentNode = $this->createMock(Folder::class); |
|
| 255 | - $parentNode->expects($this->once()) |
|
| 256 | - ->method('getPath') |
|
| 257 | - ->willReturn('testuser1/files_trashbin/files/test.d1462861890/sub'); |
|
| 258 | - |
|
| 259 | - $baseFolderFiles = $this->createMock(Folder::class); |
|
| 260 | - $baseFolderTrash = $this->createMock(Folder::class); |
|
| 261 | - |
|
| 262 | - $this->rootFolder->expects($this->any()) |
|
| 263 | - ->method('getUserFolder') |
|
| 264 | - ->with('testuser1') |
|
| 265 | - ->willReturn($baseFolderFiles); |
|
| 266 | - $this->rootFolder->expects($this->once()) |
|
| 267 | - ->method('get') |
|
| 268 | - ->with('testuser1/files_trashbin/files/') |
|
| 269 | - ->willReturn($baseFolderTrash); |
|
| 270 | - |
|
| 271 | - $baseFolderFiles->expects($this->any()) |
|
| 272 | - ->method('getFirstNodeById') |
|
| 273 | - ->with(123) |
|
| 274 | - ->willReturn(null); |
|
| 275 | - |
|
| 276 | - $node = $this->createMock(File::class); |
|
| 277 | - $node->expects($this->once()) |
|
| 278 | - ->method('getParent') |
|
| 279 | - ->willReturn($parentNode); |
|
| 280 | - |
|
| 281 | - $baseFolderTrash->expects($this->once()) |
|
| 282 | - ->method('getFirstNodeById') |
|
| 283 | - ->with(123) |
|
| 284 | - ->willReturn($node); |
|
| 285 | - $baseFolderTrash->expects($this->once()) |
|
| 286 | - ->method('getRelativePath') |
|
| 287 | - ->with('testuser1/files_trashbin/files/test.d1462861890/sub') |
|
| 288 | - ->willReturn('/test.d1462861890/sub'); |
|
| 289 | - |
|
| 290 | - $expected = new RedirectResponse('/index.php/apps/files/trashbin/123?dir=/test.d1462861890/sub'); |
|
| 291 | - $this->assertEquals($expected, $this->viewController->index('', '', '123')); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - public function testTwoFactorAuthEnabled(): void { |
|
| 295 | - $this->twoFactorRegistry->method('getProviderStates') |
|
| 296 | - ->willReturn([ |
|
| 297 | - 'totp' => true, |
|
| 298 | - 'backup_codes' => true, |
|
| 299 | - ]); |
|
| 300 | - |
|
| 301 | - $invokedCountProvideInitialState = $this->exactly(9); |
|
| 302 | - $this->initialState->expects($invokedCountProvideInitialState) |
|
| 303 | - ->method('provideInitialState') |
|
| 304 | - ->willReturnCallback(function ($key, $data) use ($invokedCountProvideInitialState): void { |
|
| 305 | - if ($invokedCountProvideInitialState->numberOfInvocations() === 9) { |
|
| 306 | - $this->assertEquals('isTwoFactorEnabled', $key); |
|
| 307 | - $this->assertTrue($data); |
|
| 308 | - } |
|
| 309 | - }); |
|
| 310 | - |
|
| 311 | - $this->viewController->index('', '', null); |
|
| 312 | - } |
|
| 49 | + private ContainerInterface&MockObject $container; |
|
| 50 | + private IAppManager&MockObject $appManager; |
|
| 51 | + private ICacheFactory&MockObject $cacheFactory; |
|
| 52 | + private IConfig&MockObject $config; |
|
| 53 | + private IEventDispatcher $eventDispatcher; |
|
| 54 | + private IEventLogger&MockObject $eventLogger; |
|
| 55 | + private IInitialState&MockObject $initialState; |
|
| 56 | + private IL10N&MockObject $l10n; |
|
| 57 | + private IRequest&MockObject $request; |
|
| 58 | + private IRootFolder&MockObject $rootFolder; |
|
| 59 | + private ITemplateManager&MockObject $templateManager; |
|
| 60 | + private IURLGenerator $urlGenerator; |
|
| 61 | + private IUser&MockObject $user; |
|
| 62 | + private IUserSession&MockObject $userSession; |
|
| 63 | + private LoggerInterface&MockObject $logger; |
|
| 64 | + private UserConfig&MockObject $userConfig; |
|
| 65 | + private ViewConfig&MockObject $viewConfig; |
|
| 66 | + private Router $router; |
|
| 67 | + private IRegistry&MockObject $twoFactorRegistry; |
|
| 68 | + |
|
| 69 | + private ViewController&MockObject $viewController; |
|
| 70 | + |
|
| 71 | + protected function setUp(): void { |
|
| 72 | + parent::setUp(); |
|
| 73 | + $this->appManager = $this->createMock(IAppManager::class); |
|
| 74 | + $this->config = $this->createMock(IConfig::class); |
|
| 75 | + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
| 76 | + $this->initialState = $this->createMock(IInitialState::class); |
|
| 77 | + $this->l10n = $this->createMock(IL10N::class); |
|
| 78 | + $this->request = $this->createMock(IRequest::class); |
|
| 79 | + $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 80 | + $this->templateManager = $this->createMock(ITemplateManager::class); |
|
| 81 | + $this->userConfig = $this->createMock(UserConfig::class); |
|
| 82 | + $this->userSession = $this->createMock(IUserSession::class); |
|
| 83 | + $this->viewConfig = $this->createMock(ViewConfig::class); |
|
| 84 | + $this->twoFactorRegistry = $this->createMock(IRegistry::class); |
|
| 85 | + |
|
| 86 | + $this->user = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 87 | + $this->user->expects($this->any()) |
|
| 88 | + ->method('getUID') |
|
| 89 | + ->willReturn('testuser1'); |
|
| 90 | + $this->userSession->expects($this->any()) |
|
| 91 | + ->method('getUser') |
|
| 92 | + ->willReturn($this->user); |
|
| 93 | + |
|
| 94 | + // Make sure we know the app is enabled |
|
| 95 | + $this->appManager->expects($this->any()) |
|
| 96 | + ->method('cleanAppId') |
|
| 97 | + ->willReturnArgument(0); |
|
| 98 | + $this->appManager->expects($this->any()) |
|
| 99 | + ->method('getAppPath') |
|
| 100 | + ->willReturnCallback(fn (string $appid): string => \OC::$SERVERROOT . '/apps/' . $appid); |
|
| 101 | + $this->appManager->expects($this->any()) |
|
| 102 | + ->method('isAppLoaded') |
|
| 103 | + ->willReturn(true); |
|
| 104 | + |
|
| 105 | + $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
| 106 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 107 | + $this->eventLogger = $this->createMock(IEventLogger::class); |
|
| 108 | + $this->container = $this->createMock(ContainerInterface::class); |
|
| 109 | + $this->router = new Router( |
|
| 110 | + $this->logger, |
|
| 111 | + $this->request, |
|
| 112 | + $this->config, |
|
| 113 | + $this->eventLogger, |
|
| 114 | + $this->container, |
|
| 115 | + $this->appManager, |
|
| 116 | + ); |
|
| 117 | + |
|
| 118 | + // Create a real URLGenerator instance to generate URLs |
|
| 119 | + $this->urlGenerator = new URLGenerator( |
|
| 120 | + $this->config, |
|
| 121 | + $this->userSession, |
|
| 122 | + $this->cacheFactory, |
|
| 123 | + $this->request, |
|
| 124 | + $this->router |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + $filenameValidator = $this->createMock(FilenameValidator::class); |
|
| 128 | + $this->viewController = $this->getMockBuilder(ViewController::class) |
|
| 129 | + ->setConstructorArgs([ |
|
| 130 | + 'files', |
|
| 131 | + $this->request, |
|
| 132 | + $this->urlGenerator, |
|
| 133 | + $this->l10n, |
|
| 134 | + $this->config, |
|
| 135 | + $this->eventDispatcher, |
|
| 136 | + $this->userSession, |
|
| 137 | + $this->appManager, |
|
| 138 | + $this->rootFolder, |
|
| 139 | + $this->initialState, |
|
| 140 | + $this->templateManager, |
|
| 141 | + $this->userConfig, |
|
| 142 | + $this->viewConfig, |
|
| 143 | + $filenameValidator, |
|
| 144 | + $this->twoFactorRegistry, |
|
| 145 | + ]) |
|
| 146 | + ->onlyMethods([ |
|
| 147 | + 'getStorageInfo', |
|
| 148 | + ]) |
|
| 149 | + ->getMock(); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function testIndexWithRegularBrowser(): void { |
|
| 153 | + $this->viewController |
|
| 154 | + ->expects($this->any()) |
|
| 155 | + ->method('getStorageInfo') |
|
| 156 | + ->willReturn([ |
|
| 157 | + 'used' => 123, |
|
| 158 | + 'quota' => 100, |
|
| 159 | + 'total' => 100, |
|
| 160 | + 'relative' => 123, |
|
| 161 | + 'owner' => 'MyName', |
|
| 162 | + 'ownerDisplayName' => 'MyDisplayName', |
|
| 163 | + ]); |
|
| 164 | + |
|
| 165 | + $this->config |
|
| 166 | + ->method('getUserValue') |
|
| 167 | + ->willReturnMap([ |
|
| 168 | + [$this->user->getUID(), 'files', 'file_sorting', 'name', 'name'], |
|
| 169 | + [$this->user->getUID(), 'files', 'file_sorting_direction', 'asc', 'asc'], |
|
| 170 | + [$this->user->getUID(), 'files', 'files_sorting_configs', '{}', '{}'], |
|
| 171 | + [$this->user->getUID(), 'files', 'show_hidden', false, false], |
|
| 172 | + [$this->user->getUID(), 'files', 'crop_image_previews', true, true], |
|
| 173 | + [$this->user->getUID(), 'files', 'show_grid', true], |
|
| 174 | + ]); |
|
| 175 | + |
|
| 176 | + $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 177 | + |
|
| 178 | + $this->rootFolder->expects($this->any()) |
|
| 179 | + ->method('getUserFolder') |
|
| 180 | + ->with('testuser1') |
|
| 181 | + ->willReturn($baseFolderFiles); |
|
| 182 | + |
|
| 183 | + $this->config |
|
| 184 | + ->expects($this->any()) |
|
| 185 | + ->method('getAppValue') |
|
| 186 | + ->willReturnArgument(2); |
|
| 187 | + |
|
| 188 | + $expected = new TemplateResponse( |
|
| 189 | + 'files', |
|
| 190 | + 'index', |
|
| 191 | + ); |
|
| 192 | + $policy = new ContentSecurityPolicy(); |
|
| 193 | + $policy->addAllowedWorkerSrcDomain('\'self\''); |
|
| 194 | + $policy->addAllowedFrameDomain('\'self\''); |
|
| 195 | + $expected->setContentSecurityPolicy($policy); |
|
| 196 | + |
|
| 197 | + $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView')); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + public static function dataTestShortRedirect(): array { |
|
| 201 | + // openfile is true by default |
|
| 202 | + // opendetails is undefined by default |
|
| 203 | + // both will be evaluated as truthy |
|
| 204 | + return [ |
|
| 205 | + [null, null, '/index.php/apps/files/files/123456?openfile=true'], |
|
| 206 | + ['', null, '/index.php/apps/files/files/123456?openfile=true'], |
|
| 207 | + [null, '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
| 208 | + ['', '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
| 209 | + ['false', '', '/index.php/apps/files/files/123456?openfile=false'], |
|
| 210 | + [null, 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
| 211 | + ['true', 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
| 212 | + ['false', 'true', '/index.php/apps/files/files/123456?openfile=false&opendetails=true'], |
|
| 213 | + ['false', 'false', '/index.php/apps/files/files/123456?openfile=false&opendetails=false'], |
|
| 214 | + ]; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestShortRedirect')] |
|
| 218 | + public function testShortRedirect(?string $openfile, ?string $opendetails, string $result): void { |
|
| 219 | + $this->appManager->expects($this->any()) |
|
| 220 | + ->method('isEnabledForUser') |
|
| 221 | + ->with('files') |
|
| 222 | + ->willReturn(true); |
|
| 223 | + |
|
| 224 | + $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 225 | + $this->rootFolder->expects($this->any()) |
|
| 226 | + ->method('getUserFolder') |
|
| 227 | + ->with('testuser1') |
|
| 228 | + ->willReturn($baseFolderFiles); |
|
| 229 | + |
|
| 230 | + $parentNode = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 231 | + $parentNode->expects($this->once()) |
|
| 232 | + ->method('getPath') |
|
| 233 | + ->willReturn('testuser1/files/Folder'); |
|
| 234 | + |
|
| 235 | + $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 236 | + $node->expects($this->once()) |
|
| 237 | + ->method('getParent') |
|
| 238 | + ->willReturn($parentNode); |
|
| 239 | + |
|
| 240 | + $baseFolderFiles->expects($this->any()) |
|
| 241 | + ->method('getFirstNodeById') |
|
| 242 | + ->with(123456) |
|
| 243 | + ->willReturn($node); |
|
| 244 | + |
|
| 245 | + $response = $this->viewController->showFile('123456', $opendetails, $openfile); |
|
| 246 | + $this->assertStringContainsString($result, $response->getHeaders()['Location']); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + public function testShowFileRouteWithTrashedFile(): void { |
|
| 250 | + $this->appManager->expects($this->exactly(2)) |
|
| 251 | + ->method('isEnabledForUser') |
|
| 252 | + ->willReturn(true); |
|
| 253 | + |
|
| 254 | + $parentNode = $this->createMock(Folder::class); |
|
| 255 | + $parentNode->expects($this->once()) |
|
| 256 | + ->method('getPath') |
|
| 257 | + ->willReturn('testuser1/files_trashbin/files/test.d1462861890/sub'); |
|
| 258 | + |
|
| 259 | + $baseFolderFiles = $this->createMock(Folder::class); |
|
| 260 | + $baseFolderTrash = $this->createMock(Folder::class); |
|
| 261 | + |
|
| 262 | + $this->rootFolder->expects($this->any()) |
|
| 263 | + ->method('getUserFolder') |
|
| 264 | + ->with('testuser1') |
|
| 265 | + ->willReturn($baseFolderFiles); |
|
| 266 | + $this->rootFolder->expects($this->once()) |
|
| 267 | + ->method('get') |
|
| 268 | + ->with('testuser1/files_trashbin/files/') |
|
| 269 | + ->willReturn($baseFolderTrash); |
|
| 270 | + |
|
| 271 | + $baseFolderFiles->expects($this->any()) |
|
| 272 | + ->method('getFirstNodeById') |
|
| 273 | + ->with(123) |
|
| 274 | + ->willReturn(null); |
|
| 275 | + |
|
| 276 | + $node = $this->createMock(File::class); |
|
| 277 | + $node->expects($this->once()) |
|
| 278 | + ->method('getParent') |
|
| 279 | + ->willReturn($parentNode); |
|
| 280 | + |
|
| 281 | + $baseFolderTrash->expects($this->once()) |
|
| 282 | + ->method('getFirstNodeById') |
|
| 283 | + ->with(123) |
|
| 284 | + ->willReturn($node); |
|
| 285 | + $baseFolderTrash->expects($this->once()) |
|
| 286 | + ->method('getRelativePath') |
|
| 287 | + ->with('testuser1/files_trashbin/files/test.d1462861890/sub') |
|
| 288 | + ->willReturn('/test.d1462861890/sub'); |
|
| 289 | + |
|
| 290 | + $expected = new RedirectResponse('/index.php/apps/files/trashbin/123?dir=/test.d1462861890/sub'); |
|
| 291 | + $this->assertEquals($expected, $this->viewController->index('', '', '123')); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + public function testTwoFactorAuthEnabled(): void { |
|
| 295 | + $this->twoFactorRegistry->method('getProviderStates') |
|
| 296 | + ->willReturn([ |
|
| 297 | + 'totp' => true, |
|
| 298 | + 'backup_codes' => true, |
|
| 299 | + ]); |
|
| 300 | + |
|
| 301 | + $invokedCountProvideInitialState = $this->exactly(9); |
|
| 302 | + $this->initialState->expects($invokedCountProvideInitialState) |
|
| 303 | + ->method('provideInitialState') |
|
| 304 | + ->willReturnCallback(function ($key, $data) use ($invokedCountProvideInitialState): void { |
|
| 305 | + if ($invokedCountProvideInitialState->numberOfInvocations() === 9) { |
|
| 306 | + $this->assertEquals('isTwoFactorEnabled', $key); |
|
| 307 | + $this->assertTrue($data); |
|
| 308 | + } |
|
| 309 | + }); |
|
| 310 | + |
|
| 311 | + $this->viewController->index('', '', null); |
|
| 312 | + } |
|
| 313 | 313 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | ->willReturnArgument(0); |
| 98 | 98 | $this->appManager->expects($this->any()) |
| 99 | 99 | ->method('getAppPath') |
| 100 | - ->willReturnCallback(fn (string $appid): string => \OC::$SERVERROOT . '/apps/' . $appid); |
|
| 100 | + ->willReturnCallback(fn (string $appid): string => \OC::$SERVERROOT.'/apps/'.$appid); |
|
| 101 | 101 | $this->appManager->expects($this->any()) |
| 102 | 102 | ->method('isAppLoaded') |
| 103 | 103 | ->willReturn(true); |
@@ -202,15 +202,15 @@ discard block |
||
| 202 | 202 | // opendetails is undefined by default |
| 203 | 203 | // both will be evaluated as truthy |
| 204 | 204 | return [ |
| 205 | - [null, null, '/index.php/apps/files/files/123456?openfile=true'], |
|
| 206 | - ['', null, '/index.php/apps/files/files/123456?openfile=true'], |
|
| 207 | - [null, '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
| 208 | - ['', '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
| 209 | - ['false', '', '/index.php/apps/files/files/123456?openfile=false'], |
|
| 210 | - [null, 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
| 211 | - ['true', 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
| 212 | - ['false', 'true', '/index.php/apps/files/files/123456?openfile=false&opendetails=true'], |
|
| 213 | - ['false', 'false', '/index.php/apps/files/files/123456?openfile=false&opendetails=false'], |
|
| 205 | + [null, null, '/index.php/apps/files/files/123456?openfile=true'], |
|
| 206 | + ['', null, '/index.php/apps/files/files/123456?openfile=true'], |
|
| 207 | + [null, '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
| 208 | + ['', '', '/index.php/apps/files/files/123456?openfile=true&opendetails=true'], |
|
| 209 | + ['false', '', '/index.php/apps/files/files/123456?openfile=false'], |
|
| 210 | + [null, 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
| 211 | + ['true', 'false', '/index.php/apps/files/files/123456?openfile=true&opendetails=false'], |
|
| 212 | + ['false', 'true', '/index.php/apps/files/files/123456?openfile=false&opendetails=true'], |
|
| 213 | + ['false', 'false', '/index.php/apps/files/files/123456?openfile=false&opendetails=false'], |
|
| 214 | 214 | ]; |
| 215 | 215 | } |
| 216 | 216 | |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | $invokedCountProvideInitialState = $this->exactly(9); |
| 302 | 302 | $this->initialState->expects($invokedCountProvideInitialState) |
| 303 | 303 | ->method('provideInitialState') |
| 304 | - ->willReturnCallback(function ($key, $data) use ($invokedCountProvideInitialState): void { |
|
| 304 | + ->willReturnCallback(function($key, $data) use ($invokedCountProvideInitialState): void { |
|
| 305 | 305 | if ($invokedCountProvideInitialState->numberOfInvocations() === 9) { |
| 306 | 306 | $this->assertEquals('isTwoFactorEnabled', $key); |
| 307 | 307 | $this->assertTrue($data); |
@@ -61,513 +61,513 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | class ShareAPIControllerTest extends TestCase { |
| 63 | 63 | |
| 64 | - private string $appName = 'files_sharing'; |
|
| 65 | - private string $currentUser; |
|
| 66 | - |
|
| 67 | - private ShareAPIController $ocs; |
|
| 68 | - |
|
| 69 | - private IManager&MockObject $shareManager; |
|
| 70 | - private IGroupManager&MockObject $groupManager; |
|
| 71 | - private IUserManager&MockObject $userManager; |
|
| 72 | - private IRequest&MockObject $request; |
|
| 73 | - private IRootFolder&MockObject $rootFolder; |
|
| 74 | - private IURLGenerator&MockObject $urlGenerator; |
|
| 75 | - private IL10N&MockObject $l; |
|
| 76 | - private IConfig&MockObject $config; |
|
| 77 | - private IAppConfig&MockObject $appConfig; |
|
| 78 | - private IAppManager&MockObject $appManager; |
|
| 79 | - private ContainerInterface&MockObject $serverContainer; |
|
| 80 | - private IUserStatusManager&MockObject $userStatusManager; |
|
| 81 | - private IPreview&MockObject $previewManager; |
|
| 82 | - private IDateTimeZone&MockObject $dateTimeZone; |
|
| 83 | - private LoggerInterface&MockObject $logger; |
|
| 84 | - private IProviderFactory&MockObject $factory; |
|
| 85 | - private IMailer&MockObject $mailer; |
|
| 86 | - private ITagManager&MockObject $tagManager; |
|
| 87 | - private TrustedServers&MockObject $trustedServers; |
|
| 88 | - |
|
| 89 | - protected function setUp(): void { |
|
| 90 | - $this->shareManager = $this->createMock(IManager::class); |
|
| 91 | - $this->shareManager |
|
| 92 | - ->expects($this->any()) |
|
| 93 | - ->method('shareApiEnabled') |
|
| 94 | - ->willReturn(true); |
|
| 95 | - $this->shareManager |
|
| 96 | - ->expects($this->any()) |
|
| 97 | - ->method('shareProviderExists')->willReturn(true); |
|
| 98 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
| 99 | - $this->userManager = $this->createMock(IUserManager::class); |
|
| 100 | - $this->request = $this->createMock(IRequest::class); |
|
| 101 | - $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 102 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
| 103 | - $this->currentUser = 'currentUser'; |
|
| 104 | - |
|
| 105 | - $this->l = $this->createMock(IL10N::class); |
|
| 106 | - $this->l->method('t') |
|
| 107 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
| 108 | - return vsprintf($text, $parameters); |
|
| 109 | - }); |
|
| 110 | - $this->config = $this->createMock(IConfig::class); |
|
| 111 | - $this->appConfig = $this->createMock(IAppConfig::class); |
|
| 112 | - $this->appManager = $this->createMock(IAppManager::class); |
|
| 113 | - $this->serverContainer = $this->createMock(ContainerInterface::class); |
|
| 114 | - $this->userStatusManager = $this->createMock(IUserStatusManager::class); |
|
| 115 | - $this->previewManager = $this->createMock(IPreview::class); |
|
| 116 | - $this->previewManager->method('isAvailable') |
|
| 117 | - ->willReturnCallback(function ($fileInfo) { |
|
| 118 | - return $fileInfo->getMimeType() === 'mimeWithPreview'; |
|
| 119 | - }); |
|
| 120 | - $this->dateTimeZone = $this->createMock(IDateTimeZone::class); |
|
| 121 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 122 | - $this->factory = $this->createMock(IProviderFactory::class); |
|
| 123 | - $this->mailer = $this->createMock(IMailer::class); |
|
| 124 | - $this->tagManager = $this->createMock(ITagManager::class); |
|
| 125 | - $this->trustedServers = $this->createMock(TrustedServers::class); |
|
| 126 | - |
|
| 127 | - $this->ocs = new ShareAPIController( |
|
| 128 | - $this->appName, |
|
| 129 | - $this->request, |
|
| 130 | - $this->shareManager, |
|
| 131 | - $this->groupManager, |
|
| 132 | - $this->userManager, |
|
| 133 | - $this->rootFolder, |
|
| 134 | - $this->urlGenerator, |
|
| 135 | - $this->l, |
|
| 136 | - $this->config, |
|
| 137 | - $this->appConfig, |
|
| 138 | - $this->appManager, |
|
| 139 | - $this->serverContainer, |
|
| 140 | - $this->userStatusManager, |
|
| 141 | - $this->previewManager, |
|
| 142 | - $this->dateTimeZone, |
|
| 143 | - $this->logger, |
|
| 144 | - $this->factory, |
|
| 145 | - $this->mailer, |
|
| 146 | - $this->tagManager, |
|
| 147 | - $this->trustedServers, |
|
| 148 | - $this->currentUser |
|
| 149 | - ); |
|
| 150 | - |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @return ShareAPIController&MockObject |
|
| 155 | - */ |
|
| 156 | - private function mockFormatShare() { |
|
| 157 | - return $this->getMockBuilder(ShareAPIController::class) |
|
| 158 | - ->setConstructorArgs([ |
|
| 159 | - $this->appName, |
|
| 160 | - $this->request, |
|
| 161 | - $this->shareManager, |
|
| 162 | - $this->groupManager, |
|
| 163 | - $this->userManager, |
|
| 164 | - $this->rootFolder, |
|
| 165 | - $this->urlGenerator, |
|
| 166 | - $this->l, |
|
| 167 | - $this->config, |
|
| 168 | - $this->appConfig, |
|
| 169 | - $this->appManager, |
|
| 170 | - $this->serverContainer, |
|
| 171 | - $this->userStatusManager, |
|
| 172 | - $this->previewManager, |
|
| 173 | - $this->dateTimeZone, |
|
| 174 | - $this->logger, |
|
| 175 | - $this->factory, |
|
| 176 | - $this->mailer, |
|
| 177 | - $this->tagManager, |
|
| 178 | - $this->trustedServers, |
|
| 179 | - $this->currentUser, |
|
| 180 | - ])->onlyMethods(['formatShare']) |
|
| 181 | - ->getMock(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - private function newShare() { |
|
| 185 | - return Server::get(IManager::class)->newShare(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - private function mockShareAttributes() { |
|
| 190 | - $formattedShareAttributes = [ |
|
| 191 | - [ |
|
| 192 | - 'scope' => 'permissions', |
|
| 193 | - 'key' => 'download', |
|
| 194 | - 'value' => true |
|
| 195 | - ] |
|
| 196 | - ]; |
|
| 197 | - |
|
| 198 | - $shareAttributes = $this->createMock(IShareAttributes::class); |
|
| 199 | - $shareAttributes->method('toArray')->willReturn($formattedShareAttributes); |
|
| 200 | - $shareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(true); |
|
| 201 | - |
|
| 202 | - // send both IShare attributes class and expected json string |
|
| 203 | - return [$shareAttributes, \json_encode($formattedShareAttributes)]; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - public function testDeleteShareShareNotFound(): void { |
|
| 207 | - $this->expectException(OCSNotFoundException::class); |
|
| 208 | - $this->expectExceptionMessage('Wrong share ID, share does not exist'); |
|
| 209 | - |
|
| 210 | - $this->shareManager |
|
| 211 | - ->expects($this->exactly(7)) |
|
| 212 | - ->method('getShareById') |
|
| 213 | - ->willReturnCallback(function ($id): void { |
|
| 214 | - if ($id === 'ocinternal:42' || $id === 'ocRoomShare:42' || $id === 'ocFederatedSharing:42' || $id === 'ocCircleShare:42' || $id === 'ocMailShare:42' || $id === 'deck:42' || $id === 'sciencemesh:42') { |
|
| 215 | - throw new ShareNotFound(); |
|
| 216 | - } else { |
|
| 217 | - throw new \Exception(); |
|
| 218 | - } |
|
| 219 | - }); |
|
| 220 | - |
|
| 221 | - $this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true); |
|
| 222 | - |
|
| 223 | - $this->ocs->deleteShare(42); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - public function testDeleteShare(): void { |
|
| 227 | - $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 228 | - |
|
| 229 | - $share = $this->newShare(); |
|
| 230 | - $share->setSharedBy($this->currentUser) |
|
| 231 | - ->setNode($node); |
|
| 232 | - $this->shareManager |
|
| 233 | - ->expects($this->once()) |
|
| 234 | - ->method('getShareById') |
|
| 235 | - ->with('ocinternal:42') |
|
| 236 | - ->willReturn($share); |
|
| 237 | - $this->shareManager |
|
| 238 | - ->expects($this->once()) |
|
| 239 | - ->method('deleteShare') |
|
| 240 | - ->with($share); |
|
| 241 | - |
|
| 242 | - $node->expects($this->once()) |
|
| 243 | - ->method('lock') |
|
| 244 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 245 | - |
|
| 246 | - $expected = new DataResponse(); |
|
| 247 | - $result = $this->ocs->deleteShare(42); |
|
| 248 | - |
|
| 249 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 250 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - public function testDeleteShareLocked(): void { |
|
| 255 | - $this->expectException(OCSNotFoundException::class); |
|
| 256 | - $this->expectExceptionMessage('Could not delete share'); |
|
| 257 | - |
|
| 258 | - $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 259 | - $node->method('getId')->willReturn(1); |
|
| 260 | - |
|
| 261 | - $share = $this->newShare(); |
|
| 262 | - $share->setNode($node); |
|
| 263 | - |
|
| 264 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 265 | - $this->rootFolder->method('getUserFolder') |
|
| 266 | - ->with($this->currentUser) |
|
| 267 | - ->willReturn($userFolder); |
|
| 268 | - |
|
| 269 | - $userFolder->method('getById') |
|
| 270 | - ->with($share->getNodeId()) |
|
| 271 | - ->willReturn([$node]); |
|
| 272 | - |
|
| 273 | - $this->shareManager |
|
| 274 | - ->expects($this->once()) |
|
| 275 | - ->method('getShareById') |
|
| 276 | - ->with('ocinternal:42') |
|
| 277 | - ->willReturn($share); |
|
| 278 | - |
|
| 279 | - $this->shareManager |
|
| 280 | - ->expects($this->never()) |
|
| 281 | - ->method('deleteShare') |
|
| 282 | - ->with($share); |
|
| 283 | - |
|
| 284 | - $node->expects($this->once()) |
|
| 285 | - ->method('lock') |
|
| 286 | - ->with(ILockingProvider::LOCK_SHARED) |
|
| 287 | - ->willThrowException(new LockedException('mypath')); |
|
| 288 | - |
|
| 289 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
| 290 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 291 | - |
|
| 292 | - $this->ocs->deleteShare(42); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * You can always remove a share that was shared with you |
|
| 297 | - */ |
|
| 298 | - public function testDeleteShareWithMe(): void { |
|
| 299 | - $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 300 | - |
|
| 301 | - $share = $this->newShare(); |
|
| 302 | - $share->setSharedWith($this->currentUser) |
|
| 303 | - ->setShareType(IShare::TYPE_USER) |
|
| 304 | - ->setNode($node); |
|
| 305 | - |
|
| 306 | - $this->shareManager |
|
| 307 | - ->expects($this->once()) |
|
| 308 | - ->method('getShareById') |
|
| 309 | - ->with('ocinternal:42') |
|
| 310 | - ->willReturn($share); |
|
| 311 | - |
|
| 312 | - $this->shareManager |
|
| 313 | - ->expects($this->once()) |
|
| 314 | - ->method('deleteShare') |
|
| 315 | - ->with($share); |
|
| 316 | - |
|
| 317 | - $node->expects($this->once()) |
|
| 318 | - ->method('lock') |
|
| 319 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 320 | - |
|
| 321 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
| 322 | - $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 323 | - |
|
| 324 | - $this->ocs->deleteShare(42); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * You can always delete a share you own |
|
| 329 | - */ |
|
| 330 | - public function testDeleteShareOwner(): void { |
|
| 331 | - $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 332 | - |
|
| 333 | - $share = $this->newShare(); |
|
| 334 | - $share->setSharedBy($this->currentUser) |
|
| 335 | - ->setNode($node); |
|
| 336 | - |
|
| 337 | - $this->shareManager |
|
| 338 | - ->expects($this->once()) |
|
| 339 | - ->method('getShareById') |
|
| 340 | - ->with('ocinternal:42') |
|
| 341 | - ->willReturn($share); |
|
| 342 | - |
|
| 343 | - $this->shareManager |
|
| 344 | - ->expects($this->once()) |
|
| 345 | - ->method('deleteShare') |
|
| 346 | - ->with($share); |
|
| 347 | - |
|
| 348 | - $node->expects($this->once()) |
|
| 349 | - ->method('lock') |
|
| 350 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 351 | - |
|
| 352 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
| 353 | - $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 354 | - |
|
| 355 | - $this->ocs->deleteShare(42); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * You can always delete a share when you own |
|
| 360 | - * the file path it belong to |
|
| 361 | - */ |
|
| 362 | - public function testDeleteShareFileOwner(): void { |
|
| 363 | - $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 364 | - $node->method('getId')->willReturn(1); |
|
| 365 | - |
|
| 366 | - $share = $this->newShare(); |
|
| 367 | - $share->setShareOwner($this->currentUser) |
|
| 368 | - ->setNode($node); |
|
| 369 | - |
|
| 370 | - $this->shareManager |
|
| 371 | - ->expects($this->once()) |
|
| 372 | - ->method('getShareById') |
|
| 373 | - ->with('ocinternal:42') |
|
| 374 | - ->willReturn($share); |
|
| 375 | - |
|
| 376 | - $this->shareManager |
|
| 377 | - ->expects($this->once()) |
|
| 378 | - ->method('deleteShare') |
|
| 379 | - ->with($share); |
|
| 380 | - |
|
| 381 | - $node->expects($this->once()) |
|
| 382 | - ->method('lock') |
|
| 383 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 384 | - |
|
| 385 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
| 386 | - $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 387 | - |
|
| 388 | - $this->ocs->deleteShare(42); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * You can remove (the mountpoint, not the share) |
|
| 393 | - * a share if you're in the group the share is shared with |
|
| 394 | - */ |
|
| 395 | - public function testDeleteSharedWithMyGroup(): void { |
|
| 396 | - $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 397 | - $node->method('getId')->willReturn(1); |
|
| 398 | - |
|
| 399 | - $share = $this->newShare(); |
|
| 400 | - $share->setShareType(IShare::TYPE_GROUP) |
|
| 401 | - ->setSharedWith('group') |
|
| 402 | - ->setNode($node); |
|
| 403 | - |
|
| 404 | - $this->shareManager |
|
| 405 | - ->expects($this->once()) |
|
| 406 | - ->method('getShareById') |
|
| 407 | - ->with('ocinternal:42') |
|
| 408 | - ->willReturn($share); |
|
| 409 | - |
|
| 410 | - // canDeleteShareFromSelf |
|
| 411 | - $user = $this->createMock(IUser::class); |
|
| 412 | - $group = $this->getMockBuilder(IGroup::class)->getMock(); |
|
| 413 | - $this->groupManager |
|
| 414 | - ->method('get') |
|
| 415 | - ->with('group') |
|
| 416 | - ->willReturn($group); |
|
| 417 | - $this->userManager |
|
| 418 | - ->method('get') |
|
| 419 | - ->with($this->currentUser) |
|
| 420 | - ->willReturn($user); |
|
| 421 | - $group->method('inGroup') |
|
| 422 | - ->with($user) |
|
| 423 | - ->willReturn(true); |
|
| 424 | - |
|
| 425 | - $node->expects($this->once()) |
|
| 426 | - ->method('lock') |
|
| 427 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 428 | - |
|
| 429 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 430 | - $this->rootFolder->method('getUserFolder') |
|
| 431 | - ->with($this->currentUser) |
|
| 432 | - ->willReturn($userFolder); |
|
| 433 | - |
|
| 434 | - $userFolder->method('getById') |
|
| 435 | - ->with($share->getNodeId()) |
|
| 436 | - ->willReturn([$share->getNode()]); |
|
| 437 | - |
|
| 438 | - $this->shareManager->expects($this->once()) |
|
| 439 | - ->method('deleteFromSelf') |
|
| 440 | - ->with($share, $this->currentUser); |
|
| 441 | - |
|
| 442 | - $this->shareManager->expects($this->never()) |
|
| 443 | - ->method('deleteShare'); |
|
| 444 | - |
|
| 445 | - $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share])); |
|
| 446 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 447 | - |
|
| 448 | - $this->ocs->deleteShare(42); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * You cannot remove a share if you're not |
|
| 453 | - * in the group the share is shared with |
|
| 454 | - */ |
|
| 455 | - public function testDeleteSharedWithGroupIDontBelongTo(): void { |
|
| 456 | - $this->expectException(OCSNotFoundException::class); |
|
| 457 | - $this->expectExceptionMessage('Wrong share ID, share does not exist'); |
|
| 458 | - |
|
| 459 | - $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 460 | - $node->method('getId')->willReturn(42); |
|
| 461 | - |
|
| 462 | - $share = $this->newShare(); |
|
| 463 | - $share->setShareType(IShare::TYPE_GROUP) |
|
| 464 | - ->setSharedWith('group') |
|
| 465 | - ->setNode($node); |
|
| 466 | - |
|
| 467 | - $this->shareManager |
|
| 468 | - ->expects($this->once()) |
|
| 469 | - ->method('getShareById') |
|
| 470 | - ->with('ocinternal:42') |
|
| 471 | - ->willReturn($share); |
|
| 472 | - |
|
| 473 | - // canDeleteShareFromSelf |
|
| 474 | - $user = $this->createMock(IUser::class); |
|
| 475 | - $group = $this->getMockBuilder(IGroup::class)->getMock(); |
|
| 476 | - $this->groupManager |
|
| 477 | - ->method('get') |
|
| 478 | - ->with('group') |
|
| 479 | - ->willReturn($group); |
|
| 480 | - $this->userManager |
|
| 481 | - ->method('get') |
|
| 482 | - ->with($this->currentUser) |
|
| 483 | - ->willReturn($user); |
|
| 484 | - $group->method('inGroup') |
|
| 485 | - ->with($user) |
|
| 486 | - ->willReturn(false); |
|
| 487 | - |
|
| 488 | - $node->expects($this->once()) |
|
| 489 | - ->method('lock') |
|
| 490 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 491 | - |
|
| 492 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 493 | - $this->rootFolder->method('getUserFolder') |
|
| 494 | - ->with($this->currentUser) |
|
| 495 | - ->willReturn($userFolder); |
|
| 496 | - |
|
| 497 | - $userFolder->method('getById') |
|
| 498 | - ->with($share->getNodeId()) |
|
| 499 | - ->willReturn([$share->getNode()]); |
|
| 500 | - |
|
| 501 | - $this->shareManager->expects($this->never()) |
|
| 502 | - ->method('deleteFromSelf'); |
|
| 503 | - |
|
| 504 | - $this->shareManager->expects($this->never()) |
|
| 505 | - ->method('deleteShare'); |
|
| 506 | - |
|
| 507 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share])); |
|
| 508 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 509 | - |
|
| 510 | - $this->ocs->deleteShare(42); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - public function testDeleteShareOwnerless(): void { |
|
| 514 | - $ocs = $this->mockFormatShare(); |
|
| 515 | - |
|
| 516 | - $mount = $this->createMock(IShareOwnerlessMount::class); |
|
| 517 | - |
|
| 518 | - $file = $this->createMock(File::class); |
|
| 519 | - $file |
|
| 520 | - ->expects($this->exactly(2)) |
|
| 521 | - ->method('getPermissions') |
|
| 522 | - ->willReturn(Constants::PERMISSION_SHARE); |
|
| 523 | - $file |
|
| 524 | - ->expects($this->once()) |
|
| 525 | - ->method('getMountPoint') |
|
| 526 | - ->willReturn($mount); |
|
| 527 | - |
|
| 528 | - $userFolder = $this->createMock(Folder::class); |
|
| 529 | - $userFolder->method('getById') |
|
| 530 | - ->with(2) |
|
| 531 | - ->willReturn([$file]); |
|
| 532 | - $userFolder->method('getFirstNodeById') |
|
| 533 | - ->with(2) |
|
| 534 | - ->willReturn($file); |
|
| 535 | - |
|
| 536 | - $this->rootFolder |
|
| 537 | - ->method('getUserFolder') |
|
| 538 | - ->with($this->currentUser) |
|
| 539 | - ->willReturn($userFolder); |
|
| 540 | - |
|
| 541 | - $share = $this->createMock(IShare::class); |
|
| 542 | - $share |
|
| 543 | - ->expects($this->once()) |
|
| 544 | - ->method('getNode') |
|
| 545 | - ->willReturn($file); |
|
| 546 | - $share |
|
| 547 | - ->expects($this->exactly(2)) |
|
| 548 | - ->method('getNodeId') |
|
| 549 | - ->willReturn(2); |
|
| 550 | - $share |
|
| 551 | - ->expects($this->exactly(2)) |
|
| 552 | - ->method('getPermissions') |
|
| 553 | - ->willReturn(Constants::PERMISSION_SHARE); |
|
| 554 | - |
|
| 555 | - $this->shareManager |
|
| 556 | - ->expects($this->once()) |
|
| 557 | - ->method('getShareById') |
|
| 558 | - ->with('ocinternal:1', $this->currentUser) |
|
| 559 | - ->willReturn($share); |
|
| 560 | - |
|
| 561 | - $this->shareManager |
|
| 562 | - ->expects($this->once()) |
|
| 563 | - ->method('deleteShare') |
|
| 564 | - ->with($share); |
|
| 565 | - |
|
| 566 | - $result = $ocs->deleteShare(1); |
|
| 567 | - $this->assertInstanceOf(DataResponse::class, $result); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - /* |
|
| 64 | + private string $appName = 'files_sharing'; |
|
| 65 | + private string $currentUser; |
|
| 66 | + |
|
| 67 | + private ShareAPIController $ocs; |
|
| 68 | + |
|
| 69 | + private IManager&MockObject $shareManager; |
|
| 70 | + private IGroupManager&MockObject $groupManager; |
|
| 71 | + private IUserManager&MockObject $userManager; |
|
| 72 | + private IRequest&MockObject $request; |
|
| 73 | + private IRootFolder&MockObject $rootFolder; |
|
| 74 | + private IURLGenerator&MockObject $urlGenerator; |
|
| 75 | + private IL10N&MockObject $l; |
|
| 76 | + private IConfig&MockObject $config; |
|
| 77 | + private IAppConfig&MockObject $appConfig; |
|
| 78 | + private IAppManager&MockObject $appManager; |
|
| 79 | + private ContainerInterface&MockObject $serverContainer; |
|
| 80 | + private IUserStatusManager&MockObject $userStatusManager; |
|
| 81 | + private IPreview&MockObject $previewManager; |
|
| 82 | + private IDateTimeZone&MockObject $dateTimeZone; |
|
| 83 | + private LoggerInterface&MockObject $logger; |
|
| 84 | + private IProviderFactory&MockObject $factory; |
|
| 85 | + private IMailer&MockObject $mailer; |
|
| 86 | + private ITagManager&MockObject $tagManager; |
|
| 87 | + private TrustedServers&MockObject $trustedServers; |
|
| 88 | + |
|
| 89 | + protected function setUp(): void { |
|
| 90 | + $this->shareManager = $this->createMock(IManager::class); |
|
| 91 | + $this->shareManager |
|
| 92 | + ->expects($this->any()) |
|
| 93 | + ->method('shareApiEnabled') |
|
| 94 | + ->willReturn(true); |
|
| 95 | + $this->shareManager |
|
| 96 | + ->expects($this->any()) |
|
| 97 | + ->method('shareProviderExists')->willReturn(true); |
|
| 98 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
| 99 | + $this->userManager = $this->createMock(IUserManager::class); |
|
| 100 | + $this->request = $this->createMock(IRequest::class); |
|
| 101 | + $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 102 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
| 103 | + $this->currentUser = 'currentUser'; |
|
| 104 | + |
|
| 105 | + $this->l = $this->createMock(IL10N::class); |
|
| 106 | + $this->l->method('t') |
|
| 107 | + ->willReturnCallback(function ($text, $parameters = []) { |
|
| 108 | + return vsprintf($text, $parameters); |
|
| 109 | + }); |
|
| 110 | + $this->config = $this->createMock(IConfig::class); |
|
| 111 | + $this->appConfig = $this->createMock(IAppConfig::class); |
|
| 112 | + $this->appManager = $this->createMock(IAppManager::class); |
|
| 113 | + $this->serverContainer = $this->createMock(ContainerInterface::class); |
|
| 114 | + $this->userStatusManager = $this->createMock(IUserStatusManager::class); |
|
| 115 | + $this->previewManager = $this->createMock(IPreview::class); |
|
| 116 | + $this->previewManager->method('isAvailable') |
|
| 117 | + ->willReturnCallback(function ($fileInfo) { |
|
| 118 | + return $fileInfo->getMimeType() === 'mimeWithPreview'; |
|
| 119 | + }); |
|
| 120 | + $this->dateTimeZone = $this->createMock(IDateTimeZone::class); |
|
| 121 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 122 | + $this->factory = $this->createMock(IProviderFactory::class); |
|
| 123 | + $this->mailer = $this->createMock(IMailer::class); |
|
| 124 | + $this->tagManager = $this->createMock(ITagManager::class); |
|
| 125 | + $this->trustedServers = $this->createMock(TrustedServers::class); |
|
| 126 | + |
|
| 127 | + $this->ocs = new ShareAPIController( |
|
| 128 | + $this->appName, |
|
| 129 | + $this->request, |
|
| 130 | + $this->shareManager, |
|
| 131 | + $this->groupManager, |
|
| 132 | + $this->userManager, |
|
| 133 | + $this->rootFolder, |
|
| 134 | + $this->urlGenerator, |
|
| 135 | + $this->l, |
|
| 136 | + $this->config, |
|
| 137 | + $this->appConfig, |
|
| 138 | + $this->appManager, |
|
| 139 | + $this->serverContainer, |
|
| 140 | + $this->userStatusManager, |
|
| 141 | + $this->previewManager, |
|
| 142 | + $this->dateTimeZone, |
|
| 143 | + $this->logger, |
|
| 144 | + $this->factory, |
|
| 145 | + $this->mailer, |
|
| 146 | + $this->tagManager, |
|
| 147 | + $this->trustedServers, |
|
| 148 | + $this->currentUser |
|
| 149 | + ); |
|
| 150 | + |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @return ShareAPIController&MockObject |
|
| 155 | + */ |
|
| 156 | + private function mockFormatShare() { |
|
| 157 | + return $this->getMockBuilder(ShareAPIController::class) |
|
| 158 | + ->setConstructorArgs([ |
|
| 159 | + $this->appName, |
|
| 160 | + $this->request, |
|
| 161 | + $this->shareManager, |
|
| 162 | + $this->groupManager, |
|
| 163 | + $this->userManager, |
|
| 164 | + $this->rootFolder, |
|
| 165 | + $this->urlGenerator, |
|
| 166 | + $this->l, |
|
| 167 | + $this->config, |
|
| 168 | + $this->appConfig, |
|
| 169 | + $this->appManager, |
|
| 170 | + $this->serverContainer, |
|
| 171 | + $this->userStatusManager, |
|
| 172 | + $this->previewManager, |
|
| 173 | + $this->dateTimeZone, |
|
| 174 | + $this->logger, |
|
| 175 | + $this->factory, |
|
| 176 | + $this->mailer, |
|
| 177 | + $this->tagManager, |
|
| 178 | + $this->trustedServers, |
|
| 179 | + $this->currentUser, |
|
| 180 | + ])->onlyMethods(['formatShare']) |
|
| 181 | + ->getMock(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + private function newShare() { |
|
| 185 | + return Server::get(IManager::class)->newShare(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + private function mockShareAttributes() { |
|
| 190 | + $formattedShareAttributes = [ |
|
| 191 | + [ |
|
| 192 | + 'scope' => 'permissions', |
|
| 193 | + 'key' => 'download', |
|
| 194 | + 'value' => true |
|
| 195 | + ] |
|
| 196 | + ]; |
|
| 197 | + |
|
| 198 | + $shareAttributes = $this->createMock(IShareAttributes::class); |
|
| 199 | + $shareAttributes->method('toArray')->willReturn($formattedShareAttributes); |
|
| 200 | + $shareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(true); |
|
| 201 | + |
|
| 202 | + // send both IShare attributes class and expected json string |
|
| 203 | + return [$shareAttributes, \json_encode($formattedShareAttributes)]; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + public function testDeleteShareShareNotFound(): void { |
|
| 207 | + $this->expectException(OCSNotFoundException::class); |
|
| 208 | + $this->expectExceptionMessage('Wrong share ID, share does not exist'); |
|
| 209 | + |
|
| 210 | + $this->shareManager |
|
| 211 | + ->expects($this->exactly(7)) |
|
| 212 | + ->method('getShareById') |
|
| 213 | + ->willReturnCallback(function ($id): void { |
|
| 214 | + if ($id === 'ocinternal:42' || $id === 'ocRoomShare:42' || $id === 'ocFederatedSharing:42' || $id === 'ocCircleShare:42' || $id === 'ocMailShare:42' || $id === 'deck:42' || $id === 'sciencemesh:42') { |
|
| 215 | + throw new ShareNotFound(); |
|
| 216 | + } else { |
|
| 217 | + throw new \Exception(); |
|
| 218 | + } |
|
| 219 | + }); |
|
| 220 | + |
|
| 221 | + $this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true); |
|
| 222 | + |
|
| 223 | + $this->ocs->deleteShare(42); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + public function testDeleteShare(): void { |
|
| 227 | + $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 228 | + |
|
| 229 | + $share = $this->newShare(); |
|
| 230 | + $share->setSharedBy($this->currentUser) |
|
| 231 | + ->setNode($node); |
|
| 232 | + $this->shareManager |
|
| 233 | + ->expects($this->once()) |
|
| 234 | + ->method('getShareById') |
|
| 235 | + ->with('ocinternal:42') |
|
| 236 | + ->willReturn($share); |
|
| 237 | + $this->shareManager |
|
| 238 | + ->expects($this->once()) |
|
| 239 | + ->method('deleteShare') |
|
| 240 | + ->with($share); |
|
| 241 | + |
|
| 242 | + $node->expects($this->once()) |
|
| 243 | + ->method('lock') |
|
| 244 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 245 | + |
|
| 246 | + $expected = new DataResponse(); |
|
| 247 | + $result = $this->ocs->deleteShare(42); |
|
| 248 | + |
|
| 249 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 250 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + public function testDeleteShareLocked(): void { |
|
| 255 | + $this->expectException(OCSNotFoundException::class); |
|
| 256 | + $this->expectExceptionMessage('Could not delete share'); |
|
| 257 | + |
|
| 258 | + $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 259 | + $node->method('getId')->willReturn(1); |
|
| 260 | + |
|
| 261 | + $share = $this->newShare(); |
|
| 262 | + $share->setNode($node); |
|
| 263 | + |
|
| 264 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 265 | + $this->rootFolder->method('getUserFolder') |
|
| 266 | + ->with($this->currentUser) |
|
| 267 | + ->willReturn($userFolder); |
|
| 268 | + |
|
| 269 | + $userFolder->method('getById') |
|
| 270 | + ->with($share->getNodeId()) |
|
| 271 | + ->willReturn([$node]); |
|
| 272 | + |
|
| 273 | + $this->shareManager |
|
| 274 | + ->expects($this->once()) |
|
| 275 | + ->method('getShareById') |
|
| 276 | + ->with('ocinternal:42') |
|
| 277 | + ->willReturn($share); |
|
| 278 | + |
|
| 279 | + $this->shareManager |
|
| 280 | + ->expects($this->never()) |
|
| 281 | + ->method('deleteShare') |
|
| 282 | + ->with($share); |
|
| 283 | + |
|
| 284 | + $node->expects($this->once()) |
|
| 285 | + ->method('lock') |
|
| 286 | + ->with(ILockingProvider::LOCK_SHARED) |
|
| 287 | + ->willThrowException(new LockedException('mypath')); |
|
| 288 | + |
|
| 289 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
| 290 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 291 | + |
|
| 292 | + $this->ocs->deleteShare(42); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * You can always remove a share that was shared with you |
|
| 297 | + */ |
|
| 298 | + public function testDeleteShareWithMe(): void { |
|
| 299 | + $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 300 | + |
|
| 301 | + $share = $this->newShare(); |
|
| 302 | + $share->setSharedWith($this->currentUser) |
|
| 303 | + ->setShareType(IShare::TYPE_USER) |
|
| 304 | + ->setNode($node); |
|
| 305 | + |
|
| 306 | + $this->shareManager |
|
| 307 | + ->expects($this->once()) |
|
| 308 | + ->method('getShareById') |
|
| 309 | + ->with('ocinternal:42') |
|
| 310 | + ->willReturn($share); |
|
| 311 | + |
|
| 312 | + $this->shareManager |
|
| 313 | + ->expects($this->once()) |
|
| 314 | + ->method('deleteShare') |
|
| 315 | + ->with($share); |
|
| 316 | + |
|
| 317 | + $node->expects($this->once()) |
|
| 318 | + ->method('lock') |
|
| 319 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 320 | + |
|
| 321 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
| 322 | + $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 323 | + |
|
| 324 | + $this->ocs->deleteShare(42); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * You can always delete a share you own |
|
| 329 | + */ |
|
| 330 | + public function testDeleteShareOwner(): void { |
|
| 331 | + $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 332 | + |
|
| 333 | + $share = $this->newShare(); |
|
| 334 | + $share->setSharedBy($this->currentUser) |
|
| 335 | + ->setNode($node); |
|
| 336 | + |
|
| 337 | + $this->shareManager |
|
| 338 | + ->expects($this->once()) |
|
| 339 | + ->method('getShareById') |
|
| 340 | + ->with('ocinternal:42') |
|
| 341 | + ->willReturn($share); |
|
| 342 | + |
|
| 343 | + $this->shareManager |
|
| 344 | + ->expects($this->once()) |
|
| 345 | + ->method('deleteShare') |
|
| 346 | + ->with($share); |
|
| 347 | + |
|
| 348 | + $node->expects($this->once()) |
|
| 349 | + ->method('lock') |
|
| 350 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 351 | + |
|
| 352 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
| 353 | + $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 354 | + |
|
| 355 | + $this->ocs->deleteShare(42); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * You can always delete a share when you own |
|
| 360 | + * the file path it belong to |
|
| 361 | + */ |
|
| 362 | + public function testDeleteShareFileOwner(): void { |
|
| 363 | + $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 364 | + $node->method('getId')->willReturn(1); |
|
| 365 | + |
|
| 366 | + $share = $this->newShare(); |
|
| 367 | + $share->setShareOwner($this->currentUser) |
|
| 368 | + ->setNode($node); |
|
| 369 | + |
|
| 370 | + $this->shareManager |
|
| 371 | + ->expects($this->once()) |
|
| 372 | + ->method('getShareById') |
|
| 373 | + ->with('ocinternal:42') |
|
| 374 | + ->willReturn($share); |
|
| 375 | + |
|
| 376 | + $this->shareManager |
|
| 377 | + ->expects($this->once()) |
|
| 378 | + ->method('deleteShare') |
|
| 379 | + ->with($share); |
|
| 380 | + |
|
| 381 | + $node->expects($this->once()) |
|
| 382 | + ->method('lock') |
|
| 383 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 384 | + |
|
| 385 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share])); |
|
| 386 | + $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 387 | + |
|
| 388 | + $this->ocs->deleteShare(42); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * You can remove (the mountpoint, not the share) |
|
| 393 | + * a share if you're in the group the share is shared with |
|
| 394 | + */ |
|
| 395 | + public function testDeleteSharedWithMyGroup(): void { |
|
| 396 | + $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 397 | + $node->method('getId')->willReturn(1); |
|
| 398 | + |
|
| 399 | + $share = $this->newShare(); |
|
| 400 | + $share->setShareType(IShare::TYPE_GROUP) |
|
| 401 | + ->setSharedWith('group') |
|
| 402 | + ->setNode($node); |
|
| 403 | + |
|
| 404 | + $this->shareManager |
|
| 405 | + ->expects($this->once()) |
|
| 406 | + ->method('getShareById') |
|
| 407 | + ->with('ocinternal:42') |
|
| 408 | + ->willReturn($share); |
|
| 409 | + |
|
| 410 | + // canDeleteShareFromSelf |
|
| 411 | + $user = $this->createMock(IUser::class); |
|
| 412 | + $group = $this->getMockBuilder(IGroup::class)->getMock(); |
|
| 413 | + $this->groupManager |
|
| 414 | + ->method('get') |
|
| 415 | + ->with('group') |
|
| 416 | + ->willReturn($group); |
|
| 417 | + $this->userManager |
|
| 418 | + ->method('get') |
|
| 419 | + ->with($this->currentUser) |
|
| 420 | + ->willReturn($user); |
|
| 421 | + $group->method('inGroup') |
|
| 422 | + ->with($user) |
|
| 423 | + ->willReturn(true); |
|
| 424 | + |
|
| 425 | + $node->expects($this->once()) |
|
| 426 | + ->method('lock') |
|
| 427 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 428 | + |
|
| 429 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 430 | + $this->rootFolder->method('getUserFolder') |
|
| 431 | + ->with($this->currentUser) |
|
| 432 | + ->willReturn($userFolder); |
|
| 433 | + |
|
| 434 | + $userFolder->method('getById') |
|
| 435 | + ->with($share->getNodeId()) |
|
| 436 | + ->willReturn([$share->getNode()]); |
|
| 437 | + |
|
| 438 | + $this->shareManager->expects($this->once()) |
|
| 439 | + ->method('deleteFromSelf') |
|
| 440 | + ->with($share, $this->currentUser); |
|
| 441 | + |
|
| 442 | + $this->shareManager->expects($this->never()) |
|
| 443 | + ->method('deleteShare'); |
|
| 444 | + |
|
| 445 | + $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share])); |
|
| 446 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 447 | + |
|
| 448 | + $this->ocs->deleteShare(42); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * You cannot remove a share if you're not |
|
| 453 | + * in the group the share is shared with |
|
| 454 | + */ |
|
| 455 | + public function testDeleteSharedWithGroupIDontBelongTo(): void { |
|
| 456 | + $this->expectException(OCSNotFoundException::class); |
|
| 457 | + $this->expectExceptionMessage('Wrong share ID, share does not exist'); |
|
| 458 | + |
|
| 459 | + $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 460 | + $node->method('getId')->willReturn(42); |
|
| 461 | + |
|
| 462 | + $share = $this->newShare(); |
|
| 463 | + $share->setShareType(IShare::TYPE_GROUP) |
|
| 464 | + ->setSharedWith('group') |
|
| 465 | + ->setNode($node); |
|
| 466 | + |
|
| 467 | + $this->shareManager |
|
| 468 | + ->expects($this->once()) |
|
| 469 | + ->method('getShareById') |
|
| 470 | + ->with('ocinternal:42') |
|
| 471 | + ->willReturn($share); |
|
| 472 | + |
|
| 473 | + // canDeleteShareFromSelf |
|
| 474 | + $user = $this->createMock(IUser::class); |
|
| 475 | + $group = $this->getMockBuilder(IGroup::class)->getMock(); |
|
| 476 | + $this->groupManager |
|
| 477 | + ->method('get') |
|
| 478 | + ->with('group') |
|
| 479 | + ->willReturn($group); |
|
| 480 | + $this->userManager |
|
| 481 | + ->method('get') |
|
| 482 | + ->with($this->currentUser) |
|
| 483 | + ->willReturn($user); |
|
| 484 | + $group->method('inGroup') |
|
| 485 | + ->with($user) |
|
| 486 | + ->willReturn(false); |
|
| 487 | + |
|
| 488 | + $node->expects($this->once()) |
|
| 489 | + ->method('lock') |
|
| 490 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 491 | + |
|
| 492 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 493 | + $this->rootFolder->method('getUserFolder') |
|
| 494 | + ->with($this->currentUser) |
|
| 495 | + ->willReturn($userFolder); |
|
| 496 | + |
|
| 497 | + $userFolder->method('getById') |
|
| 498 | + ->with($share->getNodeId()) |
|
| 499 | + ->willReturn([$share->getNode()]); |
|
| 500 | + |
|
| 501 | + $this->shareManager->expects($this->never()) |
|
| 502 | + ->method('deleteFromSelf'); |
|
| 503 | + |
|
| 504 | + $this->shareManager->expects($this->never()) |
|
| 505 | + ->method('deleteShare'); |
|
| 506 | + |
|
| 507 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share])); |
|
| 508 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share])); |
|
| 509 | + |
|
| 510 | + $this->ocs->deleteShare(42); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + public function testDeleteShareOwnerless(): void { |
|
| 514 | + $ocs = $this->mockFormatShare(); |
|
| 515 | + |
|
| 516 | + $mount = $this->createMock(IShareOwnerlessMount::class); |
|
| 517 | + |
|
| 518 | + $file = $this->createMock(File::class); |
|
| 519 | + $file |
|
| 520 | + ->expects($this->exactly(2)) |
|
| 521 | + ->method('getPermissions') |
|
| 522 | + ->willReturn(Constants::PERMISSION_SHARE); |
|
| 523 | + $file |
|
| 524 | + ->expects($this->once()) |
|
| 525 | + ->method('getMountPoint') |
|
| 526 | + ->willReturn($mount); |
|
| 527 | + |
|
| 528 | + $userFolder = $this->createMock(Folder::class); |
|
| 529 | + $userFolder->method('getById') |
|
| 530 | + ->with(2) |
|
| 531 | + ->willReturn([$file]); |
|
| 532 | + $userFolder->method('getFirstNodeById') |
|
| 533 | + ->with(2) |
|
| 534 | + ->willReturn($file); |
|
| 535 | + |
|
| 536 | + $this->rootFolder |
|
| 537 | + ->method('getUserFolder') |
|
| 538 | + ->with($this->currentUser) |
|
| 539 | + ->willReturn($userFolder); |
|
| 540 | + |
|
| 541 | + $share = $this->createMock(IShare::class); |
|
| 542 | + $share |
|
| 543 | + ->expects($this->once()) |
|
| 544 | + ->method('getNode') |
|
| 545 | + ->willReturn($file); |
|
| 546 | + $share |
|
| 547 | + ->expects($this->exactly(2)) |
|
| 548 | + ->method('getNodeId') |
|
| 549 | + ->willReturn(2); |
|
| 550 | + $share |
|
| 551 | + ->expects($this->exactly(2)) |
|
| 552 | + ->method('getPermissions') |
|
| 553 | + ->willReturn(Constants::PERMISSION_SHARE); |
|
| 554 | + |
|
| 555 | + $this->shareManager |
|
| 556 | + ->expects($this->once()) |
|
| 557 | + ->method('getShareById') |
|
| 558 | + ->with('ocinternal:1', $this->currentUser) |
|
| 559 | + ->willReturn($share); |
|
| 560 | + |
|
| 561 | + $this->shareManager |
|
| 562 | + ->expects($this->once()) |
|
| 563 | + ->method('deleteShare') |
|
| 564 | + ->with($share); |
|
| 565 | + |
|
| 566 | + $result = $ocs->deleteShare(1); |
|
| 567 | + $this->assertInstanceOf(DataResponse::class, $result); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + /* |
|
| 571 | 571 | * FIXME: Enable once we have a federated Share Provider |
| 572 | 572 | |
| 573 | 573 | public function testGetGetShareNotExists() { |
@@ -582,4800 +582,4800 @@ discard block |
||
| 582 | 582 | } |
| 583 | 583 | */ |
| 584 | 584 | |
| 585 | - public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions, |
|
| 586 | - $shareTime, $expiration, $parent, $target, $mail_send, $note = '', $token = null, |
|
| 587 | - $password = null, $label = '', $attributes = null) { |
|
| 588 | - $share = $this->getMockBuilder(IShare::class)->getMock(); |
|
| 589 | - $share->method('getId')->willReturn($id); |
|
| 590 | - $share->method('getShareType')->willReturn($shareType); |
|
| 591 | - $share->method('getSharedWith')->willReturn($sharedWith); |
|
| 592 | - $share->method('getSharedBy')->willReturn($sharedBy); |
|
| 593 | - $share->method('getShareOwner')->willReturn($shareOwner); |
|
| 594 | - $share->method('getNode')->willReturn($path); |
|
| 595 | - $share->method('getPermissions')->willReturn($permissions); |
|
| 596 | - $share->method('getNote')->willReturn($note); |
|
| 597 | - $share->method('getLabel')->willReturn($label); |
|
| 598 | - $share->method('getAttributes')->willReturn($attributes); |
|
| 599 | - $time = new \DateTime(); |
|
| 600 | - $time->setTimestamp($shareTime); |
|
| 601 | - $share->method('getShareTime')->willReturn($time); |
|
| 602 | - $share->method('getExpirationDate')->willReturn($expiration); |
|
| 603 | - $share->method('getTarget')->willReturn($target); |
|
| 604 | - $share->method('getMailSend')->willReturn($mail_send); |
|
| 605 | - $share->method('getToken')->willReturn($token); |
|
| 606 | - $share->method('getPassword')->willReturn($password); |
|
| 607 | - |
|
| 608 | - if ($shareType === IShare::TYPE_USER |
|
| 609 | - || $shareType === IShare::TYPE_GROUP |
|
| 610 | - || $shareType === IShare::TYPE_LINK) { |
|
| 611 | - $share->method('getFullId')->willReturn('ocinternal:' . $id); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - return $share; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - public function dataGetShare() { |
|
| 618 | - $data = []; |
|
| 619 | - |
|
| 620 | - $cache = $this->getMockBuilder('OC\Files\Cache\Cache') |
|
| 621 | - ->disableOriginalConstructor() |
|
| 622 | - ->getMock(); |
|
| 623 | - $cache->method('getNumericStorageId')->willReturn(101); |
|
| 624 | - |
|
| 625 | - $storage = $this->getMockBuilder(IStorage::class) |
|
| 626 | - ->disableOriginalConstructor() |
|
| 627 | - ->getMock(); |
|
| 628 | - $storage->method('getId')->willReturn('STORAGE'); |
|
| 629 | - $storage->method('getCache')->willReturn($cache); |
|
| 630 | - |
|
| 631 | - $parentFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 632 | - $parentFolder->method('getId')->willReturn(3); |
|
| 633 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 634 | - $mountPoint->method('getMountType')->willReturn(''); |
|
| 635 | - |
|
| 636 | - $file = $this->getMockBuilder('OCP\Files\File')->getMock(); |
|
| 637 | - $file->method('getId')->willReturn(1); |
|
| 638 | - $file->method('getPath')->willReturn('file'); |
|
| 639 | - $file->method('getStorage')->willReturn($storage); |
|
| 640 | - $file->method('getParent')->willReturn($parentFolder); |
|
| 641 | - $file->method('getSize')->willReturn(123465); |
|
| 642 | - $file->method('getMTime')->willReturn(1234567890); |
|
| 643 | - $file->method('getMimeType')->willReturn('myMimeType'); |
|
| 644 | - $file->method('getMountPoint')->willReturn($mountPoint); |
|
| 645 | - |
|
| 646 | - $folder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 647 | - $folder->method('getId')->willReturn(2); |
|
| 648 | - $folder->method('getPath')->willReturn('folder'); |
|
| 649 | - $folder->method('getStorage')->willReturn($storage); |
|
| 650 | - $folder->method('getParent')->willReturn($parentFolder); |
|
| 651 | - $folder->method('getSize')->willReturn(123465); |
|
| 652 | - $folder->method('getMTime')->willReturn(1234567890); |
|
| 653 | - $folder->method('getMimeType')->willReturn('myFolderMimeType'); |
|
| 654 | - $folder->method('getMountPoint')->willReturn($mountPoint); |
|
| 655 | - |
|
| 656 | - [$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes(); |
|
| 657 | - |
|
| 658 | - // File shared with user |
|
| 659 | - $share = $this->createShare( |
|
| 660 | - 100, |
|
| 661 | - IShare::TYPE_USER, |
|
| 662 | - 'userId', |
|
| 663 | - 'initiatorId', |
|
| 664 | - 'ownerId', |
|
| 665 | - $file, |
|
| 666 | - 4, |
|
| 667 | - 5, |
|
| 668 | - null, |
|
| 669 | - 6, |
|
| 670 | - 'target', |
|
| 671 | - 0, |
|
| 672 | - 'personal note', |
|
| 673 | - $shareAttributes, |
|
| 674 | - ); |
|
| 675 | - $expected = [ |
|
| 676 | - 'id' => 100, |
|
| 677 | - 'share_type' => IShare::TYPE_USER, |
|
| 678 | - 'share_with' => 'userId', |
|
| 679 | - 'share_with_displayname' => 'userDisplay', |
|
| 680 | - 'share_with_displayname_unique' => '[email protected]', |
|
| 681 | - 'uid_owner' => 'initiatorId', |
|
| 682 | - 'displayname_owner' => 'initiatorDisplay', |
|
| 683 | - 'item_type' => 'file', |
|
| 684 | - 'item_source' => 1, |
|
| 685 | - 'file_source' => 1, |
|
| 686 | - 'file_target' => 'target', |
|
| 687 | - 'file_parent' => 3, |
|
| 688 | - 'token' => null, |
|
| 689 | - 'expiration' => null, |
|
| 690 | - 'permissions' => 4, |
|
| 691 | - 'attributes' => $shareAttributesReturnJson, |
|
| 692 | - 'stime' => 5, |
|
| 693 | - 'parent' => null, |
|
| 694 | - 'storage_id' => 'STORAGE', |
|
| 695 | - 'path' => 'file', |
|
| 696 | - 'storage' => 101, |
|
| 697 | - 'mail_send' => 0, |
|
| 698 | - 'uid_file_owner' => 'ownerId', |
|
| 699 | - 'note' => 'personal note', |
|
| 700 | - 'label' => '', |
|
| 701 | - 'displayname_file_owner' => 'ownerDisplay', |
|
| 702 | - 'mimetype' => 'myMimeType', |
|
| 703 | - 'has_preview' => false, |
|
| 704 | - 'hide_download' => 0, |
|
| 705 | - 'can_edit' => false, |
|
| 706 | - 'can_delete' => false, |
|
| 707 | - 'item_size' => 123465, |
|
| 708 | - 'item_mtime' => 1234567890, |
|
| 709 | - 'attributes' => null, |
|
| 710 | - 'item_permissions' => 4, |
|
| 711 | - 'is-mount-root' => false, |
|
| 712 | - 'mount-type' => '', |
|
| 713 | - ]; |
|
| 714 | - $data[] = [$share, $expected]; |
|
| 715 | - |
|
| 716 | - // Folder shared with group |
|
| 717 | - $share = $this->createShare( |
|
| 718 | - 101, |
|
| 719 | - IShare::TYPE_GROUP, |
|
| 720 | - 'groupId', |
|
| 721 | - 'initiatorId', |
|
| 722 | - 'ownerId', |
|
| 723 | - $folder, |
|
| 724 | - 4, |
|
| 725 | - 5, |
|
| 726 | - null, |
|
| 727 | - 6, |
|
| 728 | - 'target', |
|
| 729 | - 0, |
|
| 730 | - 'personal note', |
|
| 731 | - $shareAttributes, |
|
| 732 | - ); |
|
| 733 | - $expected = [ |
|
| 734 | - 'id' => 101, |
|
| 735 | - 'share_type' => IShare::TYPE_GROUP, |
|
| 736 | - 'share_with' => 'groupId', |
|
| 737 | - 'share_with_displayname' => 'groupId', |
|
| 738 | - 'uid_owner' => 'initiatorId', |
|
| 739 | - 'displayname_owner' => 'initiatorDisplay', |
|
| 740 | - 'item_type' => 'folder', |
|
| 741 | - 'item_source' => 2, |
|
| 742 | - 'file_source' => 2, |
|
| 743 | - 'file_target' => 'target', |
|
| 744 | - 'file_parent' => 3, |
|
| 745 | - 'token' => null, |
|
| 746 | - 'expiration' => null, |
|
| 747 | - 'permissions' => 4, |
|
| 748 | - 'attributes' => $shareAttributesReturnJson, |
|
| 749 | - 'stime' => 5, |
|
| 750 | - 'parent' => null, |
|
| 751 | - 'storage_id' => 'STORAGE', |
|
| 752 | - 'path' => 'folder', |
|
| 753 | - 'storage' => 101, |
|
| 754 | - 'mail_send' => 0, |
|
| 755 | - 'uid_file_owner' => 'ownerId', |
|
| 756 | - 'note' => 'personal note', |
|
| 757 | - 'label' => '', |
|
| 758 | - 'displayname_file_owner' => 'ownerDisplay', |
|
| 759 | - 'mimetype' => 'myFolderMimeType', |
|
| 760 | - 'has_preview' => false, |
|
| 761 | - 'hide_download' => 0, |
|
| 762 | - 'can_edit' => false, |
|
| 763 | - 'can_delete' => false, |
|
| 764 | - 'item_size' => 123465, |
|
| 765 | - 'item_mtime' => 1234567890, |
|
| 766 | - 'attributes' => null, |
|
| 767 | - 'item_permissions' => 4, |
|
| 768 | - 'is-mount-root' => false, |
|
| 769 | - 'mount-type' => '', |
|
| 770 | - ]; |
|
| 771 | - $data[] = [$share, $expected]; |
|
| 772 | - |
|
| 773 | - // File shared by link with Expire |
|
| 774 | - $expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03'); |
|
| 775 | - $share = $this->createShare( |
|
| 776 | - 101, |
|
| 777 | - IShare::TYPE_LINK, |
|
| 778 | - null, |
|
| 779 | - 'initiatorId', |
|
| 780 | - 'ownerId', |
|
| 781 | - $folder, |
|
| 782 | - 4, |
|
| 783 | - 5, |
|
| 784 | - $expire, |
|
| 785 | - 6, |
|
| 786 | - 'target', |
|
| 787 | - 0, |
|
| 788 | - 'personal note', |
|
| 789 | - 'token', |
|
| 790 | - 'password', |
|
| 791 | - 'first link share' |
|
| 792 | - ); |
|
| 793 | - $expected = [ |
|
| 794 | - 'id' => 101, |
|
| 795 | - 'share_type' => IShare::TYPE_LINK, |
|
| 796 | - 'password' => 'password', |
|
| 797 | - 'share_with' => 'password', |
|
| 798 | - 'share_with_displayname' => '(Shared link)', |
|
| 799 | - 'send_password_by_talk' => false, |
|
| 800 | - 'uid_owner' => 'initiatorId', |
|
| 801 | - 'displayname_owner' => 'initiatorDisplay', |
|
| 802 | - 'item_type' => 'folder', |
|
| 803 | - 'item_source' => 2, |
|
| 804 | - 'file_source' => 2, |
|
| 805 | - 'file_target' => 'target', |
|
| 806 | - 'file_parent' => 3, |
|
| 807 | - 'token' => 'token', |
|
| 808 | - 'expiration' => '2000-01-02 00:00:00', |
|
| 809 | - 'permissions' => 4, |
|
| 810 | - 'attributes' => null, |
|
| 811 | - 'stime' => 5, |
|
| 812 | - 'parent' => null, |
|
| 813 | - 'storage_id' => 'STORAGE', |
|
| 814 | - 'path' => 'folder', |
|
| 815 | - 'storage' => 101, |
|
| 816 | - 'mail_send' => 0, |
|
| 817 | - 'url' => 'url', |
|
| 818 | - 'uid_file_owner' => 'ownerId', |
|
| 819 | - 'note' => 'personal note', |
|
| 820 | - 'label' => 'first link share', |
|
| 821 | - 'displayname_file_owner' => 'ownerDisplay', |
|
| 822 | - 'mimetype' => 'myFolderMimeType', |
|
| 823 | - 'has_preview' => false, |
|
| 824 | - 'hide_download' => 0, |
|
| 825 | - 'can_edit' => false, |
|
| 826 | - 'can_delete' => false, |
|
| 827 | - 'item_size' => 123465, |
|
| 828 | - 'item_mtime' => 1234567890, |
|
| 829 | - 'attributes' => null, |
|
| 830 | - 'item_permissions' => 4, |
|
| 831 | - 'is-mount-root' => false, |
|
| 832 | - 'mount-type' => '', |
|
| 833 | - ]; |
|
| 834 | - $data[] = [$share, $expected]; |
|
| 835 | - |
|
| 836 | - return $data; |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetShare')] |
|
| 840 | - public function testGetShare(IShare $share, array $result): void { |
|
| 841 | - /** @var ShareAPIController&MockObject $ocs */ |
|
| 842 | - $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 843 | - ->setConstructorArgs([ |
|
| 844 | - $this->appName, |
|
| 845 | - $this->request, |
|
| 846 | - $this->shareManager, |
|
| 847 | - $this->groupManager, |
|
| 848 | - $this->userManager, |
|
| 849 | - $this->rootFolder, |
|
| 850 | - $this->urlGenerator, |
|
| 851 | - $this->l, |
|
| 852 | - $this->config, |
|
| 853 | - $this->appConfig, |
|
| 854 | - $this->appManager, |
|
| 855 | - $this->serverContainer, |
|
| 856 | - $this->userStatusManager, |
|
| 857 | - $this->previewManager, |
|
| 858 | - $this->dateTimeZone, |
|
| 859 | - $this->logger, |
|
| 860 | - $this->factory, |
|
| 861 | - $this->mailer, |
|
| 862 | - $this->tagManager, |
|
| 863 | - $this->trustedServers, |
|
| 864 | - $this->currentUser, |
|
| 865 | - ]) |
|
| 866 | - ->onlyMethods(['canAccessShare']) |
|
| 867 | - ->getMock(); |
|
| 868 | - |
|
| 869 | - $ocs->expects($this->any()) |
|
| 870 | - ->method('canAccessShare') |
|
| 871 | - ->willReturn(true); |
|
| 872 | - |
|
| 873 | - $this->shareManager |
|
| 874 | - ->expects($this->any()) |
|
| 875 | - ->method('getShareById') |
|
| 876 | - ->with($share->getFullId(), 'currentUser') |
|
| 877 | - ->willReturn($share); |
|
| 878 | - |
|
| 879 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 880 | - $userFolder |
|
| 881 | - ->method('getRelativePath') |
|
| 882 | - ->willReturnArgument(0); |
|
| 883 | - |
|
| 884 | - $userFolder->method('getById') |
|
| 885 | - ->with($share->getNodeId()) |
|
| 886 | - ->willReturn([$share->getNode()]); |
|
| 887 | - $userFolder->method('getFirstNodeById') |
|
| 888 | - ->with($share->getNodeId()) |
|
| 889 | - ->willReturn($share->getNode()); |
|
| 890 | - |
|
| 891 | - $this->rootFolder->method('getUserFolder') |
|
| 892 | - ->with($this->currentUser) |
|
| 893 | - ->willReturn($userFolder); |
|
| 894 | - |
|
| 895 | - $this->urlGenerator |
|
| 896 | - ->method('linkToRouteAbsolute') |
|
| 897 | - ->willReturn('url'); |
|
| 898 | - |
|
| 899 | - $initiator = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 900 | - $initiator->method('getUID')->willReturn('initiatorId'); |
|
| 901 | - $initiator->method('getDisplayName')->willReturn('initiatorDisplay'); |
|
| 902 | - |
|
| 903 | - $owner = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 904 | - $owner->method('getUID')->willReturn('ownerId'); |
|
| 905 | - $owner->method('getDisplayName')->willReturn('ownerDisplay'); |
|
| 906 | - |
|
| 907 | - $user = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 908 | - $user->method('getUID')->willReturn('userId'); |
|
| 909 | - $user->method('getDisplayName')->willReturn('userDisplay'); |
|
| 910 | - $user->method('getSystemEMailAddress')->willReturn('[email protected]'); |
|
| 911 | - |
|
| 912 | - $group = $this->getMockBuilder(IGroup::class)->getMock(); |
|
| 913 | - $group->method('getGID')->willReturn('groupId'); |
|
| 914 | - |
|
| 915 | - $this->userManager->method('get')->willReturnMap([ |
|
| 916 | - ['userId', $user], |
|
| 917 | - ['initiatorId', $initiator], |
|
| 918 | - ['ownerId', $owner], |
|
| 919 | - ]); |
|
| 920 | - $this->groupManager->method('get')->willReturnMap([ |
|
| 921 | - ['group', $group], |
|
| 922 | - ]); |
|
| 923 | - $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC')); |
|
| 924 | - |
|
| 925 | - $data = $ocs->getShare($share->getId())->getData()[0]; |
|
| 926 | - $this->assertEquals($result, $data); |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - public function testGetShareInvalidNode(): void { |
|
| 931 | - $this->expectException(OCSNotFoundException::class); |
|
| 932 | - $this->expectExceptionMessage('Wrong share ID, share does not exist'); |
|
| 933 | - |
|
| 934 | - $share = Server::get(IManager::class)->newShare(); |
|
| 935 | - $share->setSharedBy('initiator') |
|
| 936 | - ->setSharedWith('recipient') |
|
| 937 | - ->setShareOwner('owner'); |
|
| 938 | - |
|
| 939 | - $this->shareManager |
|
| 940 | - ->expects($this->once()) |
|
| 941 | - ->method('getShareById') |
|
| 942 | - ->with('ocinternal:42', 'currentUser') |
|
| 943 | - ->willReturn($share); |
|
| 944 | - |
|
| 945 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 946 | - $this->rootFolder->method('getUserFolder') |
|
| 947 | - ->with($this->currentUser) |
|
| 948 | - ->willReturn($userFolder); |
|
| 949 | - |
|
| 950 | - $this->ocs->getShare(42); |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - public function dataGetShares() { |
|
| 954 | - $folder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 955 | - $file1 = $this->getMockBuilder(File::class)->getMock(); |
|
| 956 | - $file1->method('getName') |
|
| 957 | - ->willReturn('file1'); |
|
| 958 | - $file2 = $this->getMockBuilder(File::class)->getMock(); |
|
| 959 | - $file2->method('getName') |
|
| 960 | - ->willReturn('file2'); |
|
| 961 | - |
|
| 962 | - $folder->method('getDirectoryListing') |
|
| 963 | - ->willReturn([$file1, $file2]); |
|
| 964 | - |
|
| 965 | - $file1UserShareOwner = Server::get(IManager::class)->newShare(); |
|
| 966 | - $file1UserShareOwner->setShareType(IShare::TYPE_USER) |
|
| 967 | - ->setSharedWith('recipient') |
|
| 968 | - ->setSharedBy('initiator') |
|
| 969 | - ->setShareOwner('currentUser') |
|
| 970 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 971 | - ->setNode($file1) |
|
| 972 | - ->setId(4); |
|
| 973 | - |
|
| 974 | - $file1UserShareOwnerExpected = [ |
|
| 975 | - 'id' => 4, |
|
| 976 | - 'share_type' => IShare::TYPE_USER, |
|
| 977 | - ]; |
|
| 978 | - |
|
| 979 | - $file1UserShareInitiator = Server::get(IManager::class)->newShare(); |
|
| 980 | - $file1UserShareInitiator->setShareType(IShare::TYPE_USER) |
|
| 981 | - ->setSharedWith('recipient') |
|
| 982 | - ->setSharedBy('currentUser') |
|
| 983 | - ->setShareOwner('owner') |
|
| 984 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 985 | - ->setNode($file1) |
|
| 986 | - ->setId(8); |
|
| 987 | - |
|
| 988 | - $file1UserShareInitiatorExpected = [ |
|
| 989 | - 'id' => 8, |
|
| 990 | - 'share_type' => IShare::TYPE_USER, |
|
| 991 | - ]; |
|
| 992 | - |
|
| 993 | - $file1UserShareRecipient = Server::get(IManager::class)->newShare(); |
|
| 994 | - $file1UserShareRecipient->setShareType(IShare::TYPE_USER) |
|
| 995 | - ->setSharedWith('currentUser') |
|
| 996 | - ->setSharedBy('initiator') |
|
| 997 | - ->setShareOwner('owner') |
|
| 998 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 999 | - ->setNode($file1) |
|
| 1000 | - ->setId(15); |
|
| 1001 | - |
|
| 1002 | - $file1UserShareRecipientExpected = [ |
|
| 1003 | - 'id' => 15, |
|
| 1004 | - 'share_type' => IShare::TYPE_USER, |
|
| 1005 | - ]; |
|
| 1006 | - |
|
| 1007 | - $file1UserShareOther = Server::get(IManager::class)->newShare(); |
|
| 1008 | - $file1UserShareOther->setShareType(IShare::TYPE_USER) |
|
| 1009 | - ->setSharedWith('recipient') |
|
| 1010 | - ->setSharedBy('initiator') |
|
| 1011 | - ->setShareOwner('owner') |
|
| 1012 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1013 | - ->setNode($file1) |
|
| 1014 | - ->setId(16); |
|
| 1015 | - |
|
| 1016 | - $file1UserShareOtherExpected = [ |
|
| 1017 | - 'id' => 16, |
|
| 1018 | - 'share_type' => IShare::TYPE_USER, |
|
| 1019 | - ]; |
|
| 1020 | - |
|
| 1021 | - $file1GroupShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1022 | - $file1GroupShareOwner->setShareType(IShare::TYPE_GROUP) |
|
| 1023 | - ->setSharedWith('recipient') |
|
| 1024 | - ->setSharedBy('initiator') |
|
| 1025 | - ->setShareOwner('currentUser') |
|
| 1026 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1027 | - ->setNode($file1) |
|
| 1028 | - ->setId(23); |
|
| 1029 | - |
|
| 1030 | - $file1GroupShareOwnerExpected = [ |
|
| 1031 | - 'id' => 23, |
|
| 1032 | - 'share_type' => IShare::TYPE_GROUP, |
|
| 1033 | - ]; |
|
| 1034 | - |
|
| 1035 | - $file1GroupShareRecipient = Server::get(IManager::class)->newShare(); |
|
| 1036 | - $file1GroupShareRecipient->setShareType(IShare::TYPE_GROUP) |
|
| 1037 | - ->setSharedWith('currentUserGroup') |
|
| 1038 | - ->setSharedBy('initiator') |
|
| 1039 | - ->setShareOwner('owner') |
|
| 1040 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1041 | - ->setNode($file1) |
|
| 1042 | - ->setId(42); |
|
| 1043 | - |
|
| 1044 | - $file1GroupShareRecipientExpected = [ |
|
| 1045 | - 'id' => 42, |
|
| 1046 | - 'share_type' => IShare::TYPE_GROUP, |
|
| 1047 | - ]; |
|
| 1048 | - |
|
| 1049 | - $file1GroupShareOther = Server::get(IManager::class)->newShare(); |
|
| 1050 | - $file1GroupShareOther->setShareType(IShare::TYPE_GROUP) |
|
| 1051 | - ->setSharedWith('recipient') |
|
| 1052 | - ->setSharedBy('initiator') |
|
| 1053 | - ->setShareOwner('owner') |
|
| 1054 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1055 | - ->setNode($file1) |
|
| 1056 | - ->setId(108); |
|
| 1057 | - |
|
| 1058 | - $file1LinkShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1059 | - $file1LinkShareOwner->setShareType(IShare::TYPE_LINK) |
|
| 1060 | - ->setSharedWith('recipient') |
|
| 1061 | - ->setSharedBy('initiator') |
|
| 1062 | - ->setShareOwner('currentUser') |
|
| 1063 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1064 | - ->setNode($file1) |
|
| 1065 | - ->setId(415); |
|
| 1066 | - |
|
| 1067 | - $file1LinkShareOwnerExpected = [ |
|
| 1068 | - 'id' => 415, |
|
| 1069 | - 'share_type' => IShare::TYPE_LINK, |
|
| 1070 | - ]; |
|
| 1071 | - |
|
| 1072 | - $file1EmailShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1073 | - $file1EmailShareOwner->setShareType(IShare::TYPE_EMAIL) |
|
| 1074 | - ->setSharedWith('recipient') |
|
| 1075 | - ->setSharedBy('initiator') |
|
| 1076 | - ->setShareOwner('currentUser') |
|
| 1077 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1078 | - ->setNode($file1) |
|
| 1079 | - ->setId(416); |
|
| 1080 | - |
|
| 1081 | - $file1EmailShareOwnerExpected = [ |
|
| 1082 | - 'id' => 416, |
|
| 1083 | - 'share_type' => IShare::TYPE_EMAIL, |
|
| 1084 | - ]; |
|
| 1085 | - |
|
| 1086 | - $file1CircleShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1087 | - $file1CircleShareOwner->setShareType(IShare::TYPE_CIRCLE) |
|
| 1088 | - ->setSharedWith('recipient') |
|
| 1089 | - ->setSharedBy('initiator') |
|
| 1090 | - ->setShareOwner('currentUser') |
|
| 1091 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1092 | - ->setNode($file1) |
|
| 1093 | - ->setId(423); |
|
| 1094 | - |
|
| 1095 | - $file1CircleShareOwnerExpected = [ |
|
| 1096 | - 'id' => 423, |
|
| 1097 | - 'share_type' => IShare::TYPE_CIRCLE, |
|
| 1098 | - ]; |
|
| 1099 | - |
|
| 1100 | - $file1RoomShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1101 | - $file1RoomShareOwner->setShareType(IShare::TYPE_ROOM) |
|
| 1102 | - ->setSharedWith('recipient') |
|
| 1103 | - ->setSharedBy('initiator') |
|
| 1104 | - ->setShareOwner('currentUser') |
|
| 1105 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1106 | - ->setNode($file1) |
|
| 1107 | - ->setId(442); |
|
| 1108 | - |
|
| 1109 | - $file1RoomShareOwnerExpected = [ |
|
| 1110 | - 'id' => 442, |
|
| 1111 | - 'share_type' => IShare::TYPE_ROOM, |
|
| 1112 | - ]; |
|
| 1113 | - |
|
| 1114 | - $file1RemoteShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1115 | - $file1RemoteShareOwner->setShareType(IShare::TYPE_REMOTE) |
|
| 1116 | - ->setSharedWith('recipient') |
|
| 1117 | - ->setSharedBy('initiator') |
|
| 1118 | - ->setShareOwner('currentUser') |
|
| 1119 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1120 | - ->setExpirationDate(new \DateTime('2000-01-01T01:02:03')) |
|
| 1121 | - ->setNode($file1) |
|
| 1122 | - ->setId(815); |
|
| 1123 | - |
|
| 1124 | - $file1RemoteShareOwnerExpected = [ |
|
| 1125 | - 'id' => 815, |
|
| 1126 | - 'share_type' => IShare::TYPE_REMOTE, |
|
| 1127 | - ]; |
|
| 1128 | - |
|
| 1129 | - $file1RemoteGroupShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1130 | - $file1RemoteGroupShareOwner->setShareType(IShare::TYPE_REMOTE_GROUP) |
|
| 1131 | - ->setSharedWith('recipient') |
|
| 1132 | - ->setSharedBy('initiator') |
|
| 1133 | - ->setShareOwner('currentUser') |
|
| 1134 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1135 | - ->setExpirationDate(new \DateTime('2000-01-02T01:02:03')) |
|
| 1136 | - ->setNode($file1) |
|
| 1137 | - ->setId(816); |
|
| 1138 | - |
|
| 1139 | - $file1RemoteGroupShareOwnerExpected = [ |
|
| 1140 | - 'id' => 816, |
|
| 1141 | - 'share_type' => IShare::TYPE_REMOTE_GROUP, |
|
| 1142 | - ]; |
|
| 1143 | - |
|
| 1144 | - $file2UserShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1145 | - $file2UserShareOwner->setShareType(IShare::TYPE_USER) |
|
| 1146 | - ->setSharedWith('recipient') |
|
| 1147 | - ->setSharedBy('initiator') |
|
| 1148 | - ->setShareOwner('currentUser') |
|
| 1149 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 1150 | - ->setNode($file2) |
|
| 1151 | - ->setId(823); |
|
| 1152 | - |
|
| 1153 | - $file2UserShareOwnerExpected = [ |
|
| 1154 | - 'id' => 823, |
|
| 1155 | - 'share_type' => IShare::TYPE_USER, |
|
| 1156 | - ]; |
|
| 1157 | - |
|
| 1158 | - $data = [ |
|
| 1159 | - [ |
|
| 1160 | - [ |
|
| 1161 | - 'path' => $file1, |
|
| 1162 | - ], |
|
| 1163 | - [ |
|
| 1164 | - 'file1' => [ |
|
| 1165 | - IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareOwner, $file1UserShareOwner], |
|
| 1166 | - ], |
|
| 1167 | - ], |
|
| 1168 | - [ |
|
| 1169 | - ], |
|
| 1170 | - [ |
|
| 1171 | - $file1UserShareOwnerExpected |
|
| 1172 | - ] |
|
| 1173 | - ], |
|
| 1174 | - [ |
|
| 1175 | - [ |
|
| 1176 | - 'path' => $file1, |
|
| 1177 | - ], |
|
| 1178 | - [ |
|
| 1179 | - 'file1' => [ |
|
| 1180 | - IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient], |
|
| 1181 | - ], |
|
| 1182 | - ], |
|
| 1183 | - [ |
|
| 1184 | - ], |
|
| 1185 | - [ |
|
| 1186 | - $file1UserShareOwnerExpected, |
|
| 1187 | - ] |
|
| 1188 | - ], |
|
| 1189 | - [ |
|
| 1190 | - [ |
|
| 1191 | - 'path' => $file1, |
|
| 1192 | - ], |
|
| 1193 | - [ |
|
| 1194 | - 'file1' => [ |
|
| 1195 | - IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther], |
|
| 1196 | - ], |
|
| 1197 | - ], |
|
| 1198 | - [ |
|
| 1199 | - ], |
|
| 1200 | - [ |
|
| 1201 | - $file1UserShareOwnerExpected, |
|
| 1202 | - $file1UserShareInitiatorExpected, |
|
| 1203 | - $file1UserShareOtherExpected, |
|
| 1204 | - ] |
|
| 1205 | - ], |
|
| 1206 | - [ |
|
| 1207 | - [ |
|
| 1208 | - 'path' => $file1, |
|
| 1209 | - ], |
|
| 1210 | - [ |
|
| 1211 | - 'file1' => [ |
|
| 1212 | - IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther], |
|
| 1213 | - ], |
|
| 1214 | - ], |
|
| 1215 | - [ |
|
| 1216 | - ], |
|
| 1217 | - [ |
|
| 1218 | - $file1UserShareInitiatorExpected, |
|
| 1219 | - ] |
|
| 1220 | - ], |
|
| 1221 | - [ |
|
| 1222 | - [ |
|
| 1223 | - 'path' => $file1, |
|
| 1224 | - ], |
|
| 1225 | - [ |
|
| 1226 | - 'file1' => [ |
|
| 1227 | - IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1228 | - IShare::TYPE_GROUP => [$file1GroupShareRecipient], |
|
| 1229 | - ], |
|
| 1230 | - ], |
|
| 1231 | - [ |
|
| 1232 | - ], |
|
| 1233 | - [ |
|
| 1234 | - $file1UserShareOwnerExpected, |
|
| 1235 | - $file1GroupShareRecipientExpected, |
|
| 1236 | - ] |
|
| 1237 | - ], |
|
| 1238 | - [ |
|
| 1239 | - [ |
|
| 1240 | - 'path' => $file1, |
|
| 1241 | - ], |
|
| 1242 | - [ |
|
| 1243 | - 'file1' => [ |
|
| 1244 | - IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1245 | - IShare::TYPE_GROUP => [$file1GroupShareOwner], |
|
| 1246 | - IShare::TYPE_LINK => [$file1LinkShareOwner], |
|
| 1247 | - IShare::TYPE_EMAIL => [$file1EmailShareOwner], |
|
| 1248 | - IShare::TYPE_CIRCLE => [$file1CircleShareOwner], |
|
| 1249 | - IShare::TYPE_ROOM => [$file1RoomShareOwner], |
|
| 1250 | - IShare::TYPE_REMOTE => [$file1RemoteShareOwner], |
|
| 1251 | - IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner], |
|
| 1252 | - ], |
|
| 1253 | - ], |
|
| 1254 | - [ |
|
| 1255 | - ], |
|
| 1256 | - [ |
|
| 1257 | - $file1UserShareOwnerExpected, |
|
| 1258 | - $file1GroupShareOwnerExpected, |
|
| 1259 | - $file1LinkShareOwnerExpected, |
|
| 1260 | - $file1EmailShareOwnerExpected, |
|
| 1261 | - $file1CircleShareOwnerExpected, |
|
| 1262 | - $file1RoomShareOwnerExpected, |
|
| 1263 | - ] |
|
| 1264 | - ], |
|
| 1265 | - [ |
|
| 1266 | - [ |
|
| 1267 | - 'path' => $file1, |
|
| 1268 | - ], |
|
| 1269 | - [ |
|
| 1270 | - 'file1' => [ |
|
| 1271 | - IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1272 | - IShare::TYPE_GROUP => [$file1GroupShareOwner], |
|
| 1273 | - IShare::TYPE_LINK => [$file1LinkShareOwner], |
|
| 1274 | - IShare::TYPE_EMAIL => [$file1EmailShareOwner], |
|
| 1275 | - IShare::TYPE_CIRCLE => [$file1CircleShareOwner], |
|
| 1276 | - IShare::TYPE_ROOM => [$file1RoomShareOwner], |
|
| 1277 | - IShare::TYPE_REMOTE => [$file1RemoteShareOwner], |
|
| 1278 | - IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner], |
|
| 1279 | - ], |
|
| 1280 | - ], |
|
| 1281 | - [ |
|
| 1282 | - IShare::TYPE_REMOTE => true, |
|
| 1283 | - IShare::TYPE_REMOTE_GROUP => true, |
|
| 1284 | - ], |
|
| 1285 | - [ |
|
| 1286 | - $file1UserShareOwnerExpected, |
|
| 1287 | - $file1GroupShareOwnerExpected, |
|
| 1288 | - $file1LinkShareOwnerExpected, |
|
| 1289 | - $file1EmailShareOwnerExpected, |
|
| 1290 | - $file1CircleShareOwnerExpected, |
|
| 1291 | - $file1RoomShareOwnerExpected, |
|
| 1292 | - $file1RemoteShareOwnerExpected, |
|
| 1293 | - $file1RemoteGroupShareOwnerExpected, |
|
| 1294 | - ] |
|
| 1295 | - ], |
|
| 1296 | - [ |
|
| 1297 | - [ |
|
| 1298 | - 'path' => $folder, |
|
| 1299 | - 'subfiles' => 'true', |
|
| 1300 | - ], |
|
| 1301 | - [ |
|
| 1302 | - 'file1' => [ |
|
| 1303 | - IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1304 | - ], |
|
| 1305 | - 'file2' => [ |
|
| 1306 | - IShare::TYPE_USER => [$file2UserShareOwner], |
|
| 1307 | - ], |
|
| 1308 | - ], |
|
| 1309 | - [ |
|
| 1310 | - ], |
|
| 1311 | - [ |
|
| 1312 | - $file1UserShareOwnerExpected, |
|
| 1313 | - $file2UserShareOwnerExpected, |
|
| 1314 | - ] |
|
| 1315 | - ], |
|
| 1316 | - [ |
|
| 1317 | - [ |
|
| 1318 | - 'path' => $folder, |
|
| 1319 | - 'subfiles' => 'true', |
|
| 1320 | - ], |
|
| 1321 | - [ |
|
| 1322 | - 'file1' => [ |
|
| 1323 | - IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareOwner, $file1UserShareOwner], |
|
| 1324 | - ], |
|
| 1325 | - ], |
|
| 1326 | - [ |
|
| 1327 | - ], |
|
| 1328 | - [ |
|
| 1329 | - $file1UserShareOwnerExpected, |
|
| 1330 | - ] |
|
| 1331 | - ], |
|
| 1332 | - [ |
|
| 1333 | - [ |
|
| 1334 | - 'path' => $folder, |
|
| 1335 | - 'subfiles' => 'true', |
|
| 1336 | - ], |
|
| 1337 | - [ |
|
| 1338 | - 'file1' => [ |
|
| 1339 | - IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient], |
|
| 1340 | - ], |
|
| 1341 | - ], |
|
| 1342 | - [ |
|
| 1343 | - ], |
|
| 1344 | - [ |
|
| 1345 | - $file1UserShareOwnerExpected |
|
| 1346 | - ] |
|
| 1347 | - ], |
|
| 1348 | - [ |
|
| 1349 | - [ |
|
| 1350 | - 'path' => $folder, |
|
| 1351 | - 'subfiles' => 'true', |
|
| 1352 | - ], |
|
| 1353 | - [ |
|
| 1354 | - 'file1' => [ |
|
| 1355 | - IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther], |
|
| 1356 | - ], |
|
| 1357 | - 'file2' => [ |
|
| 1358 | - IShare::TYPE_USER => [$file2UserShareOwner], |
|
| 1359 | - ], |
|
| 1360 | - ], |
|
| 1361 | - [ |
|
| 1362 | - ], |
|
| 1363 | - [ |
|
| 1364 | - $file1UserShareInitiatorExpected, |
|
| 1365 | - $file1UserShareOtherExpected, |
|
| 1366 | - $file2UserShareOwnerExpected, |
|
| 1367 | - ] |
|
| 1368 | - ], |
|
| 1369 | - // This might not happen in a real environment, as the combination |
|
| 1370 | - // of shares does not seem to be possible on a folder without |
|
| 1371 | - // resharing rights; if the folder has resharing rights then the |
|
| 1372 | - // share with others would be included too in the results. |
|
| 1373 | - [ |
|
| 1374 | - [ |
|
| 1375 | - 'path' => $folder, |
|
| 1376 | - 'subfiles' => 'true', |
|
| 1377 | - ], |
|
| 1378 | - [ |
|
| 1379 | - 'file1' => [ |
|
| 1380 | - IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther], |
|
| 1381 | - ], |
|
| 1382 | - ], |
|
| 1383 | - [ |
|
| 1384 | - ], |
|
| 1385 | - [ |
|
| 1386 | - $file1UserShareInitiatorExpected, |
|
| 1387 | - ] |
|
| 1388 | - ], |
|
| 1389 | - [ |
|
| 1390 | - [ |
|
| 1391 | - 'path' => $folder, |
|
| 1392 | - 'subfiles' => 'true', |
|
| 1393 | - ], |
|
| 1394 | - [ |
|
| 1395 | - 'file1' => [ |
|
| 1396 | - IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1397 | - IShare::TYPE_GROUP => [$file1GroupShareRecipient], |
|
| 1398 | - ], |
|
| 1399 | - ], |
|
| 1400 | - [ |
|
| 1401 | - ], |
|
| 1402 | - [ |
|
| 1403 | - $file1UserShareOwnerExpected, |
|
| 1404 | - $file1GroupShareRecipientExpected, |
|
| 1405 | - ] |
|
| 1406 | - ], |
|
| 1407 | - [ |
|
| 1408 | - [ |
|
| 1409 | - 'path' => $folder, |
|
| 1410 | - 'subfiles' => 'true', |
|
| 1411 | - ], |
|
| 1412 | - [ |
|
| 1413 | - 'file1' => [ |
|
| 1414 | - IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1415 | - IShare::TYPE_GROUP => [$file1GroupShareOwner], |
|
| 1416 | - IShare::TYPE_LINK => [$file1LinkShareOwner], |
|
| 1417 | - IShare::TYPE_EMAIL => [$file1EmailShareOwner], |
|
| 1418 | - IShare::TYPE_CIRCLE => [$file1CircleShareOwner], |
|
| 1419 | - IShare::TYPE_ROOM => [$file1RoomShareOwner], |
|
| 1420 | - IShare::TYPE_REMOTE => [$file1RemoteShareOwner], |
|
| 1421 | - IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner], |
|
| 1422 | - ], |
|
| 1423 | - ], |
|
| 1424 | - [ |
|
| 1425 | - ], |
|
| 1426 | - [ |
|
| 1427 | - $file1UserShareOwnerExpected, |
|
| 1428 | - $file1GroupShareOwnerExpected, |
|
| 1429 | - $file1LinkShareOwnerExpected, |
|
| 1430 | - $file1EmailShareOwnerExpected, |
|
| 1431 | - $file1CircleShareOwnerExpected, |
|
| 1432 | - $file1RoomShareOwnerExpected, |
|
| 1433 | - ] |
|
| 1434 | - ], |
|
| 1435 | - [ |
|
| 1436 | - [ |
|
| 1437 | - 'path' => $folder, |
|
| 1438 | - 'subfiles' => 'true', |
|
| 1439 | - ], |
|
| 1440 | - [ |
|
| 1441 | - 'file1' => [ |
|
| 1442 | - IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1443 | - IShare::TYPE_GROUP => [$file1GroupShareOwner], |
|
| 1444 | - IShare::TYPE_LINK => [$file1LinkShareOwner], |
|
| 1445 | - IShare::TYPE_EMAIL => [$file1EmailShareOwner], |
|
| 1446 | - IShare::TYPE_CIRCLE => [$file1CircleShareOwner], |
|
| 1447 | - IShare::TYPE_ROOM => [$file1RoomShareOwner], |
|
| 1448 | - IShare::TYPE_REMOTE => [$file1RemoteShareOwner], |
|
| 1449 | - IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner], |
|
| 1450 | - ], |
|
| 1451 | - ], |
|
| 1452 | - [ |
|
| 1453 | - IShare::TYPE_REMOTE => true, |
|
| 1454 | - IShare::TYPE_REMOTE_GROUP => true, |
|
| 1455 | - ], |
|
| 1456 | - [ |
|
| 1457 | - $file1UserShareOwnerExpected, |
|
| 1458 | - $file1GroupShareOwnerExpected, |
|
| 1459 | - $file1LinkShareOwnerExpected, |
|
| 1460 | - $file1EmailShareOwnerExpected, |
|
| 1461 | - $file1CircleShareOwnerExpected, |
|
| 1462 | - $file1RoomShareOwnerExpected, |
|
| 1463 | - $file1RemoteShareOwnerExpected, |
|
| 1464 | - $file1RemoteGroupShareOwnerExpected, |
|
| 1465 | - ] |
|
| 1466 | - ], |
|
| 1467 | - ]; |
|
| 1468 | - |
|
| 1469 | - return $data; |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetShares')] |
|
| 1473 | - public function testGetShares(array $getSharesParameters, array $shares, array $extraShareTypes, array $expected): void { |
|
| 1474 | - /** @var ShareAPIController&MockObject $ocs */ |
|
| 1475 | - $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 1476 | - ->setConstructorArgs([ |
|
| 1477 | - $this->appName, |
|
| 1478 | - $this->request, |
|
| 1479 | - $this->shareManager, |
|
| 1480 | - $this->groupManager, |
|
| 1481 | - $this->userManager, |
|
| 1482 | - $this->rootFolder, |
|
| 1483 | - $this->urlGenerator, |
|
| 1484 | - $this->l, |
|
| 1485 | - $this->config, |
|
| 1486 | - $this->appConfig, |
|
| 1487 | - $this->appManager, |
|
| 1488 | - $this->serverContainer, |
|
| 1489 | - $this->userStatusManager, |
|
| 1490 | - $this->previewManager, |
|
| 1491 | - $this->dateTimeZone, |
|
| 1492 | - $this->logger, |
|
| 1493 | - $this->factory, |
|
| 1494 | - $this->mailer, |
|
| 1495 | - $this->tagManager, |
|
| 1496 | - $this->trustedServers, |
|
| 1497 | - $this->currentUser, |
|
| 1498 | - ]) |
|
| 1499 | - ->onlyMethods(['formatShare']) |
|
| 1500 | - ->getMock(); |
|
| 1501 | - |
|
| 1502 | - $ocs->method('formatShare') |
|
| 1503 | - ->willReturnCallback( |
|
| 1504 | - function ($share) { |
|
| 1505 | - return [ |
|
| 1506 | - 'id' => $share->getId(), |
|
| 1507 | - 'share_type' => $share->getShareType() |
|
| 1508 | - ]; |
|
| 1509 | - } |
|
| 1510 | - ); |
|
| 1511 | - |
|
| 1512 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 1513 | - $userFolder->method('get') |
|
| 1514 | - ->with('path') |
|
| 1515 | - ->willReturn($getSharesParameters['path']); |
|
| 1516 | - |
|
| 1517 | - $this->rootFolder->method('getUserFolder') |
|
| 1518 | - ->with($this->currentUser) |
|
| 1519 | - ->willReturn($userFolder); |
|
| 1520 | - |
|
| 1521 | - $this->shareManager |
|
| 1522 | - ->method('getSharesBy') |
|
| 1523 | - ->willReturnCallback( |
|
| 1524 | - function ($user, $shareType, $node) use ($shares) { |
|
| 1525 | - if (!isset($shares[$node->getName()]) || !isset($shares[$node->getName()][$shareType])) { |
|
| 1526 | - return []; |
|
| 1527 | - } |
|
| 1528 | - return $shares[$node->getName()][$shareType]; |
|
| 1529 | - } |
|
| 1530 | - ); |
|
| 1531 | - |
|
| 1532 | - $this->shareManager |
|
| 1533 | - ->method('outgoingServer2ServerSharesAllowed') |
|
| 1534 | - ->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE] ?? false); |
|
| 1535 | - |
|
| 1536 | - $this->shareManager |
|
| 1537 | - ->method('outgoingServer2ServerGroupSharesAllowed') |
|
| 1538 | - ->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE_GROUP] ?? false); |
|
| 1539 | - |
|
| 1540 | - $this->groupManager |
|
| 1541 | - ->method('isInGroup') |
|
| 1542 | - ->willReturnCallback( |
|
| 1543 | - function ($user, $group) { |
|
| 1544 | - return $group === 'currentUserGroup'; |
|
| 1545 | - } |
|
| 1546 | - ); |
|
| 1547 | - |
|
| 1548 | - $result = $ocs->getShares( |
|
| 1549 | - $getSharesParameters['sharedWithMe'] ?? 'false', |
|
| 1550 | - $getSharesParameters['reshares'] ?? 'false', |
|
| 1551 | - $getSharesParameters['subfiles'] ?? 'false', |
|
| 1552 | - 'path' |
|
| 1553 | - ); |
|
| 1554 | - |
|
| 1555 | - $this->assertEquals($expected, $result->getData()); |
|
| 1556 | - } |
|
| 1557 | - |
|
| 1558 | - public function testCanAccessShareAsOwner(): void { |
|
| 1559 | - $share = $this->createMock(IShare::class); |
|
| 1560 | - $share->method('getShareOwner')->willReturn($this->currentUser); |
|
| 1561 | - $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1562 | - } |
|
| 1563 | - |
|
| 1564 | - public function testCanAccessShareAsSharer(): void { |
|
| 1565 | - $share = $this->createMock(IShare::class); |
|
| 1566 | - $share->method('getSharedBy')->willReturn($this->currentUser); |
|
| 1567 | - $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1568 | - } |
|
| 1569 | - |
|
| 1570 | - public function testCanAccessShareAsSharee(): void { |
|
| 1571 | - $share = $this->createMock(IShare::class); |
|
| 1572 | - $share->method('getShareType')->willReturn(IShare::TYPE_USER); |
|
| 1573 | - $share->method('getSharedWith')->willReturn($this->currentUser); |
|
| 1574 | - $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1575 | - } |
|
| 1576 | - |
|
| 1577 | - public function testCannotAccessLinkShare(): void { |
|
| 1578 | - $share = $this->createMock(IShare::class); |
|
| 1579 | - $share->method('getShareType')->willReturn(IShare::TYPE_LINK); |
|
| 1580 | - $share->method('getNodeId')->willReturn(42); |
|
| 1581 | - |
|
| 1582 | - $userFolder = $this->createMock(Folder::class); |
|
| 1583 | - $this->rootFolder->method('getUserFolder') |
|
| 1584 | - ->with($this->currentUser) |
|
| 1585 | - ->willReturn($userFolder); |
|
| 1586 | - |
|
| 1587 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareWithPermissions')] |
|
| 1591 | - public function testCanAccessShareWithPermissions(int $permissions, bool $expected): void { |
|
| 1592 | - $share = $this->createMock(IShare::class); |
|
| 1593 | - $share->method('getShareType')->willReturn(IShare::TYPE_USER); |
|
| 1594 | - $share->method('getSharedWith')->willReturn($this->createMock(IUser::class)); |
|
| 1595 | - $share->method('getNodeId')->willReturn(42); |
|
| 1596 | - |
|
| 1597 | - $file = $this->createMock(File::class); |
|
| 1598 | - |
|
| 1599 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 1600 | - $userFolder->method('getFirstNodeById') |
|
| 1601 | - ->with($share->getNodeId()) |
|
| 1602 | - ->willReturn($file); |
|
| 1603 | - $userFolder->method('getById') |
|
| 1604 | - ->with($share->getNodeId()) |
|
| 1605 | - ->willReturn([$file]); |
|
| 1606 | - $this->rootFolder->method('getUserFolder') |
|
| 1607 | - ->with($this->currentUser) |
|
| 1608 | - ->willReturn($userFolder); |
|
| 1609 | - |
|
| 1610 | - $file->method('getPermissions') |
|
| 1611 | - ->willReturn($permissions); |
|
| 1612 | - |
|
| 1613 | - if ($expected) { |
|
| 1614 | - $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1615 | - } else { |
|
| 1616 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1617 | - } |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - public static function dataCanAccessShareWithPermissions(): array { |
|
| 1621 | - return [ |
|
| 1622 | - [Constants::PERMISSION_SHARE, true], |
|
| 1623 | - [Constants::PERMISSION_READ, false], |
|
| 1624 | - [Constants::PERMISSION_READ | Constants::PERMISSION_SHARE, true], |
|
| 1625 | - ]; |
|
| 1626 | - } |
|
| 1627 | - |
|
| 1628 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareAsGroupMember')] |
|
| 1629 | - public function testCanAccessShareAsGroupMember(string $group, bool $expected): void { |
|
| 1630 | - $share = $this->createMock(IShare::class); |
|
| 1631 | - $share->method('getShareType')->willReturn(IShare::TYPE_GROUP); |
|
| 1632 | - $share->method('getSharedWith')->willReturn($group); |
|
| 1633 | - $share->method('getNodeId')->willReturn(42); |
|
| 1634 | - |
|
| 1635 | - $file = $this->createMock(File::class); |
|
| 1636 | - |
|
| 1637 | - $userFolder = $this->createMock(Folder::class); |
|
| 1638 | - $userFolder->method('getFirstNodeById') |
|
| 1639 | - ->with($share->getNodeId()) |
|
| 1640 | - ->willReturn($file); |
|
| 1641 | - $userFolder->method('getById') |
|
| 1642 | - ->with($share->getNodeId()) |
|
| 1643 | - ->willReturn([$file]); |
|
| 1644 | - $this->rootFolder->method('getUserFolder') |
|
| 1645 | - ->with($this->currentUser) |
|
| 1646 | - ->willReturn($userFolder); |
|
| 1647 | - |
|
| 1648 | - $user = $this->createMock(IUser::class); |
|
| 1649 | - $this->userManager->method('get') |
|
| 1650 | - ->with($this->currentUser) |
|
| 1651 | - ->willReturn($user); |
|
| 1652 | - |
|
| 1653 | - $group = $this->createMock(IGroup::class); |
|
| 1654 | - $group->method('inGroup')->with($user)->willReturn(true); |
|
| 1655 | - $group2 = $this->createMock(IGroup::class); |
|
| 1656 | - $group2->method('inGroup')->with($user)->willReturn(false); |
|
| 1657 | - |
|
| 1658 | - $this->groupManager->method('get')->willReturnMap([ |
|
| 1659 | - ['group', $group], |
|
| 1660 | - ['group2', $group2], |
|
| 1661 | - ['group-null', null], |
|
| 1662 | - ]); |
|
| 1663 | - |
|
| 1664 | - if ($expected) { |
|
| 1665 | - $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1666 | - } else { |
|
| 1667 | - $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1668 | - } |
|
| 1669 | - } |
|
| 1670 | - |
|
| 1671 | - public static function dataCanAccessShareAsGroupMember(): array { |
|
| 1672 | - return [ |
|
| 1673 | - ['group', true], |
|
| 1674 | - ['group2', false], |
|
| 1675 | - ['group-null', false], |
|
| 1676 | - ]; |
|
| 1677 | - } |
|
| 1678 | - |
|
| 1679 | - public function dataCanAccessRoomShare() { |
|
| 1680 | - $result = []; |
|
| 1681 | - |
|
| 1682 | - $share = $this->createMock(IShare::class); |
|
| 1683 | - $share->method('getShareType')->willReturn(IShare::TYPE_ROOM); |
|
| 1684 | - $share->method('getSharedWith')->willReturn('recipientRoom'); |
|
| 1685 | - |
|
| 1686 | - $result[] = [ |
|
| 1687 | - false, $share, false, false |
|
| 1688 | - ]; |
|
| 1689 | - |
|
| 1690 | - $result[] = [ |
|
| 1691 | - false, $share, false, true |
|
| 1692 | - ]; |
|
| 1693 | - |
|
| 1694 | - $result[] = [ |
|
| 1695 | - true, $share, true, true |
|
| 1696 | - ]; |
|
| 1697 | - |
|
| 1698 | - $result[] = [ |
|
| 1699 | - false, $share, true, false |
|
| 1700 | - ]; |
|
| 1701 | - |
|
| 1702 | - return $result; |
|
| 1703 | - } |
|
| 1704 | - |
|
| 1705 | - /** |
|
| 1706 | - * |
|
| 1707 | - * @param bool $expects |
|
| 1708 | - * @param IShare $share |
|
| 1709 | - * @param bool helperAvailable |
|
| 1710 | - * @param bool canAccessShareByHelper |
|
| 1711 | - */ |
|
| 1712 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessRoomShare')] |
|
| 1713 | - public function testCanAccessRoomShare(bool $expected, IShare $share, bool $helperAvailable, bool $canAccessShareByHelper): void { |
|
| 1714 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 1715 | - $this->rootFolder->method('getUserFolder') |
|
| 1716 | - ->with($this->currentUser) |
|
| 1717 | - ->willReturn($userFolder); |
|
| 1718 | - |
|
| 1719 | - $userFolder->method('getById') |
|
| 1720 | - ->with($share->getNodeId()) |
|
| 1721 | - ->willReturn([$share->getNode()]); |
|
| 1722 | - |
|
| 1723 | - if (!$helperAvailable) { |
|
| 1724 | - $this->appManager->method('isEnabledForUser') |
|
| 1725 | - ->with('spreed') |
|
| 1726 | - ->willReturn(false); |
|
| 1727 | - } else { |
|
| 1728 | - $this->appManager->method('isEnabledForUser') |
|
| 1729 | - ->with('spreed') |
|
| 1730 | - ->willReturn(true); |
|
| 1731 | - |
|
| 1732 | - // This is not possible anymore with PHPUnit 10+ |
|
| 1733 | - // as `setMethods` was removed and now real reflection is used, thus the class needs to exist. |
|
| 1734 | - // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 1735 | - $helper = $this->getMockBuilder(\stdClass::class) |
|
| 1736 | - ->addMethods(['canAccessShare']) |
|
| 1737 | - ->getMock(); |
|
| 1738 | - $helper->method('canAccessShare') |
|
| 1739 | - ->with($share, $this->currentUser) |
|
| 1740 | - ->willReturn($canAccessShareByHelper); |
|
| 1741 | - |
|
| 1742 | - $this->serverContainer->method('get') |
|
| 1743 | - ->with('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 1744 | - ->willReturn($helper); |
|
| 1745 | - } |
|
| 1746 | - |
|
| 1747 | - $this->assertEquals($expected, $this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1748 | - } |
|
| 1749 | - |
|
| 1750 | - |
|
| 1751 | - public function testCreateShareNoPath(): void { |
|
| 1752 | - $this->expectException(OCSNotFoundException::class); |
|
| 1753 | - $this->expectExceptionMessage('Please specify a file or folder path'); |
|
| 1754 | - |
|
| 1755 | - $this->ocs->createShare(); |
|
| 1756 | - } |
|
| 1757 | - |
|
| 1758 | - |
|
| 1759 | - public function testCreateShareInvalidPath(): void { |
|
| 1760 | - $this->expectException(OCSNotFoundException::class); |
|
| 1761 | - $this->expectExceptionMessage('Wrong path, file/folder does not exist'); |
|
| 1762 | - |
|
| 1763 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 1764 | - $this->rootFolder->expects($this->once()) |
|
| 1765 | - ->method('getUserFolder') |
|
| 1766 | - ->with('currentUser') |
|
| 1767 | - ->willReturn($userFolder); |
|
| 1768 | - |
|
| 1769 | - $userFolder->expects($this->once()) |
|
| 1770 | - ->method('get') |
|
| 1771 | - ->with('invalid-path') |
|
| 1772 | - ->willThrowException(new NotFoundException()); |
|
| 1773 | - |
|
| 1774 | - $this->ocs->createShare('invalid-path'); |
|
| 1775 | - } |
|
| 1776 | - |
|
| 1777 | - public function testCreateShareInvalidShareType(): void { |
|
| 1778 | - $this->expectException(OCSBadRequestException::class); |
|
| 1779 | - $this->expectExceptionMessage('Unknown share type'); |
|
| 1780 | - |
|
| 1781 | - $share = $this->newShare(); |
|
| 1782 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 1783 | - |
|
| 1784 | - [$userFolder, $file] = $this->getNonSharedUserFile(); |
|
| 1785 | - $this->rootFolder->expects($this->atLeastOnce()) |
|
| 1786 | - ->method('getUserFolder') |
|
| 1787 | - ->with('currentUser') |
|
| 1788 | - ->willReturn($userFolder); |
|
| 1789 | - |
|
| 1790 | - $userFolder->expects($this->atLeastOnce()) |
|
| 1791 | - ->method('get') |
|
| 1792 | - ->with('valid-path') |
|
| 1793 | - ->willReturn($file); |
|
| 1794 | - $userFolder->method('getById') |
|
| 1795 | - ->willReturn([]); |
|
| 1796 | - |
|
| 1797 | - $file->expects($this->once()) |
|
| 1798 | - ->method('lock') |
|
| 1799 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 1800 | - |
|
| 1801 | - $this->ocs->createShare('valid-path', 31); |
|
| 1802 | - } |
|
| 1803 | - |
|
| 1804 | - public function testCreateShareUserNoShareWith(): void { |
|
| 1805 | - $this->expectException(OCSNotFoundException::class); |
|
| 1806 | - $this->expectExceptionMessage('Please specify a valid account to share with'); |
|
| 1807 | - |
|
| 1808 | - $share = $this->newShare(); |
|
| 1809 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 1810 | - |
|
| 1811 | - [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 1812 | - $this->rootFolder->method('getUserFolder') |
|
| 1813 | - ->with('currentUser') |
|
| 1814 | - ->willReturn($userFolder); |
|
| 1815 | - |
|
| 1816 | - $userFolder->expects($this->once()) |
|
| 1817 | - ->method('get') |
|
| 1818 | - ->with('valid-path') |
|
| 1819 | - ->willReturn($path); |
|
| 1820 | - $userFolder->method('getById') |
|
| 1821 | - ->willReturn([]); |
|
| 1822 | - |
|
| 1823 | - $path->expects($this->once()) |
|
| 1824 | - ->method('lock') |
|
| 1825 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 1826 | - |
|
| 1827 | - $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER); |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - |
|
| 1831 | - public function testCreateShareUserNoValidShareWith(): void { |
|
| 1832 | - $this->expectException(OCSNotFoundException::class); |
|
| 1833 | - $this->expectExceptionMessage('Please specify a valid account to share with'); |
|
| 1834 | - |
|
| 1835 | - $share = $this->newShare(); |
|
| 1836 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 1837 | - |
|
| 1838 | - [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 1839 | - $this->rootFolder->method('getUserFolder') |
|
| 1840 | - ->with('currentUser') |
|
| 1841 | - ->willReturn($userFolder); |
|
| 1842 | - |
|
| 1843 | - $userFolder->expects($this->once()) |
|
| 1844 | - ->method('get') |
|
| 1845 | - ->with('valid-path') |
|
| 1846 | - ->willReturn($path); |
|
| 1847 | - $userFolder->method('getById') |
|
| 1848 | - ->willReturn([]); |
|
| 1849 | - $path->expects($this->once()) |
|
| 1850 | - ->method('lock') |
|
| 1851 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 1852 | - $this->userManager->method('userExists') |
|
| 1853 | - ->with('invalidUser') |
|
| 1854 | - ->willReturn(false); |
|
| 1855 | - |
|
| 1856 | - $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'invalidUser'); |
|
| 1857 | - } |
|
| 1858 | - |
|
| 1859 | - public function testCreateShareUser(): void { |
|
| 1860 | - $share = $this->newShare(); |
|
| 1861 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 1862 | - |
|
| 1863 | - /** @var ShareAPIController $ocs */ |
|
| 1864 | - $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 1865 | - ->setConstructorArgs([ |
|
| 1866 | - $this->appName, |
|
| 1867 | - $this->request, |
|
| 1868 | - $this->shareManager, |
|
| 1869 | - $this->groupManager, |
|
| 1870 | - $this->userManager, |
|
| 1871 | - $this->rootFolder, |
|
| 1872 | - $this->urlGenerator, |
|
| 1873 | - $this->l, |
|
| 1874 | - $this->config, |
|
| 1875 | - $this->appConfig, |
|
| 1876 | - $this->appManager, |
|
| 1877 | - $this->serverContainer, |
|
| 1878 | - $this->userStatusManager, |
|
| 1879 | - $this->previewManager, |
|
| 1880 | - $this->dateTimeZone, |
|
| 1881 | - $this->logger, |
|
| 1882 | - $this->factory, |
|
| 1883 | - $this->mailer, |
|
| 1884 | - $this->tagManager, |
|
| 1885 | - $this->trustedServers, |
|
| 1886 | - $this->currentUser, |
|
| 1887 | - ])->onlyMethods(['formatShare']) |
|
| 1888 | - ->getMock(); |
|
| 1889 | - |
|
| 1890 | - [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 1891 | - $this->rootFolder->expects($this->exactly(2)) |
|
| 1892 | - ->method('getUserFolder') |
|
| 1893 | - ->with('currentUser') |
|
| 1894 | - ->willReturn($userFolder); |
|
| 1895 | - |
|
| 1896 | - $userFolder->expects($this->once()) |
|
| 1897 | - ->method('get') |
|
| 1898 | - ->with('valid-path') |
|
| 1899 | - ->willReturn($path); |
|
| 1900 | - $userFolder->method('getById') |
|
| 1901 | - ->willReturn([]); |
|
| 1902 | - |
|
| 1903 | - $this->userManager->method('userExists')->with('validUser')->willReturn(true); |
|
| 1904 | - |
|
| 1905 | - $path->expects($this->once()) |
|
| 1906 | - ->method('lock') |
|
| 1907 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 1908 | - |
|
| 1909 | - $this->shareManager->method('createShare') |
|
| 1910 | - ->with($this->callback(function (IShare $share) use ($path) { |
|
| 1911 | - return $share->getNode() === $path |
|
| 1912 | - && $share->getPermissions() === ( |
|
| 1913 | - Constants::PERMISSION_ALL |
|
| 1914 | - & ~Constants::PERMISSION_DELETE |
|
| 1915 | - & ~Constants::PERMISSION_CREATE |
|
| 1916 | - ) |
|
| 1917 | - && $share->getShareType() === IShare::TYPE_USER |
|
| 1918 | - && $share->getSharedWith() === 'validUser' |
|
| 1919 | - && $share->getSharedBy() === 'currentUser'; |
|
| 1920 | - })) |
|
| 1921 | - ->willReturnArgument(0); |
|
| 1922 | - |
|
| 1923 | - $expected = new DataResponse([]); |
|
| 1924 | - $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'validUser'); |
|
| 1925 | - |
|
| 1926 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 1927 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 1928 | - } |
|
| 1929 | - |
|
| 1930 | - |
|
| 1931 | - public function testCreateShareGroupNoValidShareWith(): void { |
|
| 1932 | - $this->expectException(OCSNotFoundException::class); |
|
| 1933 | - $this->expectExceptionMessage('Please specify a valid group'); |
|
| 1934 | - |
|
| 1935 | - $share = $this->newShare(); |
|
| 1936 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 1937 | - $this->shareManager->method('createShare')->willReturnArgument(0); |
|
| 1938 | - $this->shareManager->method('allowGroupSharing')->willReturn(true); |
|
| 1939 | - |
|
| 1940 | - [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 1941 | - $this->rootFolder->method('getUserFolder') |
|
| 1942 | - ->with('currentUser') |
|
| 1943 | - ->willReturn($userFolder); |
|
| 1944 | - |
|
| 1945 | - $userFolder->expects($this->once()) |
|
| 1946 | - ->method('get') |
|
| 1947 | - ->with('valid-path') |
|
| 1948 | - ->willReturn($path); |
|
| 1949 | - $userFolder->method('getById') |
|
| 1950 | - ->willReturn([]); |
|
| 1951 | - |
|
| 1952 | - $path->expects($this->once()) |
|
| 1953 | - ->method('lock') |
|
| 1954 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 1955 | - |
|
| 1956 | - $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'invalidGroup'); |
|
| 1957 | - } |
|
| 1958 | - |
|
| 1959 | - public function testCreateShareGroup(): void { |
|
| 1960 | - $share = $this->newShare(); |
|
| 1961 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 1962 | - |
|
| 1963 | - /** @var ShareAPIController&MockObject $ocs */ |
|
| 1964 | - $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 1965 | - ->setConstructorArgs([ |
|
| 1966 | - $this->appName, |
|
| 1967 | - $this->request, |
|
| 1968 | - $this->shareManager, |
|
| 1969 | - $this->groupManager, |
|
| 1970 | - $this->userManager, |
|
| 1971 | - $this->rootFolder, |
|
| 1972 | - $this->urlGenerator, |
|
| 1973 | - $this->l, |
|
| 1974 | - $this->config, |
|
| 1975 | - $this->appConfig, |
|
| 1976 | - $this->appManager, |
|
| 1977 | - $this->serverContainer, |
|
| 1978 | - $this->userStatusManager, |
|
| 1979 | - $this->previewManager, |
|
| 1980 | - $this->dateTimeZone, |
|
| 1981 | - $this->logger, |
|
| 1982 | - $this->factory, |
|
| 1983 | - $this->mailer, |
|
| 1984 | - $this->tagManager, |
|
| 1985 | - $this->trustedServers, |
|
| 1986 | - $this->currentUser, |
|
| 1987 | - ])->onlyMethods(['formatShare']) |
|
| 1988 | - ->getMock(); |
|
| 1989 | - |
|
| 1990 | - $this->request |
|
| 1991 | - ->method('getParam') |
|
| 1992 | - ->willReturnMap([ |
|
| 1993 | - ['path', null, 'valid-path'], |
|
| 1994 | - ['permissions', null, Constants::PERMISSION_ALL], |
|
| 1995 | - ['shareType', '-1', IShare::TYPE_GROUP], |
|
| 1996 | - ['shareWith', null, 'validGroup'], |
|
| 1997 | - ]); |
|
| 1998 | - |
|
| 1999 | - [$userFolder, $path] = $this->getNonSharedUserFolder(); |
|
| 2000 | - $this->rootFolder->expects($this->exactly(2)) |
|
| 2001 | - ->method('getUserFolder') |
|
| 2002 | - ->with('currentUser') |
|
| 2003 | - ->willReturn($userFolder); |
|
| 2004 | - |
|
| 2005 | - $userFolder->expects($this->once()) |
|
| 2006 | - ->method('get') |
|
| 2007 | - ->with('valid-path') |
|
| 2008 | - ->willReturn($path); |
|
| 2009 | - $userFolder->method('getById') |
|
| 2010 | - ->willReturn([]); |
|
| 2011 | - |
|
| 2012 | - $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true); |
|
| 2013 | - |
|
| 2014 | - $this->shareManager->expects($this->once()) |
|
| 2015 | - ->method('allowGroupSharing') |
|
| 2016 | - ->willReturn(true); |
|
| 2017 | - |
|
| 2018 | - $path->expects($this->once()) |
|
| 2019 | - ->method('lock') |
|
| 2020 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 2021 | - |
|
| 2022 | - $this->shareManager->method('createShare') |
|
| 2023 | - ->with($this->callback(function (IShare $share) use ($path) { |
|
| 2024 | - return $share->getNode() === $path |
|
| 2025 | - && $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 2026 | - && $share->getShareType() === IShare::TYPE_GROUP |
|
| 2027 | - && $share->getSharedWith() === 'validGroup' |
|
| 2028 | - && $share->getSharedBy() === 'currentUser'; |
|
| 2029 | - })) |
|
| 2030 | - ->willReturnArgument(0); |
|
| 2031 | - |
|
| 2032 | - $expected = new DataResponse([]); |
|
| 2033 | - $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'validGroup'); |
|
| 2034 | - |
|
| 2035 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 2036 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2037 | - } |
|
| 2038 | - |
|
| 2039 | - |
|
| 2040 | - public function testCreateShareGroupNotAllowed(): void { |
|
| 2041 | - $this->expectException(OCSNotFoundException::class); |
|
| 2042 | - $this->expectExceptionMessage('Group sharing is disabled by the administrator'); |
|
| 2043 | - |
|
| 2044 | - $share = $this->newShare(); |
|
| 2045 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 2046 | - |
|
| 2047 | - [$userFolder, $path] = $this->getNonSharedUserFolder(); |
|
| 2048 | - $this->rootFolder->method('getUserFolder') |
|
| 2049 | - ->with('currentUser') |
|
| 2050 | - ->willReturn($userFolder); |
|
| 2051 | - |
|
| 2052 | - $userFolder->expects($this->once()) |
|
| 2053 | - ->method('get') |
|
| 2054 | - ->with('valid-path') |
|
| 2055 | - ->willReturn($path); |
|
| 2056 | - $userFolder->method('getById') |
|
| 2057 | - ->willReturn([]); |
|
| 2058 | - |
|
| 2059 | - $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true); |
|
| 2060 | - |
|
| 2061 | - $this->shareManager->expects($this->once()) |
|
| 2062 | - ->method('allowGroupSharing') |
|
| 2063 | - ->willReturn(false); |
|
| 2064 | - |
|
| 2065 | - $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'invalidGroup'); |
|
| 2066 | - } |
|
| 2067 | - |
|
| 2068 | - |
|
| 2069 | - public function testCreateShareLinkNoLinksAllowed(): void { |
|
| 2070 | - $this->expectException(OCSNotFoundException::class); |
|
| 2071 | - $this->expectExceptionMessage('Public link sharing is disabled by the administrator'); |
|
| 2072 | - |
|
| 2073 | - $this->request |
|
| 2074 | - ->method('getParam') |
|
| 2075 | - ->willReturnMap([ |
|
| 2076 | - ['path', null, 'valid-path'], |
|
| 2077 | - ['shareType', '-1', IShare::TYPE_LINK], |
|
| 2078 | - ]); |
|
| 2079 | - |
|
| 2080 | - $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2081 | - $path->method('getId')->willReturn(42); |
|
| 2082 | - $storage = $this->createMock(IStorage::class); |
|
| 2083 | - $storage->method('instanceOfStorage') |
|
| 2084 | - ->willReturnMap([ |
|
| 2085 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 2086 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2087 | - ]); |
|
| 2088 | - $path->method('getStorage')->willReturn($storage); |
|
| 2089 | - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2090 | - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2091 | - $this->rootFolder->method('getById') |
|
| 2092 | - ->willReturn([]); |
|
| 2093 | - |
|
| 2094 | - $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2095 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2096 | - $this->shareManager->method('shareApiAllowLinks')->willReturn(false); |
|
| 2097 | - |
|
| 2098 | - $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK); |
|
| 2099 | - } |
|
| 2100 | - |
|
| 2101 | - |
|
| 2102 | - public function testCreateShareLinkNoPublicUpload(): void { |
|
| 2103 | - $this->expectException(OCSForbiddenException::class); |
|
| 2104 | - $this->expectExceptionMessage('Public upload disabled by the administrator'); |
|
| 2105 | - |
|
| 2106 | - $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2107 | - $path->method('getId')->willReturn(42); |
|
| 2108 | - $storage = $this->createMock(IStorage::class); |
|
| 2109 | - $storage->method('instanceOfStorage') |
|
| 2110 | - ->willReturnMap([ |
|
| 2111 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 2112 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2113 | - ]); |
|
| 2114 | - $path->method('getStorage')->willReturn($storage); |
|
| 2115 | - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2116 | - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2117 | - $this->rootFolder->method('getById') |
|
| 2118 | - ->willReturn([]); |
|
| 2119 | - |
|
| 2120 | - $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2121 | - $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2122 | - |
|
| 2123 | - $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true'); |
|
| 2124 | - } |
|
| 2125 | - |
|
| 2126 | - |
|
| 2127 | - public function testCreateShareLinkPublicUploadFile(): void { |
|
| 2128 | - $this->expectException(OCSBadRequestException::class); |
|
| 2129 | - $this->expectExceptionMessage('Public upload is only possible for publicly shared folders'); |
|
| 2130 | - |
|
| 2131 | - $storage = $this->createMock(IStorage::class); |
|
| 2132 | - $storage->method('instanceOfStorage') |
|
| 2133 | - ->willReturnMap([ |
|
| 2134 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 2135 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2136 | - ]); |
|
| 2137 | - |
|
| 2138 | - $file = $this->createMock(File::class); |
|
| 2139 | - $file->method('getId')->willReturn(42); |
|
| 2140 | - $file->method('getStorage')->willReturn($storage); |
|
| 2141 | - |
|
| 2142 | - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2143 | - $this->rootFolder->method('get')->with('valid-path')->willReturn($file); |
|
| 2144 | - $this->rootFolder->method('getById') |
|
| 2145 | - ->willReturn([]); |
|
| 2146 | - |
|
| 2147 | - $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2148 | - $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2149 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2150 | - |
|
| 2151 | - $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true'); |
|
| 2152 | - } |
|
| 2153 | - |
|
| 2154 | - public function testCreateShareLinkPublicUploadFolder(): void { |
|
| 2155 | - $ocs = $this->mockFormatShare(); |
|
| 2156 | - |
|
| 2157 | - $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2158 | - $path->method('getId')->willReturn(1); |
|
| 2159 | - $storage = $this->createMock(IStorage::class); |
|
| 2160 | - $storage->method('instanceOfStorage') |
|
| 2161 | - ->willReturnMap([ |
|
| 2162 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 2163 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2164 | - ]); |
|
| 2165 | - $path->method('getStorage')->willReturn($storage); |
|
| 2166 | - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2167 | - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2168 | - $this->rootFolder->method('getById') |
|
| 2169 | - ->willReturn([]); |
|
| 2170 | - |
|
| 2171 | - $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2172 | - $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2173 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2174 | - |
|
| 2175 | - $this->shareManager->expects($this->once())->method('createShare')->with( |
|
| 2176 | - $this->callback(function (IShare $share) use ($path) { |
|
| 2177 | - return $share->getNode() === $path |
|
| 2178 | - && $share->getShareType() === IShare::TYPE_LINK |
|
| 2179 | - && $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 2180 | - && $share->getSharedBy() === 'currentUser' |
|
| 2181 | - && $share->getPassword() === null |
|
| 2182 | - && $share->getExpirationDate() === null; |
|
| 2183 | - }) |
|
| 2184 | - )->willReturnArgument(0); |
|
| 2185 | - |
|
| 2186 | - $expected = new DataResponse([]); |
|
| 2187 | - $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true', '', null, ''); |
|
| 2188 | - |
|
| 2189 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 2190 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2191 | - } |
|
| 2192 | - |
|
| 2193 | - public function testCreateShareLinkPassword(): void { |
|
| 2194 | - $ocs = $this->mockFormatShare(); |
|
| 2195 | - |
|
| 2196 | - $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2197 | - $path->method('getId')->willReturn(42); |
|
| 2198 | - $storage = $this->createMock(IStorage::class); |
|
| 2199 | - $storage->method('instanceOfStorage') |
|
| 2200 | - ->willReturnMap([ |
|
| 2201 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 2202 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2203 | - ]); |
|
| 2204 | - $path->method('getStorage')->willReturn($storage); |
|
| 2205 | - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2206 | - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2207 | - $this->rootFolder->method('getById') |
|
| 2208 | - ->willReturn([]); |
|
| 2209 | - |
|
| 2210 | - $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2211 | - $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2212 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2213 | - |
|
| 2214 | - $this->shareManager->expects($this->once())->method('createShare')->with( |
|
| 2215 | - $this->callback(function (IShare $share) use ($path) { |
|
| 2216 | - return $share->getNode() === $path |
|
| 2217 | - && $share->getShareType() === IShare::TYPE_LINK |
|
| 2218 | - && $share->getPermissions() === Constants::PERMISSION_READ // publicUpload was set to false |
|
| 2219 | - && $share->getSharedBy() === 'currentUser' |
|
| 2220 | - && $share->getPassword() === 'password' |
|
| 2221 | - && $share->getExpirationDate() === null; |
|
| 2222 | - }) |
|
| 2223 | - )->willReturnArgument(0); |
|
| 2224 | - |
|
| 2225 | - $expected = new DataResponse([]); |
|
| 2226 | - $result = $ocs->createShare('valid-path', Constants::PERMISSION_READ, IShare::TYPE_LINK, null, 'false', 'password', null, ''); |
|
| 2227 | - |
|
| 2228 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 2229 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2230 | - } |
|
| 2231 | - |
|
| 2232 | - public function testCreateShareLinkSendPasswordByTalk(): void { |
|
| 2233 | - $ocs = $this->mockFormatShare(); |
|
| 2234 | - |
|
| 2235 | - $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2236 | - $path->method('getId')->willReturn(42); |
|
| 2237 | - $storage = $this->createMock(IStorage::class); |
|
| 2238 | - $storage->method('instanceOfStorage') |
|
| 2239 | - ->willReturnMap([ |
|
| 2240 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 2241 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2242 | - ]); |
|
| 2243 | - $path->method('getStorage')->willReturn($storage); |
|
| 2244 | - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2245 | - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2246 | - $this->rootFolder->method('getById') |
|
| 2247 | - ->willReturn([]); |
|
| 2248 | - |
|
| 2249 | - $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2250 | - $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2251 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2252 | - |
|
| 2253 | - $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true); |
|
| 2254 | - |
|
| 2255 | - $this->shareManager->expects($this->once())->method('createShare')->with( |
|
| 2256 | - $this->callback(function (IShare $share) use ($path) { |
|
| 2257 | - return $share->getNode() === $path |
|
| 2258 | - && $share->getShareType() === IShare::TYPE_LINK |
|
| 2259 | - && $share->getPermissions() === (Constants::PERMISSION_ALL & ~(Constants::PERMISSION_SHARE)) |
|
| 2260 | - && $share->getSharedBy() === 'currentUser' |
|
| 2261 | - && $share->getPassword() === 'password' |
|
| 2262 | - && $share->getSendPasswordByTalk() === true |
|
| 2263 | - && $share->getExpirationDate() === null; |
|
| 2264 | - }) |
|
| 2265 | - )->willReturnArgument(0); |
|
| 2266 | - |
|
| 2267 | - $expected = new DataResponse([]); |
|
| 2268 | - $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true', 'password', 'true', ''); |
|
| 2269 | - |
|
| 2270 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 2271 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2272 | - } |
|
| 2273 | - |
|
| 2274 | - |
|
| 2275 | - public function testCreateShareLinkSendPasswordByTalkWithTalkDisabled(): void { |
|
| 2276 | - $this->expectException(OCSForbiddenException::class); |
|
| 2277 | - $this->expectExceptionMessage('Sharing valid-path sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled'); |
|
| 2278 | - |
|
| 2279 | - $ocs = $this->mockFormatShare(); |
|
| 2280 | - |
|
| 2281 | - $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2282 | - $path->method('getId')->willReturn(42); |
|
| 2283 | - $storage = $this->createMock(IStorage::class); |
|
| 2284 | - $storage->method('instanceOfStorage') |
|
| 2285 | - ->willReturnMap([ |
|
| 2286 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 2287 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2288 | - ]); |
|
| 2289 | - $path->method('getStorage')->willReturn($storage); |
|
| 2290 | - $path->method('getPath')->willReturn('valid-path'); |
|
| 2291 | - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2292 | - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2293 | - $this->rootFolder->method('getById') |
|
| 2294 | - ->willReturn([]); |
|
| 2295 | - |
|
| 2296 | - $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2297 | - $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2298 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2299 | - |
|
| 2300 | - $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false); |
|
| 2301 | - |
|
| 2302 | - $this->shareManager->expects($this->never())->method('createShare'); |
|
| 2303 | - |
|
| 2304 | - $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', 'password', 'true', ''); |
|
| 2305 | - } |
|
| 2306 | - |
|
| 2307 | - public function testCreateShareValidExpireDate(): void { |
|
| 2308 | - $ocs = $this->mockFormatShare(); |
|
| 2309 | - |
|
| 2310 | - $this->request |
|
| 2311 | - ->method('getParam') |
|
| 2312 | - ->willReturnMap([ |
|
| 2313 | - ['path', null, 'valid-path'], |
|
| 2314 | - ['shareType', '-1', IShare::TYPE_LINK], |
|
| 2315 | - ['publicUpload', null, 'false'], |
|
| 2316 | - ['expireDate', '', '2000-01-01'], |
|
| 2317 | - ['password', '', ''], |
|
| 2318 | - ]); |
|
| 2319 | - |
|
| 2320 | - $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2321 | - $path->method('getId')->willReturn(42); |
|
| 2322 | - $storage = $this->createMock(IStorage::class); |
|
| 2323 | - $storage->method('instanceOfStorage') |
|
| 2324 | - ->willReturnMap([ |
|
| 2325 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 2326 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2327 | - ]); |
|
| 2328 | - $path->method('getStorage')->willReturn($storage); |
|
| 2329 | - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2330 | - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2331 | - $this->rootFolder->method('getById') |
|
| 2332 | - ->willReturn([]); |
|
| 2333 | - |
|
| 2334 | - $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2335 | - $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2336 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2337 | - |
|
| 2338 | - $this->shareManager->expects($this->once())->method('createShare')->with( |
|
| 2339 | - $this->callback(function (IShare $share) use ($path) { |
|
| 2340 | - $date = new \DateTime('2000-01-01'); |
|
| 2341 | - $date->setTime(0, 0, 0); |
|
| 2342 | - |
|
| 2343 | - return $share->getNode() === $path |
|
| 2344 | - && $share->getShareType() === IShare::TYPE_LINK |
|
| 2345 | - && $share->getPermissions() === Constants::PERMISSION_READ | Constants::PERMISSION_SHARE |
|
| 2346 | - && $share->getSharedBy() === 'currentUser' |
|
| 2347 | - && $share->getPassword() === null |
|
| 2348 | - && $share->getExpirationDate() == $date; |
|
| 2349 | - }) |
|
| 2350 | - )->willReturnArgument(0); |
|
| 2351 | - |
|
| 2352 | - $expected = new DataResponse([]); |
|
| 2353 | - $result = $ocs->createShare('valid-path', null, IShare::TYPE_LINK, null, 'false', '', null, '2000-01-01'); |
|
| 2354 | - |
|
| 2355 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 2356 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2357 | - } |
|
| 2358 | - |
|
| 2359 | - |
|
| 2360 | - public function testCreateShareInvalidExpireDate(): void { |
|
| 2361 | - $this->expectException(OCSNotFoundException::class); |
|
| 2362 | - $this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD'); |
|
| 2363 | - |
|
| 2364 | - $ocs = $this->mockFormatShare(); |
|
| 2365 | - |
|
| 2366 | - $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2367 | - $path->method('getId')->willReturn(42); |
|
| 2368 | - $storage = $this->createMock(IStorage::class); |
|
| 2369 | - $storage->method('instanceOfStorage') |
|
| 2370 | - ->willReturnMap([ |
|
| 2371 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 2372 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2373 | - ]); |
|
| 2374 | - $path->method('getStorage')->willReturn($storage); |
|
| 2375 | - $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2376 | - $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2377 | - $this->rootFolder->method('getById') |
|
| 2378 | - ->willReturn([]); |
|
| 2379 | - |
|
| 2380 | - $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2381 | - $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2382 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2383 | - |
|
| 2384 | - $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '', null, 'a1b2d3'); |
|
| 2385 | - } |
|
| 2386 | - |
|
| 2387 | - public function testCreateShareRemote(): void { |
|
| 2388 | - $share = $this->newShare(); |
|
| 2389 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 2390 | - |
|
| 2391 | - /** @var ShareAPIController $ocs */ |
|
| 2392 | - $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 2393 | - ->setConstructorArgs([ |
|
| 2394 | - $this->appName, |
|
| 2395 | - $this->request, |
|
| 2396 | - $this->shareManager, |
|
| 2397 | - $this->groupManager, |
|
| 2398 | - $this->userManager, |
|
| 2399 | - $this->rootFolder, |
|
| 2400 | - $this->urlGenerator, |
|
| 2401 | - $this->l, |
|
| 2402 | - $this->config, |
|
| 2403 | - $this->appConfig, |
|
| 2404 | - $this->appManager, |
|
| 2405 | - $this->serverContainer, |
|
| 2406 | - $this->userStatusManager, |
|
| 2407 | - $this->previewManager, |
|
| 2408 | - $this->dateTimeZone, |
|
| 2409 | - $this->logger, |
|
| 2410 | - $this->factory, |
|
| 2411 | - $this->mailer, |
|
| 2412 | - $this->tagManager, |
|
| 2413 | - $this->trustedServers, |
|
| 2414 | - $this->currentUser, |
|
| 2415 | - ])->onlyMethods(['formatShare']) |
|
| 2416 | - ->getMock(); |
|
| 2417 | - |
|
| 2418 | - [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 2419 | - $this->rootFolder->expects($this->exactly(2)) |
|
| 2420 | - ->method('getUserFolder') |
|
| 2421 | - ->with('currentUser') |
|
| 2422 | - ->willReturn($userFolder); |
|
| 2423 | - |
|
| 2424 | - $userFolder->expects($this->once()) |
|
| 2425 | - ->method('get') |
|
| 2426 | - ->with('valid-path') |
|
| 2427 | - ->willReturn($path); |
|
| 2428 | - $userFolder->method('getById') |
|
| 2429 | - ->willReturn([]); |
|
| 2430 | - |
|
| 2431 | - $this->userManager->method('userExists')->with('validUser')->willReturn(true); |
|
| 2432 | - |
|
| 2433 | - $path->expects($this->once()) |
|
| 2434 | - ->method('lock') |
|
| 2435 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 2436 | - |
|
| 2437 | - $this->shareManager->method('createShare') |
|
| 2438 | - ->with($this->callback(function (IShare $share) use ($path) { |
|
| 2439 | - return $share->getNode() === $path |
|
| 2440 | - && $share->getPermissions() === ( |
|
| 2441 | - Constants::PERMISSION_ALL |
|
| 2442 | - & ~Constants::PERMISSION_DELETE |
|
| 2443 | - & ~Constants::PERMISSION_CREATE |
|
| 2444 | - ) |
|
| 2445 | - && $share->getShareType() === IShare::TYPE_REMOTE |
|
| 2446 | - && $share->getSharedWith() === '[email protected]' |
|
| 2447 | - && $share->getSharedBy() === 'currentUser'; |
|
| 2448 | - })) |
|
| 2449 | - ->willReturnArgument(0); |
|
| 2450 | - |
|
| 2451 | - $this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true); |
|
| 2452 | - |
|
| 2453 | - $expected = new DataResponse([]); |
|
| 2454 | - $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_REMOTE, '[email protected]'); |
|
| 2455 | - |
|
| 2456 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 2457 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2458 | - } |
|
| 2459 | - |
|
| 2460 | - public function testCreateShareRemoteGroup(): void { |
|
| 2461 | - $share = $this->newShare(); |
|
| 2462 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 2463 | - |
|
| 2464 | - /** @var ShareAPIController $ocs */ |
|
| 2465 | - $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 2466 | - ->setConstructorArgs([ |
|
| 2467 | - $this->appName, |
|
| 2468 | - $this->request, |
|
| 2469 | - $this->shareManager, |
|
| 2470 | - $this->groupManager, |
|
| 2471 | - $this->userManager, |
|
| 2472 | - $this->rootFolder, |
|
| 2473 | - $this->urlGenerator, |
|
| 2474 | - $this->l, |
|
| 2475 | - $this->config, |
|
| 2476 | - $this->appConfig, |
|
| 2477 | - $this->appManager, |
|
| 2478 | - $this->serverContainer, |
|
| 2479 | - $this->userStatusManager, |
|
| 2480 | - $this->previewManager, |
|
| 2481 | - $this->dateTimeZone, |
|
| 2482 | - $this->logger, |
|
| 2483 | - $this->factory, |
|
| 2484 | - $this->mailer, |
|
| 2485 | - $this->tagManager, |
|
| 2486 | - $this->trustedServers, |
|
| 2487 | - $this->currentUser, |
|
| 2488 | - ])->onlyMethods(['formatShare']) |
|
| 2489 | - ->getMock(); |
|
| 2490 | - |
|
| 2491 | - [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 2492 | - $this->rootFolder->expects($this->exactly(2)) |
|
| 2493 | - ->method('getUserFolder') |
|
| 2494 | - ->with('currentUser') |
|
| 2495 | - ->willReturn($userFolder); |
|
| 2496 | - |
|
| 2497 | - $userFolder->expects($this->once()) |
|
| 2498 | - ->method('get') |
|
| 2499 | - ->with('valid-path') |
|
| 2500 | - ->willReturn($path); |
|
| 2501 | - $userFolder->method('getById') |
|
| 2502 | - ->willReturn([]); |
|
| 2503 | - |
|
| 2504 | - $this->userManager->method('userExists')->with('validUser')->willReturn(true); |
|
| 2505 | - |
|
| 2506 | - $path->expects($this->once()) |
|
| 2507 | - ->method('lock') |
|
| 2508 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 2509 | - |
|
| 2510 | - $this->shareManager->method('createShare') |
|
| 2511 | - ->with($this->callback(function (IShare $share) use ($path) { |
|
| 2512 | - return $share->getNode() === $path |
|
| 2513 | - && $share->getPermissions() === ( |
|
| 2514 | - Constants::PERMISSION_ALL |
|
| 2515 | - & ~Constants::PERMISSION_DELETE |
|
| 2516 | - & ~Constants::PERMISSION_CREATE |
|
| 2517 | - ) |
|
| 2518 | - && $share->getShareType() === IShare::TYPE_REMOTE_GROUP |
|
| 2519 | - && $share->getSharedWith() === '[email protected]' |
|
| 2520 | - && $share->getSharedBy() === 'currentUser'; |
|
| 2521 | - })) |
|
| 2522 | - ->willReturnArgument(0); |
|
| 2523 | - |
|
| 2524 | - $this->shareManager->method('outgoingServer2ServerGroupSharesAllowed')->willReturn(true); |
|
| 2525 | - |
|
| 2526 | - $expected = new DataResponse([]); |
|
| 2527 | - $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_REMOTE_GROUP, '[email protected]'); |
|
| 2528 | - |
|
| 2529 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 2530 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2531 | - } |
|
| 2532 | - |
|
| 2533 | - public function testCreateShareRoom(): void { |
|
| 2534 | - $ocs = $this->mockFormatShare(); |
|
| 2535 | - |
|
| 2536 | - $share = $this->newShare(); |
|
| 2537 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 2538 | - |
|
| 2539 | - [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 2540 | - $this->rootFolder->expects($this->exactly(2)) |
|
| 2541 | - ->method('getUserFolder') |
|
| 2542 | - ->with('currentUser') |
|
| 2543 | - ->willReturn($userFolder); |
|
| 2544 | - |
|
| 2545 | - $userFolder->expects($this->once()) |
|
| 2546 | - ->method('get') |
|
| 2547 | - ->with('valid-path') |
|
| 2548 | - ->willReturn($path); |
|
| 2549 | - $userFolder->method('getById') |
|
| 2550 | - ->willReturn([]); |
|
| 2551 | - |
|
| 2552 | - $path->expects($this->once()) |
|
| 2553 | - ->method('lock') |
|
| 2554 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 2555 | - |
|
| 2556 | - $this->appManager->method('isEnabledForUser') |
|
| 2557 | - ->with('spreed') |
|
| 2558 | - ->willReturn(true); |
|
| 2559 | - |
|
| 2560 | - // This is not possible anymore with PHPUnit 10+ |
|
| 2561 | - // as `setMethods` was removed and now real reflection is used, thus the class needs to exist. |
|
| 2562 | - // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 2563 | - $helper = $this->getMockBuilder(\stdClass::class) |
|
| 2564 | - ->addMethods(['createShare']) |
|
| 2565 | - ->getMock(); |
|
| 2566 | - $helper->method('createShare') |
|
| 2567 | - ->with( |
|
| 2568 | - $share, |
|
| 2569 | - 'recipientRoom', |
|
| 2570 | - Constants::PERMISSION_ALL |
|
| 2571 | - & ~Constants::PERMISSION_DELETE |
|
| 2572 | - & ~Constants::PERMISSION_CREATE, |
|
| 2573 | - '' |
|
| 2574 | - )->willReturnCallback( |
|
| 2575 | - function ($share): void { |
|
| 2576 | - $share->setSharedWith('recipientRoom'); |
|
| 2577 | - $share->setPermissions(Constants::PERMISSION_ALL); |
|
| 2578 | - } |
|
| 2579 | - ); |
|
| 2580 | - |
|
| 2581 | - $this->serverContainer->method('get') |
|
| 2582 | - ->with('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 2583 | - ->willReturn($helper); |
|
| 2584 | - |
|
| 2585 | - $this->shareManager->method('createShare') |
|
| 2586 | - ->with($this->callback(function (IShare $share) use ($path) { |
|
| 2587 | - return $share->getNode() === $path |
|
| 2588 | - && $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 2589 | - && $share->getShareType() === IShare::TYPE_ROOM |
|
| 2590 | - && $share->getSharedWith() === 'recipientRoom' |
|
| 2591 | - && $share->getSharedBy() === 'currentUser'; |
|
| 2592 | - })) |
|
| 2593 | - ->willReturnArgument(0); |
|
| 2594 | - |
|
| 2595 | - $expected = new DataResponse([]); |
|
| 2596 | - $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom'); |
|
| 2597 | - |
|
| 2598 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 2599 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2600 | - } |
|
| 2601 | - |
|
| 2602 | - |
|
| 2603 | - public function testCreateShareRoomHelperNotAvailable(): void { |
|
| 2604 | - $this->expectException(OCSForbiddenException::class); |
|
| 2605 | - $this->expectExceptionMessage('Sharing valid-path failed because the back end does not support room shares'); |
|
| 2606 | - |
|
| 2607 | - $ocs = $this->mockFormatShare(); |
|
| 2608 | - |
|
| 2609 | - $share = $this->newShare(); |
|
| 2610 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 2611 | - |
|
| 2612 | - [$userFolder, $path] = $this->getNonSharedUserFolder(); |
|
| 2613 | - $this->rootFolder->method('getUserFolder') |
|
| 2614 | - ->with('currentUser') |
|
| 2615 | - ->willReturn($userFolder); |
|
| 2616 | - |
|
| 2617 | - $path->method('getPath')->willReturn('valid-path'); |
|
| 2618 | - $userFolder->expects($this->once()) |
|
| 2619 | - ->method('get') |
|
| 2620 | - ->with('valid-path') |
|
| 2621 | - ->willReturn($path); |
|
| 2622 | - $userFolder->method('getById') |
|
| 2623 | - ->willReturn([]); |
|
| 2624 | - |
|
| 2625 | - $path->expects($this->once()) |
|
| 2626 | - ->method('lock') |
|
| 2627 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 2628 | - |
|
| 2629 | - $this->appManager->method('isEnabledForUser') |
|
| 2630 | - ->with('spreed') |
|
| 2631 | - ->willReturn(false); |
|
| 2632 | - |
|
| 2633 | - $this->shareManager->expects($this->never())->method('createShare'); |
|
| 2634 | - |
|
| 2635 | - $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom'); |
|
| 2636 | - } |
|
| 2637 | - |
|
| 2638 | - |
|
| 2639 | - public function testCreateShareRoomHelperThrowException(): void { |
|
| 2640 | - $this->expectException(OCSNotFoundException::class); |
|
| 2641 | - $this->expectExceptionMessage('Exception thrown by the helper'); |
|
| 2642 | - |
|
| 2643 | - $ocs = $this->mockFormatShare(); |
|
| 2644 | - |
|
| 2645 | - $share = $this->newShare(); |
|
| 2646 | - $share->setSharedBy('currentUser'); |
|
| 2647 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 2648 | - |
|
| 2649 | - [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 2650 | - $this->rootFolder->method('getUserFolder') |
|
| 2651 | - ->with('currentUser') |
|
| 2652 | - ->willReturn($userFolder); |
|
| 2653 | - |
|
| 2654 | - $userFolder->expects($this->once()) |
|
| 2655 | - ->method('get') |
|
| 2656 | - ->with('valid-path') |
|
| 2657 | - ->willReturn($path); |
|
| 2658 | - $userFolder->method('getById') |
|
| 2659 | - ->willReturn([]); |
|
| 2660 | - |
|
| 2661 | - $path->expects($this->once()) |
|
| 2662 | - ->method('lock') |
|
| 2663 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 2664 | - |
|
| 2665 | - $this->appManager->method('isEnabledForUser') |
|
| 2666 | - ->with('spreed') |
|
| 2667 | - ->willReturn(true); |
|
| 2668 | - |
|
| 2669 | - // This is not possible anymore with PHPUnit 10+ |
|
| 2670 | - // as `setMethods` was removed and now real reflection is used, thus the class needs to exist. |
|
| 2671 | - // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 2672 | - $helper = $this->getMockBuilder(\stdClass::class) |
|
| 2673 | - ->addMethods(['createShare']) |
|
| 2674 | - ->getMock(); |
|
| 2675 | - $helper->method('createShare') |
|
| 2676 | - ->with( |
|
| 2677 | - $share, |
|
| 2678 | - 'recipientRoom', |
|
| 2679 | - Constants::PERMISSION_ALL & ~(Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE), |
|
| 2680 | - '' |
|
| 2681 | - )->willReturnCallback( |
|
| 2682 | - function ($share): void { |
|
| 2683 | - throw new OCSNotFoundException('Exception thrown by the helper'); |
|
| 2684 | - } |
|
| 2685 | - ); |
|
| 2686 | - |
|
| 2687 | - $this->serverContainer->method('get') |
|
| 2688 | - ->with('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 2689 | - ->willReturn($helper); |
|
| 2690 | - |
|
| 2691 | - $this->shareManager->expects($this->never())->method('createShare'); |
|
| 2692 | - |
|
| 2693 | - $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom'); |
|
| 2694 | - } |
|
| 2695 | - |
|
| 2696 | - /** |
|
| 2697 | - * Test for https://github.com/owncloud/core/issues/22587 |
|
| 2698 | - * TODO: Remove once proper solution is in place |
|
| 2699 | - */ |
|
| 2700 | - public function testCreateReshareOfFederatedMountNoDeletePermissions(): void { |
|
| 2701 | - $share = Server::get(IManager::class)->newShare(); |
|
| 2702 | - $this->shareManager->method('newShare')->willReturn($share); |
|
| 2703 | - |
|
| 2704 | - /** @var ShareAPIController&MockObject $ocs */ |
|
| 2705 | - $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 2706 | - ->setConstructorArgs([ |
|
| 2707 | - $this->appName, |
|
| 2708 | - $this->request, |
|
| 2709 | - $this->shareManager, |
|
| 2710 | - $this->groupManager, |
|
| 2711 | - $this->userManager, |
|
| 2712 | - $this->rootFolder, |
|
| 2713 | - $this->urlGenerator, |
|
| 2714 | - $this->l, |
|
| 2715 | - $this->config, |
|
| 2716 | - $this->appConfig, |
|
| 2717 | - $this->appManager, |
|
| 2718 | - $this->serverContainer, |
|
| 2719 | - $this->userStatusManager, |
|
| 2720 | - $this->previewManager, |
|
| 2721 | - $this->dateTimeZone, |
|
| 2722 | - $this->logger, |
|
| 2723 | - $this->factory, |
|
| 2724 | - $this->mailer, |
|
| 2725 | - $this->tagManager, |
|
| 2726 | - $this->trustedServers, |
|
| 2727 | - $this->currentUser, |
|
| 2728 | - ])->onlyMethods(['formatShare']) |
|
| 2729 | - ->getMock(); |
|
| 2730 | - |
|
| 2731 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2732 | - $this->rootFolder->expects($this->exactly(2)) |
|
| 2733 | - ->method('getUserFolder') |
|
| 2734 | - ->with('currentUser') |
|
| 2735 | - ->willReturn($userFolder); |
|
| 2736 | - |
|
| 2737 | - $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2738 | - $path->method('getId')->willReturn(42); |
|
| 2739 | - |
|
| 2740 | - $storage = $this->createMock(IStorage::class); |
|
| 2741 | - $storage->method('instanceOfStorage') |
|
| 2742 | - ->willReturnMap([ |
|
| 2743 | - ['OCA\Files_Sharing\External\Storage', true], |
|
| 2744 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2745 | - ]); |
|
| 2746 | - $userFolder->method('getStorage')->willReturn($storage); |
|
| 2747 | - $path->method('getStorage')->willReturn($storage); |
|
| 2748 | - |
|
| 2749 | - $path->method('getPermissions')->willReturn(Constants::PERMISSION_READ); |
|
| 2750 | - $userFolder->expects($this->once()) |
|
| 2751 | - ->method('get') |
|
| 2752 | - ->with('valid-path') |
|
| 2753 | - ->willReturn($path); |
|
| 2754 | - $userFolder->method('getById') |
|
| 2755 | - ->willReturn([]); |
|
| 2756 | - |
|
| 2757 | - $this->userManager->method('userExists')->with('validUser')->willReturn(true); |
|
| 2758 | - |
|
| 2759 | - $this->shareManager |
|
| 2760 | - ->expects($this->once()) |
|
| 2761 | - ->method('createShare') |
|
| 2762 | - ->with($this->callback(function (IShare $share) { |
|
| 2763 | - return $share->getPermissions() === Constants::PERMISSION_READ; |
|
| 2764 | - })) |
|
| 2765 | - ->willReturnArgument(0); |
|
| 2766 | - |
|
| 2767 | - $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'validUser'); |
|
| 2768 | - } |
|
| 2769 | - |
|
| 2770 | - |
|
| 2771 | - public function testUpdateShareCantAccess(): void { |
|
| 2772 | - $this->expectException(OCSNotFoundException::class); |
|
| 2773 | - $this->expectExceptionMessage('Wrong share ID, share does not exist'); |
|
| 2774 | - |
|
| 2775 | - [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 2776 | - $share = $this->newShare(); |
|
| 2777 | - $share->setNode($node); |
|
| 2778 | - |
|
| 2779 | - $node->expects($this->once()) |
|
| 2780 | - ->method('lock') |
|
| 2781 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 2782 | - |
|
| 2783 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2784 | - |
|
| 2785 | - $this->rootFolder->method('getUserFolder') |
|
| 2786 | - ->with($this->currentUser) |
|
| 2787 | - ->willReturn($userFolder); |
|
| 2788 | - |
|
| 2789 | - $userFolder->method('getById') |
|
| 2790 | - ->with($share->getNodeId()) |
|
| 2791 | - ->willReturn([$share->getNode()]); |
|
| 2792 | - |
|
| 2793 | - $this->ocs->updateShare(42); |
|
| 2794 | - } |
|
| 2795 | - |
|
| 2796 | - |
|
| 2797 | - public function testUpdateNoParametersLink(): void { |
|
| 2798 | - $this->expectException(OCSBadRequestException::class); |
|
| 2799 | - $this->expectExceptionMessage('Wrong or no update parameter given'); |
|
| 2800 | - |
|
| 2801 | - $node = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2802 | - $share = $this->newShare(); |
|
| 2803 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 2804 | - ->setSharedBy($this->currentUser) |
|
| 2805 | - ->setShareType(IShare::TYPE_LINK) |
|
| 2806 | - ->setNode($node); |
|
| 2807 | - |
|
| 2808 | - $node->expects($this->once()) |
|
| 2809 | - ->method('lock') |
|
| 2810 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 2811 | - |
|
| 2812 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2813 | - |
|
| 2814 | - $this->ocs->updateShare(42); |
|
| 2815 | - } |
|
| 2816 | - |
|
| 2817 | - |
|
| 2818 | - public function testUpdateNoParametersOther(): void { |
|
| 2819 | - $this->expectException(OCSBadRequestException::class); |
|
| 2820 | - $this->expectExceptionMessage('Wrong or no update parameter given'); |
|
| 2821 | - |
|
| 2822 | - $node = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2823 | - $share = $this->newShare(); |
|
| 2824 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 2825 | - ->setSharedBy($this->currentUser) |
|
| 2826 | - ->setShareType(IShare::TYPE_GROUP) |
|
| 2827 | - ->setNode($node); |
|
| 2828 | - |
|
| 2829 | - $node->expects($this->once()) |
|
| 2830 | - ->method('lock') |
|
| 2831 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 2832 | - |
|
| 2833 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2834 | - |
|
| 2835 | - $this->ocs->updateShare(42); |
|
| 2836 | - } |
|
| 2837 | - |
|
| 2838 | - public function testUpdateLinkShareClear(): void { |
|
| 2839 | - $ocs = $this->mockFormatShare(); |
|
| 2840 | - |
|
| 2841 | - [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 2842 | - $node->method('getId') |
|
| 2843 | - ->willReturn(42); |
|
| 2844 | - $share = $this->newShare(); |
|
| 2845 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 2846 | - ->setSharedBy($this->currentUser) |
|
| 2847 | - ->setShareType(IShare::TYPE_LINK) |
|
| 2848 | - ->setPassword('password') |
|
| 2849 | - ->setExpirationDate(new \DateTime()) |
|
| 2850 | - ->setNote('note') |
|
| 2851 | - ->setLabel('label') |
|
| 2852 | - ->setHideDownload(true) |
|
| 2853 | - ->setPermissions(Constants::PERMISSION_ALL) |
|
| 2854 | - ->setNode($node); |
|
| 2855 | - |
|
| 2856 | - $node->expects($this->once()) |
|
| 2857 | - ->method('lock') |
|
| 2858 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 2859 | - |
|
| 2860 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2861 | - |
|
| 2862 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 2863 | - $this->callback(function (IShare $share) { |
|
| 2864 | - return $share->getPermissions() === Constants::PERMISSION_READ |
|
| 2865 | - && $share->getPassword() === null |
|
| 2866 | - && $share->getExpirationDate() === null |
|
| 2867 | - // Once set a note or a label are never back to null, only to an |
|
| 2868 | - // empty string. |
|
| 2869 | - && $share->getNote() === '' |
|
| 2870 | - && $share->getLabel() === '' |
|
| 2871 | - && $share->getHideDownload() === false; |
|
| 2872 | - }) |
|
| 2873 | - )->willReturnArgument(0); |
|
| 2874 | - |
|
| 2875 | - $this->shareManager->method('getSharedWith') |
|
| 2876 | - ->willReturn([]); |
|
| 2877 | - |
|
| 2878 | - $this->rootFolder->method('getUserFolder') |
|
| 2879 | - ->with($this->currentUser) |
|
| 2880 | - ->willReturn($userFolder); |
|
| 2881 | - |
|
| 2882 | - $userFolder->method('getById') |
|
| 2883 | - ->with(42) |
|
| 2884 | - ->willReturn([$node]); |
|
| 2885 | - $userFolder->method('getFirstNodeById') |
|
| 2886 | - ->with(42) |
|
| 2887 | - ->willReturn($node); |
|
| 2888 | - |
|
| 2889 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 2890 | - $node->method('getMountPoint') |
|
| 2891 | - ->willReturn($mountPoint); |
|
| 2892 | - $mountPoint->method('getStorageRootId') |
|
| 2893 | - ->willReturn(42); |
|
| 2894 | - |
|
| 2895 | - $expected = new DataResponse([]); |
|
| 2896 | - $result = $ocs->updateShare(42, null, '', null, 'false', '', '', '', 'false'); |
|
| 2897 | - |
|
| 2898 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 2899 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2900 | - } |
|
| 2901 | - |
|
| 2902 | - public function testUpdateLinkShareSet(): void { |
|
| 2903 | - $ocs = $this->mockFormatShare(); |
|
| 2904 | - |
|
| 2905 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 2906 | - $folder->method('getId') |
|
| 2907 | - ->willReturn(42); |
|
| 2908 | - |
|
| 2909 | - $share = Server::get(IManager::class)->newShare(); |
|
| 2910 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 2911 | - ->setSharedBy($this->currentUser) |
|
| 2912 | - ->setShareType(IShare::TYPE_LINK) |
|
| 2913 | - ->setNode($folder); |
|
| 2914 | - |
|
| 2915 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2916 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2917 | - |
|
| 2918 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 2919 | - $this->callback(function (IShare $share) { |
|
| 2920 | - $date = new \DateTime('2000-01-01'); |
|
| 2921 | - $date->setTime(0, 0, 0); |
|
| 2922 | - |
|
| 2923 | - return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 2924 | - && $share->getPassword() === 'password' |
|
| 2925 | - && $share->getExpirationDate() == $date |
|
| 2926 | - && $share->getNote() === 'note' |
|
| 2927 | - && $share->getLabel() === 'label' |
|
| 2928 | - && $share->getHideDownload() === true; |
|
| 2929 | - }) |
|
| 2930 | - )->willReturnArgument(0); |
|
| 2931 | - |
|
| 2932 | - $this->shareManager->method('getSharedWith') |
|
| 2933 | - ->willReturn([]); |
|
| 2934 | - |
|
| 2935 | - $this->rootFolder->method('getUserFolder') |
|
| 2936 | - ->with($this->currentUser) |
|
| 2937 | - ->willReturn($userFolder); |
|
| 2938 | - |
|
| 2939 | - $userFolder->method('getById') |
|
| 2940 | - ->with(42) |
|
| 2941 | - ->willReturn([$folder]); |
|
| 2942 | - |
|
| 2943 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 2944 | - $folder->method('getMountPoint') |
|
| 2945 | - ->willReturn($mountPoint); |
|
| 2946 | - $mountPoint->method('getStorageRootId') |
|
| 2947 | - ->willReturn(42); |
|
| 2948 | - |
|
| 2949 | - $expected = new DataResponse([]); |
|
| 2950 | - $result = $ocs->updateShare(42, null, 'password', null, 'true', '2000-01-01', 'note', 'label', 'true'); |
|
| 2951 | - |
|
| 2952 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 2953 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2954 | - } |
|
| 2955 | - |
|
| 2956 | - #[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')] |
|
| 2957 | - public function testUpdateLinkShareEnablePublicUpload($permissions, $publicUpload, $expireDate, $password): void { |
|
| 2958 | - $ocs = $this->mockFormatShare(); |
|
| 2959 | - |
|
| 2960 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 2961 | - $folder->method('getId') |
|
| 2962 | - ->willReturn(42); |
|
| 2963 | - |
|
| 2964 | - $share = Server::get(IManager::class)->newShare(); |
|
| 2965 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 2966 | - ->setSharedBy($this->currentUser) |
|
| 2967 | - ->setShareType(IShare::TYPE_LINK) |
|
| 2968 | - ->setPassword('password') |
|
| 2969 | - ->setNode($folder); |
|
| 2970 | - |
|
| 2971 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2972 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2973 | - $this->shareManager->method('getSharedWith')->willReturn([]); |
|
| 2974 | - |
|
| 2975 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 2976 | - $this->callback(function (IShare $share) { |
|
| 2977 | - return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 2978 | - && $share->getPassword() === 'password' |
|
| 2979 | - && $share->getExpirationDate() === null; |
|
| 2980 | - }) |
|
| 2981 | - )->willReturnArgument(0); |
|
| 2982 | - |
|
| 2983 | - $this->rootFolder->method('getUserFolder') |
|
| 2984 | - ->with($this->currentUser) |
|
| 2985 | - ->willReturn($userFolder); |
|
| 2986 | - |
|
| 2987 | - $userFolder->method('getById') |
|
| 2988 | - ->with(42) |
|
| 2989 | - ->willReturn([$folder]); |
|
| 2990 | - |
|
| 2991 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 2992 | - $folder->method('getMountPoint') |
|
| 2993 | - ->willReturn($mountPoint); |
|
| 2994 | - $mountPoint->method('getStorageRootId') |
|
| 2995 | - ->willReturn(42); |
|
| 2996 | - |
|
| 2997 | - $expected = new DataResponse([]); |
|
| 2998 | - $result = $ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate); |
|
| 2999 | - |
|
| 3000 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3001 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3002 | - } |
|
| 3003 | - |
|
| 3004 | - |
|
| 3005 | - public static function publicLinkValidPermissionsProvider() { |
|
| 3006 | - return [ |
|
| 3007 | - [Constants::PERMISSION_CREATE], |
|
| 3008 | - [Constants::PERMISSION_READ], |
|
| 3009 | - [Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE], |
|
| 3010 | - [Constants::PERMISSION_READ | Constants::PERMISSION_DELETE], |
|
| 3011 | - [Constants::PERMISSION_READ | Constants::PERMISSION_CREATE], |
|
| 3012 | - ]; |
|
| 3013 | - } |
|
| 3014 | - |
|
| 3015 | - #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkValidPermissionsProvider')] |
|
| 3016 | - public function testUpdateLinkShareSetCRUDPermissions($permissions): void { |
|
| 3017 | - $ocs = $this->mockFormatShare(); |
|
| 3018 | - |
|
| 3019 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3020 | - $folder->method('getId') |
|
| 3021 | - ->willReturn(42); |
|
| 3022 | - |
|
| 3023 | - $share = Server::get(IManager::class)->newShare(); |
|
| 3024 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3025 | - ->setSharedBy($this->currentUser) |
|
| 3026 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3027 | - ->setPassword('password') |
|
| 3028 | - ->setNode($folder); |
|
| 3029 | - |
|
| 3030 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3031 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3032 | - $this->shareManager->method('getSharedWith')->willReturn([]); |
|
| 3033 | - |
|
| 3034 | - $this->shareManager |
|
| 3035 | - ->expects($this->any()) |
|
| 3036 | - ->method('updateShare') |
|
| 3037 | - ->willReturnArgument(0); |
|
| 3038 | - |
|
| 3039 | - $this->rootFolder->method('getUserFolder') |
|
| 3040 | - ->with($this->currentUser) |
|
| 3041 | - ->willReturn($userFolder); |
|
| 3042 | - |
|
| 3043 | - $userFolder->method('getById') |
|
| 3044 | - ->with(42) |
|
| 3045 | - ->willReturn([$folder]); |
|
| 3046 | - |
|
| 3047 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3048 | - $folder->method('getMountPoint') |
|
| 3049 | - ->willReturn($mountPoint); |
|
| 3050 | - $mountPoint->method('getStorageRootId') |
|
| 3051 | - ->willReturn(42); |
|
| 3052 | - |
|
| 3053 | - $expected = new DataResponse([]); |
|
| 3054 | - $result = $ocs->updateShare(42, $permissions, 'password', null, null, null); |
|
| 3055 | - |
|
| 3056 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3057 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3058 | - } |
|
| 3059 | - |
|
| 3060 | - public static function publicLinkInvalidPermissionsProvider1() { |
|
| 3061 | - return [ |
|
| 3062 | - [Constants::PERMISSION_DELETE], |
|
| 3063 | - [Constants::PERMISSION_UPDATE], |
|
| 3064 | - [Constants::PERMISSION_SHARE], |
|
| 3065 | - ]; |
|
| 3066 | - } |
|
| 3067 | - |
|
| 3068 | - #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider1')] |
|
| 3069 | - public function testUpdateLinkShareSetInvalidCRUDPermissions1($permissions): void { |
|
| 3070 | - $this->expectException(OCSBadRequestException::class); |
|
| 3071 | - $this->expectExceptionMessage('Share must at least have READ or CREATE permissions'); |
|
| 3072 | - |
|
| 3073 | - $this->testUpdateLinkShareSetCRUDPermissions($permissions, null); |
|
| 3074 | - } |
|
| 3075 | - |
|
| 3076 | - public static function publicLinkInvalidPermissionsProvider2() { |
|
| 3077 | - return [ |
|
| 3078 | - [Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE], |
|
| 3079 | - [Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE], |
|
| 3080 | - ]; |
|
| 3081 | - } |
|
| 3082 | - |
|
| 3083 | - #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider2')] |
|
| 3084 | - public function testUpdateLinkShareSetInvalidCRUDPermissions2($permissions): void { |
|
| 3085 | - $this->expectException(OCSBadRequestException::class); |
|
| 3086 | - $this->expectExceptionMessage('Share must have READ permission if UPDATE or DELETE permission is set'); |
|
| 3087 | - |
|
| 3088 | - $this->testUpdateLinkShareSetCRUDPermissions($permissions); |
|
| 3089 | - } |
|
| 3090 | - |
|
| 3091 | - public function testUpdateLinkShareInvalidDate(): void { |
|
| 3092 | - $this->expectException(OCSBadRequestException::class); |
|
| 3093 | - $this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD'); |
|
| 3094 | - |
|
| 3095 | - $ocs = $this->mockFormatShare(); |
|
| 3096 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3097 | - $userFolder->method('getById') |
|
| 3098 | - ->with(42) |
|
| 3099 | - ->willReturn([$folder]); |
|
| 3100 | - $this->rootFolder->method('getUserFolder') |
|
| 3101 | - ->with($this->currentUser) |
|
| 3102 | - ->willReturn($userFolder); |
|
| 3103 | - |
|
| 3104 | - $folder->method('getId') |
|
| 3105 | - ->willReturn(42); |
|
| 3106 | - |
|
| 3107 | - $share = Server::get(IManager::class)->newShare(); |
|
| 3108 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3109 | - ->setSharedBy($this->currentUser) |
|
| 3110 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3111 | - ->setNode($folder); |
|
| 3112 | - |
|
| 3113 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3114 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3115 | - |
|
| 3116 | - $ocs->updateShare(42, null, 'password', null, 'true', '2000-01-a'); |
|
| 3117 | - } |
|
| 3118 | - |
|
| 3119 | - public static function publicUploadParamsProvider() { |
|
| 3120 | - return [ |
|
| 3121 | - [null, 'true', null, 'password'], |
|
| 3122 | - // legacy had no delete |
|
| 3123 | - [ |
|
| 3124 | - Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, |
|
| 3125 | - 'true', null, 'password' |
|
| 3126 | - ], |
|
| 3127 | - // correct |
|
| 3128 | - [ |
|
| 3129 | - Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, |
|
| 3130 | - null, null, 'password' |
|
| 3131 | - ], |
|
| 3132 | - ]; |
|
| 3133 | - } |
|
| 3134 | - |
|
| 3135 | - #[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')] |
|
| 3136 | - public function testUpdateLinkSharePublicUploadNotAllowed($permissions, $publicUpload, $expireDate, $password): void { |
|
| 3137 | - $this->expectException(OCSForbiddenException::class); |
|
| 3138 | - $this->expectExceptionMessage('Public upload disabled by the administrator'); |
|
| 3139 | - |
|
| 3140 | - $ocs = $this->mockFormatShare(); |
|
| 3141 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3142 | - $userFolder->method('getById') |
|
| 3143 | - ->with(42) |
|
| 3144 | - ->willReturn([$folder]); |
|
| 3145 | - $this->rootFolder->method('getUserFolder') |
|
| 3146 | - ->with($this->currentUser) |
|
| 3147 | - ->willReturn($userFolder); |
|
| 3148 | - |
|
| 3149 | - $folder->method('getId')->willReturn(42); |
|
| 3150 | - |
|
| 3151 | - $share = Server::get(IManager::class)->newShare(); |
|
| 3152 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3153 | - ->setSharedBy($this->currentUser) |
|
| 3154 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3155 | - ->setNode($folder); |
|
| 3156 | - |
|
| 3157 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3158 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(false); |
|
| 3159 | - |
|
| 3160 | - $ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate); |
|
| 3161 | - } |
|
| 3162 | - |
|
| 3163 | - |
|
| 3164 | - public function testUpdateLinkSharePublicUploadOnFile(): void { |
|
| 3165 | - $this->expectException(OCSBadRequestException::class); |
|
| 3166 | - $this->expectExceptionMessage('Public upload is only possible for publicly shared folders'); |
|
| 3167 | - |
|
| 3168 | - $ocs = $this->mockFormatShare(); |
|
| 3169 | - |
|
| 3170 | - $file = $this->getMockBuilder(File::class)->getMock(); |
|
| 3171 | - $file->method('getId') |
|
| 3172 | - ->willReturn(42); |
|
| 3173 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3174 | - $userFolder->method('getById') |
|
| 3175 | - ->with(42) |
|
| 3176 | - ->willReturn([$folder]); |
|
| 3177 | - $this->rootFolder->method('getUserFolder') |
|
| 3178 | - ->with($this->currentUser) |
|
| 3179 | - ->willReturn($userFolder); |
|
| 3180 | - |
|
| 3181 | - $share = Server::get(IManager::class)->newShare(); |
|
| 3182 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3183 | - ->setSharedBy($this->currentUser) |
|
| 3184 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3185 | - ->setNode($file); |
|
| 3186 | - |
|
| 3187 | - $this->shareManager |
|
| 3188 | - ->method('getShareById') |
|
| 3189 | - ->with('ocinternal:42') |
|
| 3190 | - ->willReturn($share); |
|
| 3191 | - $this->shareManager |
|
| 3192 | - ->method('shareApiLinkAllowPublicUpload') |
|
| 3193 | - ->willReturn(true); |
|
| 3194 | - $this->shareManager |
|
| 3195 | - ->method('updateShare') |
|
| 3196 | - ->with($share) |
|
| 3197 | - ->willThrowException(new \InvalidArgumentException('File shares cannot have create or delete permissions')); |
|
| 3198 | - |
|
| 3199 | - $ocs->updateShare(42, null, 'password', null, 'true', ''); |
|
| 3200 | - } |
|
| 3201 | - |
|
| 3202 | - public function testUpdateLinkSharePasswordDoesNotChangeOther(): void { |
|
| 3203 | - $ocs = $this->mockFormatShare(); |
|
| 3204 | - |
|
| 3205 | - $date = new \DateTime('2000-01-01'); |
|
| 3206 | - $date->setTime(0, 0, 0); |
|
| 3207 | - |
|
| 3208 | - [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3209 | - $node->method('getId')->willReturn(42); |
|
| 3210 | - $userFolder->method('getById') |
|
| 3211 | - ->with(42) |
|
| 3212 | - ->willReturn([$node]); |
|
| 3213 | - $this->rootFolder->method('getUserFolder') |
|
| 3214 | - ->with($this->currentUser) |
|
| 3215 | - ->willReturn($userFolder); |
|
| 3216 | - $share = $this->newShare(); |
|
| 3217 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3218 | - ->setSharedBy($this->currentUser) |
|
| 3219 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3220 | - ->setPassword('password') |
|
| 3221 | - ->setSendPasswordByTalk(true) |
|
| 3222 | - ->setExpirationDate($date) |
|
| 3223 | - ->setNote('note') |
|
| 3224 | - ->setLabel('label') |
|
| 3225 | - ->setHideDownload(true) |
|
| 3226 | - ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3227 | - ->setNode($node); |
|
| 3228 | - |
|
| 3229 | - $node->expects($this->once()) |
|
| 3230 | - ->method('lock') |
|
| 3231 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 3232 | - |
|
| 3233 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3234 | - |
|
| 3235 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3236 | - $this->callback(function (IShare $share) use ($date) { |
|
| 3237 | - return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3238 | - && $share->getPassword() === 'newpassword' |
|
| 3239 | - && $share->getSendPasswordByTalk() === true |
|
| 3240 | - && $share->getExpirationDate() === $date |
|
| 3241 | - && $share->getNote() === 'note' |
|
| 3242 | - && $share->getLabel() === 'label' |
|
| 3243 | - && $share->getHideDownload() === true; |
|
| 3244 | - }) |
|
| 3245 | - )->willReturnArgument(0); |
|
| 3246 | - |
|
| 3247 | - $expected = new DataResponse([]); |
|
| 3248 | - $result = $ocs->updateShare(42, null, 'newpassword', null, null, null, null, null, null); |
|
| 3249 | - |
|
| 3250 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3251 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3252 | - } |
|
| 3253 | - |
|
| 3254 | - public function testUpdateLinkShareSendPasswordByTalkDoesNotChangeOther(): void { |
|
| 3255 | - $ocs = $this->mockFormatShare(); |
|
| 3256 | - |
|
| 3257 | - $date = new \DateTime('2000-01-01'); |
|
| 3258 | - $date->setTime(0, 0, 0); |
|
| 3259 | - |
|
| 3260 | - [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3261 | - $userFolder->method('getById') |
|
| 3262 | - ->with(42) |
|
| 3263 | - ->willReturn([$node]); |
|
| 3264 | - $this->rootFolder->method('getUserFolder') |
|
| 3265 | - ->with($this->currentUser) |
|
| 3266 | - ->willReturn($userFolder); |
|
| 3267 | - $node->method('getId')->willReturn(42); |
|
| 3268 | - $share = $this->newShare(); |
|
| 3269 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3270 | - ->setSharedBy($this->currentUser) |
|
| 3271 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3272 | - ->setPassword('password') |
|
| 3273 | - ->setSendPasswordByTalk(false) |
|
| 3274 | - ->setExpirationDate($date) |
|
| 3275 | - ->setNote('note') |
|
| 3276 | - ->setLabel('label') |
|
| 3277 | - ->setHideDownload(true) |
|
| 3278 | - ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3279 | - ->setNode($node); |
|
| 3280 | - |
|
| 3281 | - $node->expects($this->once()) |
|
| 3282 | - ->method('lock') |
|
| 3283 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 3284 | - |
|
| 3285 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3286 | - |
|
| 3287 | - $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true); |
|
| 3288 | - |
|
| 3289 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3290 | - $this->callback(function (IShare $share) use ($date) { |
|
| 3291 | - return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3292 | - && $share->getPassword() === 'password' |
|
| 3293 | - && $share->getSendPasswordByTalk() === true |
|
| 3294 | - && $share->getExpirationDate() === $date |
|
| 3295 | - && $share->getNote() === 'note' |
|
| 3296 | - && $share->getLabel() === 'label' |
|
| 3297 | - && $share->getHideDownload() === true; |
|
| 3298 | - }) |
|
| 3299 | - )->willReturnArgument(0); |
|
| 3300 | - |
|
| 3301 | - $expected = new DataResponse([]); |
|
| 3302 | - $result = $ocs->updateShare(42, null, null, 'true', null, null, null, null, null); |
|
| 3303 | - |
|
| 3304 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3305 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3306 | - } |
|
| 3307 | - |
|
| 3308 | - |
|
| 3309 | - public function testUpdateLinkShareSendPasswordByTalkWithTalkDisabledDoesNotChangeOther(): void { |
|
| 3310 | - $this->expectException(OCSForbiddenException::class); |
|
| 3311 | - $this->expectExceptionMessage('"Sending the password by Nextcloud Talk" for sharing a file or folder failed because Nextcloud Talk is not enabled.'); |
|
| 3312 | - |
|
| 3313 | - $ocs = $this->mockFormatShare(); |
|
| 3314 | - |
|
| 3315 | - $date = new \DateTime('2000-01-01'); |
|
| 3316 | - $date->setTime(0, 0, 0); |
|
| 3317 | - |
|
| 3318 | - [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3319 | - $userFolder->method('getById') |
|
| 3320 | - ->with(42) |
|
| 3321 | - ->willReturn([$node]); |
|
| 3322 | - $this->rootFolder->method('getUserFolder') |
|
| 3323 | - ->with($this->currentUser) |
|
| 3324 | - ->willReturn($userFolder); |
|
| 3325 | - $node->method('getId')->willReturn(42); |
|
| 3326 | - $share = $this->newShare(); |
|
| 3327 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3328 | - ->setSharedBy($this->currentUser) |
|
| 3329 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3330 | - ->setPassword('password') |
|
| 3331 | - ->setSendPasswordByTalk(false) |
|
| 3332 | - ->setExpirationDate($date) |
|
| 3333 | - ->setNote('note') |
|
| 3334 | - ->setLabel('label') |
|
| 3335 | - ->setHideDownload(true) |
|
| 3336 | - ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3337 | - ->setNode($node); |
|
| 3338 | - |
|
| 3339 | - $node->expects($this->once()) |
|
| 3340 | - ->method('lock') |
|
| 3341 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 3342 | - |
|
| 3343 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3344 | - |
|
| 3345 | - $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false); |
|
| 3346 | - |
|
| 3347 | - $this->shareManager->expects($this->never())->method('updateShare'); |
|
| 3348 | - |
|
| 3349 | - $ocs->updateShare(42, null, null, 'true', null, null, null, null, null); |
|
| 3350 | - } |
|
| 3351 | - |
|
| 3352 | - public function testUpdateLinkShareDoNotSendPasswordByTalkDoesNotChangeOther(): void { |
|
| 3353 | - $ocs = $this->mockFormatShare(); |
|
| 3354 | - |
|
| 3355 | - $date = new \DateTime('2000-01-01'); |
|
| 3356 | - $date->setTime(0, 0, 0); |
|
| 3357 | - |
|
| 3358 | - [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3359 | - $userFolder->method('getById') |
|
| 3360 | - ->with(42) |
|
| 3361 | - ->willReturn([$node]); |
|
| 3362 | - $this->rootFolder->method('getUserFolder') |
|
| 3363 | - ->with($this->currentUser) |
|
| 3364 | - ->willReturn($userFolder); |
|
| 3365 | - $node->method('getId')->willReturn(42); |
|
| 3366 | - $share = $this->newShare(); |
|
| 3367 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3368 | - ->setSharedBy($this->currentUser) |
|
| 3369 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3370 | - ->setPassword('password') |
|
| 3371 | - ->setSendPasswordByTalk(true) |
|
| 3372 | - ->setExpirationDate($date) |
|
| 3373 | - ->setNote('note') |
|
| 3374 | - ->setLabel('label') |
|
| 3375 | - ->setHideDownload(true) |
|
| 3376 | - ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3377 | - ->setNode($node); |
|
| 3378 | - |
|
| 3379 | - $node->expects($this->once()) |
|
| 3380 | - ->method('lock') |
|
| 3381 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 3382 | - |
|
| 3383 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3384 | - |
|
| 3385 | - $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true); |
|
| 3386 | - |
|
| 3387 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3388 | - $this->callback(function (IShare $share) use ($date) { |
|
| 3389 | - return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3390 | - && $share->getPassword() === 'password' |
|
| 3391 | - && $share->getSendPasswordByTalk() === false |
|
| 3392 | - && $share->getExpirationDate() === $date |
|
| 3393 | - && $share->getNote() === 'note' |
|
| 3394 | - && $share->getLabel() === 'label' |
|
| 3395 | - && $share->getHideDownload() === true; |
|
| 3396 | - }) |
|
| 3397 | - )->willReturnArgument(0); |
|
| 3398 | - |
|
| 3399 | - $expected = new DataResponse([]); |
|
| 3400 | - $result = $ocs->updateShare(42, null, null, 'false', null, null, null, null, null); |
|
| 3401 | - |
|
| 3402 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3403 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3404 | - } |
|
| 3405 | - |
|
| 3406 | - public function testUpdateLinkShareDoNotSendPasswordByTalkWithTalkDisabledDoesNotChangeOther(): void { |
|
| 3407 | - $ocs = $this->mockFormatShare(); |
|
| 3408 | - |
|
| 3409 | - $date = new \DateTime('2000-01-01'); |
|
| 3410 | - $date->setTime(0, 0, 0); |
|
| 3411 | - |
|
| 3412 | - [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3413 | - $node->method('getId') |
|
| 3414 | - ->willReturn(42); |
|
| 3415 | - |
|
| 3416 | - $share = $this->newShare(); |
|
| 3417 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3418 | - ->setSharedBy($this->currentUser) |
|
| 3419 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3420 | - ->setPassword('password') |
|
| 3421 | - ->setSendPasswordByTalk(true) |
|
| 3422 | - ->setExpirationDate($date) |
|
| 3423 | - ->setNote('note') |
|
| 3424 | - ->setLabel('label') |
|
| 3425 | - ->setHideDownload(true) |
|
| 3426 | - ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3427 | - ->setNode($node); |
|
| 3428 | - |
|
| 3429 | - $node->expects($this->once()) |
|
| 3430 | - ->method('lock') |
|
| 3431 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 3432 | - |
|
| 3433 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3434 | - |
|
| 3435 | - $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false); |
|
| 3436 | - |
|
| 3437 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3438 | - $this->callback(function (IShare $share) use ($date) { |
|
| 3439 | - return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3440 | - && $share->getPassword() === 'password' |
|
| 3441 | - && $share->getSendPasswordByTalk() === false |
|
| 3442 | - && $share->getExpirationDate() === $date |
|
| 3443 | - && $share->getNote() === 'note' |
|
| 3444 | - && $share->getLabel() === 'label' |
|
| 3445 | - && $share->getHideDownload() === true; |
|
| 3446 | - }) |
|
| 3447 | - )->willReturnArgument(0); |
|
| 3448 | - |
|
| 3449 | - $this->rootFolder->method('getUserFolder') |
|
| 3450 | - ->with($this->currentUser) |
|
| 3451 | - ->willReturn($userFolder); |
|
| 3452 | - |
|
| 3453 | - $userFolder->method('getById') |
|
| 3454 | - ->with(42) |
|
| 3455 | - ->willReturn([$node]); |
|
| 3456 | - |
|
| 3457 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3458 | - $node->method('getMountPoint') |
|
| 3459 | - ->willReturn($mountPoint); |
|
| 3460 | - $mountPoint->method('getStorageRootId') |
|
| 3461 | - ->willReturn(42); |
|
| 3462 | - |
|
| 3463 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3464 | - $node->method('getMountPoint') |
|
| 3465 | - ->willReturn($mountPoint); |
|
| 3466 | - $mountPoint->method('getStorageRootId') |
|
| 3467 | - ->willReturn(42); |
|
| 3468 | - |
|
| 3469 | - $expected = new DataResponse([]); |
|
| 3470 | - $result = $ocs->updateShare(42, null, null, 'false', null, null, null, null, null); |
|
| 3471 | - |
|
| 3472 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3473 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3474 | - } |
|
| 3475 | - |
|
| 3476 | - public function testUpdateLinkShareExpireDateDoesNotChangeOther(): void { |
|
| 3477 | - $ocs = $this->mockFormatShare(); |
|
| 3478 | - |
|
| 3479 | - [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3480 | - $node->method('getId') |
|
| 3481 | - ->willReturn(42); |
|
| 3482 | - |
|
| 3483 | - $share = $this->newShare(); |
|
| 3484 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3485 | - ->setSharedBy($this->currentUser) |
|
| 3486 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3487 | - ->setPassword('password') |
|
| 3488 | - ->setSendPasswordByTalk(true) |
|
| 3489 | - ->setExpirationDate(new \DateTime()) |
|
| 3490 | - ->setNote('note') |
|
| 3491 | - ->setLabel('label') |
|
| 3492 | - ->setHideDownload(true) |
|
| 3493 | - ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3494 | - ->setNode($node); |
|
| 3495 | - |
|
| 3496 | - $node->expects($this->once()) |
|
| 3497 | - ->method('lock') |
|
| 3498 | - ->with(ILockingProvider::LOCK_SHARED); |
|
| 3499 | - |
|
| 3500 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3501 | - |
|
| 3502 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3503 | - $this->callback(function (IShare $share) { |
|
| 3504 | - $date = new \DateTime('2010-12-23'); |
|
| 3505 | - $date->setTime(0, 0, 0); |
|
| 3506 | - |
|
| 3507 | - return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3508 | - && $share->getPassword() === 'password' |
|
| 3509 | - && $share->getSendPasswordByTalk() === true |
|
| 3510 | - && $share->getExpirationDate() == $date |
|
| 3511 | - && $share->getNote() === 'note' |
|
| 3512 | - && $share->getLabel() === 'label' |
|
| 3513 | - && $share->getHideDownload() === true; |
|
| 3514 | - }) |
|
| 3515 | - )->willReturnArgument(0); |
|
| 3516 | - |
|
| 3517 | - $this->rootFolder->method('getUserFolder') |
|
| 3518 | - ->with($this->currentUser) |
|
| 3519 | - ->willReturn($userFolder); |
|
| 3520 | - |
|
| 3521 | - $userFolder->method('getById') |
|
| 3522 | - ->with(42) |
|
| 3523 | - ->willReturn([$node]); |
|
| 3524 | - |
|
| 3525 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3526 | - $node->method('getMountPoint') |
|
| 3527 | - ->willReturn($mountPoint); |
|
| 3528 | - $mountPoint->method('getStorageRootId') |
|
| 3529 | - ->willReturn(42); |
|
| 3530 | - |
|
| 3531 | - $expected = new DataResponse([]); |
|
| 3532 | - $result = $ocs->updateShare(42, null, null, null, null, '2010-12-23', null, null, null); |
|
| 3533 | - |
|
| 3534 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3535 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3536 | - } |
|
| 3537 | - |
|
| 3538 | - public function testUpdateLinkSharePublicUploadDoesNotChangeOther(): void { |
|
| 3539 | - $ocs = $this->mockFormatShare(); |
|
| 3540 | - |
|
| 3541 | - $date = new \DateTime('2000-01-01'); |
|
| 3542 | - |
|
| 3543 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3544 | - $folder->method('getId') |
|
| 3545 | - ->willReturn(42); |
|
| 3546 | - |
|
| 3547 | - $share = Server::get(IManager::class)->newShare(); |
|
| 3548 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3549 | - ->setSharedBy($this->currentUser) |
|
| 3550 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3551 | - ->setPassword('password') |
|
| 3552 | - ->setSendPasswordByTalk(true) |
|
| 3553 | - ->setExpirationDate($date) |
|
| 3554 | - ->setNote('note') |
|
| 3555 | - ->setLabel('label') |
|
| 3556 | - ->setHideDownload(true) |
|
| 3557 | - ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3558 | - ->setNode($folder); |
|
| 3559 | - |
|
| 3560 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3561 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3562 | - |
|
| 3563 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3564 | - $this->callback(function (IShare $share) use ($date) { |
|
| 3565 | - return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 3566 | - && $share->getPassword() === 'password' |
|
| 3567 | - && $share->getSendPasswordByTalk() === true |
|
| 3568 | - && $share->getExpirationDate() === $date |
|
| 3569 | - && $share->getNote() === 'note' |
|
| 3570 | - && $share->getLabel() === 'label' |
|
| 3571 | - && $share->getHideDownload() === true; |
|
| 3572 | - }) |
|
| 3573 | - )->willReturnArgument(0); |
|
| 3574 | - |
|
| 3575 | - $this->shareManager->method('getSharedWith') |
|
| 3576 | - ->willReturn([]); |
|
| 3577 | - |
|
| 3578 | - $this->rootFolder->method('getUserFolder') |
|
| 3579 | - ->with($this->currentUser) |
|
| 3580 | - ->willReturn($userFolder); |
|
| 3581 | - |
|
| 3582 | - $userFolder->method('getById') |
|
| 3583 | - ->with(42) |
|
| 3584 | - ->willReturn([$folder]); |
|
| 3585 | - |
|
| 3586 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3587 | - $folder->method('getMountPoint') |
|
| 3588 | - ->willReturn($mountPoint); |
|
| 3589 | - $mountPoint->method('getStorageRootId') |
|
| 3590 | - ->willReturn(42); |
|
| 3591 | - |
|
| 3592 | - $expected = new DataResponse([]); |
|
| 3593 | - $result = $ocs->updateShare(42, null, null, null, 'true', null, null, null, null); |
|
| 3594 | - |
|
| 3595 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3596 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3597 | - } |
|
| 3598 | - |
|
| 3599 | - public function testUpdateLinkSharePermissions(): void { |
|
| 3600 | - $ocs = $this->mockFormatShare(); |
|
| 3601 | - |
|
| 3602 | - $date = new \DateTime('2000-01-01'); |
|
| 3603 | - |
|
| 3604 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3605 | - $folder->method('getId') |
|
| 3606 | - ->willReturn(42); |
|
| 3607 | - |
|
| 3608 | - $share = Server::get(IManager::class)->newShare(); |
|
| 3609 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3610 | - ->setSharedBy($this->currentUser) |
|
| 3611 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3612 | - ->setPassword('password') |
|
| 3613 | - ->setSendPasswordByTalk(true) |
|
| 3614 | - ->setExpirationDate($date) |
|
| 3615 | - ->setNote('note') |
|
| 3616 | - ->setLabel('label') |
|
| 3617 | - ->setHideDownload(true) |
|
| 3618 | - ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3619 | - ->setNode($folder); |
|
| 3620 | - |
|
| 3621 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3622 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3623 | - |
|
| 3624 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3625 | - $this->callback(function (IShare $share) use ($date): bool { |
|
| 3626 | - return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 3627 | - && $share->getPassword() === 'password' |
|
| 3628 | - && $share->getSendPasswordByTalk() === true |
|
| 3629 | - && $share->getExpirationDate() === $date |
|
| 3630 | - && $share->getNote() === 'note' |
|
| 3631 | - && $share->getLabel() === 'label' |
|
| 3632 | - && $share->getHideDownload() === true; |
|
| 3633 | - }) |
|
| 3634 | - )->willReturnArgument(0); |
|
| 3635 | - |
|
| 3636 | - $this->shareManager->method('getSharedWith')->willReturn([]); |
|
| 3637 | - |
|
| 3638 | - $this->rootFolder->method('getUserFolder') |
|
| 3639 | - ->with($this->currentUser) |
|
| 3640 | - ->willReturn($userFolder); |
|
| 3641 | - |
|
| 3642 | - $userFolder->method('getById') |
|
| 3643 | - ->with(42) |
|
| 3644 | - ->willReturn([$folder]); |
|
| 3645 | - |
|
| 3646 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3647 | - $folder->method('getMountPoint') |
|
| 3648 | - ->willReturn($mountPoint); |
|
| 3649 | - $mountPoint->method('getStorageRootId') |
|
| 3650 | - ->willReturn(42); |
|
| 3651 | - |
|
| 3652 | - $expected = new DataResponse([]); |
|
| 3653 | - $result = $ocs->updateShare(42, 7, null, null, 'true', null, null, null, null); |
|
| 3654 | - |
|
| 3655 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3656 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3657 | - } |
|
| 3658 | - |
|
| 3659 | - public function testUpdateLinkSharePermissionsShare(): void { |
|
| 3660 | - $ocs = $this->mockFormatShare(); |
|
| 3661 | - |
|
| 3662 | - $date = new \DateTime('2000-01-01'); |
|
| 3663 | - |
|
| 3664 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3665 | - $folder->method('getId') |
|
| 3666 | - ->willReturn(42); |
|
| 3667 | - |
|
| 3668 | - $share = Server::get(IManager::class)->newShare(); |
|
| 3669 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3670 | - ->setSharedBy($this->currentUser) |
|
| 3671 | - ->setShareType(IShare::TYPE_LINK) |
|
| 3672 | - ->setPassword('password') |
|
| 3673 | - ->setSendPasswordByTalk(true) |
|
| 3674 | - ->setExpirationDate($date) |
|
| 3675 | - ->setNote('note') |
|
| 3676 | - ->setLabel('label') |
|
| 3677 | - ->setHideDownload(true) |
|
| 3678 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 3679 | - ->setNode($folder); |
|
| 3680 | - |
|
| 3681 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3682 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3683 | - |
|
| 3684 | - $this->shareManager->expects($this->once()) |
|
| 3685 | - ->method('updateShare') |
|
| 3686 | - ->with( |
|
| 3687 | - $this->callback(function (IShare $share) use ($date) { |
|
| 3688 | - return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3689 | - && $share->getPassword() === 'password' |
|
| 3690 | - && $share->getSendPasswordByTalk() === true |
|
| 3691 | - && $share->getExpirationDate() === $date |
|
| 3692 | - && $share->getNote() === 'note' |
|
| 3693 | - && $share->getLabel() === 'label' |
|
| 3694 | - && $share->getHideDownload() === true; |
|
| 3695 | - }) |
|
| 3696 | - )->willReturnArgument(0); |
|
| 3697 | - |
|
| 3698 | - $this->rootFolder->method('getUserFolder') |
|
| 3699 | - ->with($this->currentUser) |
|
| 3700 | - ->willReturn($userFolder); |
|
| 3701 | - |
|
| 3702 | - $userFolder->method('getById') |
|
| 3703 | - ->with(42) |
|
| 3704 | - ->willReturn([$folder]); |
|
| 3705 | - |
|
| 3706 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3707 | - $folder->method('getMountPoint') |
|
| 3708 | - ->willReturn($mountPoint); |
|
| 3709 | - $mountPoint->method('getStorageRootId') |
|
| 3710 | - ->willReturn(42); |
|
| 3711 | - |
|
| 3712 | - $this->shareManager->method('getSharedWith')->willReturn([]); |
|
| 3713 | - |
|
| 3714 | - $expected = new DataResponse([]); |
|
| 3715 | - $result = $ocs->updateShare(42, Constants::PERMISSION_ALL, null, null, null, null, null, null, null); |
|
| 3716 | - |
|
| 3717 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3718 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3719 | - } |
|
| 3720 | - |
|
| 3721 | - public function testUpdateOtherPermissions(): void { |
|
| 3722 | - $ocs = $this->mockFormatShare(); |
|
| 3723 | - |
|
| 3724 | - [$userFolder, $file] = $this->getNonSharedUserFolder(); |
|
| 3725 | - $file->method('getId') |
|
| 3726 | - ->willReturn(42); |
|
| 3727 | - |
|
| 3728 | - $share = Server::get(IManager::class)->newShare(); |
|
| 3729 | - $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3730 | - ->setSharedBy($this->currentUser) |
|
| 3731 | - ->setShareType(IShare::TYPE_USER) |
|
| 3732 | - ->setNode($file); |
|
| 3733 | - |
|
| 3734 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3735 | - $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3736 | - |
|
| 3737 | - $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3738 | - $this->callback(function (IShare $share) { |
|
| 3739 | - return $share->getPermissions() === Constants::PERMISSION_ALL; |
|
| 3740 | - }) |
|
| 3741 | - )->willReturnArgument(0); |
|
| 3742 | - |
|
| 3743 | - $this->shareManager->method('getSharedWith')->willReturn([]); |
|
| 3744 | - |
|
| 3745 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3746 | - $this->rootFolder->method('getUserFolder') |
|
| 3747 | - ->with($this->currentUser) |
|
| 3748 | - ->willReturn($userFolder); |
|
| 3749 | - |
|
| 3750 | - $userFolder->method('getById') |
|
| 3751 | - ->with(42) |
|
| 3752 | - ->willReturn([$file]); |
|
| 3753 | - |
|
| 3754 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3755 | - $file->method('getMountPoint') |
|
| 3756 | - ->willReturn($mountPoint); |
|
| 3757 | - $mountPoint->method('getStorageRootId') |
|
| 3758 | - ->willReturn(42); |
|
| 3759 | - |
|
| 3760 | - $expected = new DataResponse([]); |
|
| 3761 | - $result = $ocs->updateShare(42, 31, null, null, null, null); |
|
| 3762 | - |
|
| 3763 | - $this->assertInstanceOf(get_class($expected), $result); |
|
| 3764 | - $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3765 | - } |
|
| 3766 | - |
|
| 3767 | - public function testUpdateShareCannotIncreasePermissions(): void { |
|
| 3768 | - $ocs = $this->mockFormatShare(); |
|
| 3769 | - |
|
| 3770 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3771 | - $folder->method('getId') |
|
| 3772 | - ->willReturn(42); |
|
| 3773 | - |
|
| 3774 | - $share = Server::get(IManager::class)->newShare(); |
|
| 3775 | - $share |
|
| 3776 | - ->setId(42) |
|
| 3777 | - ->setSharedBy($this->currentUser) |
|
| 3778 | - ->setShareOwner('anotheruser') |
|
| 3779 | - ->setShareType(IShare::TYPE_GROUP) |
|
| 3780 | - ->setSharedWith('group1') |
|
| 3781 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 3782 | - ->setNode($folder); |
|
| 3783 | - |
|
| 3784 | - // note: updateShare will modify the received instance but getSharedWith will reread from the database, |
|
| 3785 | - // so their values will be different |
|
| 3786 | - $incomingShare = Server::get(IManager::class)->newShare(); |
|
| 3787 | - $incomingShare |
|
| 3788 | - ->setId(42) |
|
| 3789 | - ->setSharedBy($this->currentUser) |
|
| 3790 | - ->setShareOwner('anotheruser') |
|
| 3791 | - ->setShareType(IShare::TYPE_GROUP) |
|
| 3792 | - ->setSharedWith('group1') |
|
| 3793 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 3794 | - ->setNode($folder); |
|
| 3795 | - |
|
| 3796 | - $this->request |
|
| 3797 | - ->method('getParam') |
|
| 3798 | - ->willReturnMap([ |
|
| 3799 | - ['permissions', null, '31'], |
|
| 3800 | - ]); |
|
| 3801 | - |
|
| 3802 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3803 | - |
|
| 3804 | - $this->shareManager->expects($this->any()) |
|
| 3805 | - ->method('getSharedWith') |
|
| 3806 | - ->willReturnMap([ |
|
| 3807 | - ['currentUser', IShare::TYPE_USER, $share->getNode(), -1, 0, []], |
|
| 3808 | - ['currentUser', IShare::TYPE_GROUP, $share->getNode(), -1, 0, [$incomingShare]], |
|
| 3809 | - ['currentUser', IShare::TYPE_ROOM, $share->getNode(), -1, 0, []] |
|
| 3810 | - ]); |
|
| 3811 | - |
|
| 3812 | - $this->rootFolder->method('getUserFolder') |
|
| 3813 | - ->with($this->currentUser) |
|
| 3814 | - ->willReturn($userFolder); |
|
| 3815 | - |
|
| 3816 | - $userFolder->method('getById') |
|
| 3817 | - ->with(42) |
|
| 3818 | - ->willReturn([$folder]); |
|
| 3819 | - $userFolder->method('getFirstNodeById') |
|
| 3820 | - ->with(42) |
|
| 3821 | - ->willReturn($folder); |
|
| 3822 | - |
|
| 3823 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3824 | - $folder->method('getMountPoint') |
|
| 3825 | - ->willReturn($mountPoint); |
|
| 3826 | - $mountPoint->method('getStorageRootId') |
|
| 3827 | - ->willReturn(42); |
|
| 3828 | - |
|
| 3829 | - $this->shareManager->expects($this->once()) |
|
| 3830 | - ->method('updateShare') |
|
| 3831 | - ->with($share) |
|
| 3832 | - ->willThrowException(new GenericShareException('Cannot increase permissions of path/file', 'Cannot increase permissions of path/file', 404)); |
|
| 3833 | - |
|
| 3834 | - try { |
|
| 3835 | - $ocs->updateShare(42, 31); |
|
| 3836 | - $this->fail(); |
|
| 3837 | - } catch (OCSException $e) { |
|
| 3838 | - $this->assertEquals('Cannot increase permissions of path/file', $e->getMessage()); |
|
| 3839 | - } |
|
| 3840 | - } |
|
| 3841 | - |
|
| 3842 | - public function testUpdateShareCanIncreasePermissionsIfOwner(): void { |
|
| 3843 | - $ocs = $this->mockFormatShare(); |
|
| 3844 | - |
|
| 3845 | - [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3846 | - $folder->method('getId') |
|
| 3847 | - ->willReturn(42); |
|
| 3848 | - |
|
| 3849 | - $share = Server::get(IManager::class)->newShare(); |
|
| 3850 | - $share |
|
| 3851 | - ->setId(42) |
|
| 3852 | - ->setSharedBy($this->currentUser) |
|
| 3853 | - ->setShareOwner($this->currentUser) |
|
| 3854 | - ->setShareType(IShare::TYPE_GROUP) |
|
| 3855 | - ->setSharedWith('group1') |
|
| 3856 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 3857 | - ->setNode($folder); |
|
| 3858 | - |
|
| 3859 | - // note: updateShare will modify the received instance but getSharedWith will reread from the database, |
|
| 3860 | - // so their values will be different |
|
| 3861 | - $incomingShare = Server::get(IManager::class)->newShare(); |
|
| 3862 | - $incomingShare |
|
| 3863 | - ->setId(42) |
|
| 3864 | - ->setSharedBy($this->currentUser) |
|
| 3865 | - ->setShareOwner($this->currentUser) |
|
| 3866 | - ->setShareType(IShare::TYPE_GROUP) |
|
| 3867 | - ->setSharedWith('group1') |
|
| 3868 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 3869 | - ->setNode($folder); |
|
| 3870 | - |
|
| 3871 | - $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3872 | - |
|
| 3873 | - $this->shareManager->expects($this->any()) |
|
| 3874 | - ->method('getSharedWith') |
|
| 3875 | - ->willReturnMap([ |
|
| 3876 | - ['currentUser', IShare::TYPE_USER, $share->getNode(), -1, 0, []], |
|
| 3877 | - ['currentUser', IShare::TYPE_GROUP, $share->getNode(), -1, 0, [$incomingShare]] |
|
| 3878 | - ]); |
|
| 3879 | - |
|
| 3880 | - $this->shareManager->expects($this->once()) |
|
| 3881 | - ->method('updateShare') |
|
| 3882 | - ->with($share) |
|
| 3883 | - ->willReturn($share); |
|
| 3884 | - |
|
| 3885 | - $this->rootFolder->method('getUserFolder') |
|
| 3886 | - ->with($this->currentUser) |
|
| 3887 | - ->willReturn($userFolder); |
|
| 3888 | - |
|
| 3889 | - $userFolder->method('getById') |
|
| 3890 | - ->with(42) |
|
| 3891 | - ->willReturn([$folder]); |
|
| 3892 | - |
|
| 3893 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3894 | - $folder->method('getMountPoint') |
|
| 3895 | - ->willReturn($mountPoint); |
|
| 3896 | - $mountPoint->method('getStorageRootId') |
|
| 3897 | - ->willReturn(42); |
|
| 3898 | - |
|
| 3899 | - $result = $ocs->updateShare(42, 31); |
|
| 3900 | - $this->assertInstanceOf(DataResponse::class, $result); |
|
| 3901 | - } |
|
| 3902 | - |
|
| 3903 | - public function testUpdateShareOwnerless(): void { |
|
| 3904 | - $ocs = $this->mockFormatShare(); |
|
| 3905 | - |
|
| 3906 | - $mount = $this->createMock(IShareOwnerlessMount::class); |
|
| 3907 | - |
|
| 3908 | - $file = $this->createMock(File::class); |
|
| 3909 | - $file |
|
| 3910 | - ->expects($this->exactly(2)) |
|
| 3911 | - ->method('getPermissions') |
|
| 3912 | - ->willReturn(Constants::PERMISSION_SHARE); |
|
| 3913 | - $file |
|
| 3914 | - ->expects($this->once()) |
|
| 3915 | - ->method('getMountPoint') |
|
| 3916 | - ->willReturn($mount); |
|
| 3917 | - |
|
| 3918 | - $userFolder = $this->createMock(Folder::class); |
|
| 3919 | - $userFolder->method('getById') |
|
| 3920 | - ->with(2) |
|
| 3921 | - ->willReturn([$file]); |
|
| 3922 | - $userFolder->method('getFirstNodeById') |
|
| 3923 | - ->with(2) |
|
| 3924 | - ->willReturn($file); |
|
| 3925 | - |
|
| 3926 | - $this->rootFolder |
|
| 3927 | - ->method('getUserFolder') |
|
| 3928 | - ->with($this->currentUser) |
|
| 3929 | - ->willReturn($userFolder); |
|
| 3930 | - |
|
| 3931 | - $share = $this->createMock(IShare::class); |
|
| 3932 | - $share |
|
| 3933 | - ->expects($this->once()) |
|
| 3934 | - ->method('getNode') |
|
| 3935 | - ->willReturn($file); |
|
| 3936 | - $share |
|
| 3937 | - ->expects($this->exactly(2)) |
|
| 3938 | - ->method('getNodeId') |
|
| 3939 | - ->willReturn(2); |
|
| 3940 | - $share |
|
| 3941 | - ->expects($this->exactly(2)) |
|
| 3942 | - ->method('getPermissions') |
|
| 3943 | - ->willReturn(Constants::PERMISSION_SHARE); |
|
| 3944 | - |
|
| 3945 | - $this->shareManager |
|
| 3946 | - ->expects($this->once()) |
|
| 3947 | - ->method('getShareById') |
|
| 3948 | - ->with('ocinternal:1', $this->currentUser) |
|
| 3949 | - ->willReturn($share); |
|
| 3950 | - |
|
| 3951 | - $this->shareManager |
|
| 3952 | - ->expects($this->once()) |
|
| 3953 | - ->method('updateShare') |
|
| 3954 | - ->with($share) |
|
| 3955 | - ->willReturn($share); |
|
| 3956 | - |
|
| 3957 | - $result = $ocs->updateShare(1, Constants::PERMISSION_ALL); |
|
| 3958 | - $this->assertInstanceOf(DataResponse::class, $result); |
|
| 3959 | - } |
|
| 3960 | - |
|
| 3961 | - public function dataFormatShare() { |
|
| 3962 | - $file = $this->getMockBuilder(File::class)->getMock(); |
|
| 3963 | - $folder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 3964 | - $parent = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 3965 | - $fileWithPreview = $this->getMockBuilder(File::class)->getMock(); |
|
| 3966 | - |
|
| 3967 | - $file->method('getMimeType')->willReturn('myMimeType'); |
|
| 3968 | - $folder->method('getMimeType')->willReturn('myFolderMimeType'); |
|
| 3969 | - $fileWithPreview->method('getMimeType')->willReturn('mimeWithPreview'); |
|
| 3970 | - |
|
| 3971 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3972 | - $mountPoint->method('getMountType')->willReturn(''); |
|
| 3973 | - $file->method('getMountPoint')->willReturn($mountPoint); |
|
| 3974 | - $folder->method('getMountPoint')->willReturn($mountPoint); |
|
| 3975 | - $fileWithPreview->method('getMountPoint')->willReturn($mountPoint); |
|
| 3976 | - |
|
| 3977 | - $file->method('getPath')->willReturn('file'); |
|
| 3978 | - $folder->method('getPath')->willReturn('folder'); |
|
| 3979 | - $fileWithPreview->method('getPath')->willReturn('fileWithPreview'); |
|
| 3980 | - |
|
| 3981 | - $parent->method('getId')->willReturn(1); |
|
| 3982 | - $folder->method('getId')->willReturn(2); |
|
| 3983 | - $file->method('getId')->willReturn(3); |
|
| 3984 | - $fileWithPreview->method('getId')->willReturn(4); |
|
| 3985 | - |
|
| 3986 | - $file->method('getParent')->willReturn($parent); |
|
| 3987 | - $folder->method('getParent')->willReturn($parent); |
|
| 3988 | - $fileWithPreview->method('getParent')->willReturn($parent); |
|
| 3989 | - |
|
| 3990 | - $file->method('getSize')->willReturn(123456); |
|
| 3991 | - $folder->method('getSize')->willReturn(123456); |
|
| 3992 | - $fileWithPreview->method('getSize')->willReturn(123456); |
|
| 3993 | - $file->method('getMTime')->willReturn(1234567890); |
|
| 3994 | - $folder->method('getMTime')->willReturn(1234567890); |
|
| 3995 | - $fileWithPreview->method('getMTime')->willReturn(1234567890); |
|
| 3996 | - |
|
| 3997 | - $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock(); |
|
| 3998 | - $cache->method('getNumericStorageId')->willReturn(100); |
|
| 3999 | - $storage = $this->createMock(IStorage::class); |
|
| 4000 | - $storage->method('getId')->willReturn('storageId'); |
|
| 4001 | - $storage->method('getCache')->willReturn($cache); |
|
| 4002 | - |
|
| 4003 | - $file->method('getStorage')->willReturn($storage); |
|
| 4004 | - $folder->method('getStorage')->willReturn($storage); |
|
| 4005 | - $fileWithPreview->method('getStorage')->willReturn($storage); |
|
| 4006 | - |
|
| 4007 | - |
|
| 4008 | - $mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock(); |
|
| 4009 | - $mountPoint->method('getMountType')->willReturn(''); |
|
| 4010 | - $file->method('getMountPoint')->willReturn($mountPoint); |
|
| 4011 | - $folder->method('getMountPoint')->willReturn($mountPoint); |
|
| 4012 | - |
|
| 4013 | - $owner = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 4014 | - $owner->method('getDisplayName')->willReturn('ownerDN'); |
|
| 4015 | - $initiator = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 4016 | - $initiator->method('getDisplayName')->willReturn('initiatorDN'); |
|
| 4017 | - $recipient = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 4018 | - $recipient->method('getDisplayName')->willReturn('recipientDN'); |
|
| 4019 | - $recipient->method('getSystemEMailAddress')->willReturn('recipient'); |
|
| 4020 | - [$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes(); |
|
| 4021 | - |
|
| 4022 | - $result = []; |
|
| 4023 | - |
|
| 4024 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4025 | - $share->setShareType(IShare::TYPE_USER) |
|
| 4026 | - ->setSharedWith('recipient') |
|
| 4027 | - ->setSharedBy('initiator') |
|
| 4028 | - ->setShareOwner('owner') |
|
| 4029 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4030 | - ->setAttributes($shareAttributes) |
|
| 4031 | - ->setNode($file) |
|
| 4032 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4033 | - ->setTarget('myTarget') |
|
| 4034 | - ->setNote('personal note') |
|
| 4035 | - ->setId(42); |
|
| 4036 | - |
|
| 4037 | - // User backend down |
|
| 4038 | - $result[] = [ |
|
| 4039 | - [ |
|
| 4040 | - 'id' => '42', |
|
| 4041 | - 'share_type' => IShare::TYPE_USER, |
|
| 4042 | - 'uid_owner' => 'initiator', |
|
| 4043 | - 'displayname_owner' => 'initiator', |
|
| 4044 | - 'permissions' => 1, |
|
| 4045 | - 'attributes' => $shareAttributesReturnJson, |
|
| 4046 | - 'stime' => 946684862, |
|
| 4047 | - 'parent' => null, |
|
| 4048 | - 'expiration' => null, |
|
| 4049 | - 'token' => null, |
|
| 4050 | - 'uid_file_owner' => 'owner', |
|
| 4051 | - 'displayname_file_owner' => 'owner', |
|
| 4052 | - 'path' => 'file', |
|
| 4053 | - 'item_type' => 'file', |
|
| 4054 | - 'storage_id' => 'storageId', |
|
| 4055 | - 'storage' => 100, |
|
| 4056 | - 'item_source' => 3, |
|
| 4057 | - 'file_source' => 3, |
|
| 4058 | - 'file_parent' => 1, |
|
| 4059 | - 'file_target' => 'myTarget', |
|
| 4060 | - 'share_with' => 'recipient', |
|
| 4061 | - 'share_with_displayname' => 'recipient', |
|
| 4062 | - 'share_with_displayname_unique' => 'recipient', |
|
| 4063 | - 'note' => 'personal note', |
|
| 4064 | - 'label' => '', |
|
| 4065 | - 'mail_send' => 0, |
|
| 4066 | - 'mimetype' => 'myMimeType', |
|
| 4067 | - 'has_preview' => false, |
|
| 4068 | - 'hide_download' => 0, |
|
| 4069 | - 'can_edit' => false, |
|
| 4070 | - 'can_delete' => false, |
|
| 4071 | - 'item_size' => 123456, |
|
| 4072 | - 'item_mtime' => 1234567890, |
|
| 4073 | - 'is-mount-root' => false, |
|
| 4074 | - 'mount-type' => '', |
|
| 4075 | - 'attributes' => '[{"scope":"permissions","key":"download","value":true}]', |
|
| 4076 | - 'item_permissions' => 1, |
|
| 4077 | - ], $share, [], false |
|
| 4078 | - ]; |
|
| 4079 | - // User backend up |
|
| 4080 | - $result[] = [ |
|
| 4081 | - [ |
|
| 4082 | - 'id' => '42', |
|
| 4083 | - 'share_type' => IShare::TYPE_USER, |
|
| 4084 | - 'uid_owner' => 'initiator', |
|
| 4085 | - 'displayname_owner' => 'initiatorDN', |
|
| 4086 | - 'permissions' => 1, |
|
| 4087 | - 'attributes' => $shareAttributesReturnJson, |
|
| 4088 | - 'stime' => 946684862, |
|
| 4089 | - 'parent' => null, |
|
| 4090 | - 'expiration' => null, |
|
| 4091 | - 'token' => null, |
|
| 4092 | - 'uid_file_owner' => 'owner', |
|
| 4093 | - 'displayname_file_owner' => 'ownerDN', |
|
| 4094 | - 'note' => 'personal note', |
|
| 4095 | - 'label' => '', |
|
| 4096 | - 'path' => 'file', |
|
| 4097 | - 'item_type' => 'file', |
|
| 4098 | - 'storage_id' => 'storageId', |
|
| 4099 | - 'storage' => 100, |
|
| 4100 | - 'item_source' => 3, |
|
| 4101 | - 'file_source' => 3, |
|
| 4102 | - 'file_parent' => 1, |
|
| 4103 | - 'file_target' => 'myTarget', |
|
| 4104 | - 'share_with' => 'recipient', |
|
| 4105 | - 'share_with_displayname' => 'recipientDN', |
|
| 4106 | - 'share_with_displayname_unique' => 'recipient', |
|
| 4107 | - 'mail_send' => 0, |
|
| 4108 | - 'mimetype' => 'myMimeType', |
|
| 4109 | - 'has_preview' => false, |
|
| 4110 | - 'hide_download' => 0, |
|
| 4111 | - 'can_edit' => false, |
|
| 4112 | - 'can_delete' => false, |
|
| 4113 | - 'item_size' => 123456, |
|
| 4114 | - 'item_mtime' => 1234567890, |
|
| 4115 | - 'is-mount-root' => false, |
|
| 4116 | - 'mount-type' => '', |
|
| 4117 | - 'attributes' => '[{"scope":"permissions","key":"download","value":true}]', |
|
| 4118 | - 'item_permissions' => 1, |
|
| 4119 | - ], $share, [ |
|
| 4120 | - ['owner', $owner], |
|
| 4121 | - ['initiator', $initiator], |
|
| 4122 | - ['recipient', $recipient], |
|
| 4123 | - ], false |
|
| 4124 | - ]; |
|
| 4125 | - |
|
| 4126 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4127 | - $share->setShareType(IShare::TYPE_USER) |
|
| 4128 | - ->setSharedWith('recipient') |
|
| 4129 | - ->setSharedBy('initiator') |
|
| 4130 | - ->setShareOwner('owner') |
|
| 4131 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4132 | - ->setNode($file) |
|
| 4133 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4134 | - ->setTarget('myTarget') |
|
| 4135 | - ->setNote('personal note') |
|
| 4136 | - ->setId(42); |
|
| 4137 | - // User backend down |
|
| 4138 | - $result[] = [ |
|
| 4139 | - [ |
|
| 4140 | - 'id' => '42', |
|
| 4141 | - 'share_type' => IShare::TYPE_USER, |
|
| 4142 | - 'uid_owner' => 'initiator', |
|
| 4143 | - 'displayname_owner' => 'initiator', |
|
| 4144 | - 'permissions' => 1, |
|
| 4145 | - 'attributes' => null, |
|
| 4146 | - 'stime' => 946684862, |
|
| 4147 | - 'parent' => null, |
|
| 4148 | - 'expiration' => null, |
|
| 4149 | - 'token' => null, |
|
| 4150 | - 'uid_file_owner' => 'owner', |
|
| 4151 | - 'displayname_file_owner' => 'owner', |
|
| 4152 | - 'note' => 'personal note', |
|
| 4153 | - 'label' => '', |
|
| 4154 | - 'path' => 'file', |
|
| 4155 | - 'item_type' => 'file', |
|
| 4156 | - 'storage_id' => 'storageId', |
|
| 4157 | - 'storage' => 100, |
|
| 4158 | - 'item_source' => 3, |
|
| 4159 | - 'file_source' => 3, |
|
| 4160 | - 'file_parent' => 1, |
|
| 4161 | - 'file_target' => 'myTarget', |
|
| 4162 | - 'share_with' => 'recipient', |
|
| 4163 | - 'share_with_displayname' => 'recipient', |
|
| 4164 | - 'share_with_displayname_unique' => 'recipient', |
|
| 4165 | - 'mail_send' => 0, |
|
| 4166 | - 'mimetype' => 'myMimeType', |
|
| 4167 | - 'has_preview' => false, |
|
| 4168 | - 'hide_download' => 0, |
|
| 4169 | - 'can_edit' => false, |
|
| 4170 | - 'can_delete' => false, |
|
| 4171 | - 'item_size' => 123456, |
|
| 4172 | - 'item_mtime' => 1234567890, |
|
| 4173 | - 'is-mount-root' => false, |
|
| 4174 | - 'mount-type' => '', |
|
| 4175 | - 'attributes' => null, |
|
| 4176 | - 'item_permissions' => 1, |
|
| 4177 | - ], $share, [], false |
|
| 4178 | - ]; |
|
| 4179 | - |
|
| 4180 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4181 | - $share->setShareType(IShare::TYPE_USER) |
|
| 4182 | - ->setSharedWith('recipient') |
|
| 4183 | - ->setSharedBy('initiator') |
|
| 4184 | - ->setShareOwner('currentUser') |
|
| 4185 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4186 | - ->setNode($file) |
|
| 4187 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4188 | - ->setTarget('myTarget') |
|
| 4189 | - ->setNote('personal note') |
|
| 4190 | - ->setId(42); |
|
| 4191 | - // User backend down |
|
| 4192 | - $result[] = [ |
|
| 4193 | - [ |
|
| 4194 | - 'id' => '42', |
|
| 4195 | - 'share_type' => IShare::TYPE_USER, |
|
| 4196 | - 'uid_owner' => 'initiator', |
|
| 4197 | - 'displayname_owner' => 'initiator', |
|
| 4198 | - 'permissions' => 1, |
|
| 4199 | - 'attributes' => null, |
|
| 4200 | - 'stime' => 946684862, |
|
| 4201 | - 'parent' => null, |
|
| 4202 | - 'expiration' => null, |
|
| 4203 | - 'token' => null, |
|
| 4204 | - 'uid_file_owner' => 'currentUser', |
|
| 4205 | - 'displayname_file_owner' => 'currentUser', |
|
| 4206 | - 'note' => 'personal note', |
|
| 4207 | - 'label' => '', |
|
| 4208 | - 'path' => 'file', |
|
| 4209 | - 'item_type' => 'file', |
|
| 4210 | - 'storage_id' => 'storageId', |
|
| 4211 | - 'storage' => 100, |
|
| 4212 | - 'item_source' => 3, |
|
| 4213 | - 'file_source' => 3, |
|
| 4214 | - 'file_parent' => 1, |
|
| 4215 | - 'file_target' => 'myTarget', |
|
| 4216 | - 'share_with' => 'recipient', |
|
| 4217 | - 'share_with_displayname' => 'recipient', |
|
| 4218 | - 'share_with_displayname_unique' => 'recipient', |
|
| 4219 | - 'mail_send' => 0, |
|
| 4220 | - 'mimetype' => 'myMimeType', |
|
| 4221 | - 'has_preview' => false, |
|
| 4222 | - 'hide_download' => 0, |
|
| 4223 | - 'can_edit' => true, |
|
| 4224 | - 'can_delete' => true, |
|
| 4225 | - 'item_size' => 123456, |
|
| 4226 | - 'item_mtime' => 1234567890, |
|
| 4227 | - 'is-mount-root' => false, |
|
| 4228 | - 'mount-type' => '', |
|
| 4229 | - 'attributes' => null, |
|
| 4230 | - 'item_permissions' => 11, |
|
| 4231 | - ], $share, [], false |
|
| 4232 | - ]; |
|
| 4233 | - |
|
| 4234 | - // with existing group |
|
| 4235 | - |
|
| 4236 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4237 | - $share->setShareType(IShare::TYPE_GROUP) |
|
| 4238 | - ->setSharedWith('recipientGroup') |
|
| 4239 | - ->setSharedBy('initiator') |
|
| 4240 | - ->setShareOwner('owner') |
|
| 4241 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4242 | - ->setNode($file) |
|
| 4243 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4244 | - ->setTarget('myTarget') |
|
| 4245 | - ->setNote('personal note') |
|
| 4246 | - ->setId(42); |
|
| 4247 | - |
|
| 4248 | - $result[] = [ |
|
| 4249 | - [ |
|
| 4250 | - 'id' => '42', |
|
| 4251 | - 'share_type' => IShare::TYPE_GROUP, |
|
| 4252 | - 'uid_owner' => 'initiator', |
|
| 4253 | - 'displayname_owner' => 'initiator', |
|
| 4254 | - 'permissions' => 1, |
|
| 4255 | - 'attributes' => null, |
|
| 4256 | - 'stime' => 946684862, |
|
| 4257 | - 'parent' => null, |
|
| 4258 | - 'expiration' => null, |
|
| 4259 | - 'token' => null, |
|
| 4260 | - 'uid_file_owner' => 'owner', |
|
| 4261 | - 'displayname_file_owner' => 'owner', |
|
| 4262 | - 'note' => 'personal note', |
|
| 4263 | - 'label' => '', |
|
| 4264 | - 'path' => 'file', |
|
| 4265 | - 'item_type' => 'file', |
|
| 4266 | - 'storage_id' => 'storageId', |
|
| 4267 | - 'storage' => 100, |
|
| 4268 | - 'item_source' => 3, |
|
| 4269 | - 'file_source' => 3, |
|
| 4270 | - 'file_parent' => 1, |
|
| 4271 | - 'file_target' => 'myTarget', |
|
| 4272 | - 'share_with' => 'recipientGroup', |
|
| 4273 | - 'share_with_displayname' => 'recipientGroupDisplayName', |
|
| 4274 | - 'mail_send' => 0, |
|
| 4275 | - 'mimetype' => 'myMimeType', |
|
| 4276 | - 'has_preview' => false, |
|
| 4277 | - 'hide_download' => 0, |
|
| 4278 | - 'can_edit' => false, |
|
| 4279 | - 'can_delete' => false, |
|
| 4280 | - 'item_size' => 123456, |
|
| 4281 | - 'item_mtime' => 1234567890, |
|
| 4282 | - 'is-mount-root' => false, |
|
| 4283 | - 'mount-type' => '', |
|
| 4284 | - 'attributes' => null, |
|
| 4285 | - 'item_permissions' => 1, |
|
| 4286 | - ], $share, [], false |
|
| 4287 | - ]; |
|
| 4288 | - |
|
| 4289 | - // with unknown group / no group backend |
|
| 4290 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4291 | - $share->setShareType(IShare::TYPE_GROUP) |
|
| 4292 | - ->setSharedWith('recipientGroup2') |
|
| 4293 | - ->setSharedBy('initiator') |
|
| 4294 | - ->setShareOwner('owner') |
|
| 4295 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4296 | - ->setNode($file) |
|
| 4297 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4298 | - ->setTarget('myTarget') |
|
| 4299 | - ->setNote('personal note') |
|
| 4300 | - ->setId(42); |
|
| 4301 | - $result[] = [ |
|
| 4302 | - [ |
|
| 4303 | - 'id' => '42', |
|
| 4304 | - 'share_type' => IShare::TYPE_GROUP, |
|
| 4305 | - 'uid_owner' => 'initiator', |
|
| 4306 | - 'displayname_owner' => 'initiator', |
|
| 4307 | - 'permissions' => 1, |
|
| 4308 | - 'stime' => 946684862, |
|
| 4309 | - 'parent' => null, |
|
| 4310 | - 'expiration' => null, |
|
| 4311 | - 'token' => null, |
|
| 4312 | - 'uid_file_owner' => 'owner', |
|
| 4313 | - 'displayname_file_owner' => 'owner', |
|
| 4314 | - 'note' => 'personal note', |
|
| 4315 | - 'label' => '', |
|
| 4316 | - 'path' => 'file', |
|
| 4317 | - 'item_type' => 'file', |
|
| 4318 | - 'storage_id' => 'storageId', |
|
| 4319 | - 'storage' => 100, |
|
| 4320 | - 'item_source' => 3, |
|
| 4321 | - 'file_source' => 3, |
|
| 4322 | - 'file_parent' => 1, |
|
| 4323 | - 'file_target' => 'myTarget', |
|
| 4324 | - 'share_with' => 'recipientGroup2', |
|
| 4325 | - 'share_with_displayname' => 'recipientGroup2', |
|
| 4326 | - 'mail_send' => 0, |
|
| 4327 | - 'mimetype' => 'myMimeType', |
|
| 4328 | - 'has_preview' => false, |
|
| 4329 | - 'hide_download' => 0, |
|
| 4330 | - 'can_edit' => false, |
|
| 4331 | - 'can_delete' => false, |
|
| 4332 | - 'item_size' => 123456, |
|
| 4333 | - 'item_mtime' => 1234567890, |
|
| 4334 | - 'is-mount-root' => false, |
|
| 4335 | - 'mount-type' => '', |
|
| 4336 | - 'attributes' => null, |
|
| 4337 | - 'item_permissions' => 1, |
|
| 4338 | - ], $share, [], false |
|
| 4339 | - ]; |
|
| 4340 | - |
|
| 4341 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4342 | - $share->setShareType(IShare::TYPE_LINK) |
|
| 4343 | - ->setSharedBy('initiator') |
|
| 4344 | - ->setShareOwner('owner') |
|
| 4345 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4346 | - ->setNode($file) |
|
| 4347 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4348 | - ->setTarget('myTarget') |
|
| 4349 | - ->setPassword('mypassword') |
|
| 4350 | - ->setExpirationDate(new \DateTime('2001-01-02T00:00:00')) |
|
| 4351 | - ->setToken('myToken') |
|
| 4352 | - ->setNote('personal note') |
|
| 4353 | - ->setLabel('new link share') |
|
| 4354 | - ->setId(42); |
|
| 4355 | - |
|
| 4356 | - $result[] = [ |
|
| 4357 | - [ |
|
| 4358 | - 'id' => '42', |
|
| 4359 | - 'share_type' => IShare::TYPE_LINK, |
|
| 4360 | - 'uid_owner' => 'initiator', |
|
| 4361 | - 'displayname_owner' => 'initiator', |
|
| 4362 | - 'permissions' => 1, |
|
| 4363 | - 'attributes' => null, |
|
| 4364 | - 'stime' => 946684862, |
|
| 4365 | - 'parent' => null, |
|
| 4366 | - 'expiration' => '2001-01-02 00:00:00', |
|
| 4367 | - 'token' => 'myToken', |
|
| 4368 | - 'uid_file_owner' => 'owner', |
|
| 4369 | - 'displayname_file_owner' => 'owner', |
|
| 4370 | - 'note' => 'personal note', |
|
| 4371 | - 'label' => 'new link share', |
|
| 4372 | - 'path' => 'file', |
|
| 4373 | - 'item_type' => 'file', |
|
| 4374 | - 'storage_id' => 'storageId', |
|
| 4375 | - 'storage' => 100, |
|
| 4376 | - 'item_source' => 3, |
|
| 4377 | - 'file_source' => 3, |
|
| 4378 | - 'file_parent' => 1, |
|
| 4379 | - 'file_target' => 'myTarget', |
|
| 4380 | - 'password' => 'mypassword', |
|
| 4381 | - 'share_with' => 'mypassword', |
|
| 4382 | - 'share_with_displayname' => '(Shared link)', |
|
| 4383 | - 'send_password_by_talk' => false, |
|
| 4384 | - 'mail_send' => 0, |
|
| 4385 | - 'url' => 'myLink', |
|
| 4386 | - 'mimetype' => 'myMimeType', |
|
| 4387 | - 'has_preview' => false, |
|
| 4388 | - 'hide_download' => 0, |
|
| 4389 | - 'can_edit' => false, |
|
| 4390 | - 'can_delete' => false, |
|
| 4391 | - 'item_size' => 123456, |
|
| 4392 | - 'item_mtime' => 1234567890, |
|
| 4393 | - 'is-mount-root' => false, |
|
| 4394 | - 'mount-type' => '', |
|
| 4395 | - 'attributes' => null, |
|
| 4396 | - 'item_permissions' => 1, |
|
| 4397 | - ], $share, [], false |
|
| 4398 | - ]; |
|
| 4399 | - |
|
| 4400 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4401 | - $share->setShareType(IShare::TYPE_LINK) |
|
| 4402 | - ->setSharedBy('initiator') |
|
| 4403 | - ->setShareOwner('owner') |
|
| 4404 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4405 | - ->setNode($file) |
|
| 4406 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4407 | - ->setTarget('myTarget') |
|
| 4408 | - ->setPassword('mypassword') |
|
| 4409 | - ->setSendPasswordByTalk(true) |
|
| 4410 | - ->setExpirationDate(new \DateTime('2001-01-02T00:00:00')) |
|
| 4411 | - ->setToken('myToken') |
|
| 4412 | - ->setNote('personal note') |
|
| 4413 | - ->setLabel('new link share') |
|
| 4414 | - ->setId(42); |
|
| 4415 | - |
|
| 4416 | - $result[] = [ |
|
| 4417 | - [ |
|
| 4418 | - 'id' => '42', |
|
| 4419 | - 'share_type' => IShare::TYPE_LINK, |
|
| 4420 | - 'uid_owner' => 'initiator', |
|
| 4421 | - 'displayname_owner' => 'initiator', |
|
| 4422 | - 'permissions' => 1, |
|
| 4423 | - 'stime' => 946684862, |
|
| 4424 | - 'parent' => null, |
|
| 4425 | - 'expiration' => '2001-01-02 00:00:00', |
|
| 4426 | - 'token' => 'myToken', |
|
| 4427 | - 'uid_file_owner' => 'owner', |
|
| 4428 | - 'displayname_file_owner' => 'owner', |
|
| 4429 | - 'note' => 'personal note', |
|
| 4430 | - 'label' => 'new link share', |
|
| 4431 | - 'path' => 'file', |
|
| 4432 | - 'item_type' => 'file', |
|
| 4433 | - 'storage_id' => 'storageId', |
|
| 4434 | - 'storage' => 100, |
|
| 4435 | - 'item_source' => 3, |
|
| 4436 | - 'file_source' => 3, |
|
| 4437 | - 'file_parent' => 1, |
|
| 4438 | - 'file_target' => 'myTarget', |
|
| 4439 | - 'password' => 'mypassword', |
|
| 4440 | - 'share_with' => 'mypassword', |
|
| 4441 | - 'share_with_displayname' => '(Shared link)', |
|
| 4442 | - 'send_password_by_talk' => true, |
|
| 4443 | - 'mail_send' => 0, |
|
| 4444 | - 'url' => 'myLink', |
|
| 4445 | - 'mimetype' => 'myMimeType', |
|
| 4446 | - 'has_preview' => false, |
|
| 4447 | - 'hide_download' => 0, |
|
| 4448 | - 'can_edit' => false, |
|
| 4449 | - 'can_delete' => false, |
|
| 4450 | - 'item_size' => 123456, |
|
| 4451 | - 'item_mtime' => 1234567890, |
|
| 4452 | - 'is-mount-root' => false, |
|
| 4453 | - 'mount-type' => '', |
|
| 4454 | - 'attributes' => null, |
|
| 4455 | - 'item_permissions' => 1, |
|
| 4456 | - ], $share, [], false |
|
| 4457 | - ]; |
|
| 4458 | - |
|
| 4459 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4460 | - $share->setShareType(IShare::TYPE_REMOTE) |
|
| 4461 | - ->setSharedBy('initiator') |
|
| 4462 | - ->setSharedWith('[email protected]') |
|
| 4463 | - ->setShareOwner('owner') |
|
| 4464 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4465 | - ->setNode($folder) |
|
| 4466 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4467 | - ->setExpirationDate(new \DateTime('2001-02-03T04:05:06')) |
|
| 4468 | - ->setTarget('myTarget') |
|
| 4469 | - ->setNote('personal note') |
|
| 4470 | - ->setId(42); |
|
| 4471 | - |
|
| 4472 | - $result[] = [ |
|
| 4473 | - [ |
|
| 4474 | - 'id' => '42', |
|
| 4475 | - 'share_type' => IShare::TYPE_REMOTE, |
|
| 4476 | - 'uid_owner' => 'initiator', |
|
| 4477 | - 'displayname_owner' => 'initiator', |
|
| 4478 | - 'permissions' => 1, |
|
| 4479 | - 'stime' => 946684862, |
|
| 4480 | - 'parent' => null, |
|
| 4481 | - 'expiration' => '2001-02-03 00:00:00', |
|
| 4482 | - 'token' => null, |
|
| 4483 | - 'uid_file_owner' => 'owner', |
|
| 4484 | - 'displayname_file_owner' => 'owner', |
|
| 4485 | - 'note' => 'personal note', |
|
| 4486 | - 'label' => '', |
|
| 4487 | - 'path' => 'folder', |
|
| 4488 | - 'item_type' => 'folder', |
|
| 4489 | - 'storage_id' => 'storageId', |
|
| 4490 | - 'storage' => 100, |
|
| 4491 | - 'item_source' => 2, |
|
| 4492 | - 'file_source' => 2, |
|
| 4493 | - 'file_parent' => 1, |
|
| 4494 | - 'file_target' => 'myTarget', |
|
| 4495 | - 'share_with' => '[email protected]', |
|
| 4496 | - 'share_with_displayname' => 'foobar', |
|
| 4497 | - 'mail_send' => 0, |
|
| 4498 | - 'mimetype' => 'myFolderMimeType', |
|
| 4499 | - 'has_preview' => false, |
|
| 4500 | - 'hide_download' => 0, |
|
| 4501 | - 'can_edit' => false, |
|
| 4502 | - 'can_delete' => false, |
|
| 4503 | - 'item_size' => 123456, |
|
| 4504 | - 'item_mtime' => 1234567890, |
|
| 4505 | - 'is-mount-root' => false, |
|
| 4506 | - 'mount-type' => '', |
|
| 4507 | - 'attributes' => null, |
|
| 4508 | - 'item_permissions' => 1, |
|
| 4509 | - 'is_trusted_server' => false, |
|
| 4510 | - ], $share, [], false |
|
| 4511 | - ]; |
|
| 4512 | - |
|
| 4513 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4514 | - $share->setShareType(IShare::TYPE_REMOTE_GROUP) |
|
| 4515 | - ->setSharedBy('initiator') |
|
| 4516 | - ->setSharedWith('[email protected]') |
|
| 4517 | - ->setShareOwner('owner') |
|
| 4518 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4519 | - ->setNode($folder) |
|
| 4520 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4521 | - ->setExpirationDate(new \DateTime('2001-02-03T04:05:06')) |
|
| 4522 | - ->setTarget('myTarget') |
|
| 4523 | - ->setNote('personal note') |
|
| 4524 | - ->setId(42); |
|
| 4525 | - |
|
| 4526 | - $result[] = [ |
|
| 4527 | - [ |
|
| 4528 | - 'id' => '42', |
|
| 4529 | - 'share_type' => IShare::TYPE_REMOTE_GROUP, |
|
| 4530 | - 'uid_owner' => 'initiator', |
|
| 4531 | - 'displayname_owner' => 'initiator', |
|
| 4532 | - 'permissions' => 1, |
|
| 4533 | - 'stime' => 946684862, |
|
| 4534 | - 'parent' => null, |
|
| 4535 | - 'expiration' => '2001-02-03 00:00:00', |
|
| 4536 | - 'token' => null, |
|
| 4537 | - 'uid_file_owner' => 'owner', |
|
| 4538 | - 'displayname_file_owner' => 'owner', |
|
| 4539 | - 'note' => 'personal note', |
|
| 4540 | - 'label' => '', |
|
| 4541 | - 'path' => 'folder', |
|
| 4542 | - 'item_type' => 'folder', |
|
| 4543 | - 'storage_id' => 'storageId', |
|
| 4544 | - 'storage' => 100, |
|
| 4545 | - 'item_source' => 2, |
|
| 4546 | - 'file_source' => 2, |
|
| 4547 | - 'file_parent' => 1, |
|
| 4548 | - 'file_target' => 'myTarget', |
|
| 4549 | - 'share_with' => '[email protected]', |
|
| 4550 | - 'share_with_displayname' => 'foobar', |
|
| 4551 | - 'mail_send' => 0, |
|
| 4552 | - 'mimetype' => 'myFolderMimeType', |
|
| 4553 | - 'has_preview' => false, |
|
| 4554 | - 'hide_download' => 0, |
|
| 4555 | - 'can_edit' => false, |
|
| 4556 | - 'can_delete' => false, |
|
| 4557 | - 'item_size' => 123456, |
|
| 4558 | - 'item_mtime' => 1234567890, |
|
| 4559 | - 'is-mount-root' => false, |
|
| 4560 | - 'mount-type' => '', |
|
| 4561 | - 'attributes' => null, |
|
| 4562 | - 'item_permissions' => 1, |
|
| 4563 | - 'is_trusted_server' => false, |
|
| 4564 | - ], $share, [], false |
|
| 4565 | - ]; |
|
| 4566 | - |
|
| 4567 | - // Circle with id, display name and avatar set by the Circles app |
|
| 4568 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4569 | - $share->setShareType(IShare::TYPE_CIRCLE) |
|
| 4570 | - ->setSharedBy('initiator') |
|
| 4571 | - ->setSharedWith('Circle (Public circle, circleOwner) [4815162342]') |
|
| 4572 | - ->setSharedWithDisplayName('The display name') |
|
| 4573 | - ->setSharedWithAvatar('path/to/the/avatar') |
|
| 4574 | - ->setShareOwner('owner') |
|
| 4575 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4576 | - ->setNode($folder) |
|
| 4577 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4578 | - ->setTarget('myTarget') |
|
| 4579 | - ->setId(42); |
|
| 4580 | - |
|
| 4581 | - $result[] = [ |
|
| 4582 | - [ |
|
| 4583 | - 'id' => '42', |
|
| 4584 | - 'share_type' => IShare::TYPE_CIRCLE, |
|
| 4585 | - 'uid_owner' => 'initiator', |
|
| 4586 | - 'displayname_owner' => 'initiator', |
|
| 4587 | - 'permissions' => 1, |
|
| 4588 | - 'attributes' => null, |
|
| 4589 | - 'stime' => 946684862, |
|
| 4590 | - 'parent' => null, |
|
| 4591 | - 'expiration' => null, |
|
| 4592 | - 'token' => null, |
|
| 4593 | - 'uid_file_owner' => 'owner', |
|
| 4594 | - 'displayname_file_owner' => 'owner', |
|
| 4595 | - 'note' => '', |
|
| 4596 | - 'label' => '', |
|
| 4597 | - 'path' => 'folder', |
|
| 4598 | - 'item_type' => 'folder', |
|
| 4599 | - 'storage_id' => 'storageId', |
|
| 4600 | - 'storage' => 100, |
|
| 4601 | - 'item_source' => 2, |
|
| 4602 | - 'file_source' => 2, |
|
| 4603 | - 'file_parent' => 1, |
|
| 4604 | - 'file_target' => 'myTarget', |
|
| 4605 | - 'share_with' => '4815162342', |
|
| 4606 | - 'share_with_displayname' => 'The display name', |
|
| 4607 | - 'share_with_avatar' => 'path/to/the/avatar', |
|
| 4608 | - 'mail_send' => 0, |
|
| 4609 | - 'mimetype' => 'myFolderMimeType', |
|
| 4610 | - 'has_preview' => false, |
|
| 4611 | - 'hide_download' => 0, |
|
| 4612 | - 'can_edit' => false, |
|
| 4613 | - 'can_delete' => false, |
|
| 4614 | - 'item_size' => 123456, |
|
| 4615 | - 'item_mtime' => 1234567890, |
|
| 4616 | - 'is-mount-root' => false, |
|
| 4617 | - 'mount-type' => '', |
|
| 4618 | - 'attributes' => null, |
|
| 4619 | - 'item_permissions' => 1, |
|
| 4620 | - ], $share, [], false |
|
| 4621 | - ]; |
|
| 4622 | - |
|
| 4623 | - // Circle with id set by the Circles app |
|
| 4624 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4625 | - $share->setShareType(IShare::TYPE_CIRCLE) |
|
| 4626 | - ->setSharedBy('initiator') |
|
| 4627 | - ->setSharedWith('Circle (Public circle, circleOwner) [4815162342]') |
|
| 4628 | - ->setShareOwner('owner') |
|
| 4629 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4630 | - ->setNode($folder) |
|
| 4631 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4632 | - ->setTarget('myTarget') |
|
| 4633 | - ->setId(42); |
|
| 4634 | - |
|
| 4635 | - $result[] = [ |
|
| 4636 | - [ |
|
| 4637 | - 'id' => '42', |
|
| 4638 | - 'share_type' => IShare::TYPE_CIRCLE, |
|
| 4639 | - 'uid_owner' => 'initiator', |
|
| 4640 | - 'displayname_owner' => 'initiator', |
|
| 4641 | - 'permissions' => 1, |
|
| 4642 | - 'stime' => 946684862, |
|
| 4643 | - 'parent' => null, |
|
| 4644 | - 'expiration' => null, |
|
| 4645 | - 'token' => null, |
|
| 4646 | - 'uid_file_owner' => 'owner', |
|
| 4647 | - 'displayname_file_owner' => 'owner', |
|
| 4648 | - 'note' => '', |
|
| 4649 | - 'label' => '', |
|
| 4650 | - 'path' => 'folder', |
|
| 4651 | - 'item_type' => 'folder', |
|
| 4652 | - 'storage_id' => 'storageId', |
|
| 4653 | - 'storage' => 100, |
|
| 4654 | - 'item_source' => 2, |
|
| 4655 | - 'file_source' => 2, |
|
| 4656 | - 'file_parent' => 1, |
|
| 4657 | - 'file_target' => 'myTarget', |
|
| 4658 | - 'share_with' => '4815162342', |
|
| 4659 | - 'share_with_displayname' => 'Circle (Public circle, circleOwner)', |
|
| 4660 | - 'share_with_avatar' => '', |
|
| 4661 | - 'mail_send' => 0, |
|
| 4662 | - 'mimetype' => 'myFolderMimeType', |
|
| 4663 | - 'has_preview' => false, |
|
| 4664 | - 'hide_download' => 0, |
|
| 4665 | - 'can_edit' => false, |
|
| 4666 | - 'can_delete' => false, |
|
| 4667 | - 'item_size' => 123456, |
|
| 4668 | - 'item_mtime' => 1234567890, |
|
| 4669 | - 'is-mount-root' => false, |
|
| 4670 | - 'mount-type' => '', |
|
| 4671 | - 'attributes' => null, |
|
| 4672 | - 'item_permissions' => 1, |
|
| 4673 | - ], $share, [], false |
|
| 4674 | - ]; |
|
| 4675 | - |
|
| 4676 | - // Circle with id not set by the Circles app |
|
| 4677 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4678 | - $share->setShareType(IShare::TYPE_CIRCLE) |
|
| 4679 | - ->setSharedBy('initiator') |
|
| 4680 | - ->setSharedWith('Circle (Public circle, circleOwner)') |
|
| 4681 | - ->setShareOwner('owner') |
|
| 4682 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4683 | - ->setNode($folder) |
|
| 4684 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4685 | - ->setTarget('myTarget') |
|
| 4686 | - ->setId(42); |
|
| 4687 | - |
|
| 4688 | - $result[] = [ |
|
| 4689 | - [ |
|
| 4690 | - 'id' => '42', |
|
| 4691 | - 'share_type' => IShare::TYPE_CIRCLE, |
|
| 4692 | - 'uid_owner' => 'initiator', |
|
| 4693 | - 'displayname_owner' => 'initiator', |
|
| 4694 | - 'permissions' => 1, |
|
| 4695 | - 'stime' => 946684862, |
|
| 4696 | - 'parent' => null, |
|
| 4697 | - 'expiration' => null, |
|
| 4698 | - 'token' => null, |
|
| 4699 | - 'uid_file_owner' => 'owner', |
|
| 4700 | - 'displayname_file_owner' => 'owner', |
|
| 4701 | - 'note' => '', |
|
| 4702 | - 'label' => '', |
|
| 4703 | - 'path' => 'folder', |
|
| 4704 | - 'item_type' => 'folder', |
|
| 4705 | - 'storage_id' => 'storageId', |
|
| 4706 | - 'storage' => 100, |
|
| 4707 | - 'item_source' => 2, |
|
| 4708 | - 'file_source' => 2, |
|
| 4709 | - 'file_parent' => 1, |
|
| 4710 | - 'file_target' => 'myTarget', |
|
| 4711 | - 'share_with' => 'Circle', |
|
| 4712 | - 'share_with_displayname' => 'Circle (Public circle, circleOwner)', |
|
| 4713 | - 'share_with_avatar' => '', |
|
| 4714 | - 'mail_send' => 0, |
|
| 4715 | - 'mimetype' => 'myFolderMimeType', |
|
| 4716 | - 'has_preview' => false, |
|
| 4717 | - 'hide_download' => 0, |
|
| 4718 | - 'can_edit' => false, |
|
| 4719 | - 'can_delete' => false, |
|
| 4720 | - 'item_size' => 123456, |
|
| 4721 | - 'item_mtime' => 1234567890, |
|
| 4722 | - 'is-mount-root' => false, |
|
| 4723 | - 'mount-type' => '', |
|
| 4724 | - 'attributes' => null, |
|
| 4725 | - 'item_permissions' => 1, |
|
| 4726 | - ], $share, [], false |
|
| 4727 | - ]; |
|
| 4728 | - |
|
| 4729 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4730 | - $share->setShareType(IShare::TYPE_USER) |
|
| 4731 | - ->setSharedBy('initiator') |
|
| 4732 | - ->setSharedWith('recipient') |
|
| 4733 | - ->setShareOwner('owner') |
|
| 4734 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4735 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4736 | - ->setTarget('myTarget') |
|
| 4737 | - ->setNote('personal note') |
|
| 4738 | - ->setId(42); |
|
| 4739 | - |
|
| 4740 | - $result[] = [ |
|
| 4741 | - [], $share, [], true |
|
| 4742 | - ]; |
|
| 4743 | - |
|
| 4744 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4745 | - $share->setShareType(IShare::TYPE_EMAIL) |
|
| 4746 | - ->setSharedBy('initiator') |
|
| 4747 | - ->setSharedWith('[email protected]') |
|
| 4748 | - ->setShareOwner('owner') |
|
| 4749 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4750 | - ->setNode($folder) |
|
| 4751 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4752 | - ->setTarget('myTarget') |
|
| 4753 | - ->setId(42) |
|
| 4754 | - ->setPassword('password'); |
|
| 4755 | - |
|
| 4756 | - $result[] = [ |
|
| 4757 | - [ |
|
| 4758 | - 'id' => '42', |
|
| 4759 | - 'share_type' => IShare::TYPE_EMAIL, |
|
| 4760 | - 'uid_owner' => 'initiator', |
|
| 4761 | - 'displayname_owner' => 'initiator', |
|
| 4762 | - 'permissions' => 1, |
|
| 4763 | - 'stime' => 946684862, |
|
| 4764 | - 'parent' => null, |
|
| 4765 | - 'expiration' => null, |
|
| 4766 | - 'token' => null, |
|
| 4767 | - 'uid_file_owner' => 'owner', |
|
| 4768 | - 'displayname_file_owner' => 'owner', |
|
| 4769 | - 'note' => '', |
|
| 4770 | - 'label' => '', |
|
| 4771 | - 'path' => 'folder', |
|
| 4772 | - 'item_type' => 'folder', |
|
| 4773 | - 'storage_id' => 'storageId', |
|
| 4774 | - 'storage' => 100, |
|
| 4775 | - 'item_source' => 2, |
|
| 4776 | - 'file_source' => 2, |
|
| 4777 | - 'file_parent' => 1, |
|
| 4778 | - 'file_target' => 'myTarget', |
|
| 4779 | - 'share_with' => '[email protected]', |
|
| 4780 | - 'share_with_displayname' => 'mail display name', |
|
| 4781 | - 'mail_send' => 0, |
|
| 4782 | - 'mimetype' => 'myFolderMimeType', |
|
| 4783 | - 'has_preview' => false, |
|
| 4784 | - 'password' => 'password', |
|
| 4785 | - 'send_password_by_talk' => false, |
|
| 4786 | - 'hide_download' => 0, |
|
| 4787 | - 'can_edit' => false, |
|
| 4788 | - 'can_delete' => false, |
|
| 4789 | - 'password_expiration_time' => null, |
|
| 4790 | - 'item_size' => 123456, |
|
| 4791 | - 'item_mtime' => 1234567890, |
|
| 4792 | - 'is-mount-root' => false, |
|
| 4793 | - 'mount-type' => '', |
|
| 4794 | - 'attributes' => null, |
|
| 4795 | - 'item_permissions' => 1, |
|
| 4796 | - ], $share, [], false |
|
| 4797 | - ]; |
|
| 4798 | - |
|
| 4799 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4800 | - $share->setShareType(IShare::TYPE_EMAIL) |
|
| 4801 | - ->setSharedBy('initiator') |
|
| 4802 | - ->setSharedWith('[email protected]') |
|
| 4803 | - ->setShareOwner('owner') |
|
| 4804 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4805 | - ->setNode($folder) |
|
| 4806 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4807 | - ->setTarget('myTarget') |
|
| 4808 | - ->setId(42) |
|
| 4809 | - ->setPassword('password') |
|
| 4810 | - ->setSendPasswordByTalk(true); |
|
| 4811 | - |
|
| 4812 | - $result[] = [ |
|
| 4813 | - [ |
|
| 4814 | - 'id' => '42', |
|
| 4815 | - 'share_type' => IShare::TYPE_EMAIL, |
|
| 4816 | - 'uid_owner' => 'initiator', |
|
| 4817 | - 'displayname_owner' => 'initiator', |
|
| 4818 | - 'permissions' => 1, |
|
| 4819 | - 'stime' => 946684862, |
|
| 4820 | - 'parent' => null, |
|
| 4821 | - 'expiration' => null, |
|
| 4822 | - 'token' => null, |
|
| 4823 | - 'uid_file_owner' => 'owner', |
|
| 4824 | - 'displayname_file_owner' => 'owner', |
|
| 4825 | - 'note' => '', |
|
| 4826 | - 'label' => '', |
|
| 4827 | - 'path' => 'folder', |
|
| 4828 | - 'item_type' => 'folder', |
|
| 4829 | - 'storage_id' => 'storageId', |
|
| 4830 | - 'storage' => 100, |
|
| 4831 | - 'item_source' => 2, |
|
| 4832 | - 'file_source' => 2, |
|
| 4833 | - 'file_parent' => 1, |
|
| 4834 | - 'file_target' => 'myTarget', |
|
| 4835 | - 'share_with' => '[email protected]', |
|
| 4836 | - 'share_with_displayname' => 'mail display name', |
|
| 4837 | - 'mail_send' => 0, |
|
| 4838 | - 'mimetype' => 'myFolderMimeType', |
|
| 4839 | - 'has_preview' => false, |
|
| 4840 | - 'password' => 'password', |
|
| 4841 | - 'send_password_by_talk' => true, |
|
| 4842 | - 'hide_download' => 0, |
|
| 4843 | - 'can_edit' => false, |
|
| 4844 | - 'can_delete' => false, |
|
| 4845 | - 'password_expiration_time' => null, |
|
| 4846 | - 'item_size' => 123456, |
|
| 4847 | - 'item_mtime' => 1234567890, |
|
| 4848 | - 'is-mount-root' => false, |
|
| 4849 | - 'mount-type' => '', |
|
| 4850 | - 'attributes' => null, |
|
| 4851 | - 'item_permissions' => 1, |
|
| 4852 | - ], $share, [], false |
|
| 4853 | - ]; |
|
| 4854 | - |
|
| 4855 | - // Preview is available |
|
| 4856 | - $share = Server::get(IManager::class)->newShare(); |
|
| 4857 | - $share->setShareType(IShare::TYPE_USER) |
|
| 4858 | - ->setSharedWith('recipient') |
|
| 4859 | - ->setSharedBy('initiator') |
|
| 4860 | - ->setShareOwner('currentUser') |
|
| 4861 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 4862 | - ->setNode($fileWithPreview) |
|
| 4863 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4864 | - ->setTarget('myTarget') |
|
| 4865 | - ->setNote('personal note') |
|
| 4866 | - ->setId(42); |
|
| 4867 | - |
|
| 4868 | - $result[] = [ |
|
| 4869 | - [ |
|
| 4870 | - 'id' => '42', |
|
| 4871 | - 'share_type' => IShare::TYPE_USER, |
|
| 4872 | - 'uid_owner' => 'initiator', |
|
| 4873 | - 'displayname_owner' => 'initiator', |
|
| 4874 | - 'permissions' => 1, |
|
| 4875 | - 'stime' => 946684862, |
|
| 4876 | - 'parent' => null, |
|
| 4877 | - 'expiration' => null, |
|
| 4878 | - 'token' => null, |
|
| 4879 | - 'uid_file_owner' => 'currentUser', |
|
| 4880 | - 'displayname_file_owner' => 'currentUser', |
|
| 4881 | - 'note' => 'personal note', |
|
| 4882 | - 'label' => '', |
|
| 4883 | - 'path' => 'fileWithPreview', |
|
| 4884 | - 'item_type' => 'file', |
|
| 4885 | - 'storage_id' => 'storageId', |
|
| 4886 | - 'storage' => 100, |
|
| 4887 | - 'item_source' => 4, |
|
| 4888 | - 'file_source' => 4, |
|
| 4889 | - 'file_parent' => 1, |
|
| 4890 | - 'file_target' => 'myTarget', |
|
| 4891 | - 'share_with' => 'recipient', |
|
| 4892 | - 'share_with_displayname' => 'recipient', |
|
| 4893 | - 'share_with_displayname_unique' => 'recipient', |
|
| 4894 | - 'mail_send' => 0, |
|
| 4895 | - 'mimetype' => 'mimeWithPreview', |
|
| 4896 | - 'has_preview' => true, |
|
| 4897 | - 'hide_download' => 0, |
|
| 4898 | - 'can_edit' => true, |
|
| 4899 | - 'can_delete' => true, |
|
| 4900 | - 'item_size' => 123456, |
|
| 4901 | - 'item_mtime' => 1234567890, |
|
| 4902 | - 'is-mount-root' => false, |
|
| 4903 | - 'mount-type' => '', |
|
| 4904 | - 'attributes' => null, |
|
| 4905 | - 'item_permissions' => 11, |
|
| 4906 | - ], $share, [], false |
|
| 4907 | - ]; |
|
| 4908 | - |
|
| 4909 | - return $result; |
|
| 4910 | - } |
|
| 4911 | - |
|
| 4912 | - /** |
|
| 4913 | - * |
|
| 4914 | - * @param array $expects |
|
| 4915 | - * @param IShare $share |
|
| 4916 | - * @param array $users |
|
| 4917 | - * @param $exception |
|
| 4918 | - */ |
|
| 4919 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFormatShare')] |
|
| 4920 | - public function testFormatShare(array $expects, IShare $share, array $users, $exception): void { |
|
| 4921 | - $this->userManager->method('get')->willReturnMap($users); |
|
| 4922 | - |
|
| 4923 | - $recipientGroup = $this->createMock(IGroup::class); |
|
| 4924 | - $recipientGroup->method('getDisplayName')->willReturn('recipientGroupDisplayName'); |
|
| 4925 | - $this->groupManager->method('get')->willReturnMap([ |
|
| 4926 | - ['recipientGroup', $recipientGroup], |
|
| 4927 | - ]); |
|
| 4928 | - |
|
| 4929 | - $this->urlGenerator->method('linkToRouteAbsolute') |
|
| 4930 | - ->with('files_sharing.sharecontroller.showShare', ['token' => 'myToken']) |
|
| 4931 | - ->willReturn('myLink'); |
|
| 4932 | - |
|
| 4933 | - $this->rootFolder->method('getUserFolder') |
|
| 4934 | - ->with($this->currentUser) |
|
| 4935 | - ->willReturnSelf(); |
|
| 4936 | - $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC')); |
|
| 4937 | - |
|
| 4938 | - if (!$exception) { |
|
| 4939 | - $this->rootFolder->method('getFirstNodeById') |
|
| 4940 | - ->with($share->getNodeId()) |
|
| 4941 | - ->willReturn($share->getNode()); |
|
| 4942 | - |
|
| 4943 | - $this->rootFolder->method('getRelativePath') |
|
| 4944 | - ->with($share->getNode()->getPath()) |
|
| 4945 | - ->willReturnArgument(0); |
|
| 4946 | - } |
|
| 4947 | - |
|
| 4948 | - $cm = $this->createMock(\OCP\Contacts\IManager::class); |
|
| 4949 | - $this->overwriteService(\OCP\Contacts\IManager::class, $cm); |
|
| 4950 | - |
|
| 4951 | - $cm->method('search') |
|
| 4952 | - ->willReturnMap([ |
|
| 4953 | - ['[email protected]', ['CLOUD'], [ |
|
| 4954 | - 'limit' => 1, |
|
| 4955 | - 'enumeration' => false, |
|
| 4956 | - 'strict_search' => true, |
|
| 4957 | - ], |
|
| 4958 | - [ |
|
| 4959 | - [ |
|
| 4960 | - 'CLOUD' => [ |
|
| 4961 | - '[email protected]', |
|
| 4962 | - ], |
|
| 4963 | - 'FN' => 'foobar', |
|
| 4964 | - ], |
|
| 4965 | - ], |
|
| 4966 | - ], |
|
| 4967 | - ['[email protected]', ['EMAIL'], [ |
|
| 4968 | - 'limit' => 1, |
|
| 4969 | - 'enumeration' => false, |
|
| 4970 | - 'strict_search' => true, |
|
| 4971 | - ], |
|
| 4972 | - [ |
|
| 4973 | - [ |
|
| 4974 | - 'EMAIL' => [ |
|
| 4975 | - '[email protected]', |
|
| 4976 | - ], |
|
| 4977 | - 'FN' => 'mail display name', |
|
| 4978 | - ], |
|
| 4979 | - ], |
|
| 4980 | - ], |
|
| 4981 | - ]); |
|
| 4982 | - |
|
| 4983 | - try { |
|
| 4984 | - $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); |
|
| 4985 | - $this->assertFalse($exception); |
|
| 4986 | - $this->assertEquals($expects, $result); |
|
| 4987 | - } catch (NotFoundException $e) { |
|
| 4988 | - $this->assertTrue($exception); |
|
| 4989 | - } |
|
| 4990 | - } |
|
| 4991 | - |
|
| 4992 | - public function dataFormatRoomShare() { |
|
| 4993 | - $file = $this->getMockBuilder(File::class)->getMock(); |
|
| 4994 | - $parent = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 4995 | - |
|
| 4996 | - $file->method('getMimeType')->willReturn('myMimeType'); |
|
| 4997 | - |
|
| 4998 | - $file->method('getPath')->willReturn('file'); |
|
| 4999 | - |
|
| 5000 | - $parent->method('getId')->willReturn(1); |
|
| 5001 | - $file->method('getId')->willReturn(3); |
|
| 5002 | - |
|
| 5003 | - $file->method('getParent')->willReturn($parent); |
|
| 5004 | - |
|
| 5005 | - $file->method('getSize')->willReturn(123456); |
|
| 5006 | - $file->method('getMTime')->willReturn(1234567890); |
|
| 5007 | - |
|
| 5008 | - $mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock(); |
|
| 5009 | - $mountPoint->method('getMountType')->willReturn(''); |
|
| 5010 | - $file->method('getMountPoint')->willReturn($mountPoint); |
|
| 5011 | - |
|
| 5012 | - $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock(); |
|
| 5013 | - $cache->method('getNumericStorageId')->willReturn(100); |
|
| 5014 | - $storage = $this->createMock(IStorage::class); |
|
| 5015 | - $storage->method('getId')->willReturn('storageId'); |
|
| 5016 | - $storage->method('getCache')->willReturn($cache); |
|
| 5017 | - |
|
| 5018 | - $file->method('getStorage')->willReturn($storage); |
|
| 5019 | - |
|
| 5020 | - $result = []; |
|
| 5021 | - |
|
| 5022 | - $share = Server::get(IManager::class)->newShare(); |
|
| 5023 | - $share->setShareType(IShare::TYPE_ROOM) |
|
| 5024 | - ->setSharedWith('recipientRoom') |
|
| 5025 | - ->setSharedBy('initiator') |
|
| 5026 | - ->setShareOwner('owner') |
|
| 5027 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 5028 | - ->setNode($file) |
|
| 5029 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 5030 | - ->setTarget('myTarget') |
|
| 5031 | - ->setNote('personal note') |
|
| 5032 | - ->setId(42); |
|
| 5033 | - |
|
| 5034 | - $result[] = [ |
|
| 5035 | - [ |
|
| 5036 | - 'id' => '42', |
|
| 5037 | - 'share_type' => IShare::TYPE_ROOM, |
|
| 5038 | - 'uid_owner' => 'initiator', |
|
| 5039 | - 'displayname_owner' => 'initiator', |
|
| 5040 | - 'permissions' => 1, |
|
| 5041 | - 'stime' => 946684862, |
|
| 5042 | - 'parent' => null, |
|
| 5043 | - 'expiration' => null, |
|
| 5044 | - 'token' => null, |
|
| 5045 | - 'uid_file_owner' => 'owner', |
|
| 5046 | - 'displayname_file_owner' => 'owner', |
|
| 5047 | - 'note' => 'personal note', |
|
| 5048 | - 'path' => 'file', |
|
| 5049 | - 'item_type' => 'file', |
|
| 5050 | - 'storage_id' => 'storageId', |
|
| 5051 | - 'storage' => 100, |
|
| 5052 | - 'item_source' => 3, |
|
| 5053 | - 'file_source' => 3, |
|
| 5054 | - 'file_parent' => 1, |
|
| 5055 | - 'file_target' => 'myTarget', |
|
| 5056 | - 'share_with' => 'recipientRoom', |
|
| 5057 | - 'share_with_displayname' => '', |
|
| 5058 | - 'mail_send' => 0, |
|
| 5059 | - 'mimetype' => 'myMimeType', |
|
| 5060 | - 'has_preview' => false, |
|
| 5061 | - 'hide_download' => 0, |
|
| 5062 | - 'label' => '', |
|
| 5063 | - 'can_edit' => false, |
|
| 5064 | - 'can_delete' => false, |
|
| 5065 | - 'item_size' => 123456, |
|
| 5066 | - 'item_mtime' => 1234567890, |
|
| 5067 | - 'is-mount-root' => false, |
|
| 5068 | - 'mount-type' => '', |
|
| 5069 | - 'attributes' => null, |
|
| 5070 | - 'item_permissions' => 1, |
|
| 5071 | - ], $share, false, [] |
|
| 5072 | - ]; |
|
| 5073 | - |
|
| 5074 | - $share = Server::get(IManager::class)->newShare(); |
|
| 5075 | - $share->setShareType(IShare::TYPE_ROOM) |
|
| 5076 | - ->setSharedWith('recipientRoom') |
|
| 5077 | - ->setSharedBy('initiator') |
|
| 5078 | - ->setShareOwner('owner') |
|
| 5079 | - ->setPermissions(Constants::PERMISSION_READ) |
|
| 5080 | - ->setNode($file) |
|
| 5081 | - ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 5082 | - ->setTarget('myTarget') |
|
| 5083 | - ->setNote('personal note') |
|
| 5084 | - ->setId(42); |
|
| 5085 | - |
|
| 5086 | - $result[] = [ |
|
| 5087 | - [ |
|
| 5088 | - 'id' => '42', |
|
| 5089 | - 'share_type' => IShare::TYPE_ROOM, |
|
| 5090 | - 'uid_owner' => 'initiator', |
|
| 5091 | - 'displayname_owner' => 'initiator', |
|
| 5092 | - 'permissions' => 1, |
|
| 5093 | - 'stime' => 946684862, |
|
| 5094 | - 'parent' => null, |
|
| 5095 | - 'expiration' => null, |
|
| 5096 | - 'token' => null, |
|
| 5097 | - 'uid_file_owner' => 'owner', |
|
| 5098 | - 'displayname_file_owner' => 'owner', |
|
| 5099 | - 'note' => 'personal note', |
|
| 5100 | - 'path' => 'file', |
|
| 5101 | - 'item_type' => 'file', |
|
| 5102 | - 'storage_id' => 'storageId', |
|
| 5103 | - 'storage' => 100, |
|
| 5104 | - 'item_source' => 3, |
|
| 5105 | - 'file_source' => 3, |
|
| 5106 | - 'file_parent' => 1, |
|
| 5107 | - 'file_target' => 'myTarget', |
|
| 5108 | - 'share_with' => 'recipientRoom', |
|
| 5109 | - 'share_with_displayname' => 'recipientRoomName', |
|
| 5110 | - 'mail_send' => 0, |
|
| 5111 | - 'mimetype' => 'myMimeType', |
|
| 5112 | - 'has_preview' => false, |
|
| 5113 | - 'hide_download' => 0, |
|
| 5114 | - 'label' => '', |
|
| 5115 | - 'can_edit' => false, |
|
| 5116 | - 'can_delete' => false, |
|
| 5117 | - 'item_size' => 123456, |
|
| 5118 | - 'item_mtime' => 1234567890, |
|
| 5119 | - 'is-mount-root' => false, |
|
| 5120 | - 'mount-type' => '', |
|
| 5121 | - 'attributes' => null, |
|
| 5122 | - 'item_permissions' => 9, |
|
| 5123 | - ], $share, true, [ |
|
| 5124 | - 'share_with_displayname' => 'recipientRoomName' |
|
| 5125 | - ] |
|
| 5126 | - ]; |
|
| 5127 | - |
|
| 5128 | - return $result; |
|
| 5129 | - } |
|
| 5130 | - |
|
| 5131 | - /** |
|
| 5132 | - * |
|
| 5133 | - * @param array $expects |
|
| 5134 | - * @param IShare $share |
|
| 5135 | - * @param bool $helperAvailable |
|
| 5136 | - * @param array $formatShareByHelper |
|
| 5137 | - */ |
|
| 5138 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataFormatRoomShare')] |
|
| 5139 | - public function testFormatRoomShare(array $expects, IShare $share, bool $helperAvailable, array $formatShareByHelper): void { |
|
| 5140 | - $this->rootFolder->method('getUserFolder') |
|
| 5141 | - ->with($this->currentUser) |
|
| 5142 | - ->willReturnSelf(); |
|
| 5143 | - |
|
| 5144 | - $this->rootFolder->method('getFirstNodeById') |
|
| 5145 | - ->with($share->getNodeId()) |
|
| 5146 | - ->willReturn($share->getNode()); |
|
| 5147 | - |
|
| 5148 | - $this->rootFolder->method('getRelativePath') |
|
| 5149 | - ->with($share->getNode()->getPath()) |
|
| 5150 | - ->willReturnArgument(0); |
|
| 5151 | - |
|
| 5152 | - if (!$helperAvailable) { |
|
| 5153 | - $this->appManager->method('isEnabledForUser') |
|
| 5154 | - ->with('spreed') |
|
| 5155 | - ->willReturn(false); |
|
| 5156 | - } else { |
|
| 5157 | - $this->appManager->method('isEnabledForUser') |
|
| 5158 | - ->with('spreed') |
|
| 5159 | - ->willReturn(true); |
|
| 5160 | - |
|
| 5161 | - // This is not possible anymore with PHPUnit 10+ |
|
| 5162 | - // as `setMethods` was removed and now real reflection is used, thus the class needs to exist. |
|
| 5163 | - // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 5164 | - $helper = $this->getMockBuilder(\stdClass::class) |
|
| 5165 | - ->addMethods(['formatShare', 'canAccessShare']) |
|
| 5166 | - ->getMock(); |
|
| 5167 | - $helper->method('formatShare') |
|
| 5168 | - ->with($share) |
|
| 5169 | - ->willReturn($formatShareByHelper); |
|
| 5170 | - $helper->method('canAccessShare') |
|
| 5171 | - ->with($share) |
|
| 5172 | - ->willReturn(true); |
|
| 5173 | - |
|
| 5174 | - $this->serverContainer->method('get') |
|
| 5175 | - ->with('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 5176 | - ->willReturn($helper); |
|
| 5177 | - } |
|
| 5178 | - |
|
| 5179 | - $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); |
|
| 5180 | - $this->assertEquals($expects, $result); |
|
| 5181 | - } |
|
| 5182 | - |
|
| 5183 | - /** |
|
| 5184 | - * @return list{Folder, Folder} |
|
| 5185 | - */ |
|
| 5186 | - private function getNonSharedUserFolder(): array { |
|
| 5187 | - $node = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 5188 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 5189 | - $storage = $this->createMock(IStorage::class); |
|
| 5190 | - $storage->method('instanceOfStorage') |
|
| 5191 | - ->willReturnMap([ |
|
| 5192 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 5193 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 5194 | - ]); |
|
| 5195 | - $userFolder->method('getStorage')->willReturn($storage); |
|
| 5196 | - $node->method('getStorage')->willReturn($storage); |
|
| 5197 | - $node->method('getId')->willReturn(42); |
|
| 5198 | - $user = $this->createMock(IUser::class); |
|
| 5199 | - $user->method('getUID')->willReturn($this->currentUser); |
|
| 5200 | - $node->method('getOwner')->willReturn($user); |
|
| 5201 | - return [$userFolder, $node]; |
|
| 5202 | - } |
|
| 5203 | - |
|
| 5204 | - /** |
|
| 5205 | - * @return list{Folder, File} |
|
| 5206 | - */ |
|
| 5207 | - private function getNonSharedUserFile(): array { |
|
| 5208 | - $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 5209 | - $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 5210 | - $storage = $this->createMock(IStorage::class); |
|
| 5211 | - $storage->method('instanceOfStorage') |
|
| 5212 | - ->willReturnMap([ |
|
| 5213 | - ['OCA\Files_Sharing\External\Storage', false], |
|
| 5214 | - ['OCA\Files_Sharing\SharedStorage', false], |
|
| 5215 | - ]); |
|
| 5216 | - $userFolder->method('getStorage')->willReturn($storage); |
|
| 5217 | - $node->method('getStorage')->willReturn($storage); |
|
| 5218 | - $node->method('getId')->willReturn(42); |
|
| 5219 | - return [$userFolder, $node]; |
|
| 5220 | - } |
|
| 5221 | - |
|
| 5222 | - public function testPopulateTags(): void { |
|
| 5223 | - $tagger = $this->createMock(ITags::class); |
|
| 5224 | - $this->tagManager->method('load') |
|
| 5225 | - ->with('files') |
|
| 5226 | - ->willReturn($tagger); |
|
| 5227 | - $data = [ |
|
| 5228 | - ['file_source' => 10], |
|
| 5229 | - ['file_source' => 22, 'foo' => 'bar'], |
|
| 5230 | - ['file_source' => 42, 'x' => 'y'], |
|
| 5231 | - ]; |
|
| 5232 | - $tags = [ |
|
| 5233 | - 10 => ['tag3'], |
|
| 5234 | - 42 => ['tag1', 'tag2'], |
|
| 5235 | - ]; |
|
| 5236 | - $tagger->method('getTagsForObjects') |
|
| 5237 | - ->with([10, 22, 42]) |
|
| 5238 | - ->willReturn($tags); |
|
| 5239 | - |
|
| 5240 | - $result = self::invokePrivate($this->ocs, 'populateTags', [$data]); |
|
| 5241 | - $this->assertSame([ |
|
| 5242 | - ['file_source' => 10, 'tags' => ['tag3']], |
|
| 5243 | - ['file_source' => 22, 'foo' => 'bar', 'tags' => []], |
|
| 5244 | - ['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']], |
|
| 5245 | - ], $result); |
|
| 5246 | - } |
|
| 5247 | - |
|
| 5248 | - public static function trustedServerProvider(): array { |
|
| 5249 | - return [ |
|
| 5250 | - 'Trusted server' => [true, true], |
|
| 5251 | - 'Untrusted server' => [false, false], |
|
| 5252 | - ]; |
|
| 5253 | - } |
|
| 5254 | - |
|
| 5255 | - /** |
|
| 5256 | - * @dataProvider trustedServerProvider |
|
| 5257 | - */ |
|
| 5258 | - public function testFormatShareWithFederatedShare(bool $isKnownServer, bool $isTrusted): void { |
|
| 5259 | - $nodeId = 12; |
|
| 5260 | - $nodePath = '/test.txt'; |
|
| 5261 | - $share = $this->createShare( |
|
| 5262 | - 1, |
|
| 5263 | - IShare::TYPE_REMOTE, |
|
| 5264 | - '[email protected]', // shared with |
|
| 5265 | - '[email protected]', // shared by |
|
| 5266 | - 'shareOwner', // share owner |
|
| 5267 | - $nodePath, // path |
|
| 5268 | - Constants::PERMISSION_READ, |
|
| 5269 | - time(), |
|
| 5270 | - null, |
|
| 5271 | - null, |
|
| 5272 | - $nodePath, |
|
| 5273 | - $nodeId |
|
| 5274 | - ); |
|
| 5275 | - |
|
| 5276 | - $node = $this->createMock(File::class); |
|
| 5277 | - $node->method('getId')->willReturn($nodeId); |
|
| 5278 | - $node->method('getPath')->willReturn($nodePath); |
|
| 5279 | - $node->method('getInternalPath')->willReturn(ltrim($nodePath, '/')); |
|
| 5280 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 5281 | - $mountPoint->method('getMountType')->willReturn('local'); |
|
| 5282 | - $node->method('getMountPoint')->willReturn($mountPoint); |
|
| 5283 | - $node->method('getMimetype')->willReturn('text/plain'); |
|
| 5284 | - $storage = $this->createMock(IStorage::class); |
|
| 5285 | - $storageCache = $this->createMock(ICache::class); |
|
| 5286 | - $storageCache->method('getNumericStorageId')->willReturn(1); |
|
| 5287 | - $storage->method('getCache')->willReturn($storageCache); |
|
| 5288 | - $storage->method('getId')->willReturn('home::shareOwner'); |
|
| 5289 | - $node->method('getStorage')->willReturn($storage); |
|
| 5290 | - $parent = $this->createMock(Folder::class); |
|
| 5291 | - $parent->method('getId')->willReturn(2); |
|
| 5292 | - $node->method('getParent')->willReturn($parent); |
|
| 5293 | - $node->method('getSize')->willReturn(1234); |
|
| 5294 | - $node->method('getMTime')->willReturn(1234567890); |
|
| 5295 | - |
|
| 5296 | - $this->previewManager->method('isAvailable')->with($node)->willReturn(false); |
|
| 5297 | - |
|
| 5298 | - $this->rootFolder->method('getUserFolder') |
|
| 5299 | - ->with($this->currentUser) |
|
| 5300 | - ->willReturnSelf(); |
|
| 5301 | - |
|
| 5302 | - $this->rootFolder->method('getFirstNodeById') |
|
| 5303 | - ->with($share->getNodeId()) |
|
| 5304 | - ->willReturn($node); |
|
| 5305 | - |
|
| 5306 | - $this->rootFolder->method('getRelativePath') |
|
| 5307 | - ->with($node->getPath()) |
|
| 5308 | - ->willReturnArgument(0); |
|
| 5309 | - |
|
| 5310 | - $serverName = 'remoteserver.com'; |
|
| 5311 | - $this->trustedServers->method('isTrustedServer') |
|
| 5312 | - ->with($serverName) |
|
| 5313 | - ->willReturn($isKnownServer); |
|
| 5314 | - |
|
| 5315 | - $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); |
|
| 5316 | - |
|
| 5317 | - $this->assertSame($isTrusted, $result['is_trusted_server']); |
|
| 5318 | - } |
|
| 5319 | - |
|
| 5320 | - public function testFormatShareWithFederatedShareWithAtInUsername(): void { |
|
| 5321 | - $nodeId = 12; |
|
| 5322 | - $nodePath = '/test.txt'; |
|
| 5323 | - $share = $this->createShare( |
|
| 5324 | - 1, |
|
| 5325 | - IShare::TYPE_REMOTE, |
|
| 5326 | - '[email protected]@remoteserver.com', |
|
| 5327 | - '[email protected]', |
|
| 5328 | - 'shareOwner', |
|
| 5329 | - $nodePath, |
|
| 5330 | - Constants::PERMISSION_READ, |
|
| 5331 | - time(), |
|
| 5332 | - null, |
|
| 5333 | - null, |
|
| 5334 | - $nodePath, |
|
| 5335 | - $nodeId |
|
| 5336 | - ); |
|
| 5337 | - |
|
| 5338 | - $node = $this->createMock(File::class); |
|
| 5339 | - $node->method('getId')->willReturn($nodeId); |
|
| 5340 | - $node->method('getPath')->willReturn($nodePath); |
|
| 5341 | - $node->method('getInternalPath')->willReturn(ltrim($nodePath, '/')); |
|
| 5342 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 5343 | - $mountPoint->method('getMountType')->willReturn('local'); |
|
| 5344 | - $node->method('getMountPoint')->willReturn($mountPoint); |
|
| 5345 | - $node->method('getMimetype')->willReturn('text/plain'); |
|
| 5346 | - $storage = $this->createMock(IStorage::class); |
|
| 5347 | - $storageCache = $this->createMock(ICache::class); |
|
| 5348 | - $storageCache->method('getNumericStorageId')->willReturn(1); |
|
| 5349 | - $storage->method('getCache')->willReturn($storageCache); |
|
| 5350 | - $storage->method('getId')->willReturn('home::shareOwner'); |
|
| 5351 | - $node->method('getStorage')->willReturn($storage); |
|
| 5352 | - $parent = $this->createMock(Folder::class); |
|
| 5353 | - $parent->method('getId')->willReturn(2); |
|
| 5354 | - $node->method('getParent')->willReturn($parent); |
|
| 5355 | - $node->method('getSize')->willReturn(1234); |
|
| 5356 | - $node->method('getMTime')->willReturn(1234567890); |
|
| 5357 | - |
|
| 5358 | - $this->previewManager->method('isAvailable')->with($node)->willReturn(false); |
|
| 5359 | - |
|
| 5360 | - $this->rootFolder->method('getUserFolder') |
|
| 5361 | - ->with($this->currentUser) |
|
| 5362 | - ->willReturnSelf(); |
|
| 5363 | - |
|
| 5364 | - $this->rootFolder->method('getFirstNodeById') |
|
| 5365 | - ->with($share->getNodeId()) |
|
| 5366 | - ->willReturn($node); |
|
| 5367 | - |
|
| 5368 | - $this->rootFolder->method('getRelativePath') |
|
| 5369 | - ->with($node->getPath()) |
|
| 5370 | - ->willReturnArgument(0); |
|
| 5371 | - |
|
| 5372 | - $serverName = 'remoteserver.com'; |
|
| 5373 | - $this->trustedServers->method('isTrustedServer') |
|
| 5374 | - ->with($serverName) |
|
| 5375 | - ->willReturn(true); |
|
| 5376 | - |
|
| 5377 | - $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); |
|
| 5378 | - |
|
| 5379 | - $this->assertTrue($result['is_trusted_server']); |
|
| 5380 | - } |
|
| 585 | + public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions, |
|
| 586 | + $shareTime, $expiration, $parent, $target, $mail_send, $note = '', $token = null, |
|
| 587 | + $password = null, $label = '', $attributes = null) { |
|
| 588 | + $share = $this->getMockBuilder(IShare::class)->getMock(); |
|
| 589 | + $share->method('getId')->willReturn($id); |
|
| 590 | + $share->method('getShareType')->willReturn($shareType); |
|
| 591 | + $share->method('getSharedWith')->willReturn($sharedWith); |
|
| 592 | + $share->method('getSharedBy')->willReturn($sharedBy); |
|
| 593 | + $share->method('getShareOwner')->willReturn($shareOwner); |
|
| 594 | + $share->method('getNode')->willReturn($path); |
|
| 595 | + $share->method('getPermissions')->willReturn($permissions); |
|
| 596 | + $share->method('getNote')->willReturn($note); |
|
| 597 | + $share->method('getLabel')->willReturn($label); |
|
| 598 | + $share->method('getAttributes')->willReturn($attributes); |
|
| 599 | + $time = new \DateTime(); |
|
| 600 | + $time->setTimestamp($shareTime); |
|
| 601 | + $share->method('getShareTime')->willReturn($time); |
|
| 602 | + $share->method('getExpirationDate')->willReturn($expiration); |
|
| 603 | + $share->method('getTarget')->willReturn($target); |
|
| 604 | + $share->method('getMailSend')->willReturn($mail_send); |
|
| 605 | + $share->method('getToken')->willReturn($token); |
|
| 606 | + $share->method('getPassword')->willReturn($password); |
|
| 607 | + |
|
| 608 | + if ($shareType === IShare::TYPE_USER |
|
| 609 | + || $shareType === IShare::TYPE_GROUP |
|
| 610 | + || $shareType === IShare::TYPE_LINK) { |
|
| 611 | + $share->method('getFullId')->willReturn('ocinternal:' . $id); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + return $share; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + public function dataGetShare() { |
|
| 618 | + $data = []; |
|
| 619 | + |
|
| 620 | + $cache = $this->getMockBuilder('OC\Files\Cache\Cache') |
|
| 621 | + ->disableOriginalConstructor() |
|
| 622 | + ->getMock(); |
|
| 623 | + $cache->method('getNumericStorageId')->willReturn(101); |
|
| 624 | + |
|
| 625 | + $storage = $this->getMockBuilder(IStorage::class) |
|
| 626 | + ->disableOriginalConstructor() |
|
| 627 | + ->getMock(); |
|
| 628 | + $storage->method('getId')->willReturn('STORAGE'); |
|
| 629 | + $storage->method('getCache')->willReturn($cache); |
|
| 630 | + |
|
| 631 | + $parentFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 632 | + $parentFolder->method('getId')->willReturn(3); |
|
| 633 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 634 | + $mountPoint->method('getMountType')->willReturn(''); |
|
| 635 | + |
|
| 636 | + $file = $this->getMockBuilder('OCP\Files\File')->getMock(); |
|
| 637 | + $file->method('getId')->willReturn(1); |
|
| 638 | + $file->method('getPath')->willReturn('file'); |
|
| 639 | + $file->method('getStorage')->willReturn($storage); |
|
| 640 | + $file->method('getParent')->willReturn($parentFolder); |
|
| 641 | + $file->method('getSize')->willReturn(123465); |
|
| 642 | + $file->method('getMTime')->willReturn(1234567890); |
|
| 643 | + $file->method('getMimeType')->willReturn('myMimeType'); |
|
| 644 | + $file->method('getMountPoint')->willReturn($mountPoint); |
|
| 645 | + |
|
| 646 | + $folder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 647 | + $folder->method('getId')->willReturn(2); |
|
| 648 | + $folder->method('getPath')->willReturn('folder'); |
|
| 649 | + $folder->method('getStorage')->willReturn($storage); |
|
| 650 | + $folder->method('getParent')->willReturn($parentFolder); |
|
| 651 | + $folder->method('getSize')->willReturn(123465); |
|
| 652 | + $folder->method('getMTime')->willReturn(1234567890); |
|
| 653 | + $folder->method('getMimeType')->willReturn('myFolderMimeType'); |
|
| 654 | + $folder->method('getMountPoint')->willReturn($mountPoint); |
|
| 655 | + |
|
| 656 | + [$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes(); |
|
| 657 | + |
|
| 658 | + // File shared with user |
|
| 659 | + $share = $this->createShare( |
|
| 660 | + 100, |
|
| 661 | + IShare::TYPE_USER, |
|
| 662 | + 'userId', |
|
| 663 | + 'initiatorId', |
|
| 664 | + 'ownerId', |
|
| 665 | + $file, |
|
| 666 | + 4, |
|
| 667 | + 5, |
|
| 668 | + null, |
|
| 669 | + 6, |
|
| 670 | + 'target', |
|
| 671 | + 0, |
|
| 672 | + 'personal note', |
|
| 673 | + $shareAttributes, |
|
| 674 | + ); |
|
| 675 | + $expected = [ |
|
| 676 | + 'id' => 100, |
|
| 677 | + 'share_type' => IShare::TYPE_USER, |
|
| 678 | + 'share_with' => 'userId', |
|
| 679 | + 'share_with_displayname' => 'userDisplay', |
|
| 680 | + 'share_with_displayname_unique' => '[email protected]', |
|
| 681 | + 'uid_owner' => 'initiatorId', |
|
| 682 | + 'displayname_owner' => 'initiatorDisplay', |
|
| 683 | + 'item_type' => 'file', |
|
| 684 | + 'item_source' => 1, |
|
| 685 | + 'file_source' => 1, |
|
| 686 | + 'file_target' => 'target', |
|
| 687 | + 'file_parent' => 3, |
|
| 688 | + 'token' => null, |
|
| 689 | + 'expiration' => null, |
|
| 690 | + 'permissions' => 4, |
|
| 691 | + 'attributes' => $shareAttributesReturnJson, |
|
| 692 | + 'stime' => 5, |
|
| 693 | + 'parent' => null, |
|
| 694 | + 'storage_id' => 'STORAGE', |
|
| 695 | + 'path' => 'file', |
|
| 696 | + 'storage' => 101, |
|
| 697 | + 'mail_send' => 0, |
|
| 698 | + 'uid_file_owner' => 'ownerId', |
|
| 699 | + 'note' => 'personal note', |
|
| 700 | + 'label' => '', |
|
| 701 | + 'displayname_file_owner' => 'ownerDisplay', |
|
| 702 | + 'mimetype' => 'myMimeType', |
|
| 703 | + 'has_preview' => false, |
|
| 704 | + 'hide_download' => 0, |
|
| 705 | + 'can_edit' => false, |
|
| 706 | + 'can_delete' => false, |
|
| 707 | + 'item_size' => 123465, |
|
| 708 | + 'item_mtime' => 1234567890, |
|
| 709 | + 'attributes' => null, |
|
| 710 | + 'item_permissions' => 4, |
|
| 711 | + 'is-mount-root' => false, |
|
| 712 | + 'mount-type' => '', |
|
| 713 | + ]; |
|
| 714 | + $data[] = [$share, $expected]; |
|
| 715 | + |
|
| 716 | + // Folder shared with group |
|
| 717 | + $share = $this->createShare( |
|
| 718 | + 101, |
|
| 719 | + IShare::TYPE_GROUP, |
|
| 720 | + 'groupId', |
|
| 721 | + 'initiatorId', |
|
| 722 | + 'ownerId', |
|
| 723 | + $folder, |
|
| 724 | + 4, |
|
| 725 | + 5, |
|
| 726 | + null, |
|
| 727 | + 6, |
|
| 728 | + 'target', |
|
| 729 | + 0, |
|
| 730 | + 'personal note', |
|
| 731 | + $shareAttributes, |
|
| 732 | + ); |
|
| 733 | + $expected = [ |
|
| 734 | + 'id' => 101, |
|
| 735 | + 'share_type' => IShare::TYPE_GROUP, |
|
| 736 | + 'share_with' => 'groupId', |
|
| 737 | + 'share_with_displayname' => 'groupId', |
|
| 738 | + 'uid_owner' => 'initiatorId', |
|
| 739 | + 'displayname_owner' => 'initiatorDisplay', |
|
| 740 | + 'item_type' => 'folder', |
|
| 741 | + 'item_source' => 2, |
|
| 742 | + 'file_source' => 2, |
|
| 743 | + 'file_target' => 'target', |
|
| 744 | + 'file_parent' => 3, |
|
| 745 | + 'token' => null, |
|
| 746 | + 'expiration' => null, |
|
| 747 | + 'permissions' => 4, |
|
| 748 | + 'attributes' => $shareAttributesReturnJson, |
|
| 749 | + 'stime' => 5, |
|
| 750 | + 'parent' => null, |
|
| 751 | + 'storage_id' => 'STORAGE', |
|
| 752 | + 'path' => 'folder', |
|
| 753 | + 'storage' => 101, |
|
| 754 | + 'mail_send' => 0, |
|
| 755 | + 'uid_file_owner' => 'ownerId', |
|
| 756 | + 'note' => 'personal note', |
|
| 757 | + 'label' => '', |
|
| 758 | + 'displayname_file_owner' => 'ownerDisplay', |
|
| 759 | + 'mimetype' => 'myFolderMimeType', |
|
| 760 | + 'has_preview' => false, |
|
| 761 | + 'hide_download' => 0, |
|
| 762 | + 'can_edit' => false, |
|
| 763 | + 'can_delete' => false, |
|
| 764 | + 'item_size' => 123465, |
|
| 765 | + 'item_mtime' => 1234567890, |
|
| 766 | + 'attributes' => null, |
|
| 767 | + 'item_permissions' => 4, |
|
| 768 | + 'is-mount-root' => false, |
|
| 769 | + 'mount-type' => '', |
|
| 770 | + ]; |
|
| 771 | + $data[] = [$share, $expected]; |
|
| 772 | + |
|
| 773 | + // File shared by link with Expire |
|
| 774 | + $expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03'); |
|
| 775 | + $share = $this->createShare( |
|
| 776 | + 101, |
|
| 777 | + IShare::TYPE_LINK, |
|
| 778 | + null, |
|
| 779 | + 'initiatorId', |
|
| 780 | + 'ownerId', |
|
| 781 | + $folder, |
|
| 782 | + 4, |
|
| 783 | + 5, |
|
| 784 | + $expire, |
|
| 785 | + 6, |
|
| 786 | + 'target', |
|
| 787 | + 0, |
|
| 788 | + 'personal note', |
|
| 789 | + 'token', |
|
| 790 | + 'password', |
|
| 791 | + 'first link share' |
|
| 792 | + ); |
|
| 793 | + $expected = [ |
|
| 794 | + 'id' => 101, |
|
| 795 | + 'share_type' => IShare::TYPE_LINK, |
|
| 796 | + 'password' => 'password', |
|
| 797 | + 'share_with' => 'password', |
|
| 798 | + 'share_with_displayname' => '(Shared link)', |
|
| 799 | + 'send_password_by_talk' => false, |
|
| 800 | + 'uid_owner' => 'initiatorId', |
|
| 801 | + 'displayname_owner' => 'initiatorDisplay', |
|
| 802 | + 'item_type' => 'folder', |
|
| 803 | + 'item_source' => 2, |
|
| 804 | + 'file_source' => 2, |
|
| 805 | + 'file_target' => 'target', |
|
| 806 | + 'file_parent' => 3, |
|
| 807 | + 'token' => 'token', |
|
| 808 | + 'expiration' => '2000-01-02 00:00:00', |
|
| 809 | + 'permissions' => 4, |
|
| 810 | + 'attributes' => null, |
|
| 811 | + 'stime' => 5, |
|
| 812 | + 'parent' => null, |
|
| 813 | + 'storage_id' => 'STORAGE', |
|
| 814 | + 'path' => 'folder', |
|
| 815 | + 'storage' => 101, |
|
| 816 | + 'mail_send' => 0, |
|
| 817 | + 'url' => 'url', |
|
| 818 | + 'uid_file_owner' => 'ownerId', |
|
| 819 | + 'note' => 'personal note', |
|
| 820 | + 'label' => 'first link share', |
|
| 821 | + 'displayname_file_owner' => 'ownerDisplay', |
|
| 822 | + 'mimetype' => 'myFolderMimeType', |
|
| 823 | + 'has_preview' => false, |
|
| 824 | + 'hide_download' => 0, |
|
| 825 | + 'can_edit' => false, |
|
| 826 | + 'can_delete' => false, |
|
| 827 | + 'item_size' => 123465, |
|
| 828 | + 'item_mtime' => 1234567890, |
|
| 829 | + 'attributes' => null, |
|
| 830 | + 'item_permissions' => 4, |
|
| 831 | + 'is-mount-root' => false, |
|
| 832 | + 'mount-type' => '', |
|
| 833 | + ]; |
|
| 834 | + $data[] = [$share, $expected]; |
|
| 835 | + |
|
| 836 | + return $data; |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetShare')] |
|
| 840 | + public function testGetShare(IShare $share, array $result): void { |
|
| 841 | + /** @var ShareAPIController&MockObject $ocs */ |
|
| 842 | + $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 843 | + ->setConstructorArgs([ |
|
| 844 | + $this->appName, |
|
| 845 | + $this->request, |
|
| 846 | + $this->shareManager, |
|
| 847 | + $this->groupManager, |
|
| 848 | + $this->userManager, |
|
| 849 | + $this->rootFolder, |
|
| 850 | + $this->urlGenerator, |
|
| 851 | + $this->l, |
|
| 852 | + $this->config, |
|
| 853 | + $this->appConfig, |
|
| 854 | + $this->appManager, |
|
| 855 | + $this->serverContainer, |
|
| 856 | + $this->userStatusManager, |
|
| 857 | + $this->previewManager, |
|
| 858 | + $this->dateTimeZone, |
|
| 859 | + $this->logger, |
|
| 860 | + $this->factory, |
|
| 861 | + $this->mailer, |
|
| 862 | + $this->tagManager, |
|
| 863 | + $this->trustedServers, |
|
| 864 | + $this->currentUser, |
|
| 865 | + ]) |
|
| 866 | + ->onlyMethods(['canAccessShare']) |
|
| 867 | + ->getMock(); |
|
| 868 | + |
|
| 869 | + $ocs->expects($this->any()) |
|
| 870 | + ->method('canAccessShare') |
|
| 871 | + ->willReturn(true); |
|
| 872 | + |
|
| 873 | + $this->shareManager |
|
| 874 | + ->expects($this->any()) |
|
| 875 | + ->method('getShareById') |
|
| 876 | + ->with($share->getFullId(), 'currentUser') |
|
| 877 | + ->willReturn($share); |
|
| 878 | + |
|
| 879 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 880 | + $userFolder |
|
| 881 | + ->method('getRelativePath') |
|
| 882 | + ->willReturnArgument(0); |
|
| 883 | + |
|
| 884 | + $userFolder->method('getById') |
|
| 885 | + ->with($share->getNodeId()) |
|
| 886 | + ->willReturn([$share->getNode()]); |
|
| 887 | + $userFolder->method('getFirstNodeById') |
|
| 888 | + ->with($share->getNodeId()) |
|
| 889 | + ->willReturn($share->getNode()); |
|
| 890 | + |
|
| 891 | + $this->rootFolder->method('getUserFolder') |
|
| 892 | + ->with($this->currentUser) |
|
| 893 | + ->willReturn($userFolder); |
|
| 894 | + |
|
| 895 | + $this->urlGenerator |
|
| 896 | + ->method('linkToRouteAbsolute') |
|
| 897 | + ->willReturn('url'); |
|
| 898 | + |
|
| 899 | + $initiator = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 900 | + $initiator->method('getUID')->willReturn('initiatorId'); |
|
| 901 | + $initiator->method('getDisplayName')->willReturn('initiatorDisplay'); |
|
| 902 | + |
|
| 903 | + $owner = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 904 | + $owner->method('getUID')->willReturn('ownerId'); |
|
| 905 | + $owner->method('getDisplayName')->willReturn('ownerDisplay'); |
|
| 906 | + |
|
| 907 | + $user = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 908 | + $user->method('getUID')->willReturn('userId'); |
|
| 909 | + $user->method('getDisplayName')->willReturn('userDisplay'); |
|
| 910 | + $user->method('getSystemEMailAddress')->willReturn('[email protected]'); |
|
| 911 | + |
|
| 912 | + $group = $this->getMockBuilder(IGroup::class)->getMock(); |
|
| 913 | + $group->method('getGID')->willReturn('groupId'); |
|
| 914 | + |
|
| 915 | + $this->userManager->method('get')->willReturnMap([ |
|
| 916 | + ['userId', $user], |
|
| 917 | + ['initiatorId', $initiator], |
|
| 918 | + ['ownerId', $owner], |
|
| 919 | + ]); |
|
| 920 | + $this->groupManager->method('get')->willReturnMap([ |
|
| 921 | + ['group', $group], |
|
| 922 | + ]); |
|
| 923 | + $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC')); |
|
| 924 | + |
|
| 925 | + $data = $ocs->getShare($share->getId())->getData()[0]; |
|
| 926 | + $this->assertEquals($result, $data); |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + public function testGetShareInvalidNode(): void { |
|
| 931 | + $this->expectException(OCSNotFoundException::class); |
|
| 932 | + $this->expectExceptionMessage('Wrong share ID, share does not exist'); |
|
| 933 | + |
|
| 934 | + $share = Server::get(IManager::class)->newShare(); |
|
| 935 | + $share->setSharedBy('initiator') |
|
| 936 | + ->setSharedWith('recipient') |
|
| 937 | + ->setShareOwner('owner'); |
|
| 938 | + |
|
| 939 | + $this->shareManager |
|
| 940 | + ->expects($this->once()) |
|
| 941 | + ->method('getShareById') |
|
| 942 | + ->with('ocinternal:42', 'currentUser') |
|
| 943 | + ->willReturn($share); |
|
| 944 | + |
|
| 945 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 946 | + $this->rootFolder->method('getUserFolder') |
|
| 947 | + ->with($this->currentUser) |
|
| 948 | + ->willReturn($userFolder); |
|
| 949 | + |
|
| 950 | + $this->ocs->getShare(42); |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + public function dataGetShares() { |
|
| 954 | + $folder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 955 | + $file1 = $this->getMockBuilder(File::class)->getMock(); |
|
| 956 | + $file1->method('getName') |
|
| 957 | + ->willReturn('file1'); |
|
| 958 | + $file2 = $this->getMockBuilder(File::class)->getMock(); |
|
| 959 | + $file2->method('getName') |
|
| 960 | + ->willReturn('file2'); |
|
| 961 | + |
|
| 962 | + $folder->method('getDirectoryListing') |
|
| 963 | + ->willReturn([$file1, $file2]); |
|
| 964 | + |
|
| 965 | + $file1UserShareOwner = Server::get(IManager::class)->newShare(); |
|
| 966 | + $file1UserShareOwner->setShareType(IShare::TYPE_USER) |
|
| 967 | + ->setSharedWith('recipient') |
|
| 968 | + ->setSharedBy('initiator') |
|
| 969 | + ->setShareOwner('currentUser') |
|
| 970 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 971 | + ->setNode($file1) |
|
| 972 | + ->setId(4); |
|
| 973 | + |
|
| 974 | + $file1UserShareOwnerExpected = [ |
|
| 975 | + 'id' => 4, |
|
| 976 | + 'share_type' => IShare::TYPE_USER, |
|
| 977 | + ]; |
|
| 978 | + |
|
| 979 | + $file1UserShareInitiator = Server::get(IManager::class)->newShare(); |
|
| 980 | + $file1UserShareInitiator->setShareType(IShare::TYPE_USER) |
|
| 981 | + ->setSharedWith('recipient') |
|
| 982 | + ->setSharedBy('currentUser') |
|
| 983 | + ->setShareOwner('owner') |
|
| 984 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 985 | + ->setNode($file1) |
|
| 986 | + ->setId(8); |
|
| 987 | + |
|
| 988 | + $file1UserShareInitiatorExpected = [ |
|
| 989 | + 'id' => 8, |
|
| 990 | + 'share_type' => IShare::TYPE_USER, |
|
| 991 | + ]; |
|
| 992 | + |
|
| 993 | + $file1UserShareRecipient = Server::get(IManager::class)->newShare(); |
|
| 994 | + $file1UserShareRecipient->setShareType(IShare::TYPE_USER) |
|
| 995 | + ->setSharedWith('currentUser') |
|
| 996 | + ->setSharedBy('initiator') |
|
| 997 | + ->setShareOwner('owner') |
|
| 998 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 999 | + ->setNode($file1) |
|
| 1000 | + ->setId(15); |
|
| 1001 | + |
|
| 1002 | + $file1UserShareRecipientExpected = [ |
|
| 1003 | + 'id' => 15, |
|
| 1004 | + 'share_type' => IShare::TYPE_USER, |
|
| 1005 | + ]; |
|
| 1006 | + |
|
| 1007 | + $file1UserShareOther = Server::get(IManager::class)->newShare(); |
|
| 1008 | + $file1UserShareOther->setShareType(IShare::TYPE_USER) |
|
| 1009 | + ->setSharedWith('recipient') |
|
| 1010 | + ->setSharedBy('initiator') |
|
| 1011 | + ->setShareOwner('owner') |
|
| 1012 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1013 | + ->setNode($file1) |
|
| 1014 | + ->setId(16); |
|
| 1015 | + |
|
| 1016 | + $file1UserShareOtherExpected = [ |
|
| 1017 | + 'id' => 16, |
|
| 1018 | + 'share_type' => IShare::TYPE_USER, |
|
| 1019 | + ]; |
|
| 1020 | + |
|
| 1021 | + $file1GroupShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1022 | + $file1GroupShareOwner->setShareType(IShare::TYPE_GROUP) |
|
| 1023 | + ->setSharedWith('recipient') |
|
| 1024 | + ->setSharedBy('initiator') |
|
| 1025 | + ->setShareOwner('currentUser') |
|
| 1026 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1027 | + ->setNode($file1) |
|
| 1028 | + ->setId(23); |
|
| 1029 | + |
|
| 1030 | + $file1GroupShareOwnerExpected = [ |
|
| 1031 | + 'id' => 23, |
|
| 1032 | + 'share_type' => IShare::TYPE_GROUP, |
|
| 1033 | + ]; |
|
| 1034 | + |
|
| 1035 | + $file1GroupShareRecipient = Server::get(IManager::class)->newShare(); |
|
| 1036 | + $file1GroupShareRecipient->setShareType(IShare::TYPE_GROUP) |
|
| 1037 | + ->setSharedWith('currentUserGroup') |
|
| 1038 | + ->setSharedBy('initiator') |
|
| 1039 | + ->setShareOwner('owner') |
|
| 1040 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1041 | + ->setNode($file1) |
|
| 1042 | + ->setId(42); |
|
| 1043 | + |
|
| 1044 | + $file1GroupShareRecipientExpected = [ |
|
| 1045 | + 'id' => 42, |
|
| 1046 | + 'share_type' => IShare::TYPE_GROUP, |
|
| 1047 | + ]; |
|
| 1048 | + |
|
| 1049 | + $file1GroupShareOther = Server::get(IManager::class)->newShare(); |
|
| 1050 | + $file1GroupShareOther->setShareType(IShare::TYPE_GROUP) |
|
| 1051 | + ->setSharedWith('recipient') |
|
| 1052 | + ->setSharedBy('initiator') |
|
| 1053 | + ->setShareOwner('owner') |
|
| 1054 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1055 | + ->setNode($file1) |
|
| 1056 | + ->setId(108); |
|
| 1057 | + |
|
| 1058 | + $file1LinkShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1059 | + $file1LinkShareOwner->setShareType(IShare::TYPE_LINK) |
|
| 1060 | + ->setSharedWith('recipient') |
|
| 1061 | + ->setSharedBy('initiator') |
|
| 1062 | + ->setShareOwner('currentUser') |
|
| 1063 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1064 | + ->setNode($file1) |
|
| 1065 | + ->setId(415); |
|
| 1066 | + |
|
| 1067 | + $file1LinkShareOwnerExpected = [ |
|
| 1068 | + 'id' => 415, |
|
| 1069 | + 'share_type' => IShare::TYPE_LINK, |
|
| 1070 | + ]; |
|
| 1071 | + |
|
| 1072 | + $file1EmailShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1073 | + $file1EmailShareOwner->setShareType(IShare::TYPE_EMAIL) |
|
| 1074 | + ->setSharedWith('recipient') |
|
| 1075 | + ->setSharedBy('initiator') |
|
| 1076 | + ->setShareOwner('currentUser') |
|
| 1077 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1078 | + ->setNode($file1) |
|
| 1079 | + ->setId(416); |
|
| 1080 | + |
|
| 1081 | + $file1EmailShareOwnerExpected = [ |
|
| 1082 | + 'id' => 416, |
|
| 1083 | + 'share_type' => IShare::TYPE_EMAIL, |
|
| 1084 | + ]; |
|
| 1085 | + |
|
| 1086 | + $file1CircleShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1087 | + $file1CircleShareOwner->setShareType(IShare::TYPE_CIRCLE) |
|
| 1088 | + ->setSharedWith('recipient') |
|
| 1089 | + ->setSharedBy('initiator') |
|
| 1090 | + ->setShareOwner('currentUser') |
|
| 1091 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1092 | + ->setNode($file1) |
|
| 1093 | + ->setId(423); |
|
| 1094 | + |
|
| 1095 | + $file1CircleShareOwnerExpected = [ |
|
| 1096 | + 'id' => 423, |
|
| 1097 | + 'share_type' => IShare::TYPE_CIRCLE, |
|
| 1098 | + ]; |
|
| 1099 | + |
|
| 1100 | + $file1RoomShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1101 | + $file1RoomShareOwner->setShareType(IShare::TYPE_ROOM) |
|
| 1102 | + ->setSharedWith('recipient') |
|
| 1103 | + ->setSharedBy('initiator') |
|
| 1104 | + ->setShareOwner('currentUser') |
|
| 1105 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1106 | + ->setNode($file1) |
|
| 1107 | + ->setId(442); |
|
| 1108 | + |
|
| 1109 | + $file1RoomShareOwnerExpected = [ |
|
| 1110 | + 'id' => 442, |
|
| 1111 | + 'share_type' => IShare::TYPE_ROOM, |
|
| 1112 | + ]; |
|
| 1113 | + |
|
| 1114 | + $file1RemoteShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1115 | + $file1RemoteShareOwner->setShareType(IShare::TYPE_REMOTE) |
|
| 1116 | + ->setSharedWith('recipient') |
|
| 1117 | + ->setSharedBy('initiator') |
|
| 1118 | + ->setShareOwner('currentUser') |
|
| 1119 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1120 | + ->setExpirationDate(new \DateTime('2000-01-01T01:02:03')) |
|
| 1121 | + ->setNode($file1) |
|
| 1122 | + ->setId(815); |
|
| 1123 | + |
|
| 1124 | + $file1RemoteShareOwnerExpected = [ |
|
| 1125 | + 'id' => 815, |
|
| 1126 | + 'share_type' => IShare::TYPE_REMOTE, |
|
| 1127 | + ]; |
|
| 1128 | + |
|
| 1129 | + $file1RemoteGroupShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1130 | + $file1RemoteGroupShareOwner->setShareType(IShare::TYPE_REMOTE_GROUP) |
|
| 1131 | + ->setSharedWith('recipient') |
|
| 1132 | + ->setSharedBy('initiator') |
|
| 1133 | + ->setShareOwner('currentUser') |
|
| 1134 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1135 | + ->setExpirationDate(new \DateTime('2000-01-02T01:02:03')) |
|
| 1136 | + ->setNode($file1) |
|
| 1137 | + ->setId(816); |
|
| 1138 | + |
|
| 1139 | + $file1RemoteGroupShareOwnerExpected = [ |
|
| 1140 | + 'id' => 816, |
|
| 1141 | + 'share_type' => IShare::TYPE_REMOTE_GROUP, |
|
| 1142 | + ]; |
|
| 1143 | + |
|
| 1144 | + $file2UserShareOwner = Server::get(IManager::class)->newShare(); |
|
| 1145 | + $file2UserShareOwner->setShareType(IShare::TYPE_USER) |
|
| 1146 | + ->setSharedWith('recipient') |
|
| 1147 | + ->setSharedBy('initiator') |
|
| 1148 | + ->setShareOwner('currentUser') |
|
| 1149 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 1150 | + ->setNode($file2) |
|
| 1151 | + ->setId(823); |
|
| 1152 | + |
|
| 1153 | + $file2UserShareOwnerExpected = [ |
|
| 1154 | + 'id' => 823, |
|
| 1155 | + 'share_type' => IShare::TYPE_USER, |
|
| 1156 | + ]; |
|
| 1157 | + |
|
| 1158 | + $data = [ |
|
| 1159 | + [ |
|
| 1160 | + [ |
|
| 1161 | + 'path' => $file1, |
|
| 1162 | + ], |
|
| 1163 | + [ |
|
| 1164 | + 'file1' => [ |
|
| 1165 | + IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareOwner, $file1UserShareOwner], |
|
| 1166 | + ], |
|
| 1167 | + ], |
|
| 1168 | + [ |
|
| 1169 | + ], |
|
| 1170 | + [ |
|
| 1171 | + $file1UserShareOwnerExpected |
|
| 1172 | + ] |
|
| 1173 | + ], |
|
| 1174 | + [ |
|
| 1175 | + [ |
|
| 1176 | + 'path' => $file1, |
|
| 1177 | + ], |
|
| 1178 | + [ |
|
| 1179 | + 'file1' => [ |
|
| 1180 | + IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient], |
|
| 1181 | + ], |
|
| 1182 | + ], |
|
| 1183 | + [ |
|
| 1184 | + ], |
|
| 1185 | + [ |
|
| 1186 | + $file1UserShareOwnerExpected, |
|
| 1187 | + ] |
|
| 1188 | + ], |
|
| 1189 | + [ |
|
| 1190 | + [ |
|
| 1191 | + 'path' => $file1, |
|
| 1192 | + ], |
|
| 1193 | + [ |
|
| 1194 | + 'file1' => [ |
|
| 1195 | + IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther], |
|
| 1196 | + ], |
|
| 1197 | + ], |
|
| 1198 | + [ |
|
| 1199 | + ], |
|
| 1200 | + [ |
|
| 1201 | + $file1UserShareOwnerExpected, |
|
| 1202 | + $file1UserShareInitiatorExpected, |
|
| 1203 | + $file1UserShareOtherExpected, |
|
| 1204 | + ] |
|
| 1205 | + ], |
|
| 1206 | + [ |
|
| 1207 | + [ |
|
| 1208 | + 'path' => $file1, |
|
| 1209 | + ], |
|
| 1210 | + [ |
|
| 1211 | + 'file1' => [ |
|
| 1212 | + IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther], |
|
| 1213 | + ], |
|
| 1214 | + ], |
|
| 1215 | + [ |
|
| 1216 | + ], |
|
| 1217 | + [ |
|
| 1218 | + $file1UserShareInitiatorExpected, |
|
| 1219 | + ] |
|
| 1220 | + ], |
|
| 1221 | + [ |
|
| 1222 | + [ |
|
| 1223 | + 'path' => $file1, |
|
| 1224 | + ], |
|
| 1225 | + [ |
|
| 1226 | + 'file1' => [ |
|
| 1227 | + IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1228 | + IShare::TYPE_GROUP => [$file1GroupShareRecipient], |
|
| 1229 | + ], |
|
| 1230 | + ], |
|
| 1231 | + [ |
|
| 1232 | + ], |
|
| 1233 | + [ |
|
| 1234 | + $file1UserShareOwnerExpected, |
|
| 1235 | + $file1GroupShareRecipientExpected, |
|
| 1236 | + ] |
|
| 1237 | + ], |
|
| 1238 | + [ |
|
| 1239 | + [ |
|
| 1240 | + 'path' => $file1, |
|
| 1241 | + ], |
|
| 1242 | + [ |
|
| 1243 | + 'file1' => [ |
|
| 1244 | + IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1245 | + IShare::TYPE_GROUP => [$file1GroupShareOwner], |
|
| 1246 | + IShare::TYPE_LINK => [$file1LinkShareOwner], |
|
| 1247 | + IShare::TYPE_EMAIL => [$file1EmailShareOwner], |
|
| 1248 | + IShare::TYPE_CIRCLE => [$file1CircleShareOwner], |
|
| 1249 | + IShare::TYPE_ROOM => [$file1RoomShareOwner], |
|
| 1250 | + IShare::TYPE_REMOTE => [$file1RemoteShareOwner], |
|
| 1251 | + IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner], |
|
| 1252 | + ], |
|
| 1253 | + ], |
|
| 1254 | + [ |
|
| 1255 | + ], |
|
| 1256 | + [ |
|
| 1257 | + $file1UserShareOwnerExpected, |
|
| 1258 | + $file1GroupShareOwnerExpected, |
|
| 1259 | + $file1LinkShareOwnerExpected, |
|
| 1260 | + $file1EmailShareOwnerExpected, |
|
| 1261 | + $file1CircleShareOwnerExpected, |
|
| 1262 | + $file1RoomShareOwnerExpected, |
|
| 1263 | + ] |
|
| 1264 | + ], |
|
| 1265 | + [ |
|
| 1266 | + [ |
|
| 1267 | + 'path' => $file1, |
|
| 1268 | + ], |
|
| 1269 | + [ |
|
| 1270 | + 'file1' => [ |
|
| 1271 | + IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1272 | + IShare::TYPE_GROUP => [$file1GroupShareOwner], |
|
| 1273 | + IShare::TYPE_LINK => [$file1LinkShareOwner], |
|
| 1274 | + IShare::TYPE_EMAIL => [$file1EmailShareOwner], |
|
| 1275 | + IShare::TYPE_CIRCLE => [$file1CircleShareOwner], |
|
| 1276 | + IShare::TYPE_ROOM => [$file1RoomShareOwner], |
|
| 1277 | + IShare::TYPE_REMOTE => [$file1RemoteShareOwner], |
|
| 1278 | + IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner], |
|
| 1279 | + ], |
|
| 1280 | + ], |
|
| 1281 | + [ |
|
| 1282 | + IShare::TYPE_REMOTE => true, |
|
| 1283 | + IShare::TYPE_REMOTE_GROUP => true, |
|
| 1284 | + ], |
|
| 1285 | + [ |
|
| 1286 | + $file1UserShareOwnerExpected, |
|
| 1287 | + $file1GroupShareOwnerExpected, |
|
| 1288 | + $file1LinkShareOwnerExpected, |
|
| 1289 | + $file1EmailShareOwnerExpected, |
|
| 1290 | + $file1CircleShareOwnerExpected, |
|
| 1291 | + $file1RoomShareOwnerExpected, |
|
| 1292 | + $file1RemoteShareOwnerExpected, |
|
| 1293 | + $file1RemoteGroupShareOwnerExpected, |
|
| 1294 | + ] |
|
| 1295 | + ], |
|
| 1296 | + [ |
|
| 1297 | + [ |
|
| 1298 | + 'path' => $folder, |
|
| 1299 | + 'subfiles' => 'true', |
|
| 1300 | + ], |
|
| 1301 | + [ |
|
| 1302 | + 'file1' => [ |
|
| 1303 | + IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1304 | + ], |
|
| 1305 | + 'file2' => [ |
|
| 1306 | + IShare::TYPE_USER => [$file2UserShareOwner], |
|
| 1307 | + ], |
|
| 1308 | + ], |
|
| 1309 | + [ |
|
| 1310 | + ], |
|
| 1311 | + [ |
|
| 1312 | + $file1UserShareOwnerExpected, |
|
| 1313 | + $file2UserShareOwnerExpected, |
|
| 1314 | + ] |
|
| 1315 | + ], |
|
| 1316 | + [ |
|
| 1317 | + [ |
|
| 1318 | + 'path' => $folder, |
|
| 1319 | + 'subfiles' => 'true', |
|
| 1320 | + ], |
|
| 1321 | + [ |
|
| 1322 | + 'file1' => [ |
|
| 1323 | + IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareOwner, $file1UserShareOwner], |
|
| 1324 | + ], |
|
| 1325 | + ], |
|
| 1326 | + [ |
|
| 1327 | + ], |
|
| 1328 | + [ |
|
| 1329 | + $file1UserShareOwnerExpected, |
|
| 1330 | + ] |
|
| 1331 | + ], |
|
| 1332 | + [ |
|
| 1333 | + [ |
|
| 1334 | + 'path' => $folder, |
|
| 1335 | + 'subfiles' => 'true', |
|
| 1336 | + ], |
|
| 1337 | + [ |
|
| 1338 | + 'file1' => [ |
|
| 1339 | + IShare::TYPE_USER => [$file1UserShareOwner, $file1UserShareRecipient], |
|
| 1340 | + ], |
|
| 1341 | + ], |
|
| 1342 | + [ |
|
| 1343 | + ], |
|
| 1344 | + [ |
|
| 1345 | + $file1UserShareOwnerExpected |
|
| 1346 | + ] |
|
| 1347 | + ], |
|
| 1348 | + [ |
|
| 1349 | + [ |
|
| 1350 | + 'path' => $folder, |
|
| 1351 | + 'subfiles' => 'true', |
|
| 1352 | + ], |
|
| 1353 | + [ |
|
| 1354 | + 'file1' => [ |
|
| 1355 | + IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther], |
|
| 1356 | + ], |
|
| 1357 | + 'file2' => [ |
|
| 1358 | + IShare::TYPE_USER => [$file2UserShareOwner], |
|
| 1359 | + ], |
|
| 1360 | + ], |
|
| 1361 | + [ |
|
| 1362 | + ], |
|
| 1363 | + [ |
|
| 1364 | + $file1UserShareInitiatorExpected, |
|
| 1365 | + $file1UserShareOtherExpected, |
|
| 1366 | + $file2UserShareOwnerExpected, |
|
| 1367 | + ] |
|
| 1368 | + ], |
|
| 1369 | + // This might not happen in a real environment, as the combination |
|
| 1370 | + // of shares does not seem to be possible on a folder without |
|
| 1371 | + // resharing rights; if the folder has resharing rights then the |
|
| 1372 | + // share with others would be included too in the results. |
|
| 1373 | + [ |
|
| 1374 | + [ |
|
| 1375 | + 'path' => $folder, |
|
| 1376 | + 'subfiles' => 'true', |
|
| 1377 | + ], |
|
| 1378 | + [ |
|
| 1379 | + 'file1' => [ |
|
| 1380 | + IShare::TYPE_USER => [$file1UserShareRecipient, $file1UserShareInitiator, $file1UserShareOther], |
|
| 1381 | + ], |
|
| 1382 | + ], |
|
| 1383 | + [ |
|
| 1384 | + ], |
|
| 1385 | + [ |
|
| 1386 | + $file1UserShareInitiatorExpected, |
|
| 1387 | + ] |
|
| 1388 | + ], |
|
| 1389 | + [ |
|
| 1390 | + [ |
|
| 1391 | + 'path' => $folder, |
|
| 1392 | + 'subfiles' => 'true', |
|
| 1393 | + ], |
|
| 1394 | + [ |
|
| 1395 | + 'file1' => [ |
|
| 1396 | + IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1397 | + IShare::TYPE_GROUP => [$file1GroupShareRecipient], |
|
| 1398 | + ], |
|
| 1399 | + ], |
|
| 1400 | + [ |
|
| 1401 | + ], |
|
| 1402 | + [ |
|
| 1403 | + $file1UserShareOwnerExpected, |
|
| 1404 | + $file1GroupShareRecipientExpected, |
|
| 1405 | + ] |
|
| 1406 | + ], |
|
| 1407 | + [ |
|
| 1408 | + [ |
|
| 1409 | + 'path' => $folder, |
|
| 1410 | + 'subfiles' => 'true', |
|
| 1411 | + ], |
|
| 1412 | + [ |
|
| 1413 | + 'file1' => [ |
|
| 1414 | + IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1415 | + IShare::TYPE_GROUP => [$file1GroupShareOwner], |
|
| 1416 | + IShare::TYPE_LINK => [$file1LinkShareOwner], |
|
| 1417 | + IShare::TYPE_EMAIL => [$file1EmailShareOwner], |
|
| 1418 | + IShare::TYPE_CIRCLE => [$file1CircleShareOwner], |
|
| 1419 | + IShare::TYPE_ROOM => [$file1RoomShareOwner], |
|
| 1420 | + IShare::TYPE_REMOTE => [$file1RemoteShareOwner], |
|
| 1421 | + IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner], |
|
| 1422 | + ], |
|
| 1423 | + ], |
|
| 1424 | + [ |
|
| 1425 | + ], |
|
| 1426 | + [ |
|
| 1427 | + $file1UserShareOwnerExpected, |
|
| 1428 | + $file1GroupShareOwnerExpected, |
|
| 1429 | + $file1LinkShareOwnerExpected, |
|
| 1430 | + $file1EmailShareOwnerExpected, |
|
| 1431 | + $file1CircleShareOwnerExpected, |
|
| 1432 | + $file1RoomShareOwnerExpected, |
|
| 1433 | + ] |
|
| 1434 | + ], |
|
| 1435 | + [ |
|
| 1436 | + [ |
|
| 1437 | + 'path' => $folder, |
|
| 1438 | + 'subfiles' => 'true', |
|
| 1439 | + ], |
|
| 1440 | + [ |
|
| 1441 | + 'file1' => [ |
|
| 1442 | + IShare::TYPE_USER => [$file1UserShareOwner], |
|
| 1443 | + IShare::TYPE_GROUP => [$file1GroupShareOwner], |
|
| 1444 | + IShare::TYPE_LINK => [$file1LinkShareOwner], |
|
| 1445 | + IShare::TYPE_EMAIL => [$file1EmailShareOwner], |
|
| 1446 | + IShare::TYPE_CIRCLE => [$file1CircleShareOwner], |
|
| 1447 | + IShare::TYPE_ROOM => [$file1RoomShareOwner], |
|
| 1448 | + IShare::TYPE_REMOTE => [$file1RemoteShareOwner], |
|
| 1449 | + IShare::TYPE_REMOTE_GROUP => [$file1RemoteGroupShareOwner], |
|
| 1450 | + ], |
|
| 1451 | + ], |
|
| 1452 | + [ |
|
| 1453 | + IShare::TYPE_REMOTE => true, |
|
| 1454 | + IShare::TYPE_REMOTE_GROUP => true, |
|
| 1455 | + ], |
|
| 1456 | + [ |
|
| 1457 | + $file1UserShareOwnerExpected, |
|
| 1458 | + $file1GroupShareOwnerExpected, |
|
| 1459 | + $file1LinkShareOwnerExpected, |
|
| 1460 | + $file1EmailShareOwnerExpected, |
|
| 1461 | + $file1CircleShareOwnerExpected, |
|
| 1462 | + $file1RoomShareOwnerExpected, |
|
| 1463 | + $file1RemoteShareOwnerExpected, |
|
| 1464 | + $file1RemoteGroupShareOwnerExpected, |
|
| 1465 | + ] |
|
| 1466 | + ], |
|
| 1467 | + ]; |
|
| 1468 | + |
|
| 1469 | + return $data; |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetShares')] |
|
| 1473 | + public function testGetShares(array $getSharesParameters, array $shares, array $extraShareTypes, array $expected): void { |
|
| 1474 | + /** @var ShareAPIController&MockObject $ocs */ |
|
| 1475 | + $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 1476 | + ->setConstructorArgs([ |
|
| 1477 | + $this->appName, |
|
| 1478 | + $this->request, |
|
| 1479 | + $this->shareManager, |
|
| 1480 | + $this->groupManager, |
|
| 1481 | + $this->userManager, |
|
| 1482 | + $this->rootFolder, |
|
| 1483 | + $this->urlGenerator, |
|
| 1484 | + $this->l, |
|
| 1485 | + $this->config, |
|
| 1486 | + $this->appConfig, |
|
| 1487 | + $this->appManager, |
|
| 1488 | + $this->serverContainer, |
|
| 1489 | + $this->userStatusManager, |
|
| 1490 | + $this->previewManager, |
|
| 1491 | + $this->dateTimeZone, |
|
| 1492 | + $this->logger, |
|
| 1493 | + $this->factory, |
|
| 1494 | + $this->mailer, |
|
| 1495 | + $this->tagManager, |
|
| 1496 | + $this->trustedServers, |
|
| 1497 | + $this->currentUser, |
|
| 1498 | + ]) |
|
| 1499 | + ->onlyMethods(['formatShare']) |
|
| 1500 | + ->getMock(); |
|
| 1501 | + |
|
| 1502 | + $ocs->method('formatShare') |
|
| 1503 | + ->willReturnCallback( |
|
| 1504 | + function ($share) { |
|
| 1505 | + return [ |
|
| 1506 | + 'id' => $share->getId(), |
|
| 1507 | + 'share_type' => $share->getShareType() |
|
| 1508 | + ]; |
|
| 1509 | + } |
|
| 1510 | + ); |
|
| 1511 | + |
|
| 1512 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 1513 | + $userFolder->method('get') |
|
| 1514 | + ->with('path') |
|
| 1515 | + ->willReturn($getSharesParameters['path']); |
|
| 1516 | + |
|
| 1517 | + $this->rootFolder->method('getUserFolder') |
|
| 1518 | + ->with($this->currentUser) |
|
| 1519 | + ->willReturn($userFolder); |
|
| 1520 | + |
|
| 1521 | + $this->shareManager |
|
| 1522 | + ->method('getSharesBy') |
|
| 1523 | + ->willReturnCallback( |
|
| 1524 | + function ($user, $shareType, $node) use ($shares) { |
|
| 1525 | + if (!isset($shares[$node->getName()]) || !isset($shares[$node->getName()][$shareType])) { |
|
| 1526 | + return []; |
|
| 1527 | + } |
|
| 1528 | + return $shares[$node->getName()][$shareType]; |
|
| 1529 | + } |
|
| 1530 | + ); |
|
| 1531 | + |
|
| 1532 | + $this->shareManager |
|
| 1533 | + ->method('outgoingServer2ServerSharesAllowed') |
|
| 1534 | + ->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE] ?? false); |
|
| 1535 | + |
|
| 1536 | + $this->shareManager |
|
| 1537 | + ->method('outgoingServer2ServerGroupSharesAllowed') |
|
| 1538 | + ->willReturn($extraShareTypes[ISHARE::TYPE_REMOTE_GROUP] ?? false); |
|
| 1539 | + |
|
| 1540 | + $this->groupManager |
|
| 1541 | + ->method('isInGroup') |
|
| 1542 | + ->willReturnCallback( |
|
| 1543 | + function ($user, $group) { |
|
| 1544 | + return $group === 'currentUserGroup'; |
|
| 1545 | + } |
|
| 1546 | + ); |
|
| 1547 | + |
|
| 1548 | + $result = $ocs->getShares( |
|
| 1549 | + $getSharesParameters['sharedWithMe'] ?? 'false', |
|
| 1550 | + $getSharesParameters['reshares'] ?? 'false', |
|
| 1551 | + $getSharesParameters['subfiles'] ?? 'false', |
|
| 1552 | + 'path' |
|
| 1553 | + ); |
|
| 1554 | + |
|
| 1555 | + $this->assertEquals($expected, $result->getData()); |
|
| 1556 | + } |
|
| 1557 | + |
|
| 1558 | + public function testCanAccessShareAsOwner(): void { |
|
| 1559 | + $share = $this->createMock(IShare::class); |
|
| 1560 | + $share->method('getShareOwner')->willReturn($this->currentUser); |
|
| 1561 | + $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1562 | + } |
|
| 1563 | + |
|
| 1564 | + public function testCanAccessShareAsSharer(): void { |
|
| 1565 | + $share = $this->createMock(IShare::class); |
|
| 1566 | + $share->method('getSharedBy')->willReturn($this->currentUser); |
|
| 1567 | + $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1568 | + } |
|
| 1569 | + |
|
| 1570 | + public function testCanAccessShareAsSharee(): void { |
|
| 1571 | + $share = $this->createMock(IShare::class); |
|
| 1572 | + $share->method('getShareType')->willReturn(IShare::TYPE_USER); |
|
| 1573 | + $share->method('getSharedWith')->willReturn($this->currentUser); |
|
| 1574 | + $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1575 | + } |
|
| 1576 | + |
|
| 1577 | + public function testCannotAccessLinkShare(): void { |
|
| 1578 | + $share = $this->createMock(IShare::class); |
|
| 1579 | + $share->method('getShareType')->willReturn(IShare::TYPE_LINK); |
|
| 1580 | + $share->method('getNodeId')->willReturn(42); |
|
| 1581 | + |
|
| 1582 | + $userFolder = $this->createMock(Folder::class); |
|
| 1583 | + $this->rootFolder->method('getUserFolder') |
|
| 1584 | + ->with($this->currentUser) |
|
| 1585 | + ->willReturn($userFolder); |
|
| 1586 | + |
|
| 1587 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareWithPermissions')] |
|
| 1591 | + public function testCanAccessShareWithPermissions(int $permissions, bool $expected): void { |
|
| 1592 | + $share = $this->createMock(IShare::class); |
|
| 1593 | + $share->method('getShareType')->willReturn(IShare::TYPE_USER); |
|
| 1594 | + $share->method('getSharedWith')->willReturn($this->createMock(IUser::class)); |
|
| 1595 | + $share->method('getNodeId')->willReturn(42); |
|
| 1596 | + |
|
| 1597 | + $file = $this->createMock(File::class); |
|
| 1598 | + |
|
| 1599 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 1600 | + $userFolder->method('getFirstNodeById') |
|
| 1601 | + ->with($share->getNodeId()) |
|
| 1602 | + ->willReturn($file); |
|
| 1603 | + $userFolder->method('getById') |
|
| 1604 | + ->with($share->getNodeId()) |
|
| 1605 | + ->willReturn([$file]); |
|
| 1606 | + $this->rootFolder->method('getUserFolder') |
|
| 1607 | + ->with($this->currentUser) |
|
| 1608 | + ->willReturn($userFolder); |
|
| 1609 | + |
|
| 1610 | + $file->method('getPermissions') |
|
| 1611 | + ->willReturn($permissions); |
|
| 1612 | + |
|
| 1613 | + if ($expected) { |
|
| 1614 | + $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1615 | + } else { |
|
| 1616 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1617 | + } |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + public static function dataCanAccessShareWithPermissions(): array { |
|
| 1621 | + return [ |
|
| 1622 | + [Constants::PERMISSION_SHARE, true], |
|
| 1623 | + [Constants::PERMISSION_READ, false], |
|
| 1624 | + [Constants::PERMISSION_READ | Constants::PERMISSION_SHARE, true], |
|
| 1625 | + ]; |
|
| 1626 | + } |
|
| 1627 | + |
|
| 1628 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessShareAsGroupMember')] |
|
| 1629 | + public function testCanAccessShareAsGroupMember(string $group, bool $expected): void { |
|
| 1630 | + $share = $this->createMock(IShare::class); |
|
| 1631 | + $share->method('getShareType')->willReturn(IShare::TYPE_GROUP); |
|
| 1632 | + $share->method('getSharedWith')->willReturn($group); |
|
| 1633 | + $share->method('getNodeId')->willReturn(42); |
|
| 1634 | + |
|
| 1635 | + $file = $this->createMock(File::class); |
|
| 1636 | + |
|
| 1637 | + $userFolder = $this->createMock(Folder::class); |
|
| 1638 | + $userFolder->method('getFirstNodeById') |
|
| 1639 | + ->with($share->getNodeId()) |
|
| 1640 | + ->willReturn($file); |
|
| 1641 | + $userFolder->method('getById') |
|
| 1642 | + ->with($share->getNodeId()) |
|
| 1643 | + ->willReturn([$file]); |
|
| 1644 | + $this->rootFolder->method('getUserFolder') |
|
| 1645 | + ->with($this->currentUser) |
|
| 1646 | + ->willReturn($userFolder); |
|
| 1647 | + |
|
| 1648 | + $user = $this->createMock(IUser::class); |
|
| 1649 | + $this->userManager->method('get') |
|
| 1650 | + ->with($this->currentUser) |
|
| 1651 | + ->willReturn($user); |
|
| 1652 | + |
|
| 1653 | + $group = $this->createMock(IGroup::class); |
|
| 1654 | + $group->method('inGroup')->with($user)->willReturn(true); |
|
| 1655 | + $group2 = $this->createMock(IGroup::class); |
|
| 1656 | + $group2->method('inGroup')->with($user)->willReturn(false); |
|
| 1657 | + |
|
| 1658 | + $this->groupManager->method('get')->willReturnMap([ |
|
| 1659 | + ['group', $group], |
|
| 1660 | + ['group2', $group2], |
|
| 1661 | + ['group-null', null], |
|
| 1662 | + ]); |
|
| 1663 | + |
|
| 1664 | + if ($expected) { |
|
| 1665 | + $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1666 | + } else { |
|
| 1667 | + $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1668 | + } |
|
| 1669 | + } |
|
| 1670 | + |
|
| 1671 | + public static function dataCanAccessShareAsGroupMember(): array { |
|
| 1672 | + return [ |
|
| 1673 | + ['group', true], |
|
| 1674 | + ['group2', false], |
|
| 1675 | + ['group-null', false], |
|
| 1676 | + ]; |
|
| 1677 | + } |
|
| 1678 | + |
|
| 1679 | + public function dataCanAccessRoomShare() { |
|
| 1680 | + $result = []; |
|
| 1681 | + |
|
| 1682 | + $share = $this->createMock(IShare::class); |
|
| 1683 | + $share->method('getShareType')->willReturn(IShare::TYPE_ROOM); |
|
| 1684 | + $share->method('getSharedWith')->willReturn('recipientRoom'); |
|
| 1685 | + |
|
| 1686 | + $result[] = [ |
|
| 1687 | + false, $share, false, false |
|
| 1688 | + ]; |
|
| 1689 | + |
|
| 1690 | + $result[] = [ |
|
| 1691 | + false, $share, false, true |
|
| 1692 | + ]; |
|
| 1693 | + |
|
| 1694 | + $result[] = [ |
|
| 1695 | + true, $share, true, true |
|
| 1696 | + ]; |
|
| 1697 | + |
|
| 1698 | + $result[] = [ |
|
| 1699 | + false, $share, true, false |
|
| 1700 | + ]; |
|
| 1701 | + |
|
| 1702 | + return $result; |
|
| 1703 | + } |
|
| 1704 | + |
|
| 1705 | + /** |
|
| 1706 | + * |
|
| 1707 | + * @param bool $expects |
|
| 1708 | + * @param IShare $share |
|
| 1709 | + * @param bool helperAvailable |
|
| 1710 | + * @param bool canAccessShareByHelper |
|
| 1711 | + */ |
|
| 1712 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataCanAccessRoomShare')] |
|
| 1713 | + public function testCanAccessRoomShare(bool $expected, IShare $share, bool $helperAvailable, bool $canAccessShareByHelper): void { |
|
| 1714 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 1715 | + $this->rootFolder->method('getUserFolder') |
|
| 1716 | + ->with($this->currentUser) |
|
| 1717 | + ->willReturn($userFolder); |
|
| 1718 | + |
|
| 1719 | + $userFolder->method('getById') |
|
| 1720 | + ->with($share->getNodeId()) |
|
| 1721 | + ->willReturn([$share->getNode()]); |
|
| 1722 | + |
|
| 1723 | + if (!$helperAvailable) { |
|
| 1724 | + $this->appManager->method('isEnabledForUser') |
|
| 1725 | + ->with('spreed') |
|
| 1726 | + ->willReturn(false); |
|
| 1727 | + } else { |
|
| 1728 | + $this->appManager->method('isEnabledForUser') |
|
| 1729 | + ->with('spreed') |
|
| 1730 | + ->willReturn(true); |
|
| 1731 | + |
|
| 1732 | + // This is not possible anymore with PHPUnit 10+ |
|
| 1733 | + // as `setMethods` was removed and now real reflection is used, thus the class needs to exist. |
|
| 1734 | + // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 1735 | + $helper = $this->getMockBuilder(\stdClass::class) |
|
| 1736 | + ->addMethods(['canAccessShare']) |
|
| 1737 | + ->getMock(); |
|
| 1738 | + $helper->method('canAccessShare') |
|
| 1739 | + ->with($share, $this->currentUser) |
|
| 1740 | + ->willReturn($canAccessShareByHelper); |
|
| 1741 | + |
|
| 1742 | + $this->serverContainer->method('get') |
|
| 1743 | + ->with('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 1744 | + ->willReturn($helper); |
|
| 1745 | + } |
|
| 1746 | + |
|
| 1747 | + $this->assertEquals($expected, $this->invokePrivate($this->ocs, 'canAccessShare', [$share])); |
|
| 1748 | + } |
|
| 1749 | + |
|
| 1750 | + |
|
| 1751 | + public function testCreateShareNoPath(): void { |
|
| 1752 | + $this->expectException(OCSNotFoundException::class); |
|
| 1753 | + $this->expectExceptionMessage('Please specify a file or folder path'); |
|
| 1754 | + |
|
| 1755 | + $this->ocs->createShare(); |
|
| 1756 | + } |
|
| 1757 | + |
|
| 1758 | + |
|
| 1759 | + public function testCreateShareInvalidPath(): void { |
|
| 1760 | + $this->expectException(OCSNotFoundException::class); |
|
| 1761 | + $this->expectExceptionMessage('Wrong path, file/folder does not exist'); |
|
| 1762 | + |
|
| 1763 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 1764 | + $this->rootFolder->expects($this->once()) |
|
| 1765 | + ->method('getUserFolder') |
|
| 1766 | + ->with('currentUser') |
|
| 1767 | + ->willReturn($userFolder); |
|
| 1768 | + |
|
| 1769 | + $userFolder->expects($this->once()) |
|
| 1770 | + ->method('get') |
|
| 1771 | + ->with('invalid-path') |
|
| 1772 | + ->willThrowException(new NotFoundException()); |
|
| 1773 | + |
|
| 1774 | + $this->ocs->createShare('invalid-path'); |
|
| 1775 | + } |
|
| 1776 | + |
|
| 1777 | + public function testCreateShareInvalidShareType(): void { |
|
| 1778 | + $this->expectException(OCSBadRequestException::class); |
|
| 1779 | + $this->expectExceptionMessage('Unknown share type'); |
|
| 1780 | + |
|
| 1781 | + $share = $this->newShare(); |
|
| 1782 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 1783 | + |
|
| 1784 | + [$userFolder, $file] = $this->getNonSharedUserFile(); |
|
| 1785 | + $this->rootFolder->expects($this->atLeastOnce()) |
|
| 1786 | + ->method('getUserFolder') |
|
| 1787 | + ->with('currentUser') |
|
| 1788 | + ->willReturn($userFolder); |
|
| 1789 | + |
|
| 1790 | + $userFolder->expects($this->atLeastOnce()) |
|
| 1791 | + ->method('get') |
|
| 1792 | + ->with('valid-path') |
|
| 1793 | + ->willReturn($file); |
|
| 1794 | + $userFolder->method('getById') |
|
| 1795 | + ->willReturn([]); |
|
| 1796 | + |
|
| 1797 | + $file->expects($this->once()) |
|
| 1798 | + ->method('lock') |
|
| 1799 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 1800 | + |
|
| 1801 | + $this->ocs->createShare('valid-path', 31); |
|
| 1802 | + } |
|
| 1803 | + |
|
| 1804 | + public function testCreateShareUserNoShareWith(): void { |
|
| 1805 | + $this->expectException(OCSNotFoundException::class); |
|
| 1806 | + $this->expectExceptionMessage('Please specify a valid account to share with'); |
|
| 1807 | + |
|
| 1808 | + $share = $this->newShare(); |
|
| 1809 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 1810 | + |
|
| 1811 | + [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 1812 | + $this->rootFolder->method('getUserFolder') |
|
| 1813 | + ->with('currentUser') |
|
| 1814 | + ->willReturn($userFolder); |
|
| 1815 | + |
|
| 1816 | + $userFolder->expects($this->once()) |
|
| 1817 | + ->method('get') |
|
| 1818 | + ->with('valid-path') |
|
| 1819 | + ->willReturn($path); |
|
| 1820 | + $userFolder->method('getById') |
|
| 1821 | + ->willReturn([]); |
|
| 1822 | + |
|
| 1823 | + $path->expects($this->once()) |
|
| 1824 | + ->method('lock') |
|
| 1825 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 1826 | + |
|
| 1827 | + $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER); |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + |
|
| 1831 | + public function testCreateShareUserNoValidShareWith(): void { |
|
| 1832 | + $this->expectException(OCSNotFoundException::class); |
|
| 1833 | + $this->expectExceptionMessage('Please specify a valid account to share with'); |
|
| 1834 | + |
|
| 1835 | + $share = $this->newShare(); |
|
| 1836 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 1837 | + |
|
| 1838 | + [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 1839 | + $this->rootFolder->method('getUserFolder') |
|
| 1840 | + ->with('currentUser') |
|
| 1841 | + ->willReturn($userFolder); |
|
| 1842 | + |
|
| 1843 | + $userFolder->expects($this->once()) |
|
| 1844 | + ->method('get') |
|
| 1845 | + ->with('valid-path') |
|
| 1846 | + ->willReturn($path); |
|
| 1847 | + $userFolder->method('getById') |
|
| 1848 | + ->willReturn([]); |
|
| 1849 | + $path->expects($this->once()) |
|
| 1850 | + ->method('lock') |
|
| 1851 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 1852 | + $this->userManager->method('userExists') |
|
| 1853 | + ->with('invalidUser') |
|
| 1854 | + ->willReturn(false); |
|
| 1855 | + |
|
| 1856 | + $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'invalidUser'); |
|
| 1857 | + } |
|
| 1858 | + |
|
| 1859 | + public function testCreateShareUser(): void { |
|
| 1860 | + $share = $this->newShare(); |
|
| 1861 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 1862 | + |
|
| 1863 | + /** @var ShareAPIController $ocs */ |
|
| 1864 | + $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 1865 | + ->setConstructorArgs([ |
|
| 1866 | + $this->appName, |
|
| 1867 | + $this->request, |
|
| 1868 | + $this->shareManager, |
|
| 1869 | + $this->groupManager, |
|
| 1870 | + $this->userManager, |
|
| 1871 | + $this->rootFolder, |
|
| 1872 | + $this->urlGenerator, |
|
| 1873 | + $this->l, |
|
| 1874 | + $this->config, |
|
| 1875 | + $this->appConfig, |
|
| 1876 | + $this->appManager, |
|
| 1877 | + $this->serverContainer, |
|
| 1878 | + $this->userStatusManager, |
|
| 1879 | + $this->previewManager, |
|
| 1880 | + $this->dateTimeZone, |
|
| 1881 | + $this->logger, |
|
| 1882 | + $this->factory, |
|
| 1883 | + $this->mailer, |
|
| 1884 | + $this->tagManager, |
|
| 1885 | + $this->trustedServers, |
|
| 1886 | + $this->currentUser, |
|
| 1887 | + ])->onlyMethods(['formatShare']) |
|
| 1888 | + ->getMock(); |
|
| 1889 | + |
|
| 1890 | + [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 1891 | + $this->rootFolder->expects($this->exactly(2)) |
|
| 1892 | + ->method('getUserFolder') |
|
| 1893 | + ->with('currentUser') |
|
| 1894 | + ->willReturn($userFolder); |
|
| 1895 | + |
|
| 1896 | + $userFolder->expects($this->once()) |
|
| 1897 | + ->method('get') |
|
| 1898 | + ->with('valid-path') |
|
| 1899 | + ->willReturn($path); |
|
| 1900 | + $userFolder->method('getById') |
|
| 1901 | + ->willReturn([]); |
|
| 1902 | + |
|
| 1903 | + $this->userManager->method('userExists')->with('validUser')->willReturn(true); |
|
| 1904 | + |
|
| 1905 | + $path->expects($this->once()) |
|
| 1906 | + ->method('lock') |
|
| 1907 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 1908 | + |
|
| 1909 | + $this->shareManager->method('createShare') |
|
| 1910 | + ->with($this->callback(function (IShare $share) use ($path) { |
|
| 1911 | + return $share->getNode() === $path |
|
| 1912 | + && $share->getPermissions() === ( |
|
| 1913 | + Constants::PERMISSION_ALL |
|
| 1914 | + & ~Constants::PERMISSION_DELETE |
|
| 1915 | + & ~Constants::PERMISSION_CREATE |
|
| 1916 | + ) |
|
| 1917 | + && $share->getShareType() === IShare::TYPE_USER |
|
| 1918 | + && $share->getSharedWith() === 'validUser' |
|
| 1919 | + && $share->getSharedBy() === 'currentUser'; |
|
| 1920 | + })) |
|
| 1921 | + ->willReturnArgument(0); |
|
| 1922 | + |
|
| 1923 | + $expected = new DataResponse([]); |
|
| 1924 | + $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'validUser'); |
|
| 1925 | + |
|
| 1926 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 1927 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 1928 | + } |
|
| 1929 | + |
|
| 1930 | + |
|
| 1931 | + public function testCreateShareGroupNoValidShareWith(): void { |
|
| 1932 | + $this->expectException(OCSNotFoundException::class); |
|
| 1933 | + $this->expectExceptionMessage('Please specify a valid group'); |
|
| 1934 | + |
|
| 1935 | + $share = $this->newShare(); |
|
| 1936 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 1937 | + $this->shareManager->method('createShare')->willReturnArgument(0); |
|
| 1938 | + $this->shareManager->method('allowGroupSharing')->willReturn(true); |
|
| 1939 | + |
|
| 1940 | + [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 1941 | + $this->rootFolder->method('getUserFolder') |
|
| 1942 | + ->with('currentUser') |
|
| 1943 | + ->willReturn($userFolder); |
|
| 1944 | + |
|
| 1945 | + $userFolder->expects($this->once()) |
|
| 1946 | + ->method('get') |
|
| 1947 | + ->with('valid-path') |
|
| 1948 | + ->willReturn($path); |
|
| 1949 | + $userFolder->method('getById') |
|
| 1950 | + ->willReturn([]); |
|
| 1951 | + |
|
| 1952 | + $path->expects($this->once()) |
|
| 1953 | + ->method('lock') |
|
| 1954 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 1955 | + |
|
| 1956 | + $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'invalidGroup'); |
|
| 1957 | + } |
|
| 1958 | + |
|
| 1959 | + public function testCreateShareGroup(): void { |
|
| 1960 | + $share = $this->newShare(); |
|
| 1961 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 1962 | + |
|
| 1963 | + /** @var ShareAPIController&MockObject $ocs */ |
|
| 1964 | + $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 1965 | + ->setConstructorArgs([ |
|
| 1966 | + $this->appName, |
|
| 1967 | + $this->request, |
|
| 1968 | + $this->shareManager, |
|
| 1969 | + $this->groupManager, |
|
| 1970 | + $this->userManager, |
|
| 1971 | + $this->rootFolder, |
|
| 1972 | + $this->urlGenerator, |
|
| 1973 | + $this->l, |
|
| 1974 | + $this->config, |
|
| 1975 | + $this->appConfig, |
|
| 1976 | + $this->appManager, |
|
| 1977 | + $this->serverContainer, |
|
| 1978 | + $this->userStatusManager, |
|
| 1979 | + $this->previewManager, |
|
| 1980 | + $this->dateTimeZone, |
|
| 1981 | + $this->logger, |
|
| 1982 | + $this->factory, |
|
| 1983 | + $this->mailer, |
|
| 1984 | + $this->tagManager, |
|
| 1985 | + $this->trustedServers, |
|
| 1986 | + $this->currentUser, |
|
| 1987 | + ])->onlyMethods(['formatShare']) |
|
| 1988 | + ->getMock(); |
|
| 1989 | + |
|
| 1990 | + $this->request |
|
| 1991 | + ->method('getParam') |
|
| 1992 | + ->willReturnMap([ |
|
| 1993 | + ['path', null, 'valid-path'], |
|
| 1994 | + ['permissions', null, Constants::PERMISSION_ALL], |
|
| 1995 | + ['shareType', '-1', IShare::TYPE_GROUP], |
|
| 1996 | + ['shareWith', null, 'validGroup'], |
|
| 1997 | + ]); |
|
| 1998 | + |
|
| 1999 | + [$userFolder, $path] = $this->getNonSharedUserFolder(); |
|
| 2000 | + $this->rootFolder->expects($this->exactly(2)) |
|
| 2001 | + ->method('getUserFolder') |
|
| 2002 | + ->with('currentUser') |
|
| 2003 | + ->willReturn($userFolder); |
|
| 2004 | + |
|
| 2005 | + $userFolder->expects($this->once()) |
|
| 2006 | + ->method('get') |
|
| 2007 | + ->with('valid-path') |
|
| 2008 | + ->willReturn($path); |
|
| 2009 | + $userFolder->method('getById') |
|
| 2010 | + ->willReturn([]); |
|
| 2011 | + |
|
| 2012 | + $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true); |
|
| 2013 | + |
|
| 2014 | + $this->shareManager->expects($this->once()) |
|
| 2015 | + ->method('allowGroupSharing') |
|
| 2016 | + ->willReturn(true); |
|
| 2017 | + |
|
| 2018 | + $path->expects($this->once()) |
|
| 2019 | + ->method('lock') |
|
| 2020 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 2021 | + |
|
| 2022 | + $this->shareManager->method('createShare') |
|
| 2023 | + ->with($this->callback(function (IShare $share) use ($path) { |
|
| 2024 | + return $share->getNode() === $path |
|
| 2025 | + && $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 2026 | + && $share->getShareType() === IShare::TYPE_GROUP |
|
| 2027 | + && $share->getSharedWith() === 'validGroup' |
|
| 2028 | + && $share->getSharedBy() === 'currentUser'; |
|
| 2029 | + })) |
|
| 2030 | + ->willReturnArgument(0); |
|
| 2031 | + |
|
| 2032 | + $expected = new DataResponse([]); |
|
| 2033 | + $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'validGroup'); |
|
| 2034 | + |
|
| 2035 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 2036 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2037 | + } |
|
| 2038 | + |
|
| 2039 | + |
|
| 2040 | + public function testCreateShareGroupNotAllowed(): void { |
|
| 2041 | + $this->expectException(OCSNotFoundException::class); |
|
| 2042 | + $this->expectExceptionMessage('Group sharing is disabled by the administrator'); |
|
| 2043 | + |
|
| 2044 | + $share = $this->newShare(); |
|
| 2045 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 2046 | + |
|
| 2047 | + [$userFolder, $path] = $this->getNonSharedUserFolder(); |
|
| 2048 | + $this->rootFolder->method('getUserFolder') |
|
| 2049 | + ->with('currentUser') |
|
| 2050 | + ->willReturn($userFolder); |
|
| 2051 | + |
|
| 2052 | + $userFolder->expects($this->once()) |
|
| 2053 | + ->method('get') |
|
| 2054 | + ->with('valid-path') |
|
| 2055 | + ->willReturn($path); |
|
| 2056 | + $userFolder->method('getById') |
|
| 2057 | + ->willReturn([]); |
|
| 2058 | + |
|
| 2059 | + $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true); |
|
| 2060 | + |
|
| 2061 | + $this->shareManager->expects($this->once()) |
|
| 2062 | + ->method('allowGroupSharing') |
|
| 2063 | + ->willReturn(false); |
|
| 2064 | + |
|
| 2065 | + $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_GROUP, 'invalidGroup'); |
|
| 2066 | + } |
|
| 2067 | + |
|
| 2068 | + |
|
| 2069 | + public function testCreateShareLinkNoLinksAllowed(): void { |
|
| 2070 | + $this->expectException(OCSNotFoundException::class); |
|
| 2071 | + $this->expectExceptionMessage('Public link sharing is disabled by the administrator'); |
|
| 2072 | + |
|
| 2073 | + $this->request |
|
| 2074 | + ->method('getParam') |
|
| 2075 | + ->willReturnMap([ |
|
| 2076 | + ['path', null, 'valid-path'], |
|
| 2077 | + ['shareType', '-1', IShare::TYPE_LINK], |
|
| 2078 | + ]); |
|
| 2079 | + |
|
| 2080 | + $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2081 | + $path->method('getId')->willReturn(42); |
|
| 2082 | + $storage = $this->createMock(IStorage::class); |
|
| 2083 | + $storage->method('instanceOfStorage') |
|
| 2084 | + ->willReturnMap([ |
|
| 2085 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 2086 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2087 | + ]); |
|
| 2088 | + $path->method('getStorage')->willReturn($storage); |
|
| 2089 | + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2090 | + $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2091 | + $this->rootFolder->method('getById') |
|
| 2092 | + ->willReturn([]); |
|
| 2093 | + |
|
| 2094 | + $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2095 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2096 | + $this->shareManager->method('shareApiAllowLinks')->willReturn(false); |
|
| 2097 | + |
|
| 2098 | + $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK); |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + |
|
| 2102 | + public function testCreateShareLinkNoPublicUpload(): void { |
|
| 2103 | + $this->expectException(OCSForbiddenException::class); |
|
| 2104 | + $this->expectExceptionMessage('Public upload disabled by the administrator'); |
|
| 2105 | + |
|
| 2106 | + $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2107 | + $path->method('getId')->willReturn(42); |
|
| 2108 | + $storage = $this->createMock(IStorage::class); |
|
| 2109 | + $storage->method('instanceOfStorage') |
|
| 2110 | + ->willReturnMap([ |
|
| 2111 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 2112 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2113 | + ]); |
|
| 2114 | + $path->method('getStorage')->willReturn($storage); |
|
| 2115 | + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2116 | + $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2117 | + $this->rootFolder->method('getById') |
|
| 2118 | + ->willReturn([]); |
|
| 2119 | + |
|
| 2120 | + $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2121 | + $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2122 | + |
|
| 2123 | + $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true'); |
|
| 2124 | + } |
|
| 2125 | + |
|
| 2126 | + |
|
| 2127 | + public function testCreateShareLinkPublicUploadFile(): void { |
|
| 2128 | + $this->expectException(OCSBadRequestException::class); |
|
| 2129 | + $this->expectExceptionMessage('Public upload is only possible for publicly shared folders'); |
|
| 2130 | + |
|
| 2131 | + $storage = $this->createMock(IStorage::class); |
|
| 2132 | + $storage->method('instanceOfStorage') |
|
| 2133 | + ->willReturnMap([ |
|
| 2134 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 2135 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2136 | + ]); |
|
| 2137 | + |
|
| 2138 | + $file = $this->createMock(File::class); |
|
| 2139 | + $file->method('getId')->willReturn(42); |
|
| 2140 | + $file->method('getStorage')->willReturn($storage); |
|
| 2141 | + |
|
| 2142 | + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2143 | + $this->rootFolder->method('get')->with('valid-path')->willReturn($file); |
|
| 2144 | + $this->rootFolder->method('getById') |
|
| 2145 | + ->willReturn([]); |
|
| 2146 | + |
|
| 2147 | + $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2148 | + $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2149 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2150 | + |
|
| 2151 | + $this->ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true'); |
|
| 2152 | + } |
|
| 2153 | + |
|
| 2154 | + public function testCreateShareLinkPublicUploadFolder(): void { |
|
| 2155 | + $ocs = $this->mockFormatShare(); |
|
| 2156 | + |
|
| 2157 | + $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2158 | + $path->method('getId')->willReturn(1); |
|
| 2159 | + $storage = $this->createMock(IStorage::class); |
|
| 2160 | + $storage->method('instanceOfStorage') |
|
| 2161 | + ->willReturnMap([ |
|
| 2162 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 2163 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2164 | + ]); |
|
| 2165 | + $path->method('getStorage')->willReturn($storage); |
|
| 2166 | + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2167 | + $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2168 | + $this->rootFolder->method('getById') |
|
| 2169 | + ->willReturn([]); |
|
| 2170 | + |
|
| 2171 | + $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2172 | + $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2173 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2174 | + |
|
| 2175 | + $this->shareManager->expects($this->once())->method('createShare')->with( |
|
| 2176 | + $this->callback(function (IShare $share) use ($path) { |
|
| 2177 | + return $share->getNode() === $path |
|
| 2178 | + && $share->getShareType() === IShare::TYPE_LINK |
|
| 2179 | + && $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 2180 | + && $share->getSharedBy() === 'currentUser' |
|
| 2181 | + && $share->getPassword() === null |
|
| 2182 | + && $share->getExpirationDate() === null; |
|
| 2183 | + }) |
|
| 2184 | + )->willReturnArgument(0); |
|
| 2185 | + |
|
| 2186 | + $expected = new DataResponse([]); |
|
| 2187 | + $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true', '', null, ''); |
|
| 2188 | + |
|
| 2189 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 2190 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2191 | + } |
|
| 2192 | + |
|
| 2193 | + public function testCreateShareLinkPassword(): void { |
|
| 2194 | + $ocs = $this->mockFormatShare(); |
|
| 2195 | + |
|
| 2196 | + $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2197 | + $path->method('getId')->willReturn(42); |
|
| 2198 | + $storage = $this->createMock(IStorage::class); |
|
| 2199 | + $storage->method('instanceOfStorage') |
|
| 2200 | + ->willReturnMap([ |
|
| 2201 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 2202 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2203 | + ]); |
|
| 2204 | + $path->method('getStorage')->willReturn($storage); |
|
| 2205 | + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2206 | + $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2207 | + $this->rootFolder->method('getById') |
|
| 2208 | + ->willReturn([]); |
|
| 2209 | + |
|
| 2210 | + $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2211 | + $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2212 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2213 | + |
|
| 2214 | + $this->shareManager->expects($this->once())->method('createShare')->with( |
|
| 2215 | + $this->callback(function (IShare $share) use ($path) { |
|
| 2216 | + return $share->getNode() === $path |
|
| 2217 | + && $share->getShareType() === IShare::TYPE_LINK |
|
| 2218 | + && $share->getPermissions() === Constants::PERMISSION_READ // publicUpload was set to false |
|
| 2219 | + && $share->getSharedBy() === 'currentUser' |
|
| 2220 | + && $share->getPassword() === 'password' |
|
| 2221 | + && $share->getExpirationDate() === null; |
|
| 2222 | + }) |
|
| 2223 | + )->willReturnArgument(0); |
|
| 2224 | + |
|
| 2225 | + $expected = new DataResponse([]); |
|
| 2226 | + $result = $ocs->createShare('valid-path', Constants::PERMISSION_READ, IShare::TYPE_LINK, null, 'false', 'password', null, ''); |
|
| 2227 | + |
|
| 2228 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 2229 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2230 | + } |
|
| 2231 | + |
|
| 2232 | + public function testCreateShareLinkSendPasswordByTalk(): void { |
|
| 2233 | + $ocs = $this->mockFormatShare(); |
|
| 2234 | + |
|
| 2235 | + $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2236 | + $path->method('getId')->willReturn(42); |
|
| 2237 | + $storage = $this->createMock(IStorage::class); |
|
| 2238 | + $storage->method('instanceOfStorage') |
|
| 2239 | + ->willReturnMap([ |
|
| 2240 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 2241 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2242 | + ]); |
|
| 2243 | + $path->method('getStorage')->willReturn($storage); |
|
| 2244 | + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2245 | + $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2246 | + $this->rootFolder->method('getById') |
|
| 2247 | + ->willReturn([]); |
|
| 2248 | + |
|
| 2249 | + $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2250 | + $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2251 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2252 | + |
|
| 2253 | + $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true); |
|
| 2254 | + |
|
| 2255 | + $this->shareManager->expects($this->once())->method('createShare')->with( |
|
| 2256 | + $this->callback(function (IShare $share) use ($path) { |
|
| 2257 | + return $share->getNode() === $path |
|
| 2258 | + && $share->getShareType() === IShare::TYPE_LINK |
|
| 2259 | + && $share->getPermissions() === (Constants::PERMISSION_ALL & ~(Constants::PERMISSION_SHARE)) |
|
| 2260 | + && $share->getSharedBy() === 'currentUser' |
|
| 2261 | + && $share->getPassword() === 'password' |
|
| 2262 | + && $share->getSendPasswordByTalk() === true |
|
| 2263 | + && $share->getExpirationDate() === null; |
|
| 2264 | + }) |
|
| 2265 | + )->willReturnArgument(0); |
|
| 2266 | + |
|
| 2267 | + $expected = new DataResponse([]); |
|
| 2268 | + $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true', 'password', 'true', ''); |
|
| 2269 | + |
|
| 2270 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 2271 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2272 | + } |
|
| 2273 | + |
|
| 2274 | + |
|
| 2275 | + public function testCreateShareLinkSendPasswordByTalkWithTalkDisabled(): void { |
|
| 2276 | + $this->expectException(OCSForbiddenException::class); |
|
| 2277 | + $this->expectExceptionMessage('Sharing valid-path sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled'); |
|
| 2278 | + |
|
| 2279 | + $ocs = $this->mockFormatShare(); |
|
| 2280 | + |
|
| 2281 | + $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2282 | + $path->method('getId')->willReturn(42); |
|
| 2283 | + $storage = $this->createMock(IStorage::class); |
|
| 2284 | + $storage->method('instanceOfStorage') |
|
| 2285 | + ->willReturnMap([ |
|
| 2286 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 2287 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2288 | + ]); |
|
| 2289 | + $path->method('getStorage')->willReturn($storage); |
|
| 2290 | + $path->method('getPath')->willReturn('valid-path'); |
|
| 2291 | + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2292 | + $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2293 | + $this->rootFolder->method('getById') |
|
| 2294 | + ->willReturn([]); |
|
| 2295 | + |
|
| 2296 | + $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2297 | + $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2298 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2299 | + |
|
| 2300 | + $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false); |
|
| 2301 | + |
|
| 2302 | + $this->shareManager->expects($this->never())->method('createShare'); |
|
| 2303 | + |
|
| 2304 | + $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', 'password', 'true', ''); |
|
| 2305 | + } |
|
| 2306 | + |
|
| 2307 | + public function testCreateShareValidExpireDate(): void { |
|
| 2308 | + $ocs = $this->mockFormatShare(); |
|
| 2309 | + |
|
| 2310 | + $this->request |
|
| 2311 | + ->method('getParam') |
|
| 2312 | + ->willReturnMap([ |
|
| 2313 | + ['path', null, 'valid-path'], |
|
| 2314 | + ['shareType', '-1', IShare::TYPE_LINK], |
|
| 2315 | + ['publicUpload', null, 'false'], |
|
| 2316 | + ['expireDate', '', '2000-01-01'], |
|
| 2317 | + ['password', '', ''], |
|
| 2318 | + ]); |
|
| 2319 | + |
|
| 2320 | + $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2321 | + $path->method('getId')->willReturn(42); |
|
| 2322 | + $storage = $this->createMock(IStorage::class); |
|
| 2323 | + $storage->method('instanceOfStorage') |
|
| 2324 | + ->willReturnMap([ |
|
| 2325 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 2326 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2327 | + ]); |
|
| 2328 | + $path->method('getStorage')->willReturn($storage); |
|
| 2329 | + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2330 | + $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2331 | + $this->rootFolder->method('getById') |
|
| 2332 | + ->willReturn([]); |
|
| 2333 | + |
|
| 2334 | + $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2335 | + $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2336 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2337 | + |
|
| 2338 | + $this->shareManager->expects($this->once())->method('createShare')->with( |
|
| 2339 | + $this->callback(function (IShare $share) use ($path) { |
|
| 2340 | + $date = new \DateTime('2000-01-01'); |
|
| 2341 | + $date->setTime(0, 0, 0); |
|
| 2342 | + |
|
| 2343 | + return $share->getNode() === $path |
|
| 2344 | + && $share->getShareType() === IShare::TYPE_LINK |
|
| 2345 | + && $share->getPermissions() === Constants::PERMISSION_READ | Constants::PERMISSION_SHARE |
|
| 2346 | + && $share->getSharedBy() === 'currentUser' |
|
| 2347 | + && $share->getPassword() === null |
|
| 2348 | + && $share->getExpirationDate() == $date; |
|
| 2349 | + }) |
|
| 2350 | + )->willReturnArgument(0); |
|
| 2351 | + |
|
| 2352 | + $expected = new DataResponse([]); |
|
| 2353 | + $result = $ocs->createShare('valid-path', null, IShare::TYPE_LINK, null, 'false', '', null, '2000-01-01'); |
|
| 2354 | + |
|
| 2355 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 2356 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2357 | + } |
|
| 2358 | + |
|
| 2359 | + |
|
| 2360 | + public function testCreateShareInvalidExpireDate(): void { |
|
| 2361 | + $this->expectException(OCSNotFoundException::class); |
|
| 2362 | + $this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD'); |
|
| 2363 | + |
|
| 2364 | + $ocs = $this->mockFormatShare(); |
|
| 2365 | + |
|
| 2366 | + $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2367 | + $path->method('getId')->willReturn(42); |
|
| 2368 | + $storage = $this->createMock(IStorage::class); |
|
| 2369 | + $storage->method('instanceOfStorage') |
|
| 2370 | + ->willReturnMap([ |
|
| 2371 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 2372 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2373 | + ]); |
|
| 2374 | + $path->method('getStorage')->willReturn($storage); |
|
| 2375 | + $this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf(); |
|
| 2376 | + $this->rootFolder->method('get')->with('valid-path')->willReturn($path); |
|
| 2377 | + $this->rootFolder->method('getById') |
|
| 2378 | + ->willReturn([]); |
|
| 2379 | + |
|
| 2380 | + $this->shareManager->method('newShare')->willReturn(Server::get(IManager::class)->newShare()); |
|
| 2381 | + $this->shareManager->method('shareApiAllowLinks')->willReturn(true); |
|
| 2382 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2383 | + |
|
| 2384 | + $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '', null, 'a1b2d3'); |
|
| 2385 | + } |
|
| 2386 | + |
|
| 2387 | + public function testCreateShareRemote(): void { |
|
| 2388 | + $share = $this->newShare(); |
|
| 2389 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 2390 | + |
|
| 2391 | + /** @var ShareAPIController $ocs */ |
|
| 2392 | + $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 2393 | + ->setConstructorArgs([ |
|
| 2394 | + $this->appName, |
|
| 2395 | + $this->request, |
|
| 2396 | + $this->shareManager, |
|
| 2397 | + $this->groupManager, |
|
| 2398 | + $this->userManager, |
|
| 2399 | + $this->rootFolder, |
|
| 2400 | + $this->urlGenerator, |
|
| 2401 | + $this->l, |
|
| 2402 | + $this->config, |
|
| 2403 | + $this->appConfig, |
|
| 2404 | + $this->appManager, |
|
| 2405 | + $this->serverContainer, |
|
| 2406 | + $this->userStatusManager, |
|
| 2407 | + $this->previewManager, |
|
| 2408 | + $this->dateTimeZone, |
|
| 2409 | + $this->logger, |
|
| 2410 | + $this->factory, |
|
| 2411 | + $this->mailer, |
|
| 2412 | + $this->tagManager, |
|
| 2413 | + $this->trustedServers, |
|
| 2414 | + $this->currentUser, |
|
| 2415 | + ])->onlyMethods(['formatShare']) |
|
| 2416 | + ->getMock(); |
|
| 2417 | + |
|
| 2418 | + [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 2419 | + $this->rootFolder->expects($this->exactly(2)) |
|
| 2420 | + ->method('getUserFolder') |
|
| 2421 | + ->with('currentUser') |
|
| 2422 | + ->willReturn($userFolder); |
|
| 2423 | + |
|
| 2424 | + $userFolder->expects($this->once()) |
|
| 2425 | + ->method('get') |
|
| 2426 | + ->with('valid-path') |
|
| 2427 | + ->willReturn($path); |
|
| 2428 | + $userFolder->method('getById') |
|
| 2429 | + ->willReturn([]); |
|
| 2430 | + |
|
| 2431 | + $this->userManager->method('userExists')->with('validUser')->willReturn(true); |
|
| 2432 | + |
|
| 2433 | + $path->expects($this->once()) |
|
| 2434 | + ->method('lock') |
|
| 2435 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 2436 | + |
|
| 2437 | + $this->shareManager->method('createShare') |
|
| 2438 | + ->with($this->callback(function (IShare $share) use ($path) { |
|
| 2439 | + return $share->getNode() === $path |
|
| 2440 | + && $share->getPermissions() === ( |
|
| 2441 | + Constants::PERMISSION_ALL |
|
| 2442 | + & ~Constants::PERMISSION_DELETE |
|
| 2443 | + & ~Constants::PERMISSION_CREATE |
|
| 2444 | + ) |
|
| 2445 | + && $share->getShareType() === IShare::TYPE_REMOTE |
|
| 2446 | + && $share->getSharedWith() === '[email protected]' |
|
| 2447 | + && $share->getSharedBy() === 'currentUser'; |
|
| 2448 | + })) |
|
| 2449 | + ->willReturnArgument(0); |
|
| 2450 | + |
|
| 2451 | + $this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true); |
|
| 2452 | + |
|
| 2453 | + $expected = new DataResponse([]); |
|
| 2454 | + $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_REMOTE, '[email protected]'); |
|
| 2455 | + |
|
| 2456 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 2457 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2458 | + } |
|
| 2459 | + |
|
| 2460 | + public function testCreateShareRemoteGroup(): void { |
|
| 2461 | + $share = $this->newShare(); |
|
| 2462 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 2463 | + |
|
| 2464 | + /** @var ShareAPIController $ocs */ |
|
| 2465 | + $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 2466 | + ->setConstructorArgs([ |
|
| 2467 | + $this->appName, |
|
| 2468 | + $this->request, |
|
| 2469 | + $this->shareManager, |
|
| 2470 | + $this->groupManager, |
|
| 2471 | + $this->userManager, |
|
| 2472 | + $this->rootFolder, |
|
| 2473 | + $this->urlGenerator, |
|
| 2474 | + $this->l, |
|
| 2475 | + $this->config, |
|
| 2476 | + $this->appConfig, |
|
| 2477 | + $this->appManager, |
|
| 2478 | + $this->serverContainer, |
|
| 2479 | + $this->userStatusManager, |
|
| 2480 | + $this->previewManager, |
|
| 2481 | + $this->dateTimeZone, |
|
| 2482 | + $this->logger, |
|
| 2483 | + $this->factory, |
|
| 2484 | + $this->mailer, |
|
| 2485 | + $this->tagManager, |
|
| 2486 | + $this->trustedServers, |
|
| 2487 | + $this->currentUser, |
|
| 2488 | + ])->onlyMethods(['formatShare']) |
|
| 2489 | + ->getMock(); |
|
| 2490 | + |
|
| 2491 | + [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 2492 | + $this->rootFolder->expects($this->exactly(2)) |
|
| 2493 | + ->method('getUserFolder') |
|
| 2494 | + ->with('currentUser') |
|
| 2495 | + ->willReturn($userFolder); |
|
| 2496 | + |
|
| 2497 | + $userFolder->expects($this->once()) |
|
| 2498 | + ->method('get') |
|
| 2499 | + ->with('valid-path') |
|
| 2500 | + ->willReturn($path); |
|
| 2501 | + $userFolder->method('getById') |
|
| 2502 | + ->willReturn([]); |
|
| 2503 | + |
|
| 2504 | + $this->userManager->method('userExists')->with('validUser')->willReturn(true); |
|
| 2505 | + |
|
| 2506 | + $path->expects($this->once()) |
|
| 2507 | + ->method('lock') |
|
| 2508 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 2509 | + |
|
| 2510 | + $this->shareManager->method('createShare') |
|
| 2511 | + ->with($this->callback(function (IShare $share) use ($path) { |
|
| 2512 | + return $share->getNode() === $path |
|
| 2513 | + && $share->getPermissions() === ( |
|
| 2514 | + Constants::PERMISSION_ALL |
|
| 2515 | + & ~Constants::PERMISSION_DELETE |
|
| 2516 | + & ~Constants::PERMISSION_CREATE |
|
| 2517 | + ) |
|
| 2518 | + && $share->getShareType() === IShare::TYPE_REMOTE_GROUP |
|
| 2519 | + && $share->getSharedWith() === '[email protected]' |
|
| 2520 | + && $share->getSharedBy() === 'currentUser'; |
|
| 2521 | + })) |
|
| 2522 | + ->willReturnArgument(0); |
|
| 2523 | + |
|
| 2524 | + $this->shareManager->method('outgoingServer2ServerGroupSharesAllowed')->willReturn(true); |
|
| 2525 | + |
|
| 2526 | + $expected = new DataResponse([]); |
|
| 2527 | + $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_REMOTE_GROUP, '[email protected]'); |
|
| 2528 | + |
|
| 2529 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 2530 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2531 | + } |
|
| 2532 | + |
|
| 2533 | + public function testCreateShareRoom(): void { |
|
| 2534 | + $ocs = $this->mockFormatShare(); |
|
| 2535 | + |
|
| 2536 | + $share = $this->newShare(); |
|
| 2537 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 2538 | + |
|
| 2539 | + [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 2540 | + $this->rootFolder->expects($this->exactly(2)) |
|
| 2541 | + ->method('getUserFolder') |
|
| 2542 | + ->with('currentUser') |
|
| 2543 | + ->willReturn($userFolder); |
|
| 2544 | + |
|
| 2545 | + $userFolder->expects($this->once()) |
|
| 2546 | + ->method('get') |
|
| 2547 | + ->with('valid-path') |
|
| 2548 | + ->willReturn($path); |
|
| 2549 | + $userFolder->method('getById') |
|
| 2550 | + ->willReturn([]); |
|
| 2551 | + |
|
| 2552 | + $path->expects($this->once()) |
|
| 2553 | + ->method('lock') |
|
| 2554 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 2555 | + |
|
| 2556 | + $this->appManager->method('isEnabledForUser') |
|
| 2557 | + ->with('spreed') |
|
| 2558 | + ->willReturn(true); |
|
| 2559 | + |
|
| 2560 | + // This is not possible anymore with PHPUnit 10+ |
|
| 2561 | + // as `setMethods` was removed and now real reflection is used, thus the class needs to exist. |
|
| 2562 | + // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 2563 | + $helper = $this->getMockBuilder(\stdClass::class) |
|
| 2564 | + ->addMethods(['createShare']) |
|
| 2565 | + ->getMock(); |
|
| 2566 | + $helper->method('createShare') |
|
| 2567 | + ->with( |
|
| 2568 | + $share, |
|
| 2569 | + 'recipientRoom', |
|
| 2570 | + Constants::PERMISSION_ALL |
|
| 2571 | + & ~Constants::PERMISSION_DELETE |
|
| 2572 | + & ~Constants::PERMISSION_CREATE, |
|
| 2573 | + '' |
|
| 2574 | + )->willReturnCallback( |
|
| 2575 | + function ($share): void { |
|
| 2576 | + $share->setSharedWith('recipientRoom'); |
|
| 2577 | + $share->setPermissions(Constants::PERMISSION_ALL); |
|
| 2578 | + } |
|
| 2579 | + ); |
|
| 2580 | + |
|
| 2581 | + $this->serverContainer->method('get') |
|
| 2582 | + ->with('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 2583 | + ->willReturn($helper); |
|
| 2584 | + |
|
| 2585 | + $this->shareManager->method('createShare') |
|
| 2586 | + ->with($this->callback(function (IShare $share) use ($path) { |
|
| 2587 | + return $share->getNode() === $path |
|
| 2588 | + && $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 2589 | + && $share->getShareType() === IShare::TYPE_ROOM |
|
| 2590 | + && $share->getSharedWith() === 'recipientRoom' |
|
| 2591 | + && $share->getSharedBy() === 'currentUser'; |
|
| 2592 | + })) |
|
| 2593 | + ->willReturnArgument(0); |
|
| 2594 | + |
|
| 2595 | + $expected = new DataResponse([]); |
|
| 2596 | + $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom'); |
|
| 2597 | + |
|
| 2598 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 2599 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2600 | + } |
|
| 2601 | + |
|
| 2602 | + |
|
| 2603 | + public function testCreateShareRoomHelperNotAvailable(): void { |
|
| 2604 | + $this->expectException(OCSForbiddenException::class); |
|
| 2605 | + $this->expectExceptionMessage('Sharing valid-path failed because the back end does not support room shares'); |
|
| 2606 | + |
|
| 2607 | + $ocs = $this->mockFormatShare(); |
|
| 2608 | + |
|
| 2609 | + $share = $this->newShare(); |
|
| 2610 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 2611 | + |
|
| 2612 | + [$userFolder, $path] = $this->getNonSharedUserFolder(); |
|
| 2613 | + $this->rootFolder->method('getUserFolder') |
|
| 2614 | + ->with('currentUser') |
|
| 2615 | + ->willReturn($userFolder); |
|
| 2616 | + |
|
| 2617 | + $path->method('getPath')->willReturn('valid-path'); |
|
| 2618 | + $userFolder->expects($this->once()) |
|
| 2619 | + ->method('get') |
|
| 2620 | + ->with('valid-path') |
|
| 2621 | + ->willReturn($path); |
|
| 2622 | + $userFolder->method('getById') |
|
| 2623 | + ->willReturn([]); |
|
| 2624 | + |
|
| 2625 | + $path->expects($this->once()) |
|
| 2626 | + ->method('lock') |
|
| 2627 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 2628 | + |
|
| 2629 | + $this->appManager->method('isEnabledForUser') |
|
| 2630 | + ->with('spreed') |
|
| 2631 | + ->willReturn(false); |
|
| 2632 | + |
|
| 2633 | + $this->shareManager->expects($this->never())->method('createShare'); |
|
| 2634 | + |
|
| 2635 | + $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom'); |
|
| 2636 | + } |
|
| 2637 | + |
|
| 2638 | + |
|
| 2639 | + public function testCreateShareRoomHelperThrowException(): void { |
|
| 2640 | + $this->expectException(OCSNotFoundException::class); |
|
| 2641 | + $this->expectExceptionMessage('Exception thrown by the helper'); |
|
| 2642 | + |
|
| 2643 | + $ocs = $this->mockFormatShare(); |
|
| 2644 | + |
|
| 2645 | + $share = $this->newShare(); |
|
| 2646 | + $share->setSharedBy('currentUser'); |
|
| 2647 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 2648 | + |
|
| 2649 | + [$userFolder, $path] = $this->getNonSharedUserFile(); |
|
| 2650 | + $this->rootFolder->method('getUserFolder') |
|
| 2651 | + ->with('currentUser') |
|
| 2652 | + ->willReturn($userFolder); |
|
| 2653 | + |
|
| 2654 | + $userFolder->expects($this->once()) |
|
| 2655 | + ->method('get') |
|
| 2656 | + ->with('valid-path') |
|
| 2657 | + ->willReturn($path); |
|
| 2658 | + $userFolder->method('getById') |
|
| 2659 | + ->willReturn([]); |
|
| 2660 | + |
|
| 2661 | + $path->expects($this->once()) |
|
| 2662 | + ->method('lock') |
|
| 2663 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 2664 | + |
|
| 2665 | + $this->appManager->method('isEnabledForUser') |
|
| 2666 | + ->with('spreed') |
|
| 2667 | + ->willReturn(true); |
|
| 2668 | + |
|
| 2669 | + // This is not possible anymore with PHPUnit 10+ |
|
| 2670 | + // as `setMethods` was removed and now real reflection is used, thus the class needs to exist. |
|
| 2671 | + // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 2672 | + $helper = $this->getMockBuilder(\stdClass::class) |
|
| 2673 | + ->addMethods(['createShare']) |
|
| 2674 | + ->getMock(); |
|
| 2675 | + $helper->method('createShare') |
|
| 2676 | + ->with( |
|
| 2677 | + $share, |
|
| 2678 | + 'recipientRoom', |
|
| 2679 | + Constants::PERMISSION_ALL & ~(Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE), |
|
| 2680 | + '' |
|
| 2681 | + )->willReturnCallback( |
|
| 2682 | + function ($share): void { |
|
| 2683 | + throw new OCSNotFoundException('Exception thrown by the helper'); |
|
| 2684 | + } |
|
| 2685 | + ); |
|
| 2686 | + |
|
| 2687 | + $this->serverContainer->method('get') |
|
| 2688 | + ->with('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 2689 | + ->willReturn($helper); |
|
| 2690 | + |
|
| 2691 | + $this->shareManager->expects($this->never())->method('createShare'); |
|
| 2692 | + |
|
| 2693 | + $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom'); |
|
| 2694 | + } |
|
| 2695 | + |
|
| 2696 | + /** |
|
| 2697 | + * Test for https://github.com/owncloud/core/issues/22587 |
|
| 2698 | + * TODO: Remove once proper solution is in place |
|
| 2699 | + */ |
|
| 2700 | + public function testCreateReshareOfFederatedMountNoDeletePermissions(): void { |
|
| 2701 | + $share = Server::get(IManager::class)->newShare(); |
|
| 2702 | + $this->shareManager->method('newShare')->willReturn($share); |
|
| 2703 | + |
|
| 2704 | + /** @var ShareAPIController&MockObject $ocs */ |
|
| 2705 | + $ocs = $this->getMockBuilder(ShareAPIController::class) |
|
| 2706 | + ->setConstructorArgs([ |
|
| 2707 | + $this->appName, |
|
| 2708 | + $this->request, |
|
| 2709 | + $this->shareManager, |
|
| 2710 | + $this->groupManager, |
|
| 2711 | + $this->userManager, |
|
| 2712 | + $this->rootFolder, |
|
| 2713 | + $this->urlGenerator, |
|
| 2714 | + $this->l, |
|
| 2715 | + $this->config, |
|
| 2716 | + $this->appConfig, |
|
| 2717 | + $this->appManager, |
|
| 2718 | + $this->serverContainer, |
|
| 2719 | + $this->userStatusManager, |
|
| 2720 | + $this->previewManager, |
|
| 2721 | + $this->dateTimeZone, |
|
| 2722 | + $this->logger, |
|
| 2723 | + $this->factory, |
|
| 2724 | + $this->mailer, |
|
| 2725 | + $this->tagManager, |
|
| 2726 | + $this->trustedServers, |
|
| 2727 | + $this->currentUser, |
|
| 2728 | + ])->onlyMethods(['formatShare']) |
|
| 2729 | + ->getMock(); |
|
| 2730 | + |
|
| 2731 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2732 | + $this->rootFolder->expects($this->exactly(2)) |
|
| 2733 | + ->method('getUserFolder') |
|
| 2734 | + ->with('currentUser') |
|
| 2735 | + ->willReturn($userFolder); |
|
| 2736 | + |
|
| 2737 | + $path = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2738 | + $path->method('getId')->willReturn(42); |
|
| 2739 | + |
|
| 2740 | + $storage = $this->createMock(IStorage::class); |
|
| 2741 | + $storage->method('instanceOfStorage') |
|
| 2742 | + ->willReturnMap([ |
|
| 2743 | + ['OCA\Files_Sharing\External\Storage', true], |
|
| 2744 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 2745 | + ]); |
|
| 2746 | + $userFolder->method('getStorage')->willReturn($storage); |
|
| 2747 | + $path->method('getStorage')->willReturn($storage); |
|
| 2748 | + |
|
| 2749 | + $path->method('getPermissions')->willReturn(Constants::PERMISSION_READ); |
|
| 2750 | + $userFolder->expects($this->once()) |
|
| 2751 | + ->method('get') |
|
| 2752 | + ->with('valid-path') |
|
| 2753 | + ->willReturn($path); |
|
| 2754 | + $userFolder->method('getById') |
|
| 2755 | + ->willReturn([]); |
|
| 2756 | + |
|
| 2757 | + $this->userManager->method('userExists')->with('validUser')->willReturn(true); |
|
| 2758 | + |
|
| 2759 | + $this->shareManager |
|
| 2760 | + ->expects($this->once()) |
|
| 2761 | + ->method('createShare') |
|
| 2762 | + ->with($this->callback(function (IShare $share) { |
|
| 2763 | + return $share->getPermissions() === Constants::PERMISSION_READ; |
|
| 2764 | + })) |
|
| 2765 | + ->willReturnArgument(0); |
|
| 2766 | + |
|
| 2767 | + $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_USER, 'validUser'); |
|
| 2768 | + } |
|
| 2769 | + |
|
| 2770 | + |
|
| 2771 | + public function testUpdateShareCantAccess(): void { |
|
| 2772 | + $this->expectException(OCSNotFoundException::class); |
|
| 2773 | + $this->expectExceptionMessage('Wrong share ID, share does not exist'); |
|
| 2774 | + |
|
| 2775 | + [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 2776 | + $share = $this->newShare(); |
|
| 2777 | + $share->setNode($node); |
|
| 2778 | + |
|
| 2779 | + $node->expects($this->once()) |
|
| 2780 | + ->method('lock') |
|
| 2781 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 2782 | + |
|
| 2783 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2784 | + |
|
| 2785 | + $this->rootFolder->method('getUserFolder') |
|
| 2786 | + ->with($this->currentUser) |
|
| 2787 | + ->willReturn($userFolder); |
|
| 2788 | + |
|
| 2789 | + $userFolder->method('getById') |
|
| 2790 | + ->with($share->getNodeId()) |
|
| 2791 | + ->willReturn([$share->getNode()]); |
|
| 2792 | + |
|
| 2793 | + $this->ocs->updateShare(42); |
|
| 2794 | + } |
|
| 2795 | + |
|
| 2796 | + |
|
| 2797 | + public function testUpdateNoParametersLink(): void { |
|
| 2798 | + $this->expectException(OCSBadRequestException::class); |
|
| 2799 | + $this->expectExceptionMessage('Wrong or no update parameter given'); |
|
| 2800 | + |
|
| 2801 | + $node = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2802 | + $share = $this->newShare(); |
|
| 2803 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 2804 | + ->setSharedBy($this->currentUser) |
|
| 2805 | + ->setShareType(IShare::TYPE_LINK) |
|
| 2806 | + ->setNode($node); |
|
| 2807 | + |
|
| 2808 | + $node->expects($this->once()) |
|
| 2809 | + ->method('lock') |
|
| 2810 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 2811 | + |
|
| 2812 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2813 | + |
|
| 2814 | + $this->ocs->updateShare(42); |
|
| 2815 | + } |
|
| 2816 | + |
|
| 2817 | + |
|
| 2818 | + public function testUpdateNoParametersOther(): void { |
|
| 2819 | + $this->expectException(OCSBadRequestException::class); |
|
| 2820 | + $this->expectExceptionMessage('Wrong or no update parameter given'); |
|
| 2821 | + |
|
| 2822 | + $node = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 2823 | + $share = $this->newShare(); |
|
| 2824 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 2825 | + ->setSharedBy($this->currentUser) |
|
| 2826 | + ->setShareType(IShare::TYPE_GROUP) |
|
| 2827 | + ->setNode($node); |
|
| 2828 | + |
|
| 2829 | + $node->expects($this->once()) |
|
| 2830 | + ->method('lock') |
|
| 2831 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 2832 | + |
|
| 2833 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2834 | + |
|
| 2835 | + $this->ocs->updateShare(42); |
|
| 2836 | + } |
|
| 2837 | + |
|
| 2838 | + public function testUpdateLinkShareClear(): void { |
|
| 2839 | + $ocs = $this->mockFormatShare(); |
|
| 2840 | + |
|
| 2841 | + [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 2842 | + $node->method('getId') |
|
| 2843 | + ->willReturn(42); |
|
| 2844 | + $share = $this->newShare(); |
|
| 2845 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 2846 | + ->setSharedBy($this->currentUser) |
|
| 2847 | + ->setShareType(IShare::TYPE_LINK) |
|
| 2848 | + ->setPassword('password') |
|
| 2849 | + ->setExpirationDate(new \DateTime()) |
|
| 2850 | + ->setNote('note') |
|
| 2851 | + ->setLabel('label') |
|
| 2852 | + ->setHideDownload(true) |
|
| 2853 | + ->setPermissions(Constants::PERMISSION_ALL) |
|
| 2854 | + ->setNode($node); |
|
| 2855 | + |
|
| 2856 | + $node->expects($this->once()) |
|
| 2857 | + ->method('lock') |
|
| 2858 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 2859 | + |
|
| 2860 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2861 | + |
|
| 2862 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 2863 | + $this->callback(function (IShare $share) { |
|
| 2864 | + return $share->getPermissions() === Constants::PERMISSION_READ |
|
| 2865 | + && $share->getPassword() === null |
|
| 2866 | + && $share->getExpirationDate() === null |
|
| 2867 | + // Once set a note or a label are never back to null, only to an |
|
| 2868 | + // empty string. |
|
| 2869 | + && $share->getNote() === '' |
|
| 2870 | + && $share->getLabel() === '' |
|
| 2871 | + && $share->getHideDownload() === false; |
|
| 2872 | + }) |
|
| 2873 | + )->willReturnArgument(0); |
|
| 2874 | + |
|
| 2875 | + $this->shareManager->method('getSharedWith') |
|
| 2876 | + ->willReturn([]); |
|
| 2877 | + |
|
| 2878 | + $this->rootFolder->method('getUserFolder') |
|
| 2879 | + ->with($this->currentUser) |
|
| 2880 | + ->willReturn($userFolder); |
|
| 2881 | + |
|
| 2882 | + $userFolder->method('getById') |
|
| 2883 | + ->with(42) |
|
| 2884 | + ->willReturn([$node]); |
|
| 2885 | + $userFolder->method('getFirstNodeById') |
|
| 2886 | + ->with(42) |
|
| 2887 | + ->willReturn($node); |
|
| 2888 | + |
|
| 2889 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 2890 | + $node->method('getMountPoint') |
|
| 2891 | + ->willReturn($mountPoint); |
|
| 2892 | + $mountPoint->method('getStorageRootId') |
|
| 2893 | + ->willReturn(42); |
|
| 2894 | + |
|
| 2895 | + $expected = new DataResponse([]); |
|
| 2896 | + $result = $ocs->updateShare(42, null, '', null, 'false', '', '', '', 'false'); |
|
| 2897 | + |
|
| 2898 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 2899 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2900 | + } |
|
| 2901 | + |
|
| 2902 | + public function testUpdateLinkShareSet(): void { |
|
| 2903 | + $ocs = $this->mockFormatShare(); |
|
| 2904 | + |
|
| 2905 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 2906 | + $folder->method('getId') |
|
| 2907 | + ->willReturn(42); |
|
| 2908 | + |
|
| 2909 | + $share = Server::get(IManager::class)->newShare(); |
|
| 2910 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 2911 | + ->setSharedBy($this->currentUser) |
|
| 2912 | + ->setShareType(IShare::TYPE_LINK) |
|
| 2913 | + ->setNode($folder); |
|
| 2914 | + |
|
| 2915 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2916 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2917 | + |
|
| 2918 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 2919 | + $this->callback(function (IShare $share) { |
|
| 2920 | + $date = new \DateTime('2000-01-01'); |
|
| 2921 | + $date->setTime(0, 0, 0); |
|
| 2922 | + |
|
| 2923 | + return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 2924 | + && $share->getPassword() === 'password' |
|
| 2925 | + && $share->getExpirationDate() == $date |
|
| 2926 | + && $share->getNote() === 'note' |
|
| 2927 | + && $share->getLabel() === 'label' |
|
| 2928 | + && $share->getHideDownload() === true; |
|
| 2929 | + }) |
|
| 2930 | + )->willReturnArgument(0); |
|
| 2931 | + |
|
| 2932 | + $this->shareManager->method('getSharedWith') |
|
| 2933 | + ->willReturn([]); |
|
| 2934 | + |
|
| 2935 | + $this->rootFolder->method('getUserFolder') |
|
| 2936 | + ->with($this->currentUser) |
|
| 2937 | + ->willReturn($userFolder); |
|
| 2938 | + |
|
| 2939 | + $userFolder->method('getById') |
|
| 2940 | + ->with(42) |
|
| 2941 | + ->willReturn([$folder]); |
|
| 2942 | + |
|
| 2943 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 2944 | + $folder->method('getMountPoint') |
|
| 2945 | + ->willReturn($mountPoint); |
|
| 2946 | + $mountPoint->method('getStorageRootId') |
|
| 2947 | + ->willReturn(42); |
|
| 2948 | + |
|
| 2949 | + $expected = new DataResponse([]); |
|
| 2950 | + $result = $ocs->updateShare(42, null, 'password', null, 'true', '2000-01-01', 'note', 'label', 'true'); |
|
| 2951 | + |
|
| 2952 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 2953 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 2954 | + } |
|
| 2955 | + |
|
| 2956 | + #[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')] |
|
| 2957 | + public function testUpdateLinkShareEnablePublicUpload($permissions, $publicUpload, $expireDate, $password): void { |
|
| 2958 | + $ocs = $this->mockFormatShare(); |
|
| 2959 | + |
|
| 2960 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 2961 | + $folder->method('getId') |
|
| 2962 | + ->willReturn(42); |
|
| 2963 | + |
|
| 2964 | + $share = Server::get(IManager::class)->newShare(); |
|
| 2965 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 2966 | + ->setSharedBy($this->currentUser) |
|
| 2967 | + ->setShareType(IShare::TYPE_LINK) |
|
| 2968 | + ->setPassword('password') |
|
| 2969 | + ->setNode($folder); |
|
| 2970 | + |
|
| 2971 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 2972 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 2973 | + $this->shareManager->method('getSharedWith')->willReturn([]); |
|
| 2974 | + |
|
| 2975 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 2976 | + $this->callback(function (IShare $share) { |
|
| 2977 | + return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 2978 | + && $share->getPassword() === 'password' |
|
| 2979 | + && $share->getExpirationDate() === null; |
|
| 2980 | + }) |
|
| 2981 | + )->willReturnArgument(0); |
|
| 2982 | + |
|
| 2983 | + $this->rootFolder->method('getUserFolder') |
|
| 2984 | + ->with($this->currentUser) |
|
| 2985 | + ->willReturn($userFolder); |
|
| 2986 | + |
|
| 2987 | + $userFolder->method('getById') |
|
| 2988 | + ->with(42) |
|
| 2989 | + ->willReturn([$folder]); |
|
| 2990 | + |
|
| 2991 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 2992 | + $folder->method('getMountPoint') |
|
| 2993 | + ->willReturn($mountPoint); |
|
| 2994 | + $mountPoint->method('getStorageRootId') |
|
| 2995 | + ->willReturn(42); |
|
| 2996 | + |
|
| 2997 | + $expected = new DataResponse([]); |
|
| 2998 | + $result = $ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate); |
|
| 2999 | + |
|
| 3000 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3001 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3002 | + } |
|
| 3003 | + |
|
| 3004 | + |
|
| 3005 | + public static function publicLinkValidPermissionsProvider() { |
|
| 3006 | + return [ |
|
| 3007 | + [Constants::PERMISSION_CREATE], |
|
| 3008 | + [Constants::PERMISSION_READ], |
|
| 3009 | + [Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE], |
|
| 3010 | + [Constants::PERMISSION_READ | Constants::PERMISSION_DELETE], |
|
| 3011 | + [Constants::PERMISSION_READ | Constants::PERMISSION_CREATE], |
|
| 3012 | + ]; |
|
| 3013 | + } |
|
| 3014 | + |
|
| 3015 | + #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkValidPermissionsProvider')] |
|
| 3016 | + public function testUpdateLinkShareSetCRUDPermissions($permissions): void { |
|
| 3017 | + $ocs = $this->mockFormatShare(); |
|
| 3018 | + |
|
| 3019 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3020 | + $folder->method('getId') |
|
| 3021 | + ->willReturn(42); |
|
| 3022 | + |
|
| 3023 | + $share = Server::get(IManager::class)->newShare(); |
|
| 3024 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3025 | + ->setSharedBy($this->currentUser) |
|
| 3026 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3027 | + ->setPassword('password') |
|
| 3028 | + ->setNode($folder); |
|
| 3029 | + |
|
| 3030 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3031 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3032 | + $this->shareManager->method('getSharedWith')->willReturn([]); |
|
| 3033 | + |
|
| 3034 | + $this->shareManager |
|
| 3035 | + ->expects($this->any()) |
|
| 3036 | + ->method('updateShare') |
|
| 3037 | + ->willReturnArgument(0); |
|
| 3038 | + |
|
| 3039 | + $this->rootFolder->method('getUserFolder') |
|
| 3040 | + ->with($this->currentUser) |
|
| 3041 | + ->willReturn($userFolder); |
|
| 3042 | + |
|
| 3043 | + $userFolder->method('getById') |
|
| 3044 | + ->with(42) |
|
| 3045 | + ->willReturn([$folder]); |
|
| 3046 | + |
|
| 3047 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3048 | + $folder->method('getMountPoint') |
|
| 3049 | + ->willReturn($mountPoint); |
|
| 3050 | + $mountPoint->method('getStorageRootId') |
|
| 3051 | + ->willReturn(42); |
|
| 3052 | + |
|
| 3053 | + $expected = new DataResponse([]); |
|
| 3054 | + $result = $ocs->updateShare(42, $permissions, 'password', null, null, null); |
|
| 3055 | + |
|
| 3056 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3057 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3058 | + } |
|
| 3059 | + |
|
| 3060 | + public static function publicLinkInvalidPermissionsProvider1() { |
|
| 3061 | + return [ |
|
| 3062 | + [Constants::PERMISSION_DELETE], |
|
| 3063 | + [Constants::PERMISSION_UPDATE], |
|
| 3064 | + [Constants::PERMISSION_SHARE], |
|
| 3065 | + ]; |
|
| 3066 | + } |
|
| 3067 | + |
|
| 3068 | + #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider1')] |
|
| 3069 | + public function testUpdateLinkShareSetInvalidCRUDPermissions1($permissions): void { |
|
| 3070 | + $this->expectException(OCSBadRequestException::class); |
|
| 3071 | + $this->expectExceptionMessage('Share must at least have READ or CREATE permissions'); |
|
| 3072 | + |
|
| 3073 | + $this->testUpdateLinkShareSetCRUDPermissions($permissions, null); |
|
| 3074 | + } |
|
| 3075 | + |
|
| 3076 | + public static function publicLinkInvalidPermissionsProvider2() { |
|
| 3077 | + return [ |
|
| 3078 | + [Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE], |
|
| 3079 | + [Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE], |
|
| 3080 | + ]; |
|
| 3081 | + } |
|
| 3082 | + |
|
| 3083 | + #[\PHPUnit\Framework\Attributes\DataProvider('publicLinkInvalidPermissionsProvider2')] |
|
| 3084 | + public function testUpdateLinkShareSetInvalidCRUDPermissions2($permissions): void { |
|
| 3085 | + $this->expectException(OCSBadRequestException::class); |
|
| 3086 | + $this->expectExceptionMessage('Share must have READ permission if UPDATE or DELETE permission is set'); |
|
| 3087 | + |
|
| 3088 | + $this->testUpdateLinkShareSetCRUDPermissions($permissions); |
|
| 3089 | + } |
|
| 3090 | + |
|
| 3091 | + public function testUpdateLinkShareInvalidDate(): void { |
|
| 3092 | + $this->expectException(OCSBadRequestException::class); |
|
| 3093 | + $this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD'); |
|
| 3094 | + |
|
| 3095 | + $ocs = $this->mockFormatShare(); |
|
| 3096 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3097 | + $userFolder->method('getById') |
|
| 3098 | + ->with(42) |
|
| 3099 | + ->willReturn([$folder]); |
|
| 3100 | + $this->rootFolder->method('getUserFolder') |
|
| 3101 | + ->with($this->currentUser) |
|
| 3102 | + ->willReturn($userFolder); |
|
| 3103 | + |
|
| 3104 | + $folder->method('getId') |
|
| 3105 | + ->willReturn(42); |
|
| 3106 | + |
|
| 3107 | + $share = Server::get(IManager::class)->newShare(); |
|
| 3108 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3109 | + ->setSharedBy($this->currentUser) |
|
| 3110 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3111 | + ->setNode($folder); |
|
| 3112 | + |
|
| 3113 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3114 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3115 | + |
|
| 3116 | + $ocs->updateShare(42, null, 'password', null, 'true', '2000-01-a'); |
|
| 3117 | + } |
|
| 3118 | + |
|
| 3119 | + public static function publicUploadParamsProvider() { |
|
| 3120 | + return [ |
|
| 3121 | + [null, 'true', null, 'password'], |
|
| 3122 | + // legacy had no delete |
|
| 3123 | + [ |
|
| 3124 | + Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, |
|
| 3125 | + 'true', null, 'password' |
|
| 3126 | + ], |
|
| 3127 | + // correct |
|
| 3128 | + [ |
|
| 3129 | + Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, |
|
| 3130 | + null, null, 'password' |
|
| 3131 | + ], |
|
| 3132 | + ]; |
|
| 3133 | + } |
|
| 3134 | + |
|
| 3135 | + #[\PHPUnit\Framework\Attributes\DataProvider('publicUploadParamsProvider')] |
|
| 3136 | + public function testUpdateLinkSharePublicUploadNotAllowed($permissions, $publicUpload, $expireDate, $password): void { |
|
| 3137 | + $this->expectException(OCSForbiddenException::class); |
|
| 3138 | + $this->expectExceptionMessage('Public upload disabled by the administrator'); |
|
| 3139 | + |
|
| 3140 | + $ocs = $this->mockFormatShare(); |
|
| 3141 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3142 | + $userFolder->method('getById') |
|
| 3143 | + ->with(42) |
|
| 3144 | + ->willReturn([$folder]); |
|
| 3145 | + $this->rootFolder->method('getUserFolder') |
|
| 3146 | + ->with($this->currentUser) |
|
| 3147 | + ->willReturn($userFolder); |
|
| 3148 | + |
|
| 3149 | + $folder->method('getId')->willReturn(42); |
|
| 3150 | + |
|
| 3151 | + $share = Server::get(IManager::class)->newShare(); |
|
| 3152 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3153 | + ->setSharedBy($this->currentUser) |
|
| 3154 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3155 | + ->setNode($folder); |
|
| 3156 | + |
|
| 3157 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3158 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(false); |
|
| 3159 | + |
|
| 3160 | + $ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate); |
|
| 3161 | + } |
|
| 3162 | + |
|
| 3163 | + |
|
| 3164 | + public function testUpdateLinkSharePublicUploadOnFile(): void { |
|
| 3165 | + $this->expectException(OCSBadRequestException::class); |
|
| 3166 | + $this->expectExceptionMessage('Public upload is only possible for publicly shared folders'); |
|
| 3167 | + |
|
| 3168 | + $ocs = $this->mockFormatShare(); |
|
| 3169 | + |
|
| 3170 | + $file = $this->getMockBuilder(File::class)->getMock(); |
|
| 3171 | + $file->method('getId') |
|
| 3172 | + ->willReturn(42); |
|
| 3173 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3174 | + $userFolder->method('getById') |
|
| 3175 | + ->with(42) |
|
| 3176 | + ->willReturn([$folder]); |
|
| 3177 | + $this->rootFolder->method('getUserFolder') |
|
| 3178 | + ->with($this->currentUser) |
|
| 3179 | + ->willReturn($userFolder); |
|
| 3180 | + |
|
| 3181 | + $share = Server::get(IManager::class)->newShare(); |
|
| 3182 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3183 | + ->setSharedBy($this->currentUser) |
|
| 3184 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3185 | + ->setNode($file); |
|
| 3186 | + |
|
| 3187 | + $this->shareManager |
|
| 3188 | + ->method('getShareById') |
|
| 3189 | + ->with('ocinternal:42') |
|
| 3190 | + ->willReturn($share); |
|
| 3191 | + $this->shareManager |
|
| 3192 | + ->method('shareApiLinkAllowPublicUpload') |
|
| 3193 | + ->willReturn(true); |
|
| 3194 | + $this->shareManager |
|
| 3195 | + ->method('updateShare') |
|
| 3196 | + ->with($share) |
|
| 3197 | + ->willThrowException(new \InvalidArgumentException('File shares cannot have create or delete permissions')); |
|
| 3198 | + |
|
| 3199 | + $ocs->updateShare(42, null, 'password', null, 'true', ''); |
|
| 3200 | + } |
|
| 3201 | + |
|
| 3202 | + public function testUpdateLinkSharePasswordDoesNotChangeOther(): void { |
|
| 3203 | + $ocs = $this->mockFormatShare(); |
|
| 3204 | + |
|
| 3205 | + $date = new \DateTime('2000-01-01'); |
|
| 3206 | + $date->setTime(0, 0, 0); |
|
| 3207 | + |
|
| 3208 | + [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3209 | + $node->method('getId')->willReturn(42); |
|
| 3210 | + $userFolder->method('getById') |
|
| 3211 | + ->with(42) |
|
| 3212 | + ->willReturn([$node]); |
|
| 3213 | + $this->rootFolder->method('getUserFolder') |
|
| 3214 | + ->with($this->currentUser) |
|
| 3215 | + ->willReturn($userFolder); |
|
| 3216 | + $share = $this->newShare(); |
|
| 3217 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3218 | + ->setSharedBy($this->currentUser) |
|
| 3219 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3220 | + ->setPassword('password') |
|
| 3221 | + ->setSendPasswordByTalk(true) |
|
| 3222 | + ->setExpirationDate($date) |
|
| 3223 | + ->setNote('note') |
|
| 3224 | + ->setLabel('label') |
|
| 3225 | + ->setHideDownload(true) |
|
| 3226 | + ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3227 | + ->setNode($node); |
|
| 3228 | + |
|
| 3229 | + $node->expects($this->once()) |
|
| 3230 | + ->method('lock') |
|
| 3231 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 3232 | + |
|
| 3233 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3234 | + |
|
| 3235 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3236 | + $this->callback(function (IShare $share) use ($date) { |
|
| 3237 | + return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3238 | + && $share->getPassword() === 'newpassword' |
|
| 3239 | + && $share->getSendPasswordByTalk() === true |
|
| 3240 | + && $share->getExpirationDate() === $date |
|
| 3241 | + && $share->getNote() === 'note' |
|
| 3242 | + && $share->getLabel() === 'label' |
|
| 3243 | + && $share->getHideDownload() === true; |
|
| 3244 | + }) |
|
| 3245 | + )->willReturnArgument(0); |
|
| 3246 | + |
|
| 3247 | + $expected = new DataResponse([]); |
|
| 3248 | + $result = $ocs->updateShare(42, null, 'newpassword', null, null, null, null, null, null); |
|
| 3249 | + |
|
| 3250 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3251 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3252 | + } |
|
| 3253 | + |
|
| 3254 | + public function testUpdateLinkShareSendPasswordByTalkDoesNotChangeOther(): void { |
|
| 3255 | + $ocs = $this->mockFormatShare(); |
|
| 3256 | + |
|
| 3257 | + $date = new \DateTime('2000-01-01'); |
|
| 3258 | + $date->setTime(0, 0, 0); |
|
| 3259 | + |
|
| 3260 | + [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3261 | + $userFolder->method('getById') |
|
| 3262 | + ->with(42) |
|
| 3263 | + ->willReturn([$node]); |
|
| 3264 | + $this->rootFolder->method('getUserFolder') |
|
| 3265 | + ->with($this->currentUser) |
|
| 3266 | + ->willReturn($userFolder); |
|
| 3267 | + $node->method('getId')->willReturn(42); |
|
| 3268 | + $share = $this->newShare(); |
|
| 3269 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3270 | + ->setSharedBy($this->currentUser) |
|
| 3271 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3272 | + ->setPassword('password') |
|
| 3273 | + ->setSendPasswordByTalk(false) |
|
| 3274 | + ->setExpirationDate($date) |
|
| 3275 | + ->setNote('note') |
|
| 3276 | + ->setLabel('label') |
|
| 3277 | + ->setHideDownload(true) |
|
| 3278 | + ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3279 | + ->setNode($node); |
|
| 3280 | + |
|
| 3281 | + $node->expects($this->once()) |
|
| 3282 | + ->method('lock') |
|
| 3283 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 3284 | + |
|
| 3285 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3286 | + |
|
| 3287 | + $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true); |
|
| 3288 | + |
|
| 3289 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3290 | + $this->callback(function (IShare $share) use ($date) { |
|
| 3291 | + return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3292 | + && $share->getPassword() === 'password' |
|
| 3293 | + && $share->getSendPasswordByTalk() === true |
|
| 3294 | + && $share->getExpirationDate() === $date |
|
| 3295 | + && $share->getNote() === 'note' |
|
| 3296 | + && $share->getLabel() === 'label' |
|
| 3297 | + && $share->getHideDownload() === true; |
|
| 3298 | + }) |
|
| 3299 | + )->willReturnArgument(0); |
|
| 3300 | + |
|
| 3301 | + $expected = new DataResponse([]); |
|
| 3302 | + $result = $ocs->updateShare(42, null, null, 'true', null, null, null, null, null); |
|
| 3303 | + |
|
| 3304 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3305 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3306 | + } |
|
| 3307 | + |
|
| 3308 | + |
|
| 3309 | + public function testUpdateLinkShareSendPasswordByTalkWithTalkDisabledDoesNotChangeOther(): void { |
|
| 3310 | + $this->expectException(OCSForbiddenException::class); |
|
| 3311 | + $this->expectExceptionMessage('"Sending the password by Nextcloud Talk" for sharing a file or folder failed because Nextcloud Talk is not enabled.'); |
|
| 3312 | + |
|
| 3313 | + $ocs = $this->mockFormatShare(); |
|
| 3314 | + |
|
| 3315 | + $date = new \DateTime('2000-01-01'); |
|
| 3316 | + $date->setTime(0, 0, 0); |
|
| 3317 | + |
|
| 3318 | + [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3319 | + $userFolder->method('getById') |
|
| 3320 | + ->with(42) |
|
| 3321 | + ->willReturn([$node]); |
|
| 3322 | + $this->rootFolder->method('getUserFolder') |
|
| 3323 | + ->with($this->currentUser) |
|
| 3324 | + ->willReturn($userFolder); |
|
| 3325 | + $node->method('getId')->willReturn(42); |
|
| 3326 | + $share = $this->newShare(); |
|
| 3327 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3328 | + ->setSharedBy($this->currentUser) |
|
| 3329 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3330 | + ->setPassword('password') |
|
| 3331 | + ->setSendPasswordByTalk(false) |
|
| 3332 | + ->setExpirationDate($date) |
|
| 3333 | + ->setNote('note') |
|
| 3334 | + ->setLabel('label') |
|
| 3335 | + ->setHideDownload(true) |
|
| 3336 | + ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3337 | + ->setNode($node); |
|
| 3338 | + |
|
| 3339 | + $node->expects($this->once()) |
|
| 3340 | + ->method('lock') |
|
| 3341 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 3342 | + |
|
| 3343 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3344 | + |
|
| 3345 | + $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false); |
|
| 3346 | + |
|
| 3347 | + $this->shareManager->expects($this->never())->method('updateShare'); |
|
| 3348 | + |
|
| 3349 | + $ocs->updateShare(42, null, null, 'true', null, null, null, null, null); |
|
| 3350 | + } |
|
| 3351 | + |
|
| 3352 | + public function testUpdateLinkShareDoNotSendPasswordByTalkDoesNotChangeOther(): void { |
|
| 3353 | + $ocs = $this->mockFormatShare(); |
|
| 3354 | + |
|
| 3355 | + $date = new \DateTime('2000-01-01'); |
|
| 3356 | + $date->setTime(0, 0, 0); |
|
| 3357 | + |
|
| 3358 | + [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3359 | + $userFolder->method('getById') |
|
| 3360 | + ->with(42) |
|
| 3361 | + ->willReturn([$node]); |
|
| 3362 | + $this->rootFolder->method('getUserFolder') |
|
| 3363 | + ->with($this->currentUser) |
|
| 3364 | + ->willReturn($userFolder); |
|
| 3365 | + $node->method('getId')->willReturn(42); |
|
| 3366 | + $share = $this->newShare(); |
|
| 3367 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3368 | + ->setSharedBy($this->currentUser) |
|
| 3369 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3370 | + ->setPassword('password') |
|
| 3371 | + ->setSendPasswordByTalk(true) |
|
| 3372 | + ->setExpirationDate($date) |
|
| 3373 | + ->setNote('note') |
|
| 3374 | + ->setLabel('label') |
|
| 3375 | + ->setHideDownload(true) |
|
| 3376 | + ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3377 | + ->setNode($node); |
|
| 3378 | + |
|
| 3379 | + $node->expects($this->once()) |
|
| 3380 | + ->method('lock') |
|
| 3381 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 3382 | + |
|
| 3383 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3384 | + |
|
| 3385 | + $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(true); |
|
| 3386 | + |
|
| 3387 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3388 | + $this->callback(function (IShare $share) use ($date) { |
|
| 3389 | + return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3390 | + && $share->getPassword() === 'password' |
|
| 3391 | + && $share->getSendPasswordByTalk() === false |
|
| 3392 | + && $share->getExpirationDate() === $date |
|
| 3393 | + && $share->getNote() === 'note' |
|
| 3394 | + && $share->getLabel() === 'label' |
|
| 3395 | + && $share->getHideDownload() === true; |
|
| 3396 | + }) |
|
| 3397 | + )->willReturnArgument(0); |
|
| 3398 | + |
|
| 3399 | + $expected = new DataResponse([]); |
|
| 3400 | + $result = $ocs->updateShare(42, null, null, 'false', null, null, null, null, null); |
|
| 3401 | + |
|
| 3402 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3403 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3404 | + } |
|
| 3405 | + |
|
| 3406 | + public function testUpdateLinkShareDoNotSendPasswordByTalkWithTalkDisabledDoesNotChangeOther(): void { |
|
| 3407 | + $ocs = $this->mockFormatShare(); |
|
| 3408 | + |
|
| 3409 | + $date = new \DateTime('2000-01-01'); |
|
| 3410 | + $date->setTime(0, 0, 0); |
|
| 3411 | + |
|
| 3412 | + [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3413 | + $node->method('getId') |
|
| 3414 | + ->willReturn(42); |
|
| 3415 | + |
|
| 3416 | + $share = $this->newShare(); |
|
| 3417 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3418 | + ->setSharedBy($this->currentUser) |
|
| 3419 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3420 | + ->setPassword('password') |
|
| 3421 | + ->setSendPasswordByTalk(true) |
|
| 3422 | + ->setExpirationDate($date) |
|
| 3423 | + ->setNote('note') |
|
| 3424 | + ->setLabel('label') |
|
| 3425 | + ->setHideDownload(true) |
|
| 3426 | + ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3427 | + ->setNode($node); |
|
| 3428 | + |
|
| 3429 | + $node->expects($this->once()) |
|
| 3430 | + ->method('lock') |
|
| 3431 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 3432 | + |
|
| 3433 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3434 | + |
|
| 3435 | + $this->appManager->method('isEnabledForUser')->with('spreed')->willReturn(false); |
|
| 3436 | + |
|
| 3437 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3438 | + $this->callback(function (IShare $share) use ($date) { |
|
| 3439 | + return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3440 | + && $share->getPassword() === 'password' |
|
| 3441 | + && $share->getSendPasswordByTalk() === false |
|
| 3442 | + && $share->getExpirationDate() === $date |
|
| 3443 | + && $share->getNote() === 'note' |
|
| 3444 | + && $share->getLabel() === 'label' |
|
| 3445 | + && $share->getHideDownload() === true; |
|
| 3446 | + }) |
|
| 3447 | + )->willReturnArgument(0); |
|
| 3448 | + |
|
| 3449 | + $this->rootFolder->method('getUserFolder') |
|
| 3450 | + ->with($this->currentUser) |
|
| 3451 | + ->willReturn($userFolder); |
|
| 3452 | + |
|
| 3453 | + $userFolder->method('getById') |
|
| 3454 | + ->with(42) |
|
| 3455 | + ->willReturn([$node]); |
|
| 3456 | + |
|
| 3457 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3458 | + $node->method('getMountPoint') |
|
| 3459 | + ->willReturn($mountPoint); |
|
| 3460 | + $mountPoint->method('getStorageRootId') |
|
| 3461 | + ->willReturn(42); |
|
| 3462 | + |
|
| 3463 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3464 | + $node->method('getMountPoint') |
|
| 3465 | + ->willReturn($mountPoint); |
|
| 3466 | + $mountPoint->method('getStorageRootId') |
|
| 3467 | + ->willReturn(42); |
|
| 3468 | + |
|
| 3469 | + $expected = new DataResponse([]); |
|
| 3470 | + $result = $ocs->updateShare(42, null, null, 'false', null, null, null, null, null); |
|
| 3471 | + |
|
| 3472 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3473 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3474 | + } |
|
| 3475 | + |
|
| 3476 | + public function testUpdateLinkShareExpireDateDoesNotChangeOther(): void { |
|
| 3477 | + $ocs = $this->mockFormatShare(); |
|
| 3478 | + |
|
| 3479 | + [$userFolder, $node] = $this->getNonSharedUserFolder(); |
|
| 3480 | + $node->method('getId') |
|
| 3481 | + ->willReturn(42); |
|
| 3482 | + |
|
| 3483 | + $share = $this->newShare(); |
|
| 3484 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3485 | + ->setSharedBy($this->currentUser) |
|
| 3486 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3487 | + ->setPassword('password') |
|
| 3488 | + ->setSendPasswordByTalk(true) |
|
| 3489 | + ->setExpirationDate(new \DateTime()) |
|
| 3490 | + ->setNote('note') |
|
| 3491 | + ->setLabel('label') |
|
| 3492 | + ->setHideDownload(true) |
|
| 3493 | + ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3494 | + ->setNode($node); |
|
| 3495 | + |
|
| 3496 | + $node->expects($this->once()) |
|
| 3497 | + ->method('lock') |
|
| 3498 | + ->with(ILockingProvider::LOCK_SHARED); |
|
| 3499 | + |
|
| 3500 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3501 | + |
|
| 3502 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3503 | + $this->callback(function (IShare $share) { |
|
| 3504 | + $date = new \DateTime('2010-12-23'); |
|
| 3505 | + $date->setTime(0, 0, 0); |
|
| 3506 | + |
|
| 3507 | + return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3508 | + && $share->getPassword() === 'password' |
|
| 3509 | + && $share->getSendPasswordByTalk() === true |
|
| 3510 | + && $share->getExpirationDate() == $date |
|
| 3511 | + && $share->getNote() === 'note' |
|
| 3512 | + && $share->getLabel() === 'label' |
|
| 3513 | + && $share->getHideDownload() === true; |
|
| 3514 | + }) |
|
| 3515 | + )->willReturnArgument(0); |
|
| 3516 | + |
|
| 3517 | + $this->rootFolder->method('getUserFolder') |
|
| 3518 | + ->with($this->currentUser) |
|
| 3519 | + ->willReturn($userFolder); |
|
| 3520 | + |
|
| 3521 | + $userFolder->method('getById') |
|
| 3522 | + ->with(42) |
|
| 3523 | + ->willReturn([$node]); |
|
| 3524 | + |
|
| 3525 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3526 | + $node->method('getMountPoint') |
|
| 3527 | + ->willReturn($mountPoint); |
|
| 3528 | + $mountPoint->method('getStorageRootId') |
|
| 3529 | + ->willReturn(42); |
|
| 3530 | + |
|
| 3531 | + $expected = new DataResponse([]); |
|
| 3532 | + $result = $ocs->updateShare(42, null, null, null, null, '2010-12-23', null, null, null); |
|
| 3533 | + |
|
| 3534 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3535 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3536 | + } |
|
| 3537 | + |
|
| 3538 | + public function testUpdateLinkSharePublicUploadDoesNotChangeOther(): void { |
|
| 3539 | + $ocs = $this->mockFormatShare(); |
|
| 3540 | + |
|
| 3541 | + $date = new \DateTime('2000-01-01'); |
|
| 3542 | + |
|
| 3543 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3544 | + $folder->method('getId') |
|
| 3545 | + ->willReturn(42); |
|
| 3546 | + |
|
| 3547 | + $share = Server::get(IManager::class)->newShare(); |
|
| 3548 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3549 | + ->setSharedBy($this->currentUser) |
|
| 3550 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3551 | + ->setPassword('password') |
|
| 3552 | + ->setSendPasswordByTalk(true) |
|
| 3553 | + ->setExpirationDate($date) |
|
| 3554 | + ->setNote('note') |
|
| 3555 | + ->setLabel('label') |
|
| 3556 | + ->setHideDownload(true) |
|
| 3557 | + ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3558 | + ->setNode($folder); |
|
| 3559 | + |
|
| 3560 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3561 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3562 | + |
|
| 3563 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3564 | + $this->callback(function (IShare $share) use ($date) { |
|
| 3565 | + return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 3566 | + && $share->getPassword() === 'password' |
|
| 3567 | + && $share->getSendPasswordByTalk() === true |
|
| 3568 | + && $share->getExpirationDate() === $date |
|
| 3569 | + && $share->getNote() === 'note' |
|
| 3570 | + && $share->getLabel() === 'label' |
|
| 3571 | + && $share->getHideDownload() === true; |
|
| 3572 | + }) |
|
| 3573 | + )->willReturnArgument(0); |
|
| 3574 | + |
|
| 3575 | + $this->shareManager->method('getSharedWith') |
|
| 3576 | + ->willReturn([]); |
|
| 3577 | + |
|
| 3578 | + $this->rootFolder->method('getUserFolder') |
|
| 3579 | + ->with($this->currentUser) |
|
| 3580 | + ->willReturn($userFolder); |
|
| 3581 | + |
|
| 3582 | + $userFolder->method('getById') |
|
| 3583 | + ->with(42) |
|
| 3584 | + ->willReturn([$folder]); |
|
| 3585 | + |
|
| 3586 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3587 | + $folder->method('getMountPoint') |
|
| 3588 | + ->willReturn($mountPoint); |
|
| 3589 | + $mountPoint->method('getStorageRootId') |
|
| 3590 | + ->willReturn(42); |
|
| 3591 | + |
|
| 3592 | + $expected = new DataResponse([]); |
|
| 3593 | + $result = $ocs->updateShare(42, null, null, null, 'true', null, null, null, null); |
|
| 3594 | + |
|
| 3595 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3596 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3597 | + } |
|
| 3598 | + |
|
| 3599 | + public function testUpdateLinkSharePermissions(): void { |
|
| 3600 | + $ocs = $this->mockFormatShare(); |
|
| 3601 | + |
|
| 3602 | + $date = new \DateTime('2000-01-01'); |
|
| 3603 | + |
|
| 3604 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3605 | + $folder->method('getId') |
|
| 3606 | + ->willReturn(42); |
|
| 3607 | + |
|
| 3608 | + $share = Server::get(IManager::class)->newShare(); |
|
| 3609 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3610 | + ->setSharedBy($this->currentUser) |
|
| 3611 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3612 | + ->setPassword('password') |
|
| 3613 | + ->setSendPasswordByTalk(true) |
|
| 3614 | + ->setExpirationDate($date) |
|
| 3615 | + ->setNote('note') |
|
| 3616 | + ->setLabel('label') |
|
| 3617 | + ->setHideDownload(true) |
|
| 3618 | + ->setPermissions(Constants::PERMISSION_ALL) |
|
| 3619 | + ->setNode($folder); |
|
| 3620 | + |
|
| 3621 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3622 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3623 | + |
|
| 3624 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3625 | + $this->callback(function (IShare $share) use ($date): bool { |
|
| 3626 | + return $share->getPermissions() === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 3627 | + && $share->getPassword() === 'password' |
|
| 3628 | + && $share->getSendPasswordByTalk() === true |
|
| 3629 | + && $share->getExpirationDate() === $date |
|
| 3630 | + && $share->getNote() === 'note' |
|
| 3631 | + && $share->getLabel() === 'label' |
|
| 3632 | + && $share->getHideDownload() === true; |
|
| 3633 | + }) |
|
| 3634 | + )->willReturnArgument(0); |
|
| 3635 | + |
|
| 3636 | + $this->shareManager->method('getSharedWith')->willReturn([]); |
|
| 3637 | + |
|
| 3638 | + $this->rootFolder->method('getUserFolder') |
|
| 3639 | + ->with($this->currentUser) |
|
| 3640 | + ->willReturn($userFolder); |
|
| 3641 | + |
|
| 3642 | + $userFolder->method('getById') |
|
| 3643 | + ->with(42) |
|
| 3644 | + ->willReturn([$folder]); |
|
| 3645 | + |
|
| 3646 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3647 | + $folder->method('getMountPoint') |
|
| 3648 | + ->willReturn($mountPoint); |
|
| 3649 | + $mountPoint->method('getStorageRootId') |
|
| 3650 | + ->willReturn(42); |
|
| 3651 | + |
|
| 3652 | + $expected = new DataResponse([]); |
|
| 3653 | + $result = $ocs->updateShare(42, 7, null, null, 'true', null, null, null, null); |
|
| 3654 | + |
|
| 3655 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3656 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3657 | + } |
|
| 3658 | + |
|
| 3659 | + public function testUpdateLinkSharePermissionsShare(): void { |
|
| 3660 | + $ocs = $this->mockFormatShare(); |
|
| 3661 | + |
|
| 3662 | + $date = new \DateTime('2000-01-01'); |
|
| 3663 | + |
|
| 3664 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3665 | + $folder->method('getId') |
|
| 3666 | + ->willReturn(42); |
|
| 3667 | + |
|
| 3668 | + $share = Server::get(IManager::class)->newShare(); |
|
| 3669 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3670 | + ->setSharedBy($this->currentUser) |
|
| 3671 | + ->setShareType(IShare::TYPE_LINK) |
|
| 3672 | + ->setPassword('password') |
|
| 3673 | + ->setSendPasswordByTalk(true) |
|
| 3674 | + ->setExpirationDate($date) |
|
| 3675 | + ->setNote('note') |
|
| 3676 | + ->setLabel('label') |
|
| 3677 | + ->setHideDownload(true) |
|
| 3678 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 3679 | + ->setNode($folder); |
|
| 3680 | + |
|
| 3681 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3682 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3683 | + |
|
| 3684 | + $this->shareManager->expects($this->once()) |
|
| 3685 | + ->method('updateShare') |
|
| 3686 | + ->with( |
|
| 3687 | + $this->callback(function (IShare $share) use ($date) { |
|
| 3688 | + return $share->getPermissions() === Constants::PERMISSION_ALL |
|
| 3689 | + && $share->getPassword() === 'password' |
|
| 3690 | + && $share->getSendPasswordByTalk() === true |
|
| 3691 | + && $share->getExpirationDate() === $date |
|
| 3692 | + && $share->getNote() === 'note' |
|
| 3693 | + && $share->getLabel() === 'label' |
|
| 3694 | + && $share->getHideDownload() === true; |
|
| 3695 | + }) |
|
| 3696 | + )->willReturnArgument(0); |
|
| 3697 | + |
|
| 3698 | + $this->rootFolder->method('getUserFolder') |
|
| 3699 | + ->with($this->currentUser) |
|
| 3700 | + ->willReturn($userFolder); |
|
| 3701 | + |
|
| 3702 | + $userFolder->method('getById') |
|
| 3703 | + ->with(42) |
|
| 3704 | + ->willReturn([$folder]); |
|
| 3705 | + |
|
| 3706 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3707 | + $folder->method('getMountPoint') |
|
| 3708 | + ->willReturn($mountPoint); |
|
| 3709 | + $mountPoint->method('getStorageRootId') |
|
| 3710 | + ->willReturn(42); |
|
| 3711 | + |
|
| 3712 | + $this->shareManager->method('getSharedWith')->willReturn([]); |
|
| 3713 | + |
|
| 3714 | + $expected = new DataResponse([]); |
|
| 3715 | + $result = $ocs->updateShare(42, Constants::PERMISSION_ALL, null, null, null, null, null, null, null); |
|
| 3716 | + |
|
| 3717 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3718 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3719 | + } |
|
| 3720 | + |
|
| 3721 | + public function testUpdateOtherPermissions(): void { |
|
| 3722 | + $ocs = $this->mockFormatShare(); |
|
| 3723 | + |
|
| 3724 | + [$userFolder, $file] = $this->getNonSharedUserFolder(); |
|
| 3725 | + $file->method('getId') |
|
| 3726 | + ->willReturn(42); |
|
| 3727 | + |
|
| 3728 | + $share = Server::get(IManager::class)->newShare(); |
|
| 3729 | + $share->setPermissions(Constants::PERMISSION_ALL) |
|
| 3730 | + ->setSharedBy($this->currentUser) |
|
| 3731 | + ->setShareType(IShare::TYPE_USER) |
|
| 3732 | + ->setNode($file); |
|
| 3733 | + |
|
| 3734 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3735 | + $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); |
|
| 3736 | + |
|
| 3737 | + $this->shareManager->expects($this->once())->method('updateShare')->with( |
|
| 3738 | + $this->callback(function (IShare $share) { |
|
| 3739 | + return $share->getPermissions() === Constants::PERMISSION_ALL; |
|
| 3740 | + }) |
|
| 3741 | + )->willReturnArgument(0); |
|
| 3742 | + |
|
| 3743 | + $this->shareManager->method('getSharedWith')->willReturn([]); |
|
| 3744 | + |
|
| 3745 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3746 | + $this->rootFolder->method('getUserFolder') |
|
| 3747 | + ->with($this->currentUser) |
|
| 3748 | + ->willReturn($userFolder); |
|
| 3749 | + |
|
| 3750 | + $userFolder->method('getById') |
|
| 3751 | + ->with(42) |
|
| 3752 | + ->willReturn([$file]); |
|
| 3753 | + |
|
| 3754 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3755 | + $file->method('getMountPoint') |
|
| 3756 | + ->willReturn($mountPoint); |
|
| 3757 | + $mountPoint->method('getStorageRootId') |
|
| 3758 | + ->willReturn(42); |
|
| 3759 | + |
|
| 3760 | + $expected = new DataResponse([]); |
|
| 3761 | + $result = $ocs->updateShare(42, 31, null, null, null, null); |
|
| 3762 | + |
|
| 3763 | + $this->assertInstanceOf(get_class($expected), $result); |
|
| 3764 | + $this->assertEquals($expected->getData(), $result->getData()); |
|
| 3765 | + } |
|
| 3766 | + |
|
| 3767 | + public function testUpdateShareCannotIncreasePermissions(): void { |
|
| 3768 | + $ocs = $this->mockFormatShare(); |
|
| 3769 | + |
|
| 3770 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3771 | + $folder->method('getId') |
|
| 3772 | + ->willReturn(42); |
|
| 3773 | + |
|
| 3774 | + $share = Server::get(IManager::class)->newShare(); |
|
| 3775 | + $share |
|
| 3776 | + ->setId(42) |
|
| 3777 | + ->setSharedBy($this->currentUser) |
|
| 3778 | + ->setShareOwner('anotheruser') |
|
| 3779 | + ->setShareType(IShare::TYPE_GROUP) |
|
| 3780 | + ->setSharedWith('group1') |
|
| 3781 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 3782 | + ->setNode($folder); |
|
| 3783 | + |
|
| 3784 | + // note: updateShare will modify the received instance but getSharedWith will reread from the database, |
|
| 3785 | + // so their values will be different |
|
| 3786 | + $incomingShare = Server::get(IManager::class)->newShare(); |
|
| 3787 | + $incomingShare |
|
| 3788 | + ->setId(42) |
|
| 3789 | + ->setSharedBy($this->currentUser) |
|
| 3790 | + ->setShareOwner('anotheruser') |
|
| 3791 | + ->setShareType(IShare::TYPE_GROUP) |
|
| 3792 | + ->setSharedWith('group1') |
|
| 3793 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 3794 | + ->setNode($folder); |
|
| 3795 | + |
|
| 3796 | + $this->request |
|
| 3797 | + ->method('getParam') |
|
| 3798 | + ->willReturnMap([ |
|
| 3799 | + ['permissions', null, '31'], |
|
| 3800 | + ]); |
|
| 3801 | + |
|
| 3802 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3803 | + |
|
| 3804 | + $this->shareManager->expects($this->any()) |
|
| 3805 | + ->method('getSharedWith') |
|
| 3806 | + ->willReturnMap([ |
|
| 3807 | + ['currentUser', IShare::TYPE_USER, $share->getNode(), -1, 0, []], |
|
| 3808 | + ['currentUser', IShare::TYPE_GROUP, $share->getNode(), -1, 0, [$incomingShare]], |
|
| 3809 | + ['currentUser', IShare::TYPE_ROOM, $share->getNode(), -1, 0, []] |
|
| 3810 | + ]); |
|
| 3811 | + |
|
| 3812 | + $this->rootFolder->method('getUserFolder') |
|
| 3813 | + ->with($this->currentUser) |
|
| 3814 | + ->willReturn($userFolder); |
|
| 3815 | + |
|
| 3816 | + $userFolder->method('getById') |
|
| 3817 | + ->with(42) |
|
| 3818 | + ->willReturn([$folder]); |
|
| 3819 | + $userFolder->method('getFirstNodeById') |
|
| 3820 | + ->with(42) |
|
| 3821 | + ->willReturn($folder); |
|
| 3822 | + |
|
| 3823 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3824 | + $folder->method('getMountPoint') |
|
| 3825 | + ->willReturn($mountPoint); |
|
| 3826 | + $mountPoint->method('getStorageRootId') |
|
| 3827 | + ->willReturn(42); |
|
| 3828 | + |
|
| 3829 | + $this->shareManager->expects($this->once()) |
|
| 3830 | + ->method('updateShare') |
|
| 3831 | + ->with($share) |
|
| 3832 | + ->willThrowException(new GenericShareException('Cannot increase permissions of path/file', 'Cannot increase permissions of path/file', 404)); |
|
| 3833 | + |
|
| 3834 | + try { |
|
| 3835 | + $ocs->updateShare(42, 31); |
|
| 3836 | + $this->fail(); |
|
| 3837 | + } catch (OCSException $e) { |
|
| 3838 | + $this->assertEquals('Cannot increase permissions of path/file', $e->getMessage()); |
|
| 3839 | + } |
|
| 3840 | + } |
|
| 3841 | + |
|
| 3842 | + public function testUpdateShareCanIncreasePermissionsIfOwner(): void { |
|
| 3843 | + $ocs = $this->mockFormatShare(); |
|
| 3844 | + |
|
| 3845 | + [$userFolder, $folder] = $this->getNonSharedUserFolder(); |
|
| 3846 | + $folder->method('getId') |
|
| 3847 | + ->willReturn(42); |
|
| 3848 | + |
|
| 3849 | + $share = Server::get(IManager::class)->newShare(); |
|
| 3850 | + $share |
|
| 3851 | + ->setId(42) |
|
| 3852 | + ->setSharedBy($this->currentUser) |
|
| 3853 | + ->setShareOwner($this->currentUser) |
|
| 3854 | + ->setShareType(IShare::TYPE_GROUP) |
|
| 3855 | + ->setSharedWith('group1') |
|
| 3856 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 3857 | + ->setNode($folder); |
|
| 3858 | + |
|
| 3859 | + // note: updateShare will modify the received instance but getSharedWith will reread from the database, |
|
| 3860 | + // so their values will be different |
|
| 3861 | + $incomingShare = Server::get(IManager::class)->newShare(); |
|
| 3862 | + $incomingShare |
|
| 3863 | + ->setId(42) |
|
| 3864 | + ->setSharedBy($this->currentUser) |
|
| 3865 | + ->setShareOwner($this->currentUser) |
|
| 3866 | + ->setShareType(IShare::TYPE_GROUP) |
|
| 3867 | + ->setSharedWith('group1') |
|
| 3868 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 3869 | + ->setNode($folder); |
|
| 3870 | + |
|
| 3871 | + $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); |
|
| 3872 | + |
|
| 3873 | + $this->shareManager->expects($this->any()) |
|
| 3874 | + ->method('getSharedWith') |
|
| 3875 | + ->willReturnMap([ |
|
| 3876 | + ['currentUser', IShare::TYPE_USER, $share->getNode(), -1, 0, []], |
|
| 3877 | + ['currentUser', IShare::TYPE_GROUP, $share->getNode(), -1, 0, [$incomingShare]] |
|
| 3878 | + ]); |
|
| 3879 | + |
|
| 3880 | + $this->shareManager->expects($this->once()) |
|
| 3881 | + ->method('updateShare') |
|
| 3882 | + ->with($share) |
|
| 3883 | + ->willReturn($share); |
|
| 3884 | + |
|
| 3885 | + $this->rootFolder->method('getUserFolder') |
|
| 3886 | + ->with($this->currentUser) |
|
| 3887 | + ->willReturn($userFolder); |
|
| 3888 | + |
|
| 3889 | + $userFolder->method('getById') |
|
| 3890 | + ->with(42) |
|
| 3891 | + ->willReturn([$folder]); |
|
| 3892 | + |
|
| 3893 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3894 | + $folder->method('getMountPoint') |
|
| 3895 | + ->willReturn($mountPoint); |
|
| 3896 | + $mountPoint->method('getStorageRootId') |
|
| 3897 | + ->willReturn(42); |
|
| 3898 | + |
|
| 3899 | + $result = $ocs->updateShare(42, 31); |
|
| 3900 | + $this->assertInstanceOf(DataResponse::class, $result); |
|
| 3901 | + } |
|
| 3902 | + |
|
| 3903 | + public function testUpdateShareOwnerless(): void { |
|
| 3904 | + $ocs = $this->mockFormatShare(); |
|
| 3905 | + |
|
| 3906 | + $mount = $this->createMock(IShareOwnerlessMount::class); |
|
| 3907 | + |
|
| 3908 | + $file = $this->createMock(File::class); |
|
| 3909 | + $file |
|
| 3910 | + ->expects($this->exactly(2)) |
|
| 3911 | + ->method('getPermissions') |
|
| 3912 | + ->willReturn(Constants::PERMISSION_SHARE); |
|
| 3913 | + $file |
|
| 3914 | + ->expects($this->once()) |
|
| 3915 | + ->method('getMountPoint') |
|
| 3916 | + ->willReturn($mount); |
|
| 3917 | + |
|
| 3918 | + $userFolder = $this->createMock(Folder::class); |
|
| 3919 | + $userFolder->method('getById') |
|
| 3920 | + ->with(2) |
|
| 3921 | + ->willReturn([$file]); |
|
| 3922 | + $userFolder->method('getFirstNodeById') |
|
| 3923 | + ->with(2) |
|
| 3924 | + ->willReturn($file); |
|
| 3925 | + |
|
| 3926 | + $this->rootFolder |
|
| 3927 | + ->method('getUserFolder') |
|
| 3928 | + ->with($this->currentUser) |
|
| 3929 | + ->willReturn($userFolder); |
|
| 3930 | + |
|
| 3931 | + $share = $this->createMock(IShare::class); |
|
| 3932 | + $share |
|
| 3933 | + ->expects($this->once()) |
|
| 3934 | + ->method('getNode') |
|
| 3935 | + ->willReturn($file); |
|
| 3936 | + $share |
|
| 3937 | + ->expects($this->exactly(2)) |
|
| 3938 | + ->method('getNodeId') |
|
| 3939 | + ->willReturn(2); |
|
| 3940 | + $share |
|
| 3941 | + ->expects($this->exactly(2)) |
|
| 3942 | + ->method('getPermissions') |
|
| 3943 | + ->willReturn(Constants::PERMISSION_SHARE); |
|
| 3944 | + |
|
| 3945 | + $this->shareManager |
|
| 3946 | + ->expects($this->once()) |
|
| 3947 | + ->method('getShareById') |
|
| 3948 | + ->with('ocinternal:1', $this->currentUser) |
|
| 3949 | + ->willReturn($share); |
|
| 3950 | + |
|
| 3951 | + $this->shareManager |
|
| 3952 | + ->expects($this->once()) |
|
| 3953 | + ->method('updateShare') |
|
| 3954 | + ->with($share) |
|
| 3955 | + ->willReturn($share); |
|
| 3956 | + |
|
| 3957 | + $result = $ocs->updateShare(1, Constants::PERMISSION_ALL); |
|
| 3958 | + $this->assertInstanceOf(DataResponse::class, $result); |
|
| 3959 | + } |
|
| 3960 | + |
|
| 3961 | + public function dataFormatShare() { |
|
| 3962 | + $file = $this->getMockBuilder(File::class)->getMock(); |
|
| 3963 | + $folder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 3964 | + $parent = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 3965 | + $fileWithPreview = $this->getMockBuilder(File::class)->getMock(); |
|
| 3966 | + |
|
| 3967 | + $file->method('getMimeType')->willReturn('myMimeType'); |
|
| 3968 | + $folder->method('getMimeType')->willReturn('myFolderMimeType'); |
|
| 3969 | + $fileWithPreview->method('getMimeType')->willReturn('mimeWithPreview'); |
|
| 3970 | + |
|
| 3971 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 3972 | + $mountPoint->method('getMountType')->willReturn(''); |
|
| 3973 | + $file->method('getMountPoint')->willReturn($mountPoint); |
|
| 3974 | + $folder->method('getMountPoint')->willReturn($mountPoint); |
|
| 3975 | + $fileWithPreview->method('getMountPoint')->willReturn($mountPoint); |
|
| 3976 | + |
|
| 3977 | + $file->method('getPath')->willReturn('file'); |
|
| 3978 | + $folder->method('getPath')->willReturn('folder'); |
|
| 3979 | + $fileWithPreview->method('getPath')->willReturn('fileWithPreview'); |
|
| 3980 | + |
|
| 3981 | + $parent->method('getId')->willReturn(1); |
|
| 3982 | + $folder->method('getId')->willReturn(2); |
|
| 3983 | + $file->method('getId')->willReturn(3); |
|
| 3984 | + $fileWithPreview->method('getId')->willReturn(4); |
|
| 3985 | + |
|
| 3986 | + $file->method('getParent')->willReturn($parent); |
|
| 3987 | + $folder->method('getParent')->willReturn($parent); |
|
| 3988 | + $fileWithPreview->method('getParent')->willReturn($parent); |
|
| 3989 | + |
|
| 3990 | + $file->method('getSize')->willReturn(123456); |
|
| 3991 | + $folder->method('getSize')->willReturn(123456); |
|
| 3992 | + $fileWithPreview->method('getSize')->willReturn(123456); |
|
| 3993 | + $file->method('getMTime')->willReturn(1234567890); |
|
| 3994 | + $folder->method('getMTime')->willReturn(1234567890); |
|
| 3995 | + $fileWithPreview->method('getMTime')->willReturn(1234567890); |
|
| 3996 | + |
|
| 3997 | + $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock(); |
|
| 3998 | + $cache->method('getNumericStorageId')->willReturn(100); |
|
| 3999 | + $storage = $this->createMock(IStorage::class); |
|
| 4000 | + $storage->method('getId')->willReturn('storageId'); |
|
| 4001 | + $storage->method('getCache')->willReturn($cache); |
|
| 4002 | + |
|
| 4003 | + $file->method('getStorage')->willReturn($storage); |
|
| 4004 | + $folder->method('getStorage')->willReturn($storage); |
|
| 4005 | + $fileWithPreview->method('getStorage')->willReturn($storage); |
|
| 4006 | + |
|
| 4007 | + |
|
| 4008 | + $mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock(); |
|
| 4009 | + $mountPoint->method('getMountType')->willReturn(''); |
|
| 4010 | + $file->method('getMountPoint')->willReturn($mountPoint); |
|
| 4011 | + $folder->method('getMountPoint')->willReturn($mountPoint); |
|
| 4012 | + |
|
| 4013 | + $owner = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 4014 | + $owner->method('getDisplayName')->willReturn('ownerDN'); |
|
| 4015 | + $initiator = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 4016 | + $initiator->method('getDisplayName')->willReturn('initiatorDN'); |
|
| 4017 | + $recipient = $this->getMockBuilder(IUser::class)->getMock(); |
|
| 4018 | + $recipient->method('getDisplayName')->willReturn('recipientDN'); |
|
| 4019 | + $recipient->method('getSystemEMailAddress')->willReturn('recipient'); |
|
| 4020 | + [$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes(); |
|
| 4021 | + |
|
| 4022 | + $result = []; |
|
| 4023 | + |
|
| 4024 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4025 | + $share->setShareType(IShare::TYPE_USER) |
|
| 4026 | + ->setSharedWith('recipient') |
|
| 4027 | + ->setSharedBy('initiator') |
|
| 4028 | + ->setShareOwner('owner') |
|
| 4029 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4030 | + ->setAttributes($shareAttributes) |
|
| 4031 | + ->setNode($file) |
|
| 4032 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4033 | + ->setTarget('myTarget') |
|
| 4034 | + ->setNote('personal note') |
|
| 4035 | + ->setId(42); |
|
| 4036 | + |
|
| 4037 | + // User backend down |
|
| 4038 | + $result[] = [ |
|
| 4039 | + [ |
|
| 4040 | + 'id' => '42', |
|
| 4041 | + 'share_type' => IShare::TYPE_USER, |
|
| 4042 | + 'uid_owner' => 'initiator', |
|
| 4043 | + 'displayname_owner' => 'initiator', |
|
| 4044 | + 'permissions' => 1, |
|
| 4045 | + 'attributes' => $shareAttributesReturnJson, |
|
| 4046 | + 'stime' => 946684862, |
|
| 4047 | + 'parent' => null, |
|
| 4048 | + 'expiration' => null, |
|
| 4049 | + 'token' => null, |
|
| 4050 | + 'uid_file_owner' => 'owner', |
|
| 4051 | + 'displayname_file_owner' => 'owner', |
|
| 4052 | + 'path' => 'file', |
|
| 4053 | + 'item_type' => 'file', |
|
| 4054 | + 'storage_id' => 'storageId', |
|
| 4055 | + 'storage' => 100, |
|
| 4056 | + 'item_source' => 3, |
|
| 4057 | + 'file_source' => 3, |
|
| 4058 | + 'file_parent' => 1, |
|
| 4059 | + 'file_target' => 'myTarget', |
|
| 4060 | + 'share_with' => 'recipient', |
|
| 4061 | + 'share_with_displayname' => 'recipient', |
|
| 4062 | + 'share_with_displayname_unique' => 'recipient', |
|
| 4063 | + 'note' => 'personal note', |
|
| 4064 | + 'label' => '', |
|
| 4065 | + 'mail_send' => 0, |
|
| 4066 | + 'mimetype' => 'myMimeType', |
|
| 4067 | + 'has_preview' => false, |
|
| 4068 | + 'hide_download' => 0, |
|
| 4069 | + 'can_edit' => false, |
|
| 4070 | + 'can_delete' => false, |
|
| 4071 | + 'item_size' => 123456, |
|
| 4072 | + 'item_mtime' => 1234567890, |
|
| 4073 | + 'is-mount-root' => false, |
|
| 4074 | + 'mount-type' => '', |
|
| 4075 | + 'attributes' => '[{"scope":"permissions","key":"download","value":true}]', |
|
| 4076 | + 'item_permissions' => 1, |
|
| 4077 | + ], $share, [], false |
|
| 4078 | + ]; |
|
| 4079 | + // User backend up |
|
| 4080 | + $result[] = [ |
|
| 4081 | + [ |
|
| 4082 | + 'id' => '42', |
|
| 4083 | + 'share_type' => IShare::TYPE_USER, |
|
| 4084 | + 'uid_owner' => 'initiator', |
|
| 4085 | + 'displayname_owner' => 'initiatorDN', |
|
| 4086 | + 'permissions' => 1, |
|
| 4087 | + 'attributes' => $shareAttributesReturnJson, |
|
| 4088 | + 'stime' => 946684862, |
|
| 4089 | + 'parent' => null, |
|
| 4090 | + 'expiration' => null, |
|
| 4091 | + 'token' => null, |
|
| 4092 | + 'uid_file_owner' => 'owner', |
|
| 4093 | + 'displayname_file_owner' => 'ownerDN', |
|
| 4094 | + 'note' => 'personal note', |
|
| 4095 | + 'label' => '', |
|
| 4096 | + 'path' => 'file', |
|
| 4097 | + 'item_type' => 'file', |
|
| 4098 | + 'storage_id' => 'storageId', |
|
| 4099 | + 'storage' => 100, |
|
| 4100 | + 'item_source' => 3, |
|
| 4101 | + 'file_source' => 3, |
|
| 4102 | + 'file_parent' => 1, |
|
| 4103 | + 'file_target' => 'myTarget', |
|
| 4104 | + 'share_with' => 'recipient', |
|
| 4105 | + 'share_with_displayname' => 'recipientDN', |
|
| 4106 | + 'share_with_displayname_unique' => 'recipient', |
|
| 4107 | + 'mail_send' => 0, |
|
| 4108 | + 'mimetype' => 'myMimeType', |
|
| 4109 | + 'has_preview' => false, |
|
| 4110 | + 'hide_download' => 0, |
|
| 4111 | + 'can_edit' => false, |
|
| 4112 | + 'can_delete' => false, |
|
| 4113 | + 'item_size' => 123456, |
|
| 4114 | + 'item_mtime' => 1234567890, |
|
| 4115 | + 'is-mount-root' => false, |
|
| 4116 | + 'mount-type' => '', |
|
| 4117 | + 'attributes' => '[{"scope":"permissions","key":"download","value":true}]', |
|
| 4118 | + 'item_permissions' => 1, |
|
| 4119 | + ], $share, [ |
|
| 4120 | + ['owner', $owner], |
|
| 4121 | + ['initiator', $initiator], |
|
| 4122 | + ['recipient', $recipient], |
|
| 4123 | + ], false |
|
| 4124 | + ]; |
|
| 4125 | + |
|
| 4126 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4127 | + $share->setShareType(IShare::TYPE_USER) |
|
| 4128 | + ->setSharedWith('recipient') |
|
| 4129 | + ->setSharedBy('initiator') |
|
| 4130 | + ->setShareOwner('owner') |
|
| 4131 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4132 | + ->setNode($file) |
|
| 4133 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4134 | + ->setTarget('myTarget') |
|
| 4135 | + ->setNote('personal note') |
|
| 4136 | + ->setId(42); |
|
| 4137 | + // User backend down |
|
| 4138 | + $result[] = [ |
|
| 4139 | + [ |
|
| 4140 | + 'id' => '42', |
|
| 4141 | + 'share_type' => IShare::TYPE_USER, |
|
| 4142 | + 'uid_owner' => 'initiator', |
|
| 4143 | + 'displayname_owner' => 'initiator', |
|
| 4144 | + 'permissions' => 1, |
|
| 4145 | + 'attributes' => null, |
|
| 4146 | + 'stime' => 946684862, |
|
| 4147 | + 'parent' => null, |
|
| 4148 | + 'expiration' => null, |
|
| 4149 | + 'token' => null, |
|
| 4150 | + 'uid_file_owner' => 'owner', |
|
| 4151 | + 'displayname_file_owner' => 'owner', |
|
| 4152 | + 'note' => 'personal note', |
|
| 4153 | + 'label' => '', |
|
| 4154 | + 'path' => 'file', |
|
| 4155 | + 'item_type' => 'file', |
|
| 4156 | + 'storage_id' => 'storageId', |
|
| 4157 | + 'storage' => 100, |
|
| 4158 | + 'item_source' => 3, |
|
| 4159 | + 'file_source' => 3, |
|
| 4160 | + 'file_parent' => 1, |
|
| 4161 | + 'file_target' => 'myTarget', |
|
| 4162 | + 'share_with' => 'recipient', |
|
| 4163 | + 'share_with_displayname' => 'recipient', |
|
| 4164 | + 'share_with_displayname_unique' => 'recipient', |
|
| 4165 | + 'mail_send' => 0, |
|
| 4166 | + 'mimetype' => 'myMimeType', |
|
| 4167 | + 'has_preview' => false, |
|
| 4168 | + 'hide_download' => 0, |
|
| 4169 | + 'can_edit' => false, |
|
| 4170 | + 'can_delete' => false, |
|
| 4171 | + 'item_size' => 123456, |
|
| 4172 | + 'item_mtime' => 1234567890, |
|
| 4173 | + 'is-mount-root' => false, |
|
| 4174 | + 'mount-type' => '', |
|
| 4175 | + 'attributes' => null, |
|
| 4176 | + 'item_permissions' => 1, |
|
| 4177 | + ], $share, [], false |
|
| 4178 | + ]; |
|
| 4179 | + |
|
| 4180 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4181 | + $share->setShareType(IShare::TYPE_USER) |
|
| 4182 | + ->setSharedWith('recipient') |
|
| 4183 | + ->setSharedBy('initiator') |
|
| 4184 | + ->setShareOwner('currentUser') |
|
| 4185 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4186 | + ->setNode($file) |
|
| 4187 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4188 | + ->setTarget('myTarget') |
|
| 4189 | + ->setNote('personal note') |
|
| 4190 | + ->setId(42); |
|
| 4191 | + // User backend down |
|
| 4192 | + $result[] = [ |
|
| 4193 | + [ |
|
| 4194 | + 'id' => '42', |
|
| 4195 | + 'share_type' => IShare::TYPE_USER, |
|
| 4196 | + 'uid_owner' => 'initiator', |
|
| 4197 | + 'displayname_owner' => 'initiator', |
|
| 4198 | + 'permissions' => 1, |
|
| 4199 | + 'attributes' => null, |
|
| 4200 | + 'stime' => 946684862, |
|
| 4201 | + 'parent' => null, |
|
| 4202 | + 'expiration' => null, |
|
| 4203 | + 'token' => null, |
|
| 4204 | + 'uid_file_owner' => 'currentUser', |
|
| 4205 | + 'displayname_file_owner' => 'currentUser', |
|
| 4206 | + 'note' => 'personal note', |
|
| 4207 | + 'label' => '', |
|
| 4208 | + 'path' => 'file', |
|
| 4209 | + 'item_type' => 'file', |
|
| 4210 | + 'storage_id' => 'storageId', |
|
| 4211 | + 'storage' => 100, |
|
| 4212 | + 'item_source' => 3, |
|
| 4213 | + 'file_source' => 3, |
|
| 4214 | + 'file_parent' => 1, |
|
| 4215 | + 'file_target' => 'myTarget', |
|
| 4216 | + 'share_with' => 'recipient', |
|
| 4217 | + 'share_with_displayname' => 'recipient', |
|
| 4218 | + 'share_with_displayname_unique' => 'recipient', |
|
| 4219 | + 'mail_send' => 0, |
|
| 4220 | + 'mimetype' => 'myMimeType', |
|
| 4221 | + 'has_preview' => false, |
|
| 4222 | + 'hide_download' => 0, |
|
| 4223 | + 'can_edit' => true, |
|
| 4224 | + 'can_delete' => true, |
|
| 4225 | + 'item_size' => 123456, |
|
| 4226 | + 'item_mtime' => 1234567890, |
|
| 4227 | + 'is-mount-root' => false, |
|
| 4228 | + 'mount-type' => '', |
|
| 4229 | + 'attributes' => null, |
|
| 4230 | + 'item_permissions' => 11, |
|
| 4231 | + ], $share, [], false |
|
| 4232 | + ]; |
|
| 4233 | + |
|
| 4234 | + // with existing group |
|
| 4235 | + |
|
| 4236 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4237 | + $share->setShareType(IShare::TYPE_GROUP) |
|
| 4238 | + ->setSharedWith('recipientGroup') |
|
| 4239 | + ->setSharedBy('initiator') |
|
| 4240 | + ->setShareOwner('owner') |
|
| 4241 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4242 | + ->setNode($file) |
|
| 4243 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4244 | + ->setTarget('myTarget') |
|
| 4245 | + ->setNote('personal note') |
|
| 4246 | + ->setId(42); |
|
| 4247 | + |
|
| 4248 | + $result[] = [ |
|
| 4249 | + [ |
|
| 4250 | + 'id' => '42', |
|
| 4251 | + 'share_type' => IShare::TYPE_GROUP, |
|
| 4252 | + 'uid_owner' => 'initiator', |
|
| 4253 | + 'displayname_owner' => 'initiator', |
|
| 4254 | + 'permissions' => 1, |
|
| 4255 | + 'attributes' => null, |
|
| 4256 | + 'stime' => 946684862, |
|
| 4257 | + 'parent' => null, |
|
| 4258 | + 'expiration' => null, |
|
| 4259 | + 'token' => null, |
|
| 4260 | + 'uid_file_owner' => 'owner', |
|
| 4261 | + 'displayname_file_owner' => 'owner', |
|
| 4262 | + 'note' => 'personal note', |
|
| 4263 | + 'label' => '', |
|
| 4264 | + 'path' => 'file', |
|
| 4265 | + 'item_type' => 'file', |
|
| 4266 | + 'storage_id' => 'storageId', |
|
| 4267 | + 'storage' => 100, |
|
| 4268 | + 'item_source' => 3, |
|
| 4269 | + 'file_source' => 3, |
|
| 4270 | + 'file_parent' => 1, |
|
| 4271 | + 'file_target' => 'myTarget', |
|
| 4272 | + 'share_with' => 'recipientGroup', |
|
| 4273 | + 'share_with_displayname' => 'recipientGroupDisplayName', |
|
| 4274 | + 'mail_send' => 0, |
|
| 4275 | + 'mimetype' => 'myMimeType', |
|
| 4276 | + 'has_preview' => false, |
|
| 4277 | + 'hide_download' => 0, |
|
| 4278 | + 'can_edit' => false, |
|
| 4279 | + 'can_delete' => false, |
|
| 4280 | + 'item_size' => 123456, |
|
| 4281 | + 'item_mtime' => 1234567890, |
|
| 4282 | + 'is-mount-root' => false, |
|
| 4283 | + 'mount-type' => '', |
|
| 4284 | + 'attributes' => null, |
|
| 4285 | + 'item_permissions' => 1, |
|
| 4286 | + ], $share, [], false |
|
| 4287 | + ]; |
|
| 4288 | + |
|
| 4289 | + // with unknown group / no group backend |
|
| 4290 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4291 | + $share->setShareType(IShare::TYPE_GROUP) |
|
| 4292 | + ->setSharedWith('recipientGroup2') |
|
| 4293 | + ->setSharedBy('initiator') |
|
| 4294 | + ->setShareOwner('owner') |
|
| 4295 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4296 | + ->setNode($file) |
|
| 4297 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4298 | + ->setTarget('myTarget') |
|
| 4299 | + ->setNote('personal note') |
|
| 4300 | + ->setId(42); |
|
| 4301 | + $result[] = [ |
|
| 4302 | + [ |
|
| 4303 | + 'id' => '42', |
|
| 4304 | + 'share_type' => IShare::TYPE_GROUP, |
|
| 4305 | + 'uid_owner' => 'initiator', |
|
| 4306 | + 'displayname_owner' => 'initiator', |
|
| 4307 | + 'permissions' => 1, |
|
| 4308 | + 'stime' => 946684862, |
|
| 4309 | + 'parent' => null, |
|
| 4310 | + 'expiration' => null, |
|
| 4311 | + 'token' => null, |
|
| 4312 | + 'uid_file_owner' => 'owner', |
|
| 4313 | + 'displayname_file_owner' => 'owner', |
|
| 4314 | + 'note' => 'personal note', |
|
| 4315 | + 'label' => '', |
|
| 4316 | + 'path' => 'file', |
|
| 4317 | + 'item_type' => 'file', |
|
| 4318 | + 'storage_id' => 'storageId', |
|
| 4319 | + 'storage' => 100, |
|
| 4320 | + 'item_source' => 3, |
|
| 4321 | + 'file_source' => 3, |
|
| 4322 | + 'file_parent' => 1, |
|
| 4323 | + 'file_target' => 'myTarget', |
|
| 4324 | + 'share_with' => 'recipientGroup2', |
|
| 4325 | + 'share_with_displayname' => 'recipientGroup2', |
|
| 4326 | + 'mail_send' => 0, |
|
| 4327 | + 'mimetype' => 'myMimeType', |
|
| 4328 | + 'has_preview' => false, |
|
| 4329 | + 'hide_download' => 0, |
|
| 4330 | + 'can_edit' => false, |
|
| 4331 | + 'can_delete' => false, |
|
| 4332 | + 'item_size' => 123456, |
|
| 4333 | + 'item_mtime' => 1234567890, |
|
| 4334 | + 'is-mount-root' => false, |
|
| 4335 | + 'mount-type' => '', |
|
| 4336 | + 'attributes' => null, |
|
| 4337 | + 'item_permissions' => 1, |
|
| 4338 | + ], $share, [], false |
|
| 4339 | + ]; |
|
| 4340 | + |
|
| 4341 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4342 | + $share->setShareType(IShare::TYPE_LINK) |
|
| 4343 | + ->setSharedBy('initiator') |
|
| 4344 | + ->setShareOwner('owner') |
|
| 4345 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4346 | + ->setNode($file) |
|
| 4347 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4348 | + ->setTarget('myTarget') |
|
| 4349 | + ->setPassword('mypassword') |
|
| 4350 | + ->setExpirationDate(new \DateTime('2001-01-02T00:00:00')) |
|
| 4351 | + ->setToken('myToken') |
|
| 4352 | + ->setNote('personal note') |
|
| 4353 | + ->setLabel('new link share') |
|
| 4354 | + ->setId(42); |
|
| 4355 | + |
|
| 4356 | + $result[] = [ |
|
| 4357 | + [ |
|
| 4358 | + 'id' => '42', |
|
| 4359 | + 'share_type' => IShare::TYPE_LINK, |
|
| 4360 | + 'uid_owner' => 'initiator', |
|
| 4361 | + 'displayname_owner' => 'initiator', |
|
| 4362 | + 'permissions' => 1, |
|
| 4363 | + 'attributes' => null, |
|
| 4364 | + 'stime' => 946684862, |
|
| 4365 | + 'parent' => null, |
|
| 4366 | + 'expiration' => '2001-01-02 00:00:00', |
|
| 4367 | + 'token' => 'myToken', |
|
| 4368 | + 'uid_file_owner' => 'owner', |
|
| 4369 | + 'displayname_file_owner' => 'owner', |
|
| 4370 | + 'note' => 'personal note', |
|
| 4371 | + 'label' => 'new link share', |
|
| 4372 | + 'path' => 'file', |
|
| 4373 | + 'item_type' => 'file', |
|
| 4374 | + 'storage_id' => 'storageId', |
|
| 4375 | + 'storage' => 100, |
|
| 4376 | + 'item_source' => 3, |
|
| 4377 | + 'file_source' => 3, |
|
| 4378 | + 'file_parent' => 1, |
|
| 4379 | + 'file_target' => 'myTarget', |
|
| 4380 | + 'password' => 'mypassword', |
|
| 4381 | + 'share_with' => 'mypassword', |
|
| 4382 | + 'share_with_displayname' => '(Shared link)', |
|
| 4383 | + 'send_password_by_talk' => false, |
|
| 4384 | + 'mail_send' => 0, |
|
| 4385 | + 'url' => 'myLink', |
|
| 4386 | + 'mimetype' => 'myMimeType', |
|
| 4387 | + 'has_preview' => false, |
|
| 4388 | + 'hide_download' => 0, |
|
| 4389 | + 'can_edit' => false, |
|
| 4390 | + 'can_delete' => false, |
|
| 4391 | + 'item_size' => 123456, |
|
| 4392 | + 'item_mtime' => 1234567890, |
|
| 4393 | + 'is-mount-root' => false, |
|
| 4394 | + 'mount-type' => '', |
|
| 4395 | + 'attributes' => null, |
|
| 4396 | + 'item_permissions' => 1, |
|
| 4397 | + ], $share, [], false |
|
| 4398 | + ]; |
|
| 4399 | + |
|
| 4400 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4401 | + $share->setShareType(IShare::TYPE_LINK) |
|
| 4402 | + ->setSharedBy('initiator') |
|
| 4403 | + ->setShareOwner('owner') |
|
| 4404 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4405 | + ->setNode($file) |
|
| 4406 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4407 | + ->setTarget('myTarget') |
|
| 4408 | + ->setPassword('mypassword') |
|
| 4409 | + ->setSendPasswordByTalk(true) |
|
| 4410 | + ->setExpirationDate(new \DateTime('2001-01-02T00:00:00')) |
|
| 4411 | + ->setToken('myToken') |
|
| 4412 | + ->setNote('personal note') |
|
| 4413 | + ->setLabel('new link share') |
|
| 4414 | + ->setId(42); |
|
| 4415 | + |
|
| 4416 | + $result[] = [ |
|
| 4417 | + [ |
|
| 4418 | + 'id' => '42', |
|
| 4419 | + 'share_type' => IShare::TYPE_LINK, |
|
| 4420 | + 'uid_owner' => 'initiator', |
|
| 4421 | + 'displayname_owner' => 'initiator', |
|
| 4422 | + 'permissions' => 1, |
|
| 4423 | + 'stime' => 946684862, |
|
| 4424 | + 'parent' => null, |
|
| 4425 | + 'expiration' => '2001-01-02 00:00:00', |
|
| 4426 | + 'token' => 'myToken', |
|
| 4427 | + 'uid_file_owner' => 'owner', |
|
| 4428 | + 'displayname_file_owner' => 'owner', |
|
| 4429 | + 'note' => 'personal note', |
|
| 4430 | + 'label' => 'new link share', |
|
| 4431 | + 'path' => 'file', |
|
| 4432 | + 'item_type' => 'file', |
|
| 4433 | + 'storage_id' => 'storageId', |
|
| 4434 | + 'storage' => 100, |
|
| 4435 | + 'item_source' => 3, |
|
| 4436 | + 'file_source' => 3, |
|
| 4437 | + 'file_parent' => 1, |
|
| 4438 | + 'file_target' => 'myTarget', |
|
| 4439 | + 'password' => 'mypassword', |
|
| 4440 | + 'share_with' => 'mypassword', |
|
| 4441 | + 'share_with_displayname' => '(Shared link)', |
|
| 4442 | + 'send_password_by_talk' => true, |
|
| 4443 | + 'mail_send' => 0, |
|
| 4444 | + 'url' => 'myLink', |
|
| 4445 | + 'mimetype' => 'myMimeType', |
|
| 4446 | + 'has_preview' => false, |
|
| 4447 | + 'hide_download' => 0, |
|
| 4448 | + 'can_edit' => false, |
|
| 4449 | + 'can_delete' => false, |
|
| 4450 | + 'item_size' => 123456, |
|
| 4451 | + 'item_mtime' => 1234567890, |
|
| 4452 | + 'is-mount-root' => false, |
|
| 4453 | + 'mount-type' => '', |
|
| 4454 | + 'attributes' => null, |
|
| 4455 | + 'item_permissions' => 1, |
|
| 4456 | + ], $share, [], false |
|
| 4457 | + ]; |
|
| 4458 | + |
|
| 4459 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4460 | + $share->setShareType(IShare::TYPE_REMOTE) |
|
| 4461 | + ->setSharedBy('initiator') |
|
| 4462 | + ->setSharedWith('[email protected]') |
|
| 4463 | + ->setShareOwner('owner') |
|
| 4464 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4465 | + ->setNode($folder) |
|
| 4466 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4467 | + ->setExpirationDate(new \DateTime('2001-02-03T04:05:06')) |
|
| 4468 | + ->setTarget('myTarget') |
|
| 4469 | + ->setNote('personal note') |
|
| 4470 | + ->setId(42); |
|
| 4471 | + |
|
| 4472 | + $result[] = [ |
|
| 4473 | + [ |
|
| 4474 | + 'id' => '42', |
|
| 4475 | + 'share_type' => IShare::TYPE_REMOTE, |
|
| 4476 | + 'uid_owner' => 'initiator', |
|
| 4477 | + 'displayname_owner' => 'initiator', |
|
| 4478 | + 'permissions' => 1, |
|
| 4479 | + 'stime' => 946684862, |
|
| 4480 | + 'parent' => null, |
|
| 4481 | + 'expiration' => '2001-02-03 00:00:00', |
|
| 4482 | + 'token' => null, |
|
| 4483 | + 'uid_file_owner' => 'owner', |
|
| 4484 | + 'displayname_file_owner' => 'owner', |
|
| 4485 | + 'note' => 'personal note', |
|
| 4486 | + 'label' => '', |
|
| 4487 | + 'path' => 'folder', |
|
| 4488 | + 'item_type' => 'folder', |
|
| 4489 | + 'storage_id' => 'storageId', |
|
| 4490 | + 'storage' => 100, |
|
| 4491 | + 'item_source' => 2, |
|
| 4492 | + 'file_source' => 2, |
|
| 4493 | + 'file_parent' => 1, |
|
| 4494 | + 'file_target' => 'myTarget', |
|
| 4495 | + 'share_with' => '[email protected]', |
|
| 4496 | + 'share_with_displayname' => 'foobar', |
|
| 4497 | + 'mail_send' => 0, |
|
| 4498 | + 'mimetype' => 'myFolderMimeType', |
|
| 4499 | + 'has_preview' => false, |
|
| 4500 | + 'hide_download' => 0, |
|
| 4501 | + 'can_edit' => false, |
|
| 4502 | + 'can_delete' => false, |
|
| 4503 | + 'item_size' => 123456, |
|
| 4504 | + 'item_mtime' => 1234567890, |
|
| 4505 | + 'is-mount-root' => false, |
|
| 4506 | + 'mount-type' => '', |
|
| 4507 | + 'attributes' => null, |
|
| 4508 | + 'item_permissions' => 1, |
|
| 4509 | + 'is_trusted_server' => false, |
|
| 4510 | + ], $share, [], false |
|
| 4511 | + ]; |
|
| 4512 | + |
|
| 4513 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4514 | + $share->setShareType(IShare::TYPE_REMOTE_GROUP) |
|
| 4515 | + ->setSharedBy('initiator') |
|
| 4516 | + ->setSharedWith('[email protected]') |
|
| 4517 | + ->setShareOwner('owner') |
|
| 4518 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4519 | + ->setNode($folder) |
|
| 4520 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4521 | + ->setExpirationDate(new \DateTime('2001-02-03T04:05:06')) |
|
| 4522 | + ->setTarget('myTarget') |
|
| 4523 | + ->setNote('personal note') |
|
| 4524 | + ->setId(42); |
|
| 4525 | + |
|
| 4526 | + $result[] = [ |
|
| 4527 | + [ |
|
| 4528 | + 'id' => '42', |
|
| 4529 | + 'share_type' => IShare::TYPE_REMOTE_GROUP, |
|
| 4530 | + 'uid_owner' => 'initiator', |
|
| 4531 | + 'displayname_owner' => 'initiator', |
|
| 4532 | + 'permissions' => 1, |
|
| 4533 | + 'stime' => 946684862, |
|
| 4534 | + 'parent' => null, |
|
| 4535 | + 'expiration' => '2001-02-03 00:00:00', |
|
| 4536 | + 'token' => null, |
|
| 4537 | + 'uid_file_owner' => 'owner', |
|
| 4538 | + 'displayname_file_owner' => 'owner', |
|
| 4539 | + 'note' => 'personal note', |
|
| 4540 | + 'label' => '', |
|
| 4541 | + 'path' => 'folder', |
|
| 4542 | + 'item_type' => 'folder', |
|
| 4543 | + 'storage_id' => 'storageId', |
|
| 4544 | + 'storage' => 100, |
|
| 4545 | + 'item_source' => 2, |
|
| 4546 | + 'file_source' => 2, |
|
| 4547 | + 'file_parent' => 1, |
|
| 4548 | + 'file_target' => 'myTarget', |
|
| 4549 | + 'share_with' => '[email protected]', |
|
| 4550 | + 'share_with_displayname' => 'foobar', |
|
| 4551 | + 'mail_send' => 0, |
|
| 4552 | + 'mimetype' => 'myFolderMimeType', |
|
| 4553 | + 'has_preview' => false, |
|
| 4554 | + 'hide_download' => 0, |
|
| 4555 | + 'can_edit' => false, |
|
| 4556 | + 'can_delete' => false, |
|
| 4557 | + 'item_size' => 123456, |
|
| 4558 | + 'item_mtime' => 1234567890, |
|
| 4559 | + 'is-mount-root' => false, |
|
| 4560 | + 'mount-type' => '', |
|
| 4561 | + 'attributes' => null, |
|
| 4562 | + 'item_permissions' => 1, |
|
| 4563 | + 'is_trusted_server' => false, |
|
| 4564 | + ], $share, [], false |
|
| 4565 | + ]; |
|
| 4566 | + |
|
| 4567 | + // Circle with id, display name and avatar set by the Circles app |
|
| 4568 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4569 | + $share->setShareType(IShare::TYPE_CIRCLE) |
|
| 4570 | + ->setSharedBy('initiator') |
|
| 4571 | + ->setSharedWith('Circle (Public circle, circleOwner) [4815162342]') |
|
| 4572 | + ->setSharedWithDisplayName('The display name') |
|
| 4573 | + ->setSharedWithAvatar('path/to/the/avatar') |
|
| 4574 | + ->setShareOwner('owner') |
|
| 4575 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4576 | + ->setNode($folder) |
|
| 4577 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4578 | + ->setTarget('myTarget') |
|
| 4579 | + ->setId(42); |
|
| 4580 | + |
|
| 4581 | + $result[] = [ |
|
| 4582 | + [ |
|
| 4583 | + 'id' => '42', |
|
| 4584 | + 'share_type' => IShare::TYPE_CIRCLE, |
|
| 4585 | + 'uid_owner' => 'initiator', |
|
| 4586 | + 'displayname_owner' => 'initiator', |
|
| 4587 | + 'permissions' => 1, |
|
| 4588 | + 'attributes' => null, |
|
| 4589 | + 'stime' => 946684862, |
|
| 4590 | + 'parent' => null, |
|
| 4591 | + 'expiration' => null, |
|
| 4592 | + 'token' => null, |
|
| 4593 | + 'uid_file_owner' => 'owner', |
|
| 4594 | + 'displayname_file_owner' => 'owner', |
|
| 4595 | + 'note' => '', |
|
| 4596 | + 'label' => '', |
|
| 4597 | + 'path' => 'folder', |
|
| 4598 | + 'item_type' => 'folder', |
|
| 4599 | + 'storage_id' => 'storageId', |
|
| 4600 | + 'storage' => 100, |
|
| 4601 | + 'item_source' => 2, |
|
| 4602 | + 'file_source' => 2, |
|
| 4603 | + 'file_parent' => 1, |
|
| 4604 | + 'file_target' => 'myTarget', |
|
| 4605 | + 'share_with' => '4815162342', |
|
| 4606 | + 'share_with_displayname' => 'The display name', |
|
| 4607 | + 'share_with_avatar' => 'path/to/the/avatar', |
|
| 4608 | + 'mail_send' => 0, |
|
| 4609 | + 'mimetype' => 'myFolderMimeType', |
|
| 4610 | + 'has_preview' => false, |
|
| 4611 | + 'hide_download' => 0, |
|
| 4612 | + 'can_edit' => false, |
|
| 4613 | + 'can_delete' => false, |
|
| 4614 | + 'item_size' => 123456, |
|
| 4615 | + 'item_mtime' => 1234567890, |
|
| 4616 | + 'is-mount-root' => false, |
|
| 4617 | + 'mount-type' => '', |
|
| 4618 | + 'attributes' => null, |
|
| 4619 | + 'item_permissions' => 1, |
|
| 4620 | + ], $share, [], false |
|
| 4621 | + ]; |
|
| 4622 | + |
|
| 4623 | + // Circle with id set by the Circles app |
|
| 4624 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4625 | + $share->setShareType(IShare::TYPE_CIRCLE) |
|
| 4626 | + ->setSharedBy('initiator') |
|
| 4627 | + ->setSharedWith('Circle (Public circle, circleOwner) [4815162342]') |
|
| 4628 | + ->setShareOwner('owner') |
|
| 4629 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4630 | + ->setNode($folder) |
|
| 4631 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4632 | + ->setTarget('myTarget') |
|
| 4633 | + ->setId(42); |
|
| 4634 | + |
|
| 4635 | + $result[] = [ |
|
| 4636 | + [ |
|
| 4637 | + 'id' => '42', |
|
| 4638 | + 'share_type' => IShare::TYPE_CIRCLE, |
|
| 4639 | + 'uid_owner' => 'initiator', |
|
| 4640 | + 'displayname_owner' => 'initiator', |
|
| 4641 | + 'permissions' => 1, |
|
| 4642 | + 'stime' => 946684862, |
|
| 4643 | + 'parent' => null, |
|
| 4644 | + 'expiration' => null, |
|
| 4645 | + 'token' => null, |
|
| 4646 | + 'uid_file_owner' => 'owner', |
|
| 4647 | + 'displayname_file_owner' => 'owner', |
|
| 4648 | + 'note' => '', |
|
| 4649 | + 'label' => '', |
|
| 4650 | + 'path' => 'folder', |
|
| 4651 | + 'item_type' => 'folder', |
|
| 4652 | + 'storage_id' => 'storageId', |
|
| 4653 | + 'storage' => 100, |
|
| 4654 | + 'item_source' => 2, |
|
| 4655 | + 'file_source' => 2, |
|
| 4656 | + 'file_parent' => 1, |
|
| 4657 | + 'file_target' => 'myTarget', |
|
| 4658 | + 'share_with' => '4815162342', |
|
| 4659 | + 'share_with_displayname' => 'Circle (Public circle, circleOwner)', |
|
| 4660 | + 'share_with_avatar' => '', |
|
| 4661 | + 'mail_send' => 0, |
|
| 4662 | + 'mimetype' => 'myFolderMimeType', |
|
| 4663 | + 'has_preview' => false, |
|
| 4664 | + 'hide_download' => 0, |
|
| 4665 | + 'can_edit' => false, |
|
| 4666 | + 'can_delete' => false, |
|
| 4667 | + 'item_size' => 123456, |
|
| 4668 | + 'item_mtime' => 1234567890, |
|
| 4669 | + 'is-mount-root' => false, |
|
| 4670 | + 'mount-type' => '', |
|
| 4671 | + 'attributes' => null, |
|
| 4672 | + 'item_permissions' => 1, |
|
| 4673 | + ], $share, [], false |
|
| 4674 | + ]; |
|
| 4675 | + |
|
| 4676 | + // Circle with id not set by the Circles app |
|
| 4677 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4678 | + $share->setShareType(IShare::TYPE_CIRCLE) |
|
| 4679 | + ->setSharedBy('initiator') |
|
| 4680 | + ->setSharedWith('Circle (Public circle, circleOwner)') |
|
| 4681 | + ->setShareOwner('owner') |
|
| 4682 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4683 | + ->setNode($folder) |
|
| 4684 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4685 | + ->setTarget('myTarget') |
|
| 4686 | + ->setId(42); |
|
| 4687 | + |
|
| 4688 | + $result[] = [ |
|
| 4689 | + [ |
|
| 4690 | + 'id' => '42', |
|
| 4691 | + 'share_type' => IShare::TYPE_CIRCLE, |
|
| 4692 | + 'uid_owner' => 'initiator', |
|
| 4693 | + 'displayname_owner' => 'initiator', |
|
| 4694 | + 'permissions' => 1, |
|
| 4695 | + 'stime' => 946684862, |
|
| 4696 | + 'parent' => null, |
|
| 4697 | + 'expiration' => null, |
|
| 4698 | + 'token' => null, |
|
| 4699 | + 'uid_file_owner' => 'owner', |
|
| 4700 | + 'displayname_file_owner' => 'owner', |
|
| 4701 | + 'note' => '', |
|
| 4702 | + 'label' => '', |
|
| 4703 | + 'path' => 'folder', |
|
| 4704 | + 'item_type' => 'folder', |
|
| 4705 | + 'storage_id' => 'storageId', |
|
| 4706 | + 'storage' => 100, |
|
| 4707 | + 'item_source' => 2, |
|
| 4708 | + 'file_source' => 2, |
|
| 4709 | + 'file_parent' => 1, |
|
| 4710 | + 'file_target' => 'myTarget', |
|
| 4711 | + 'share_with' => 'Circle', |
|
| 4712 | + 'share_with_displayname' => 'Circle (Public circle, circleOwner)', |
|
| 4713 | + 'share_with_avatar' => '', |
|
| 4714 | + 'mail_send' => 0, |
|
| 4715 | + 'mimetype' => 'myFolderMimeType', |
|
| 4716 | + 'has_preview' => false, |
|
| 4717 | + 'hide_download' => 0, |
|
| 4718 | + 'can_edit' => false, |
|
| 4719 | + 'can_delete' => false, |
|
| 4720 | + 'item_size' => 123456, |
|
| 4721 | + 'item_mtime' => 1234567890, |
|
| 4722 | + 'is-mount-root' => false, |
|
| 4723 | + 'mount-type' => '', |
|
| 4724 | + 'attributes' => null, |
|
| 4725 | + 'item_permissions' => 1, |
|
| 4726 | + ], $share, [], false |
|
| 4727 | + ]; |
|
| 4728 | + |
|
| 4729 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4730 | + $share->setShareType(IShare::TYPE_USER) |
|
| 4731 | + ->setSharedBy('initiator') |
|
| 4732 | + ->setSharedWith('recipient') |
|
| 4733 | + ->setShareOwner('owner') |
|
| 4734 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4735 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4736 | + ->setTarget('myTarget') |
|
| 4737 | + ->setNote('personal note') |
|
| 4738 | + ->setId(42); |
|
| 4739 | + |
|
| 4740 | + $result[] = [ |
|
| 4741 | + [], $share, [], true |
|
| 4742 | + ]; |
|
| 4743 | + |
|
| 4744 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4745 | + $share->setShareType(IShare::TYPE_EMAIL) |
|
| 4746 | + ->setSharedBy('initiator') |
|
| 4747 | + ->setSharedWith('[email protected]') |
|
| 4748 | + ->setShareOwner('owner') |
|
| 4749 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4750 | + ->setNode($folder) |
|
| 4751 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4752 | + ->setTarget('myTarget') |
|
| 4753 | + ->setId(42) |
|
| 4754 | + ->setPassword('password'); |
|
| 4755 | + |
|
| 4756 | + $result[] = [ |
|
| 4757 | + [ |
|
| 4758 | + 'id' => '42', |
|
| 4759 | + 'share_type' => IShare::TYPE_EMAIL, |
|
| 4760 | + 'uid_owner' => 'initiator', |
|
| 4761 | + 'displayname_owner' => 'initiator', |
|
| 4762 | + 'permissions' => 1, |
|
| 4763 | + 'stime' => 946684862, |
|
| 4764 | + 'parent' => null, |
|
| 4765 | + 'expiration' => null, |
|
| 4766 | + 'token' => null, |
|
| 4767 | + 'uid_file_owner' => 'owner', |
|
| 4768 | + 'displayname_file_owner' => 'owner', |
|
| 4769 | + 'note' => '', |
|
| 4770 | + 'label' => '', |
|
| 4771 | + 'path' => 'folder', |
|
| 4772 | + 'item_type' => 'folder', |
|
| 4773 | + 'storage_id' => 'storageId', |
|
| 4774 | + 'storage' => 100, |
|
| 4775 | + 'item_source' => 2, |
|
| 4776 | + 'file_source' => 2, |
|
| 4777 | + 'file_parent' => 1, |
|
| 4778 | + 'file_target' => 'myTarget', |
|
| 4779 | + 'share_with' => '[email protected]', |
|
| 4780 | + 'share_with_displayname' => 'mail display name', |
|
| 4781 | + 'mail_send' => 0, |
|
| 4782 | + 'mimetype' => 'myFolderMimeType', |
|
| 4783 | + 'has_preview' => false, |
|
| 4784 | + 'password' => 'password', |
|
| 4785 | + 'send_password_by_talk' => false, |
|
| 4786 | + 'hide_download' => 0, |
|
| 4787 | + 'can_edit' => false, |
|
| 4788 | + 'can_delete' => false, |
|
| 4789 | + 'password_expiration_time' => null, |
|
| 4790 | + 'item_size' => 123456, |
|
| 4791 | + 'item_mtime' => 1234567890, |
|
| 4792 | + 'is-mount-root' => false, |
|
| 4793 | + 'mount-type' => '', |
|
| 4794 | + 'attributes' => null, |
|
| 4795 | + 'item_permissions' => 1, |
|
| 4796 | + ], $share, [], false |
|
| 4797 | + ]; |
|
| 4798 | + |
|
| 4799 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4800 | + $share->setShareType(IShare::TYPE_EMAIL) |
|
| 4801 | + ->setSharedBy('initiator') |
|
| 4802 | + ->setSharedWith('[email protected]') |
|
| 4803 | + ->setShareOwner('owner') |
|
| 4804 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4805 | + ->setNode($folder) |
|
| 4806 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4807 | + ->setTarget('myTarget') |
|
| 4808 | + ->setId(42) |
|
| 4809 | + ->setPassword('password') |
|
| 4810 | + ->setSendPasswordByTalk(true); |
|
| 4811 | + |
|
| 4812 | + $result[] = [ |
|
| 4813 | + [ |
|
| 4814 | + 'id' => '42', |
|
| 4815 | + 'share_type' => IShare::TYPE_EMAIL, |
|
| 4816 | + 'uid_owner' => 'initiator', |
|
| 4817 | + 'displayname_owner' => 'initiator', |
|
| 4818 | + 'permissions' => 1, |
|
| 4819 | + 'stime' => 946684862, |
|
| 4820 | + 'parent' => null, |
|
| 4821 | + 'expiration' => null, |
|
| 4822 | + 'token' => null, |
|
| 4823 | + 'uid_file_owner' => 'owner', |
|
| 4824 | + 'displayname_file_owner' => 'owner', |
|
| 4825 | + 'note' => '', |
|
| 4826 | + 'label' => '', |
|
| 4827 | + 'path' => 'folder', |
|
| 4828 | + 'item_type' => 'folder', |
|
| 4829 | + 'storage_id' => 'storageId', |
|
| 4830 | + 'storage' => 100, |
|
| 4831 | + 'item_source' => 2, |
|
| 4832 | + 'file_source' => 2, |
|
| 4833 | + 'file_parent' => 1, |
|
| 4834 | + 'file_target' => 'myTarget', |
|
| 4835 | + 'share_with' => '[email protected]', |
|
| 4836 | + 'share_with_displayname' => 'mail display name', |
|
| 4837 | + 'mail_send' => 0, |
|
| 4838 | + 'mimetype' => 'myFolderMimeType', |
|
| 4839 | + 'has_preview' => false, |
|
| 4840 | + 'password' => 'password', |
|
| 4841 | + 'send_password_by_talk' => true, |
|
| 4842 | + 'hide_download' => 0, |
|
| 4843 | + 'can_edit' => false, |
|
| 4844 | + 'can_delete' => false, |
|
| 4845 | + 'password_expiration_time' => null, |
|
| 4846 | + 'item_size' => 123456, |
|
| 4847 | + 'item_mtime' => 1234567890, |
|
| 4848 | + 'is-mount-root' => false, |
|
| 4849 | + 'mount-type' => '', |
|
| 4850 | + 'attributes' => null, |
|
| 4851 | + 'item_permissions' => 1, |
|
| 4852 | + ], $share, [], false |
|
| 4853 | + ]; |
|
| 4854 | + |
|
| 4855 | + // Preview is available |
|
| 4856 | + $share = Server::get(IManager::class)->newShare(); |
|
| 4857 | + $share->setShareType(IShare::TYPE_USER) |
|
| 4858 | + ->setSharedWith('recipient') |
|
| 4859 | + ->setSharedBy('initiator') |
|
| 4860 | + ->setShareOwner('currentUser') |
|
| 4861 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 4862 | + ->setNode($fileWithPreview) |
|
| 4863 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 4864 | + ->setTarget('myTarget') |
|
| 4865 | + ->setNote('personal note') |
|
| 4866 | + ->setId(42); |
|
| 4867 | + |
|
| 4868 | + $result[] = [ |
|
| 4869 | + [ |
|
| 4870 | + 'id' => '42', |
|
| 4871 | + 'share_type' => IShare::TYPE_USER, |
|
| 4872 | + 'uid_owner' => 'initiator', |
|
| 4873 | + 'displayname_owner' => 'initiator', |
|
| 4874 | + 'permissions' => 1, |
|
| 4875 | + 'stime' => 946684862, |
|
| 4876 | + 'parent' => null, |
|
| 4877 | + 'expiration' => null, |
|
| 4878 | + 'token' => null, |
|
| 4879 | + 'uid_file_owner' => 'currentUser', |
|
| 4880 | + 'displayname_file_owner' => 'currentUser', |
|
| 4881 | + 'note' => 'personal note', |
|
| 4882 | + 'label' => '', |
|
| 4883 | + 'path' => 'fileWithPreview', |
|
| 4884 | + 'item_type' => 'file', |
|
| 4885 | + 'storage_id' => 'storageId', |
|
| 4886 | + 'storage' => 100, |
|
| 4887 | + 'item_source' => 4, |
|
| 4888 | + 'file_source' => 4, |
|
| 4889 | + 'file_parent' => 1, |
|
| 4890 | + 'file_target' => 'myTarget', |
|
| 4891 | + 'share_with' => 'recipient', |
|
| 4892 | + 'share_with_displayname' => 'recipient', |
|
| 4893 | + 'share_with_displayname_unique' => 'recipient', |
|
| 4894 | + 'mail_send' => 0, |
|
| 4895 | + 'mimetype' => 'mimeWithPreview', |
|
| 4896 | + 'has_preview' => true, |
|
| 4897 | + 'hide_download' => 0, |
|
| 4898 | + 'can_edit' => true, |
|
| 4899 | + 'can_delete' => true, |
|
| 4900 | + 'item_size' => 123456, |
|
| 4901 | + 'item_mtime' => 1234567890, |
|
| 4902 | + 'is-mount-root' => false, |
|
| 4903 | + 'mount-type' => '', |
|
| 4904 | + 'attributes' => null, |
|
| 4905 | + 'item_permissions' => 11, |
|
| 4906 | + ], $share, [], false |
|
| 4907 | + ]; |
|
| 4908 | + |
|
| 4909 | + return $result; |
|
| 4910 | + } |
|
| 4911 | + |
|
| 4912 | + /** |
|
| 4913 | + * |
|
| 4914 | + * @param array $expects |
|
| 4915 | + * @param IShare $share |
|
| 4916 | + * @param array $users |
|
| 4917 | + * @param $exception |
|
| 4918 | + */ |
|
| 4919 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFormatShare')] |
|
| 4920 | + public function testFormatShare(array $expects, IShare $share, array $users, $exception): void { |
|
| 4921 | + $this->userManager->method('get')->willReturnMap($users); |
|
| 4922 | + |
|
| 4923 | + $recipientGroup = $this->createMock(IGroup::class); |
|
| 4924 | + $recipientGroup->method('getDisplayName')->willReturn('recipientGroupDisplayName'); |
|
| 4925 | + $this->groupManager->method('get')->willReturnMap([ |
|
| 4926 | + ['recipientGroup', $recipientGroup], |
|
| 4927 | + ]); |
|
| 4928 | + |
|
| 4929 | + $this->urlGenerator->method('linkToRouteAbsolute') |
|
| 4930 | + ->with('files_sharing.sharecontroller.showShare', ['token' => 'myToken']) |
|
| 4931 | + ->willReturn('myLink'); |
|
| 4932 | + |
|
| 4933 | + $this->rootFolder->method('getUserFolder') |
|
| 4934 | + ->with($this->currentUser) |
|
| 4935 | + ->willReturnSelf(); |
|
| 4936 | + $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC')); |
|
| 4937 | + |
|
| 4938 | + if (!$exception) { |
|
| 4939 | + $this->rootFolder->method('getFirstNodeById') |
|
| 4940 | + ->with($share->getNodeId()) |
|
| 4941 | + ->willReturn($share->getNode()); |
|
| 4942 | + |
|
| 4943 | + $this->rootFolder->method('getRelativePath') |
|
| 4944 | + ->with($share->getNode()->getPath()) |
|
| 4945 | + ->willReturnArgument(0); |
|
| 4946 | + } |
|
| 4947 | + |
|
| 4948 | + $cm = $this->createMock(\OCP\Contacts\IManager::class); |
|
| 4949 | + $this->overwriteService(\OCP\Contacts\IManager::class, $cm); |
|
| 4950 | + |
|
| 4951 | + $cm->method('search') |
|
| 4952 | + ->willReturnMap([ |
|
| 4953 | + ['[email protected]', ['CLOUD'], [ |
|
| 4954 | + 'limit' => 1, |
|
| 4955 | + 'enumeration' => false, |
|
| 4956 | + 'strict_search' => true, |
|
| 4957 | + ], |
|
| 4958 | + [ |
|
| 4959 | + [ |
|
| 4960 | + 'CLOUD' => [ |
|
| 4961 | + '[email protected]', |
|
| 4962 | + ], |
|
| 4963 | + 'FN' => 'foobar', |
|
| 4964 | + ], |
|
| 4965 | + ], |
|
| 4966 | + ], |
|
| 4967 | + ['[email protected]', ['EMAIL'], [ |
|
| 4968 | + 'limit' => 1, |
|
| 4969 | + 'enumeration' => false, |
|
| 4970 | + 'strict_search' => true, |
|
| 4971 | + ], |
|
| 4972 | + [ |
|
| 4973 | + [ |
|
| 4974 | + 'EMAIL' => [ |
|
| 4975 | + '[email protected]', |
|
| 4976 | + ], |
|
| 4977 | + 'FN' => 'mail display name', |
|
| 4978 | + ], |
|
| 4979 | + ], |
|
| 4980 | + ], |
|
| 4981 | + ]); |
|
| 4982 | + |
|
| 4983 | + try { |
|
| 4984 | + $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); |
|
| 4985 | + $this->assertFalse($exception); |
|
| 4986 | + $this->assertEquals($expects, $result); |
|
| 4987 | + } catch (NotFoundException $e) { |
|
| 4988 | + $this->assertTrue($exception); |
|
| 4989 | + } |
|
| 4990 | + } |
|
| 4991 | + |
|
| 4992 | + public function dataFormatRoomShare() { |
|
| 4993 | + $file = $this->getMockBuilder(File::class)->getMock(); |
|
| 4994 | + $parent = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 4995 | + |
|
| 4996 | + $file->method('getMimeType')->willReturn('myMimeType'); |
|
| 4997 | + |
|
| 4998 | + $file->method('getPath')->willReturn('file'); |
|
| 4999 | + |
|
| 5000 | + $parent->method('getId')->willReturn(1); |
|
| 5001 | + $file->method('getId')->willReturn(3); |
|
| 5002 | + |
|
| 5003 | + $file->method('getParent')->willReturn($parent); |
|
| 5004 | + |
|
| 5005 | + $file->method('getSize')->willReturn(123456); |
|
| 5006 | + $file->method('getMTime')->willReturn(1234567890); |
|
| 5007 | + |
|
| 5008 | + $mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock(); |
|
| 5009 | + $mountPoint->method('getMountType')->willReturn(''); |
|
| 5010 | + $file->method('getMountPoint')->willReturn($mountPoint); |
|
| 5011 | + |
|
| 5012 | + $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock(); |
|
| 5013 | + $cache->method('getNumericStorageId')->willReturn(100); |
|
| 5014 | + $storage = $this->createMock(IStorage::class); |
|
| 5015 | + $storage->method('getId')->willReturn('storageId'); |
|
| 5016 | + $storage->method('getCache')->willReturn($cache); |
|
| 5017 | + |
|
| 5018 | + $file->method('getStorage')->willReturn($storage); |
|
| 5019 | + |
|
| 5020 | + $result = []; |
|
| 5021 | + |
|
| 5022 | + $share = Server::get(IManager::class)->newShare(); |
|
| 5023 | + $share->setShareType(IShare::TYPE_ROOM) |
|
| 5024 | + ->setSharedWith('recipientRoom') |
|
| 5025 | + ->setSharedBy('initiator') |
|
| 5026 | + ->setShareOwner('owner') |
|
| 5027 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 5028 | + ->setNode($file) |
|
| 5029 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 5030 | + ->setTarget('myTarget') |
|
| 5031 | + ->setNote('personal note') |
|
| 5032 | + ->setId(42); |
|
| 5033 | + |
|
| 5034 | + $result[] = [ |
|
| 5035 | + [ |
|
| 5036 | + 'id' => '42', |
|
| 5037 | + 'share_type' => IShare::TYPE_ROOM, |
|
| 5038 | + 'uid_owner' => 'initiator', |
|
| 5039 | + 'displayname_owner' => 'initiator', |
|
| 5040 | + 'permissions' => 1, |
|
| 5041 | + 'stime' => 946684862, |
|
| 5042 | + 'parent' => null, |
|
| 5043 | + 'expiration' => null, |
|
| 5044 | + 'token' => null, |
|
| 5045 | + 'uid_file_owner' => 'owner', |
|
| 5046 | + 'displayname_file_owner' => 'owner', |
|
| 5047 | + 'note' => 'personal note', |
|
| 5048 | + 'path' => 'file', |
|
| 5049 | + 'item_type' => 'file', |
|
| 5050 | + 'storage_id' => 'storageId', |
|
| 5051 | + 'storage' => 100, |
|
| 5052 | + 'item_source' => 3, |
|
| 5053 | + 'file_source' => 3, |
|
| 5054 | + 'file_parent' => 1, |
|
| 5055 | + 'file_target' => 'myTarget', |
|
| 5056 | + 'share_with' => 'recipientRoom', |
|
| 5057 | + 'share_with_displayname' => '', |
|
| 5058 | + 'mail_send' => 0, |
|
| 5059 | + 'mimetype' => 'myMimeType', |
|
| 5060 | + 'has_preview' => false, |
|
| 5061 | + 'hide_download' => 0, |
|
| 5062 | + 'label' => '', |
|
| 5063 | + 'can_edit' => false, |
|
| 5064 | + 'can_delete' => false, |
|
| 5065 | + 'item_size' => 123456, |
|
| 5066 | + 'item_mtime' => 1234567890, |
|
| 5067 | + 'is-mount-root' => false, |
|
| 5068 | + 'mount-type' => '', |
|
| 5069 | + 'attributes' => null, |
|
| 5070 | + 'item_permissions' => 1, |
|
| 5071 | + ], $share, false, [] |
|
| 5072 | + ]; |
|
| 5073 | + |
|
| 5074 | + $share = Server::get(IManager::class)->newShare(); |
|
| 5075 | + $share->setShareType(IShare::TYPE_ROOM) |
|
| 5076 | + ->setSharedWith('recipientRoom') |
|
| 5077 | + ->setSharedBy('initiator') |
|
| 5078 | + ->setShareOwner('owner') |
|
| 5079 | + ->setPermissions(Constants::PERMISSION_READ) |
|
| 5080 | + ->setNode($file) |
|
| 5081 | + ->setShareTime(new \DateTime('2000-01-01T00:01:02')) |
|
| 5082 | + ->setTarget('myTarget') |
|
| 5083 | + ->setNote('personal note') |
|
| 5084 | + ->setId(42); |
|
| 5085 | + |
|
| 5086 | + $result[] = [ |
|
| 5087 | + [ |
|
| 5088 | + 'id' => '42', |
|
| 5089 | + 'share_type' => IShare::TYPE_ROOM, |
|
| 5090 | + 'uid_owner' => 'initiator', |
|
| 5091 | + 'displayname_owner' => 'initiator', |
|
| 5092 | + 'permissions' => 1, |
|
| 5093 | + 'stime' => 946684862, |
|
| 5094 | + 'parent' => null, |
|
| 5095 | + 'expiration' => null, |
|
| 5096 | + 'token' => null, |
|
| 5097 | + 'uid_file_owner' => 'owner', |
|
| 5098 | + 'displayname_file_owner' => 'owner', |
|
| 5099 | + 'note' => 'personal note', |
|
| 5100 | + 'path' => 'file', |
|
| 5101 | + 'item_type' => 'file', |
|
| 5102 | + 'storage_id' => 'storageId', |
|
| 5103 | + 'storage' => 100, |
|
| 5104 | + 'item_source' => 3, |
|
| 5105 | + 'file_source' => 3, |
|
| 5106 | + 'file_parent' => 1, |
|
| 5107 | + 'file_target' => 'myTarget', |
|
| 5108 | + 'share_with' => 'recipientRoom', |
|
| 5109 | + 'share_with_displayname' => 'recipientRoomName', |
|
| 5110 | + 'mail_send' => 0, |
|
| 5111 | + 'mimetype' => 'myMimeType', |
|
| 5112 | + 'has_preview' => false, |
|
| 5113 | + 'hide_download' => 0, |
|
| 5114 | + 'label' => '', |
|
| 5115 | + 'can_edit' => false, |
|
| 5116 | + 'can_delete' => false, |
|
| 5117 | + 'item_size' => 123456, |
|
| 5118 | + 'item_mtime' => 1234567890, |
|
| 5119 | + 'is-mount-root' => false, |
|
| 5120 | + 'mount-type' => '', |
|
| 5121 | + 'attributes' => null, |
|
| 5122 | + 'item_permissions' => 9, |
|
| 5123 | + ], $share, true, [ |
|
| 5124 | + 'share_with_displayname' => 'recipientRoomName' |
|
| 5125 | + ] |
|
| 5126 | + ]; |
|
| 5127 | + |
|
| 5128 | + return $result; |
|
| 5129 | + } |
|
| 5130 | + |
|
| 5131 | + /** |
|
| 5132 | + * |
|
| 5133 | + * @param array $expects |
|
| 5134 | + * @param IShare $share |
|
| 5135 | + * @param bool $helperAvailable |
|
| 5136 | + * @param array $formatShareByHelper |
|
| 5137 | + */ |
|
| 5138 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataFormatRoomShare')] |
|
| 5139 | + public function testFormatRoomShare(array $expects, IShare $share, bool $helperAvailable, array $formatShareByHelper): void { |
|
| 5140 | + $this->rootFolder->method('getUserFolder') |
|
| 5141 | + ->with($this->currentUser) |
|
| 5142 | + ->willReturnSelf(); |
|
| 5143 | + |
|
| 5144 | + $this->rootFolder->method('getFirstNodeById') |
|
| 5145 | + ->with($share->getNodeId()) |
|
| 5146 | + ->willReturn($share->getNode()); |
|
| 5147 | + |
|
| 5148 | + $this->rootFolder->method('getRelativePath') |
|
| 5149 | + ->with($share->getNode()->getPath()) |
|
| 5150 | + ->willReturnArgument(0); |
|
| 5151 | + |
|
| 5152 | + if (!$helperAvailable) { |
|
| 5153 | + $this->appManager->method('isEnabledForUser') |
|
| 5154 | + ->with('spreed') |
|
| 5155 | + ->willReturn(false); |
|
| 5156 | + } else { |
|
| 5157 | + $this->appManager->method('isEnabledForUser') |
|
| 5158 | + ->with('spreed') |
|
| 5159 | + ->willReturn(true); |
|
| 5160 | + |
|
| 5161 | + // This is not possible anymore with PHPUnit 10+ |
|
| 5162 | + // as `setMethods` was removed and now real reflection is used, thus the class needs to exist. |
|
| 5163 | + // $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 5164 | + $helper = $this->getMockBuilder(\stdClass::class) |
|
| 5165 | + ->addMethods(['formatShare', 'canAccessShare']) |
|
| 5166 | + ->getMock(); |
|
| 5167 | + $helper->method('formatShare') |
|
| 5168 | + ->with($share) |
|
| 5169 | + ->willReturn($formatShareByHelper); |
|
| 5170 | + $helper->method('canAccessShare') |
|
| 5171 | + ->with($share) |
|
| 5172 | + ->willReturn(true); |
|
| 5173 | + |
|
| 5174 | + $this->serverContainer->method('get') |
|
| 5175 | + ->with('\OCA\Talk\Share\Helper\ShareAPIController') |
|
| 5176 | + ->willReturn($helper); |
|
| 5177 | + } |
|
| 5178 | + |
|
| 5179 | + $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); |
|
| 5180 | + $this->assertEquals($expects, $result); |
|
| 5181 | + } |
|
| 5182 | + |
|
| 5183 | + /** |
|
| 5184 | + * @return list{Folder, Folder} |
|
| 5185 | + */ |
|
| 5186 | + private function getNonSharedUserFolder(): array { |
|
| 5187 | + $node = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 5188 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 5189 | + $storage = $this->createMock(IStorage::class); |
|
| 5190 | + $storage->method('instanceOfStorage') |
|
| 5191 | + ->willReturnMap([ |
|
| 5192 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 5193 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 5194 | + ]); |
|
| 5195 | + $userFolder->method('getStorage')->willReturn($storage); |
|
| 5196 | + $node->method('getStorage')->willReturn($storage); |
|
| 5197 | + $node->method('getId')->willReturn(42); |
|
| 5198 | + $user = $this->createMock(IUser::class); |
|
| 5199 | + $user->method('getUID')->willReturn($this->currentUser); |
|
| 5200 | + $node->method('getOwner')->willReturn($user); |
|
| 5201 | + return [$userFolder, $node]; |
|
| 5202 | + } |
|
| 5203 | + |
|
| 5204 | + /** |
|
| 5205 | + * @return list{Folder, File} |
|
| 5206 | + */ |
|
| 5207 | + private function getNonSharedUserFile(): array { |
|
| 5208 | + $node = $this->getMockBuilder(File::class)->getMock(); |
|
| 5209 | + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); |
|
| 5210 | + $storage = $this->createMock(IStorage::class); |
|
| 5211 | + $storage->method('instanceOfStorage') |
|
| 5212 | + ->willReturnMap([ |
|
| 5213 | + ['OCA\Files_Sharing\External\Storage', false], |
|
| 5214 | + ['OCA\Files_Sharing\SharedStorage', false], |
|
| 5215 | + ]); |
|
| 5216 | + $userFolder->method('getStorage')->willReturn($storage); |
|
| 5217 | + $node->method('getStorage')->willReturn($storage); |
|
| 5218 | + $node->method('getId')->willReturn(42); |
|
| 5219 | + return [$userFolder, $node]; |
|
| 5220 | + } |
|
| 5221 | + |
|
| 5222 | + public function testPopulateTags(): void { |
|
| 5223 | + $tagger = $this->createMock(ITags::class); |
|
| 5224 | + $this->tagManager->method('load') |
|
| 5225 | + ->with('files') |
|
| 5226 | + ->willReturn($tagger); |
|
| 5227 | + $data = [ |
|
| 5228 | + ['file_source' => 10], |
|
| 5229 | + ['file_source' => 22, 'foo' => 'bar'], |
|
| 5230 | + ['file_source' => 42, 'x' => 'y'], |
|
| 5231 | + ]; |
|
| 5232 | + $tags = [ |
|
| 5233 | + 10 => ['tag3'], |
|
| 5234 | + 42 => ['tag1', 'tag2'], |
|
| 5235 | + ]; |
|
| 5236 | + $tagger->method('getTagsForObjects') |
|
| 5237 | + ->with([10, 22, 42]) |
|
| 5238 | + ->willReturn($tags); |
|
| 5239 | + |
|
| 5240 | + $result = self::invokePrivate($this->ocs, 'populateTags', [$data]); |
|
| 5241 | + $this->assertSame([ |
|
| 5242 | + ['file_source' => 10, 'tags' => ['tag3']], |
|
| 5243 | + ['file_source' => 22, 'foo' => 'bar', 'tags' => []], |
|
| 5244 | + ['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']], |
|
| 5245 | + ], $result); |
|
| 5246 | + } |
|
| 5247 | + |
|
| 5248 | + public static function trustedServerProvider(): array { |
|
| 5249 | + return [ |
|
| 5250 | + 'Trusted server' => [true, true], |
|
| 5251 | + 'Untrusted server' => [false, false], |
|
| 5252 | + ]; |
|
| 5253 | + } |
|
| 5254 | + |
|
| 5255 | + /** |
|
| 5256 | + * @dataProvider trustedServerProvider |
|
| 5257 | + */ |
|
| 5258 | + public function testFormatShareWithFederatedShare(bool $isKnownServer, bool $isTrusted): void { |
|
| 5259 | + $nodeId = 12; |
|
| 5260 | + $nodePath = '/test.txt'; |
|
| 5261 | + $share = $this->createShare( |
|
| 5262 | + 1, |
|
| 5263 | + IShare::TYPE_REMOTE, |
|
| 5264 | + '[email protected]', // shared with |
|
| 5265 | + '[email protected]', // shared by |
|
| 5266 | + 'shareOwner', // share owner |
|
| 5267 | + $nodePath, // path |
|
| 5268 | + Constants::PERMISSION_READ, |
|
| 5269 | + time(), |
|
| 5270 | + null, |
|
| 5271 | + null, |
|
| 5272 | + $nodePath, |
|
| 5273 | + $nodeId |
|
| 5274 | + ); |
|
| 5275 | + |
|
| 5276 | + $node = $this->createMock(File::class); |
|
| 5277 | + $node->method('getId')->willReturn($nodeId); |
|
| 5278 | + $node->method('getPath')->willReturn($nodePath); |
|
| 5279 | + $node->method('getInternalPath')->willReturn(ltrim($nodePath, '/')); |
|
| 5280 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 5281 | + $mountPoint->method('getMountType')->willReturn('local'); |
|
| 5282 | + $node->method('getMountPoint')->willReturn($mountPoint); |
|
| 5283 | + $node->method('getMimetype')->willReturn('text/plain'); |
|
| 5284 | + $storage = $this->createMock(IStorage::class); |
|
| 5285 | + $storageCache = $this->createMock(ICache::class); |
|
| 5286 | + $storageCache->method('getNumericStorageId')->willReturn(1); |
|
| 5287 | + $storage->method('getCache')->willReturn($storageCache); |
|
| 5288 | + $storage->method('getId')->willReturn('home::shareOwner'); |
|
| 5289 | + $node->method('getStorage')->willReturn($storage); |
|
| 5290 | + $parent = $this->createMock(Folder::class); |
|
| 5291 | + $parent->method('getId')->willReturn(2); |
|
| 5292 | + $node->method('getParent')->willReturn($parent); |
|
| 5293 | + $node->method('getSize')->willReturn(1234); |
|
| 5294 | + $node->method('getMTime')->willReturn(1234567890); |
|
| 5295 | + |
|
| 5296 | + $this->previewManager->method('isAvailable')->with($node)->willReturn(false); |
|
| 5297 | + |
|
| 5298 | + $this->rootFolder->method('getUserFolder') |
|
| 5299 | + ->with($this->currentUser) |
|
| 5300 | + ->willReturnSelf(); |
|
| 5301 | + |
|
| 5302 | + $this->rootFolder->method('getFirstNodeById') |
|
| 5303 | + ->with($share->getNodeId()) |
|
| 5304 | + ->willReturn($node); |
|
| 5305 | + |
|
| 5306 | + $this->rootFolder->method('getRelativePath') |
|
| 5307 | + ->with($node->getPath()) |
|
| 5308 | + ->willReturnArgument(0); |
|
| 5309 | + |
|
| 5310 | + $serverName = 'remoteserver.com'; |
|
| 5311 | + $this->trustedServers->method('isTrustedServer') |
|
| 5312 | + ->with($serverName) |
|
| 5313 | + ->willReturn($isKnownServer); |
|
| 5314 | + |
|
| 5315 | + $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); |
|
| 5316 | + |
|
| 5317 | + $this->assertSame($isTrusted, $result['is_trusted_server']); |
|
| 5318 | + } |
|
| 5319 | + |
|
| 5320 | + public function testFormatShareWithFederatedShareWithAtInUsername(): void { |
|
| 5321 | + $nodeId = 12; |
|
| 5322 | + $nodePath = '/test.txt'; |
|
| 5323 | + $share = $this->createShare( |
|
| 5324 | + 1, |
|
| 5325 | + IShare::TYPE_REMOTE, |
|
| 5326 | + '[email protected]@remoteserver.com', |
|
| 5327 | + '[email protected]', |
|
| 5328 | + 'shareOwner', |
|
| 5329 | + $nodePath, |
|
| 5330 | + Constants::PERMISSION_READ, |
|
| 5331 | + time(), |
|
| 5332 | + null, |
|
| 5333 | + null, |
|
| 5334 | + $nodePath, |
|
| 5335 | + $nodeId |
|
| 5336 | + ); |
|
| 5337 | + |
|
| 5338 | + $node = $this->createMock(File::class); |
|
| 5339 | + $node->method('getId')->willReturn($nodeId); |
|
| 5340 | + $node->method('getPath')->willReturn($nodePath); |
|
| 5341 | + $node->method('getInternalPath')->willReturn(ltrim($nodePath, '/')); |
|
| 5342 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 5343 | + $mountPoint->method('getMountType')->willReturn('local'); |
|
| 5344 | + $node->method('getMountPoint')->willReturn($mountPoint); |
|
| 5345 | + $node->method('getMimetype')->willReturn('text/plain'); |
|
| 5346 | + $storage = $this->createMock(IStorage::class); |
|
| 5347 | + $storageCache = $this->createMock(ICache::class); |
|
| 5348 | + $storageCache->method('getNumericStorageId')->willReturn(1); |
|
| 5349 | + $storage->method('getCache')->willReturn($storageCache); |
|
| 5350 | + $storage->method('getId')->willReturn('home::shareOwner'); |
|
| 5351 | + $node->method('getStorage')->willReturn($storage); |
|
| 5352 | + $parent = $this->createMock(Folder::class); |
|
| 5353 | + $parent->method('getId')->willReturn(2); |
|
| 5354 | + $node->method('getParent')->willReturn($parent); |
|
| 5355 | + $node->method('getSize')->willReturn(1234); |
|
| 5356 | + $node->method('getMTime')->willReturn(1234567890); |
|
| 5357 | + |
|
| 5358 | + $this->previewManager->method('isAvailable')->with($node)->willReturn(false); |
|
| 5359 | + |
|
| 5360 | + $this->rootFolder->method('getUserFolder') |
|
| 5361 | + ->with($this->currentUser) |
|
| 5362 | + ->willReturnSelf(); |
|
| 5363 | + |
|
| 5364 | + $this->rootFolder->method('getFirstNodeById') |
|
| 5365 | + ->with($share->getNodeId()) |
|
| 5366 | + ->willReturn($node); |
|
| 5367 | + |
|
| 5368 | + $this->rootFolder->method('getRelativePath') |
|
| 5369 | + ->with($node->getPath()) |
|
| 5370 | + ->willReturnArgument(0); |
|
| 5371 | + |
|
| 5372 | + $serverName = 'remoteserver.com'; |
|
| 5373 | + $this->trustedServers->method('isTrustedServer') |
|
| 5374 | + ->with($serverName) |
|
| 5375 | + ->willReturn(true); |
|
| 5376 | + |
|
| 5377 | + $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); |
|
| 5378 | + |
|
| 5379 | + $this->assertTrue($result['is_trusted_server']); |
|
| 5380 | + } |
|
| 5381 | 5381 | } |
@@ -29,128 +29,128 @@ |
||
| 29 | 29 | * @package OCA\Files_Trashbin\Tests\Command |
| 30 | 30 | */ |
| 31 | 31 | class ExpireTrashTest extends TestCase { |
| 32 | - private Expiration $expiration; |
|
| 33 | - private Node $userFolder; |
|
| 34 | - private IConfig $config; |
|
| 35 | - private IUserManager $userManager; |
|
| 36 | - private IUser $user; |
|
| 37 | - private ITimeFactory $timeFactory; |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - protected function setUp(): void { |
|
| 41 | - parent::setUp(); |
|
| 42 | - |
|
| 43 | - $this->config = Server::get(IConfig::class); |
|
| 44 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 45 | - $this->expiration = Server::get(Expiration::class); |
|
| 46 | - $this->invokePrivate($this->expiration, 'timeFactory', [$this->timeFactory]); |
|
| 47 | - |
|
| 48 | - $userId = self::getUniqueID('user'); |
|
| 49 | - $this->userManager = Server::get(IUserManager::class); |
|
| 50 | - $this->user = $this->userManager->createUser($userId, $userId); |
|
| 51 | - |
|
| 52 | - $this->loginAsUser($userId); |
|
| 53 | - $this->userFolder = Server::get(IRootFolder::class)->getUserFolder($userId); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - protected function tearDown(): void { |
|
| 57 | - $this->logout(); |
|
| 58 | - |
|
| 59 | - if (isset($this->user)) { |
|
| 60 | - $this->user->delete(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $this->invokePrivate($this->expiration, 'timeFactory', [Server::get(ITimeFactory::class)]); |
|
| 64 | - parent::tearDown(); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @dataProvider retentionObligationProvider |
|
| 69 | - */ |
|
| 70 | - public function testRetentionObligation(string $obligation, string $quota, int $elapsed, int $fileSize, bool $shouldExpire): void { |
|
| 71 | - $this->config->setSystemValues(['trashbin_retention_obligation' => $obligation]); |
|
| 72 | - $this->expiration->setRetentionObligation($obligation); |
|
| 73 | - |
|
| 74 | - $this->user->setQuota($quota); |
|
| 75 | - |
|
| 76 | - $bytes = 'ABCDEFGHIKLMNOPQRSTUVWXYZ'; |
|
| 77 | - |
|
| 78 | - $file = 'foo.txt'; |
|
| 79 | - $this->userFolder->newFile($file, substr($bytes, 0, $fileSize)); |
|
| 80 | - |
|
| 81 | - $filemtime = $this->userFolder->get($file)->getMTime(); |
|
| 82 | - $this->timeFactory->expects($this->any()) |
|
| 83 | - ->method('getTime') |
|
| 84 | - ->willReturn($filemtime + $elapsed); |
|
| 85 | - $this->userFolder->get($file)->delete(); |
|
| 86 | - $this->userFolder->getStorage() |
|
| 87 | - ->getCache() |
|
| 88 | - ->put('files_trashbin', ['size' => $fileSize, 'unencrypted_size' => $fileSize]); |
|
| 89 | - |
|
| 90 | - $userId = $this->user->getUID(); |
|
| 91 | - $trashFiles = Helper::getTrashFiles('/', $userId); |
|
| 92 | - $this->assertEquals(1, count($trashFiles)); |
|
| 93 | - |
|
| 94 | - $outputInterface = $this->createMock(OutputInterface::class); |
|
| 95 | - $inputInterface = $this->createMock(InputInterface::class); |
|
| 96 | - $inputInterface->expects($this->any()) |
|
| 97 | - ->method('getArgument') |
|
| 98 | - ->with('user_id') |
|
| 99 | - ->willReturn([$userId]); |
|
| 100 | - |
|
| 101 | - $command = new ExpireTrash( |
|
| 102 | - Server::get(LoggerInterface::class), |
|
| 103 | - Server::get(IUserManager::class), |
|
| 104 | - $this->expiration |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - $this->invokePrivate($command, 'execute', [$inputInterface, $outputInterface]); |
|
| 108 | - |
|
| 109 | - $trashFiles = Helper::getTrashFiles('/', $userId); |
|
| 110 | - $this->assertEquals($shouldExpire ? 0 : 1, count($trashFiles)); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public static function retentionObligationProvider(): array { |
|
| 114 | - $hour = 3600; // 60 * 60 |
|
| 115 | - |
|
| 116 | - $oneDay = 24 * $hour; |
|
| 117 | - $fiveDays = 24 * 5 * $hour; |
|
| 118 | - $tenDays = 24 * 10 * $hour; |
|
| 119 | - $elevenDays = 24 * 11 * $hour; |
|
| 120 | - |
|
| 121 | - return [ |
|
| 122 | - ['disabled', '20 B', 0, 1, false], |
|
| 123 | - |
|
| 124 | - ['auto', '20 B', 0, 5, false], |
|
| 125 | - ['auto', '20 B', 0, 21, true], |
|
| 126 | - |
|
| 127 | - ['0, auto', '20 B', 0, 21, true], |
|
| 128 | - ['0, auto', '20 B', $oneDay, 5, false], |
|
| 129 | - ['0, auto', '20 B', $oneDay, 19, true], |
|
| 130 | - ['0, auto', '20 B', 0, 19, true], |
|
| 131 | - |
|
| 132 | - ['auto, 0', '20 B', $oneDay, 19, true], |
|
| 133 | - ['auto, 0', '20 B', $oneDay, 21, true], |
|
| 134 | - ['auto, 0', '20 B', 0, 5, false], |
|
| 135 | - ['auto, 0', '20 B', 0, 19, true], |
|
| 136 | - |
|
| 137 | - ['1, auto', '20 B', 0, 5, false], |
|
| 138 | - ['1, auto', '20 B', $fiveDays, 5, false], |
|
| 139 | - ['1, auto', '20 B', $fiveDays, 21, true], |
|
| 140 | - |
|
| 141 | - ['auto, 1', '20 B', 0, 21, true], |
|
| 142 | - ['auto, 1', '20 B', 0, 5, false], |
|
| 143 | - ['auto, 1', '20 B', $fiveDays, 5, true], |
|
| 144 | - ['auto, 1', '20 B', $oneDay, 5, false], |
|
| 145 | - |
|
| 146 | - ['2, 10', '20 B', $fiveDays, 5, false], |
|
| 147 | - ['2, 10', '20 B', $fiveDays, 20, true], |
|
| 148 | - ['2, 10', '20 B', $elevenDays, 5, true], |
|
| 149 | - |
|
| 150 | - ['10, 2', '20 B', $fiveDays, 5, false], |
|
| 151 | - ['10, 2', '20 B', $fiveDays, 21, false], |
|
| 152 | - ['10, 2', '20 B', $tenDays, 5, false], |
|
| 153 | - ['10, 2', '20 B', $elevenDays, 5, true] |
|
| 154 | - ]; |
|
| 155 | - } |
|
| 32 | + private Expiration $expiration; |
|
| 33 | + private Node $userFolder; |
|
| 34 | + private IConfig $config; |
|
| 35 | + private IUserManager $userManager; |
|
| 36 | + private IUser $user; |
|
| 37 | + private ITimeFactory $timeFactory; |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + protected function setUp(): void { |
|
| 41 | + parent::setUp(); |
|
| 42 | + |
|
| 43 | + $this->config = Server::get(IConfig::class); |
|
| 44 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 45 | + $this->expiration = Server::get(Expiration::class); |
|
| 46 | + $this->invokePrivate($this->expiration, 'timeFactory', [$this->timeFactory]); |
|
| 47 | + |
|
| 48 | + $userId = self::getUniqueID('user'); |
|
| 49 | + $this->userManager = Server::get(IUserManager::class); |
|
| 50 | + $this->user = $this->userManager->createUser($userId, $userId); |
|
| 51 | + |
|
| 52 | + $this->loginAsUser($userId); |
|
| 53 | + $this->userFolder = Server::get(IRootFolder::class)->getUserFolder($userId); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + protected function tearDown(): void { |
|
| 57 | + $this->logout(); |
|
| 58 | + |
|
| 59 | + if (isset($this->user)) { |
|
| 60 | + $this->user->delete(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $this->invokePrivate($this->expiration, 'timeFactory', [Server::get(ITimeFactory::class)]); |
|
| 64 | + parent::tearDown(); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @dataProvider retentionObligationProvider |
|
| 69 | + */ |
|
| 70 | + public function testRetentionObligation(string $obligation, string $quota, int $elapsed, int $fileSize, bool $shouldExpire): void { |
|
| 71 | + $this->config->setSystemValues(['trashbin_retention_obligation' => $obligation]); |
|
| 72 | + $this->expiration->setRetentionObligation($obligation); |
|
| 73 | + |
|
| 74 | + $this->user->setQuota($quota); |
|
| 75 | + |
|
| 76 | + $bytes = 'ABCDEFGHIKLMNOPQRSTUVWXYZ'; |
|
| 77 | + |
|
| 78 | + $file = 'foo.txt'; |
|
| 79 | + $this->userFolder->newFile($file, substr($bytes, 0, $fileSize)); |
|
| 80 | + |
|
| 81 | + $filemtime = $this->userFolder->get($file)->getMTime(); |
|
| 82 | + $this->timeFactory->expects($this->any()) |
|
| 83 | + ->method('getTime') |
|
| 84 | + ->willReturn($filemtime + $elapsed); |
|
| 85 | + $this->userFolder->get($file)->delete(); |
|
| 86 | + $this->userFolder->getStorage() |
|
| 87 | + ->getCache() |
|
| 88 | + ->put('files_trashbin', ['size' => $fileSize, 'unencrypted_size' => $fileSize]); |
|
| 89 | + |
|
| 90 | + $userId = $this->user->getUID(); |
|
| 91 | + $trashFiles = Helper::getTrashFiles('/', $userId); |
|
| 92 | + $this->assertEquals(1, count($trashFiles)); |
|
| 93 | + |
|
| 94 | + $outputInterface = $this->createMock(OutputInterface::class); |
|
| 95 | + $inputInterface = $this->createMock(InputInterface::class); |
|
| 96 | + $inputInterface->expects($this->any()) |
|
| 97 | + ->method('getArgument') |
|
| 98 | + ->with('user_id') |
|
| 99 | + ->willReturn([$userId]); |
|
| 100 | + |
|
| 101 | + $command = new ExpireTrash( |
|
| 102 | + Server::get(LoggerInterface::class), |
|
| 103 | + Server::get(IUserManager::class), |
|
| 104 | + $this->expiration |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + $this->invokePrivate($command, 'execute', [$inputInterface, $outputInterface]); |
|
| 108 | + |
|
| 109 | + $trashFiles = Helper::getTrashFiles('/', $userId); |
|
| 110 | + $this->assertEquals($shouldExpire ? 0 : 1, count($trashFiles)); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public static function retentionObligationProvider(): array { |
|
| 114 | + $hour = 3600; // 60 * 60 |
|
| 115 | + |
|
| 116 | + $oneDay = 24 * $hour; |
|
| 117 | + $fiveDays = 24 * 5 * $hour; |
|
| 118 | + $tenDays = 24 * 10 * $hour; |
|
| 119 | + $elevenDays = 24 * 11 * $hour; |
|
| 120 | + |
|
| 121 | + return [ |
|
| 122 | + ['disabled', '20 B', 0, 1, false], |
|
| 123 | + |
|
| 124 | + ['auto', '20 B', 0, 5, false], |
|
| 125 | + ['auto', '20 B', 0, 21, true], |
|
| 126 | + |
|
| 127 | + ['0, auto', '20 B', 0, 21, true], |
|
| 128 | + ['0, auto', '20 B', $oneDay, 5, false], |
|
| 129 | + ['0, auto', '20 B', $oneDay, 19, true], |
|
| 130 | + ['0, auto', '20 B', 0, 19, true], |
|
| 131 | + |
|
| 132 | + ['auto, 0', '20 B', $oneDay, 19, true], |
|
| 133 | + ['auto, 0', '20 B', $oneDay, 21, true], |
|
| 134 | + ['auto, 0', '20 B', 0, 5, false], |
|
| 135 | + ['auto, 0', '20 B', 0, 19, true], |
|
| 136 | + |
|
| 137 | + ['1, auto', '20 B', 0, 5, false], |
|
| 138 | + ['1, auto', '20 B', $fiveDays, 5, false], |
|
| 139 | + ['1, auto', '20 B', $fiveDays, 21, true], |
|
| 140 | + |
|
| 141 | + ['auto, 1', '20 B', 0, 21, true], |
|
| 142 | + ['auto, 1', '20 B', 0, 5, false], |
|
| 143 | + ['auto, 1', '20 B', $fiveDays, 5, true], |
|
| 144 | + ['auto, 1', '20 B', $oneDay, 5, false], |
|
| 145 | + |
|
| 146 | + ['2, 10', '20 B', $fiveDays, 5, false], |
|
| 147 | + ['2, 10', '20 B', $fiveDays, 20, true], |
|
| 148 | + ['2, 10', '20 B', $elevenDays, 5, true], |
|
| 149 | + |
|
| 150 | + ['10, 2', '20 B', $fiveDays, 5, false], |
|
| 151 | + ['10, 2', '20 B', $fiveDays, 21, false], |
|
| 152 | + ['10, 2', '20 B', $tenDays, 5, false], |
|
| 153 | + ['10, 2', '20 B', $elevenDays, 5, true] |
|
| 154 | + ]; |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -35,89 +35,89 @@ |
||
| 35 | 35 | use Psr\Log\LoggerInterface; |
| 36 | 36 | |
| 37 | 37 | class EmbeddedCalDavServer { |
| 38 | - private readonly \OCA\DAV\Connector\Sabre\Server $server; |
|
| 39 | - |
|
| 40 | - public function __construct(bool $public = true) { |
|
| 41 | - $baseUri = \OC::$WEBROOT . '/remote.php/dav/'; |
|
| 42 | - $logger = Server::get(LoggerInterface::class); |
|
| 43 | - $dispatcher = Server::get(IEventDispatcher::class); |
|
| 44 | - $appConfig = Server::get(IAppConfig::class); |
|
| 45 | - $l10nFactory = Server::get(IL10NFactory::class); |
|
| 46 | - $l10n = $l10nFactory->get('dav'); |
|
| 47 | - |
|
| 48 | - $root = new RootCollection(); |
|
| 49 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 50 | - |
|
| 51 | - // Add maintenance plugin |
|
| 52 | - $this->server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), $l10n)); |
|
| 53 | - |
|
| 54 | - // Set URL explicitly due to reverse-proxy situations |
|
| 55 | - $this->server->httpRequest->setUrl($baseUri); |
|
| 56 | - $this->server->setBaseUri($baseUri); |
|
| 57 | - |
|
| 58 | - $this->server->addPlugin(new BlockLegacyClientPlugin( |
|
| 59 | - Server::get(IConfig::class), |
|
| 60 | - Server::get(ThemingDefaults::class), |
|
| 61 | - )); |
|
| 62 | - $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
| 63 | - |
|
| 64 | - // allow custom principal uri option |
|
| 65 | - if ($public) { |
|
| 66 | - $this->server->addPlugin(new PublicPrincipalPlugin()); |
|
| 67 | - } else { |
|
| 68 | - $this->server->addPlugin(new CustomPrincipalPlugin()); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // allow setup of additional auth backends |
|
| 72 | - $event = new SabrePluginAuthInitEvent($this->server); |
|
| 73 | - $dispatcher->dispatchTyped($event); |
|
| 74 | - |
|
| 75 | - $this->server->addPlugin(new ExceptionLoggerPlugin('webdav', $logger)); |
|
| 76 | - $this->server->addPlugin(new LockPlugin()); |
|
| 77 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 78 | - |
|
| 79 | - // acl |
|
| 80 | - $acl = new DavAclPlugin(); |
|
| 81 | - $acl->principalCollectionSet = [ |
|
| 82 | - 'principals/users', 'principals/groups' |
|
| 83 | - ]; |
|
| 84 | - $this->server->addPlugin($acl); |
|
| 85 | - |
|
| 86 | - // calendar plugins |
|
| 87 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 88 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 89 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(Server::get(IConfig::class), Server::get(LoggerInterface::class), Server::get(DefaultCalendarValidator::class))); |
|
| 90 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 91 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 92 | - //$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 93 | - $this->server->addPlugin(new PublishPlugin( |
|
| 94 | - Server::get(IConfig::class), |
|
| 95 | - Server::get(IURLGenerator::class) |
|
| 96 | - )); |
|
| 97 | - if ($appConfig->getValueString('dav', 'sendInvitations', 'yes') === 'yes') { |
|
| 98 | - $this->server->addPlugin(Server::get(IMipPlugin::class)); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // collection preload plugin |
|
| 102 | - $this->server->addPlugin(new PropFindPreloadNotifyPlugin()); |
|
| 103 | - |
|
| 104 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 105 | - $this->server->on('beforeMethod:*', function () use ($root): void { |
|
| 106 | - // register plugins from apps |
|
| 107 | - $pluginManager = new PluginManager( |
|
| 108 | - \OC::$server, |
|
| 109 | - Server::get(IAppManager::class) |
|
| 110 | - ); |
|
| 111 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 112 | - $this->server->addPlugin($appPlugin); |
|
| 113 | - } |
|
| 114 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 115 | - $root->addChild($appCollection); |
|
| 116 | - } |
|
| 117 | - }); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - public function getServer(): \OCA\DAV\Connector\Sabre\Server { |
|
| 121 | - return $this->server; |
|
| 122 | - } |
|
| 38 | + private readonly \OCA\DAV\Connector\Sabre\Server $server; |
|
| 39 | + |
|
| 40 | + public function __construct(bool $public = true) { |
|
| 41 | + $baseUri = \OC::$WEBROOT . '/remote.php/dav/'; |
|
| 42 | + $logger = Server::get(LoggerInterface::class); |
|
| 43 | + $dispatcher = Server::get(IEventDispatcher::class); |
|
| 44 | + $appConfig = Server::get(IAppConfig::class); |
|
| 45 | + $l10nFactory = Server::get(IL10NFactory::class); |
|
| 46 | + $l10n = $l10nFactory->get('dav'); |
|
| 47 | + |
|
| 48 | + $root = new RootCollection(); |
|
| 49 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 50 | + |
|
| 51 | + // Add maintenance plugin |
|
| 52 | + $this->server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), $l10n)); |
|
| 53 | + |
|
| 54 | + // Set URL explicitly due to reverse-proxy situations |
|
| 55 | + $this->server->httpRequest->setUrl($baseUri); |
|
| 56 | + $this->server->setBaseUri($baseUri); |
|
| 57 | + |
|
| 58 | + $this->server->addPlugin(new BlockLegacyClientPlugin( |
|
| 59 | + Server::get(IConfig::class), |
|
| 60 | + Server::get(ThemingDefaults::class), |
|
| 61 | + )); |
|
| 62 | + $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
| 63 | + |
|
| 64 | + // allow custom principal uri option |
|
| 65 | + if ($public) { |
|
| 66 | + $this->server->addPlugin(new PublicPrincipalPlugin()); |
|
| 67 | + } else { |
|
| 68 | + $this->server->addPlugin(new CustomPrincipalPlugin()); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // allow setup of additional auth backends |
|
| 72 | + $event = new SabrePluginAuthInitEvent($this->server); |
|
| 73 | + $dispatcher->dispatchTyped($event); |
|
| 74 | + |
|
| 75 | + $this->server->addPlugin(new ExceptionLoggerPlugin('webdav', $logger)); |
|
| 76 | + $this->server->addPlugin(new LockPlugin()); |
|
| 77 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 78 | + |
|
| 79 | + // acl |
|
| 80 | + $acl = new DavAclPlugin(); |
|
| 81 | + $acl->principalCollectionSet = [ |
|
| 82 | + 'principals/users', 'principals/groups' |
|
| 83 | + ]; |
|
| 84 | + $this->server->addPlugin($acl); |
|
| 85 | + |
|
| 86 | + // calendar plugins |
|
| 87 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 88 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 89 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(Server::get(IConfig::class), Server::get(LoggerInterface::class), Server::get(DefaultCalendarValidator::class))); |
|
| 90 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 91 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 92 | + //$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 93 | + $this->server->addPlugin(new PublishPlugin( |
|
| 94 | + Server::get(IConfig::class), |
|
| 95 | + Server::get(IURLGenerator::class) |
|
| 96 | + )); |
|
| 97 | + if ($appConfig->getValueString('dav', 'sendInvitations', 'yes') === 'yes') { |
|
| 98 | + $this->server->addPlugin(Server::get(IMipPlugin::class)); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // collection preload plugin |
|
| 102 | + $this->server->addPlugin(new PropFindPreloadNotifyPlugin()); |
|
| 103 | + |
|
| 104 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 105 | + $this->server->on('beforeMethod:*', function () use ($root): void { |
|
| 106 | + // register plugins from apps |
|
| 107 | + $pluginManager = new PluginManager( |
|
| 108 | + \OC::$server, |
|
| 109 | + Server::get(IAppManager::class) |
|
| 110 | + ); |
|
| 111 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 112 | + $this->server->addPlugin($appPlugin); |
|
| 113 | + } |
|
| 114 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 115 | + $root->addChild($appCollection); |
|
| 116 | + } |
|
| 117 | + }); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + public function getServer(): \OCA\DAV\Connector\Sabre\Server { |
|
| 121 | + return $this->server; |
|
| 122 | + } |
|
| 123 | 123 | } |
@@ -33,270 +33,270 @@ |
||
| 33 | 33 | use function Sabre\Uri\split as uriSplit; |
| 34 | 34 | |
| 35 | 35 | class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIsWritable, ICalendarIsShared, ICalendarExport, ICalendarIsEnabled { |
| 36 | - public function __construct( |
|
| 37 | - private Calendar $calendar, |
|
| 38 | - /** @var array<string, mixed> */ |
|
| 39 | - private array $calendarInfo, |
|
| 40 | - private CalDavBackend $backend, |
|
| 41 | - ) { |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @return string defining the technical unique key |
|
| 46 | - * @since 13.0.0 |
|
| 47 | - */ |
|
| 48 | - public function getKey(): string { |
|
| 49 | - return (string)$this->calendarInfo['id']; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * {@inheritDoc} |
|
| 54 | - */ |
|
| 55 | - public function getUri(): string { |
|
| 56 | - return $this->calendarInfo['uri']; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @return string the principal URI of the calendar owner |
|
| 61 | - * @since 32.0.0 |
|
| 62 | - */ |
|
| 63 | - public function getPrincipalUri(): string { |
|
| 64 | - return $this->calendarInfo['principaluri']; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 69 | - * @since 13.0.0 |
|
| 70 | - */ |
|
| 71 | - public function getDisplayName(): ?string { |
|
| 72 | - return $this->calendarInfo['{DAV:}displayname']; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Calendar color |
|
| 77 | - * @since 13.0.0 |
|
| 78 | - */ |
|
| 79 | - public function getDisplayColor(): ?string { |
|
| 80 | - return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color']; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function getSchedulingTransparency(): ?ScheduleCalendarTransp { |
|
| 84 | - return $this->calendarInfo['{' . \OCA\DAV\CalDAV\Schedule\Plugin::NS_CALDAV . '}schedule-calendar-transp']; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function getSchedulingTimezone(): ?VTimeZone { |
|
| 88 | - $tzProp = '{' . \OCA\DAV\CalDAV\Schedule\Plugin::NS_CALDAV . '}calendar-timezone'; |
|
| 89 | - if (!isset($this->calendarInfo[$tzProp])) { |
|
| 90 | - return null; |
|
| 91 | - } |
|
| 92 | - // This property contains a VCALENDAR with a single VTIMEZONE |
|
| 93 | - /** @var string $timezoneProp */ |
|
| 94 | - $timezoneProp = $this->calendarInfo[$tzProp]; |
|
| 95 | - /** @var VCalendar $vobj */ |
|
| 96 | - $vobj = Reader::read($timezoneProp); |
|
| 97 | - $components = $vobj->getComponents(); |
|
| 98 | - if (empty($components)) { |
|
| 99 | - return null; |
|
| 100 | - } |
|
| 101 | - /** @var VTimeZone $vtimezone */ |
|
| 102 | - $vtimezone = $components[0]; |
|
| 103 | - return $vtimezone; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array { |
|
| 107 | - return $this->backend->search($this->calendarInfo, $pattern, |
|
| 108 | - $searchProperties, $options, $limit, $offset); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @return int build up using \OCP\Constants |
|
| 113 | - * @since 13.0.0 |
|
| 114 | - */ |
|
| 115 | - public function getPermissions(): int { |
|
| 116 | - $permissions = $this->calendar->getACL(); |
|
| 117 | - $result = 0; |
|
| 118 | - foreach ($permissions as $permission) { |
|
| 119 | - if ($this->calendarInfo['principaluri'] !== $permission['principal']) { |
|
| 120 | - continue; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - switch ($permission['privilege']) { |
|
| 124 | - case '{DAV:}read': |
|
| 125 | - $result |= Constants::PERMISSION_READ; |
|
| 126 | - break; |
|
| 127 | - case '{DAV:}write': |
|
| 128 | - $result |= Constants::PERMISSION_CREATE; |
|
| 129 | - $result |= Constants::PERMISSION_UPDATE; |
|
| 130 | - break; |
|
| 131 | - case '{DAV:}all': |
|
| 132 | - $result |= Constants::PERMISSION_ALL; |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $result; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @since 32.0.0 |
|
| 142 | - */ |
|
| 143 | - public function isEnabled(): bool { |
|
| 144 | - return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @since 31.0.0 |
|
| 149 | - */ |
|
| 150 | - public function isWritable(): bool { |
|
| 151 | - return $this->calendar->canWrite(); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @since 26.0.0 |
|
| 156 | - */ |
|
| 157 | - public function isDeleted(): bool { |
|
| 158 | - return $this->calendar->isDeleted(); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @since 31.0.0 |
|
| 163 | - */ |
|
| 164 | - public function isShared(): bool { |
|
| 165 | - return $this->calendar->isShared(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @throws CalendarException |
|
| 170 | - */ |
|
| 171 | - private function createFromStringInServer( |
|
| 172 | - string $name, |
|
| 173 | - string $calendarData, |
|
| 174 | - Server $server, |
|
| 175 | - ): void { |
|
| 176 | - /** @var CustomPrincipalPlugin $plugin */ |
|
| 177 | - $plugin = $server->getPlugin('auth'); |
|
| 178 | - // we're working around the previous implementation |
|
| 179 | - // that only allowed the public system principal to be used |
|
| 180 | - // so set the custom principal here |
|
| 181 | - $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI()); |
|
| 182 | - |
|
| 183 | - if (empty($this->calendarInfo['uri'])) { |
|
| 184 | - throw new CalendarException('Could not write to calendar as URI parameter is missing'); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - // Build full calendar path |
|
| 188 | - [, $user] = uriSplit($this->calendar->getPrincipalURI()); |
|
| 189 | - $fullCalendarFilename = sprintf('calendars/%s/%s/%s', $user, $this->calendarInfo['uri'], $name); |
|
| 190 | - |
|
| 191 | - // Force calendar change URI |
|
| 192 | - /** @var Schedule\Plugin $schedulingPlugin */ |
|
| 193 | - $schedulingPlugin = $server->getPlugin('caldav-schedule'); |
|
| 194 | - $schedulingPlugin->setPathOfCalendarObjectChange($fullCalendarFilename); |
|
| 195 | - |
|
| 196 | - $stream = fopen('php://memory', 'rb+'); |
|
| 197 | - fwrite($stream, $calendarData); |
|
| 198 | - rewind($stream); |
|
| 199 | - try { |
|
| 200 | - $server->createFile($fullCalendarFilename, $stream); |
|
| 201 | - } catch (Conflict $e) { |
|
| 202 | - throw new CalendarException('Could not create new calendar event: ' . $e->getMessage(), 0, $e); |
|
| 203 | - } finally { |
|
| 204 | - fclose($stream); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - public function createFromString(string $name, string $calendarData): void { |
|
| 209 | - $server = new EmbeddedCalDavServer(false); |
|
| 210 | - $this->createFromStringInServer($name, $calendarData, $server->getServer()); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - public function createFromStringMinimal(string $name, string $calendarData): void { |
|
| 214 | - $server = new InvitationResponseServer(false); |
|
| 215 | - $this->createFromStringInServer($name, $calendarData, $server->getServer()); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * @throws CalendarException |
|
| 220 | - */ |
|
| 221 | - public function handleIMipMessage(string $name, string $calendarData): void { |
|
| 222 | - $server = $this->getInvitationResponseServer(); |
|
| 223 | - |
|
| 224 | - /** @var CustomPrincipalPlugin $plugin */ |
|
| 225 | - $plugin = $server->getServer()->getPlugin('auth'); |
|
| 226 | - // we're working around the previous implementation |
|
| 227 | - // that only allowed the public system principal to be used |
|
| 228 | - // so set the custom principal here |
|
| 229 | - $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI()); |
|
| 230 | - |
|
| 231 | - if (empty($this->calendarInfo['uri'])) { |
|
| 232 | - throw new CalendarException('Could not write to calendar as URI parameter is missing'); |
|
| 233 | - } |
|
| 234 | - // Force calendar change URI |
|
| 235 | - /** @var Schedule\Plugin $schedulingPlugin */ |
|
| 236 | - $schedulingPlugin = $server->getServer()->getPlugin('caldav-schedule'); |
|
| 237 | - // Let sabre handle the rest |
|
| 238 | - $iTipMessage = new Message(); |
|
| 239 | - /** @var VCalendar $vObject */ |
|
| 240 | - $vObject = Reader::read($calendarData); |
|
| 241 | - /** @var VEvent $vEvent */ |
|
| 242 | - $vEvent = $vObject->{'VEVENT'}; |
|
| 243 | - |
|
| 244 | - if ($vObject->{'METHOD'} === null) { |
|
| 245 | - throw new CalendarException('No Method provided for scheduling data. Could not process message'); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - if (!isset($vEvent->{'ORGANIZER'}) || !isset($vEvent->{'ATTENDEE'})) { |
|
| 249 | - throw new CalendarException('Could not process scheduling data, neccessary data missing from ICAL'); |
|
| 250 | - } |
|
| 251 | - $organizer = $vEvent->{'ORGANIZER'}->getValue(); |
|
| 252 | - $attendee = $vEvent->{'ATTENDEE'}->getValue(); |
|
| 253 | - |
|
| 254 | - $iTipMessage->method = $vObject->{'METHOD'}->getValue(); |
|
| 255 | - if ($iTipMessage->method === 'REQUEST') { |
|
| 256 | - $iTipMessage->sender = $organizer; |
|
| 257 | - $iTipMessage->recipient = $attendee; |
|
| 258 | - } elseif ($iTipMessage->method === 'REPLY') { |
|
| 259 | - if ($server->isExternalAttendee($vEvent->{'ATTENDEE'}->getValue())) { |
|
| 260 | - $iTipMessage->recipient = $organizer; |
|
| 261 | - } else { |
|
| 262 | - $iTipMessage->recipient = $attendee; |
|
| 263 | - } |
|
| 264 | - $iTipMessage->sender = $attendee; |
|
| 265 | - } elseif ($iTipMessage->method === 'CANCEL') { |
|
| 266 | - $iTipMessage->recipient = $attendee; |
|
| 267 | - $iTipMessage->sender = $organizer; |
|
| 268 | - } |
|
| 269 | - $iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : ''; |
|
| 270 | - $iTipMessage->component = 'VEVENT'; |
|
| 271 | - $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0; |
|
| 272 | - $iTipMessage->message = $vObject; |
|
| 273 | - $server->server->emit('schedule', [$iTipMessage]); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - public function getInvitationResponseServer(): InvitationResponseServer { |
|
| 277 | - return new InvitationResponseServer(false); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Export objects |
|
| 282 | - * |
|
| 283 | - * @since 32.0.0 |
|
| 284 | - * |
|
| 285 | - * @return Generator<mixed, \Sabre\VObject\Component\VCalendar, mixed, mixed> |
|
| 286 | - */ |
|
| 287 | - public function export(?CalendarExportOptions $options = null): Generator { |
|
| 288 | - foreach ( |
|
| 289 | - $this->backend->exportCalendar( |
|
| 290 | - $this->calendarInfo['id'], |
|
| 291 | - $this->backend::CALENDAR_TYPE_CALENDAR, |
|
| 292 | - $options |
|
| 293 | - ) as $event |
|
| 294 | - ) { |
|
| 295 | - $vObject = Reader::read($event['calendardata']); |
|
| 296 | - if ($vObject instanceof VCalendar) { |
|
| 297 | - yield $vObject; |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - } |
|
| 36 | + public function __construct( |
|
| 37 | + private Calendar $calendar, |
|
| 38 | + /** @var array<string, mixed> */ |
|
| 39 | + private array $calendarInfo, |
|
| 40 | + private CalDavBackend $backend, |
|
| 41 | + ) { |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @return string defining the technical unique key |
|
| 46 | + * @since 13.0.0 |
|
| 47 | + */ |
|
| 48 | + public function getKey(): string { |
|
| 49 | + return (string)$this->calendarInfo['id']; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * {@inheritDoc} |
|
| 54 | + */ |
|
| 55 | + public function getUri(): string { |
|
| 56 | + return $this->calendarInfo['uri']; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @return string the principal URI of the calendar owner |
|
| 61 | + * @since 32.0.0 |
|
| 62 | + */ |
|
| 63 | + public function getPrincipalUri(): string { |
|
| 64 | + return $this->calendarInfo['principaluri']; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
| 69 | + * @since 13.0.0 |
|
| 70 | + */ |
|
| 71 | + public function getDisplayName(): ?string { |
|
| 72 | + return $this->calendarInfo['{DAV:}displayname']; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Calendar color |
|
| 77 | + * @since 13.0.0 |
|
| 78 | + */ |
|
| 79 | + public function getDisplayColor(): ?string { |
|
| 80 | + return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color']; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function getSchedulingTransparency(): ?ScheduleCalendarTransp { |
|
| 84 | + return $this->calendarInfo['{' . \OCA\DAV\CalDAV\Schedule\Plugin::NS_CALDAV . '}schedule-calendar-transp']; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function getSchedulingTimezone(): ?VTimeZone { |
|
| 88 | + $tzProp = '{' . \OCA\DAV\CalDAV\Schedule\Plugin::NS_CALDAV . '}calendar-timezone'; |
|
| 89 | + if (!isset($this->calendarInfo[$tzProp])) { |
|
| 90 | + return null; |
|
| 91 | + } |
|
| 92 | + // This property contains a VCALENDAR with a single VTIMEZONE |
|
| 93 | + /** @var string $timezoneProp */ |
|
| 94 | + $timezoneProp = $this->calendarInfo[$tzProp]; |
|
| 95 | + /** @var VCalendar $vobj */ |
|
| 96 | + $vobj = Reader::read($timezoneProp); |
|
| 97 | + $components = $vobj->getComponents(); |
|
| 98 | + if (empty($components)) { |
|
| 99 | + return null; |
|
| 100 | + } |
|
| 101 | + /** @var VTimeZone $vtimezone */ |
|
| 102 | + $vtimezone = $components[0]; |
|
| 103 | + return $vtimezone; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array { |
|
| 107 | + return $this->backend->search($this->calendarInfo, $pattern, |
|
| 108 | + $searchProperties, $options, $limit, $offset); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @return int build up using \OCP\Constants |
|
| 113 | + * @since 13.0.0 |
|
| 114 | + */ |
|
| 115 | + public function getPermissions(): int { |
|
| 116 | + $permissions = $this->calendar->getACL(); |
|
| 117 | + $result = 0; |
|
| 118 | + foreach ($permissions as $permission) { |
|
| 119 | + if ($this->calendarInfo['principaluri'] !== $permission['principal']) { |
|
| 120 | + continue; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + switch ($permission['privilege']) { |
|
| 124 | + case '{DAV:}read': |
|
| 125 | + $result |= Constants::PERMISSION_READ; |
|
| 126 | + break; |
|
| 127 | + case '{DAV:}write': |
|
| 128 | + $result |= Constants::PERMISSION_CREATE; |
|
| 129 | + $result |= Constants::PERMISSION_UPDATE; |
|
| 130 | + break; |
|
| 131 | + case '{DAV:}all': |
|
| 132 | + $result |= Constants::PERMISSION_ALL; |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $result; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @since 32.0.0 |
|
| 142 | + */ |
|
| 143 | + public function isEnabled(): bool { |
|
| 144 | + return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @since 31.0.0 |
|
| 149 | + */ |
|
| 150 | + public function isWritable(): bool { |
|
| 151 | + return $this->calendar->canWrite(); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @since 26.0.0 |
|
| 156 | + */ |
|
| 157 | + public function isDeleted(): bool { |
|
| 158 | + return $this->calendar->isDeleted(); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @since 31.0.0 |
|
| 163 | + */ |
|
| 164 | + public function isShared(): bool { |
|
| 165 | + return $this->calendar->isShared(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @throws CalendarException |
|
| 170 | + */ |
|
| 171 | + private function createFromStringInServer( |
|
| 172 | + string $name, |
|
| 173 | + string $calendarData, |
|
| 174 | + Server $server, |
|
| 175 | + ): void { |
|
| 176 | + /** @var CustomPrincipalPlugin $plugin */ |
|
| 177 | + $plugin = $server->getPlugin('auth'); |
|
| 178 | + // we're working around the previous implementation |
|
| 179 | + // that only allowed the public system principal to be used |
|
| 180 | + // so set the custom principal here |
|
| 181 | + $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI()); |
|
| 182 | + |
|
| 183 | + if (empty($this->calendarInfo['uri'])) { |
|
| 184 | + throw new CalendarException('Could not write to calendar as URI parameter is missing'); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + // Build full calendar path |
|
| 188 | + [, $user] = uriSplit($this->calendar->getPrincipalURI()); |
|
| 189 | + $fullCalendarFilename = sprintf('calendars/%s/%s/%s', $user, $this->calendarInfo['uri'], $name); |
|
| 190 | + |
|
| 191 | + // Force calendar change URI |
|
| 192 | + /** @var Schedule\Plugin $schedulingPlugin */ |
|
| 193 | + $schedulingPlugin = $server->getPlugin('caldav-schedule'); |
|
| 194 | + $schedulingPlugin->setPathOfCalendarObjectChange($fullCalendarFilename); |
|
| 195 | + |
|
| 196 | + $stream = fopen('php://memory', 'rb+'); |
|
| 197 | + fwrite($stream, $calendarData); |
|
| 198 | + rewind($stream); |
|
| 199 | + try { |
|
| 200 | + $server->createFile($fullCalendarFilename, $stream); |
|
| 201 | + } catch (Conflict $e) { |
|
| 202 | + throw new CalendarException('Could not create new calendar event: ' . $e->getMessage(), 0, $e); |
|
| 203 | + } finally { |
|
| 204 | + fclose($stream); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + public function createFromString(string $name, string $calendarData): void { |
|
| 209 | + $server = new EmbeddedCalDavServer(false); |
|
| 210 | + $this->createFromStringInServer($name, $calendarData, $server->getServer()); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + public function createFromStringMinimal(string $name, string $calendarData): void { |
|
| 214 | + $server = new InvitationResponseServer(false); |
|
| 215 | + $this->createFromStringInServer($name, $calendarData, $server->getServer()); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * @throws CalendarException |
|
| 220 | + */ |
|
| 221 | + public function handleIMipMessage(string $name, string $calendarData): void { |
|
| 222 | + $server = $this->getInvitationResponseServer(); |
|
| 223 | + |
|
| 224 | + /** @var CustomPrincipalPlugin $plugin */ |
|
| 225 | + $plugin = $server->getServer()->getPlugin('auth'); |
|
| 226 | + // we're working around the previous implementation |
|
| 227 | + // that only allowed the public system principal to be used |
|
| 228 | + // so set the custom principal here |
|
| 229 | + $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI()); |
|
| 230 | + |
|
| 231 | + if (empty($this->calendarInfo['uri'])) { |
|
| 232 | + throw new CalendarException('Could not write to calendar as URI parameter is missing'); |
|
| 233 | + } |
|
| 234 | + // Force calendar change URI |
|
| 235 | + /** @var Schedule\Plugin $schedulingPlugin */ |
|
| 236 | + $schedulingPlugin = $server->getServer()->getPlugin('caldav-schedule'); |
|
| 237 | + // Let sabre handle the rest |
|
| 238 | + $iTipMessage = new Message(); |
|
| 239 | + /** @var VCalendar $vObject */ |
|
| 240 | + $vObject = Reader::read($calendarData); |
|
| 241 | + /** @var VEvent $vEvent */ |
|
| 242 | + $vEvent = $vObject->{'VEVENT'}; |
|
| 243 | + |
|
| 244 | + if ($vObject->{'METHOD'} === null) { |
|
| 245 | + throw new CalendarException('No Method provided for scheduling data. Could not process message'); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + if (!isset($vEvent->{'ORGANIZER'}) || !isset($vEvent->{'ATTENDEE'})) { |
|
| 249 | + throw new CalendarException('Could not process scheduling data, neccessary data missing from ICAL'); |
|
| 250 | + } |
|
| 251 | + $organizer = $vEvent->{'ORGANIZER'}->getValue(); |
|
| 252 | + $attendee = $vEvent->{'ATTENDEE'}->getValue(); |
|
| 253 | + |
|
| 254 | + $iTipMessage->method = $vObject->{'METHOD'}->getValue(); |
|
| 255 | + if ($iTipMessage->method === 'REQUEST') { |
|
| 256 | + $iTipMessage->sender = $organizer; |
|
| 257 | + $iTipMessage->recipient = $attendee; |
|
| 258 | + } elseif ($iTipMessage->method === 'REPLY') { |
|
| 259 | + if ($server->isExternalAttendee($vEvent->{'ATTENDEE'}->getValue())) { |
|
| 260 | + $iTipMessage->recipient = $organizer; |
|
| 261 | + } else { |
|
| 262 | + $iTipMessage->recipient = $attendee; |
|
| 263 | + } |
|
| 264 | + $iTipMessage->sender = $attendee; |
|
| 265 | + } elseif ($iTipMessage->method === 'CANCEL') { |
|
| 266 | + $iTipMessage->recipient = $attendee; |
|
| 267 | + $iTipMessage->sender = $organizer; |
|
| 268 | + } |
|
| 269 | + $iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : ''; |
|
| 270 | + $iTipMessage->component = 'VEVENT'; |
|
| 271 | + $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0; |
|
| 272 | + $iTipMessage->message = $vObject; |
|
| 273 | + $server->server->emit('schedule', [$iTipMessage]); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + public function getInvitationResponseServer(): InvitationResponseServer { |
|
| 277 | + return new InvitationResponseServer(false); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Export objects |
|
| 282 | + * |
|
| 283 | + * @since 32.0.0 |
|
| 284 | + * |
|
| 285 | + * @return Generator<mixed, \Sabre\VObject\Component\VCalendar, mixed, mixed> |
|
| 286 | + */ |
|
| 287 | + public function export(?CalendarExportOptions $options = null): Generator { |
|
| 288 | + foreach ( |
|
| 289 | + $this->backend->exportCalendar( |
|
| 290 | + $this->calendarInfo['id'], |
|
| 291 | + $this->backend::CALENDAR_TYPE_CALENDAR, |
|
| 292 | + $options |
|
| 293 | + ) as $event |
|
| 294 | + ) { |
|
| 295 | + $vObject = Reader::read($event['calendardata']); |
|
| 296 | + if ($vObject instanceof VCalendar) { |
|
| 297 | + yield $vObject; |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | 302 | } |
@@ -17,269 +17,269 @@ |
||
| 17 | 17 | use Test\TestCase; |
| 18 | 18 | |
| 19 | 19 | class PrimaryObjectStoreConfigTest extends TestCase { |
| 20 | - private array $systemConfig = []; |
|
| 21 | - private array $userConfig = []; |
|
| 22 | - private IConfig&MockObject $config; |
|
| 23 | - private IAppManager&MockObject $appManager; |
|
| 24 | - private PrimaryObjectStoreConfig $objectStoreConfig; |
|
| 25 | - |
|
| 26 | - protected function setUp(): void { |
|
| 27 | - parent::setUp(); |
|
| 28 | - |
|
| 29 | - $this->systemConfig = []; |
|
| 30 | - $this->config = $this->createMock(IConfig::class); |
|
| 31 | - $this->appManager = $this->createMock(IAppManager::class); |
|
| 32 | - $this->config->method('getSystemValue') |
|
| 33 | - ->willReturnCallback(function ($key, $default = '') { |
|
| 34 | - if (isset($this->systemConfig[$key])) { |
|
| 35 | - return $this->systemConfig[$key]; |
|
| 36 | - } else { |
|
| 37 | - return $default; |
|
| 38 | - } |
|
| 39 | - }); |
|
| 40 | - $this->config->method('getUserValue') |
|
| 41 | - ->willReturnCallback(function ($userId, $appName, $key, $default = '') { |
|
| 42 | - if (isset($this->userConfig[$userId][$appName][$key])) { |
|
| 43 | - return $this->userConfig[$userId][$appName][$key]; |
|
| 44 | - } else { |
|
| 45 | - return $default; |
|
| 46 | - } |
|
| 47 | - }); |
|
| 48 | - $this->config->method('setUserValue') |
|
| 49 | - ->willReturnCallback(function ($userId, $appName, $key, $value): void { |
|
| 50 | - $this->userConfig[$userId][$appName][$key] = $value; |
|
| 51 | - }); |
|
| 52 | - |
|
| 53 | - $this->objectStoreConfig = new PrimaryObjectStoreConfig($this->config, $this->appManager); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - private function getUser(string $uid): IUser { |
|
| 57 | - $user = $this->createMock(IUser::class); |
|
| 58 | - $user->method('getUID') |
|
| 59 | - ->willReturn($uid); |
|
| 60 | - return $user; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - private function setConfig(string $key, $value) { |
|
| 64 | - $this->systemConfig[$key] = $value; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - public function testNewUserGetsDefault() { |
|
| 68 | - $this->setConfig('objectstore', [ |
|
| 69 | - 'default' => 'server1', |
|
| 70 | - 'server1' => [ |
|
| 71 | - 'class' => StorageObjectStore::class, |
|
| 72 | - 'arguments' => [ |
|
| 73 | - 'host' => 'server1', |
|
| 74 | - ], |
|
| 75 | - ], |
|
| 76 | - ]); |
|
| 77 | - |
|
| 78 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 79 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 80 | - |
|
| 81 | - $this->assertEquals('server1', $this->config->getUserValue('test', 'homeobjectstore', 'objectstore', null)); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function testExistingUserKeepsStorage() { |
|
| 85 | - // setup user with `server1` as storage |
|
| 86 | - $this->testNewUserGetsDefault(); |
|
| 87 | - |
|
| 88 | - $this->setConfig('objectstore', [ |
|
| 89 | - 'default' => 'server2', |
|
| 90 | - 'server1' => [ |
|
| 91 | - 'class' => StorageObjectStore::class, |
|
| 92 | - 'arguments' => [ |
|
| 93 | - 'host' => 'server1', |
|
| 94 | - ], |
|
| 95 | - ], |
|
| 96 | - 'server2' => [ |
|
| 97 | - 'class' => StorageObjectStore::class, |
|
| 98 | - 'arguments' => [ |
|
| 99 | - 'host' => 'server2', |
|
| 100 | - ], |
|
| 101 | - ], |
|
| 102 | - ]); |
|
| 103 | - |
|
| 104 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 105 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 106 | - |
|
| 107 | - $this->assertEquals('server1', $this->config->getUserValue('test', 'homeobjectstore', 'objectstore', null)); |
|
| 108 | - |
|
| 109 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('other-user')); |
|
| 110 | - $this->assertEquals('server2', $result['arguments']['host']); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function testNestedAliases() { |
|
| 114 | - $this->setConfig('objectstore', [ |
|
| 115 | - 'default' => 'a1', |
|
| 116 | - 'a1' => 'a2', |
|
| 117 | - 'a2' => 'server1', |
|
| 118 | - 'server1' => [ |
|
| 119 | - 'class' => StorageObjectStore::class, |
|
| 120 | - 'arguments' => [ |
|
| 121 | - 'host' => 'server1', |
|
| 122 | - ], |
|
| 123 | - ], |
|
| 124 | - ]); |
|
| 125 | - $this->assertEquals('server1', $this->objectStoreConfig->resolveAlias('default')); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function testMultibucketChangedConfig() { |
|
| 129 | - $this->setConfig('objectstore', [ |
|
| 130 | - 'default' => 'server1', |
|
| 131 | - 'server1' => [ |
|
| 132 | - 'class' => StorageObjectStore::class, |
|
| 133 | - 'arguments' => [ |
|
| 134 | - 'host' => 'server1', |
|
| 135 | - 'multibucket' => true, |
|
| 136 | - 'num_buckets' => 8, |
|
| 137 | - 'bucket' => 'bucket-' |
|
| 138 | - ], |
|
| 139 | - ], |
|
| 140 | - ]); |
|
| 141 | - |
|
| 142 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 143 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 144 | - $this->assertEquals('bucket-7', $result['arguments']['bucket']); |
|
| 145 | - |
|
| 146 | - $this->setConfig('objectstore', [ |
|
| 147 | - 'default' => 'server1', |
|
| 148 | - 'server1' => [ |
|
| 149 | - 'class' => StorageObjectStore::class, |
|
| 150 | - 'arguments' => [ |
|
| 151 | - 'host' => 'server1', |
|
| 152 | - 'multibucket' => true, |
|
| 153 | - 'num_buckets' => 64, |
|
| 154 | - 'bucket' => 'bucket-' |
|
| 155 | - ], |
|
| 156 | - ], |
|
| 157 | - ]); |
|
| 158 | - |
|
| 159 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 160 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 161 | - $this->assertEquals('bucket-7', $result['arguments']['bucket']); |
|
| 162 | - |
|
| 163 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test-foo')); |
|
| 164 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 165 | - $this->assertEquals('bucket-40', $result['arguments']['bucket']); |
|
| 166 | - |
|
| 167 | - $this->setConfig('objectstore', [ |
|
| 168 | - 'default' => 'server2', |
|
| 169 | - 'server1' => [ |
|
| 170 | - 'class' => StorageObjectStore::class, |
|
| 171 | - 'arguments' => [ |
|
| 172 | - 'host' => 'server1', |
|
| 173 | - 'multibucket' => true, |
|
| 174 | - 'num_buckets' => 64, |
|
| 175 | - 'bucket' => 'bucket-' |
|
| 176 | - ], |
|
| 177 | - ], |
|
| 178 | - 'server2' => [ |
|
| 179 | - 'class' => StorageObjectStore::class, |
|
| 180 | - 'arguments' => [ |
|
| 181 | - 'host' => 'server2', |
|
| 182 | - 'multibucket' => true, |
|
| 183 | - 'num_buckets' => 16, |
|
| 184 | - 'bucket' => 'bucket-' |
|
| 185 | - ], |
|
| 186 | - ], |
|
| 187 | - ]); |
|
| 188 | - |
|
| 189 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 190 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 191 | - $this->assertEquals('bucket-7', $result['arguments']['bucket']); |
|
| 192 | - |
|
| 193 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test-bar')); |
|
| 194 | - $this->assertEquals('server2', $result['arguments']['host']); |
|
| 195 | - $this->assertEquals('bucket-4', $result['arguments']['bucket']); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - public function testMultibucketOldConfig() { |
|
| 199 | - $this->setConfig('objectstore_multibucket', [ |
|
| 200 | - 'class' => StorageObjectStore::class, |
|
| 201 | - 'arguments' => [ |
|
| 202 | - 'host' => 'server1', |
|
| 203 | - 'multibucket' => true, |
|
| 204 | - 'num_buckets' => 8, |
|
| 205 | - 'bucket' => 'bucket-' |
|
| 206 | - ], |
|
| 207 | - ]); |
|
| 208 | - $configs = $this->objectStoreConfig->getObjectStoreConfigs(); |
|
| 209 | - $this->assertEquals([ |
|
| 210 | - 'default' => 'server1', |
|
| 211 | - 'root' => 'server1', |
|
| 212 | - 'server1' => [ |
|
| 213 | - 'class' => StorageObjectStore::class, |
|
| 214 | - 'arguments' => [ |
|
| 215 | - 'host' => 'server1', |
|
| 216 | - 'multibucket' => true, |
|
| 217 | - 'num_buckets' => 8, |
|
| 218 | - 'bucket' => 'bucket-' |
|
| 219 | - ], |
|
| 220 | - ], |
|
| 221 | - ], $configs); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - public function testSingleObjectStore() { |
|
| 225 | - $this->setConfig('objectstore', [ |
|
| 226 | - 'class' => StorageObjectStore::class, |
|
| 227 | - 'arguments' => [ |
|
| 228 | - 'host' => 'server1', |
|
| 229 | - ], |
|
| 230 | - ]); |
|
| 231 | - $configs = $this->objectStoreConfig->getObjectStoreConfigs(); |
|
| 232 | - $this->assertEquals([ |
|
| 233 | - 'default' => 'server1', |
|
| 234 | - 'root' => 'server1', |
|
| 235 | - 'server1' => [ |
|
| 236 | - 'class' => StorageObjectStore::class, |
|
| 237 | - 'arguments' => [ |
|
| 238 | - 'host' => 'server1', |
|
| 239 | - 'multibucket' => false, |
|
| 240 | - ], |
|
| 241 | - ], |
|
| 242 | - ], $configs); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - public function testRoot() { |
|
| 246 | - $this->setConfig('objectstore', [ |
|
| 247 | - 'default' => 'server1', |
|
| 248 | - 'server1' => [ |
|
| 249 | - 'class' => StorageObjectStore::class, |
|
| 250 | - 'arguments' => [ |
|
| 251 | - 'host' => 'server1', |
|
| 252 | - ], |
|
| 253 | - ], |
|
| 254 | - 'server2' => [ |
|
| 255 | - 'class' => StorageObjectStore::class, |
|
| 256 | - 'arguments' => [ |
|
| 257 | - 'host' => 'server2', |
|
| 258 | - ], |
|
| 259 | - ], |
|
| 260 | - ]); |
|
| 261 | - |
|
| 262 | - $result = $this->objectStoreConfig->getObjectStoreConfigForRoot(); |
|
| 263 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 264 | - |
|
| 265 | - $this->setConfig('objectstore', [ |
|
| 266 | - 'default' => 'server1', |
|
| 267 | - 'root' => 'server2', |
|
| 268 | - 'server1' => [ |
|
| 269 | - 'class' => StorageObjectStore::class, |
|
| 270 | - 'arguments' => [ |
|
| 271 | - 'host' => 'server1', |
|
| 272 | - ], |
|
| 273 | - ], |
|
| 274 | - 'server2' => [ |
|
| 275 | - 'class' => StorageObjectStore::class, |
|
| 276 | - 'arguments' => [ |
|
| 277 | - 'host' => 'server2', |
|
| 278 | - ], |
|
| 279 | - ], |
|
| 280 | - ]); |
|
| 281 | - |
|
| 282 | - $result = $this->objectStoreConfig->getObjectStoreConfigForRoot(); |
|
| 283 | - $this->assertEquals('server2', $result['arguments']['host']); |
|
| 284 | - } |
|
| 20 | + private array $systemConfig = []; |
|
| 21 | + private array $userConfig = []; |
|
| 22 | + private IConfig&MockObject $config; |
|
| 23 | + private IAppManager&MockObject $appManager; |
|
| 24 | + private PrimaryObjectStoreConfig $objectStoreConfig; |
|
| 25 | + |
|
| 26 | + protected function setUp(): void { |
|
| 27 | + parent::setUp(); |
|
| 28 | + |
|
| 29 | + $this->systemConfig = []; |
|
| 30 | + $this->config = $this->createMock(IConfig::class); |
|
| 31 | + $this->appManager = $this->createMock(IAppManager::class); |
|
| 32 | + $this->config->method('getSystemValue') |
|
| 33 | + ->willReturnCallback(function ($key, $default = '') { |
|
| 34 | + if (isset($this->systemConfig[$key])) { |
|
| 35 | + return $this->systemConfig[$key]; |
|
| 36 | + } else { |
|
| 37 | + return $default; |
|
| 38 | + } |
|
| 39 | + }); |
|
| 40 | + $this->config->method('getUserValue') |
|
| 41 | + ->willReturnCallback(function ($userId, $appName, $key, $default = '') { |
|
| 42 | + if (isset($this->userConfig[$userId][$appName][$key])) { |
|
| 43 | + return $this->userConfig[$userId][$appName][$key]; |
|
| 44 | + } else { |
|
| 45 | + return $default; |
|
| 46 | + } |
|
| 47 | + }); |
|
| 48 | + $this->config->method('setUserValue') |
|
| 49 | + ->willReturnCallback(function ($userId, $appName, $key, $value): void { |
|
| 50 | + $this->userConfig[$userId][$appName][$key] = $value; |
|
| 51 | + }); |
|
| 52 | + |
|
| 53 | + $this->objectStoreConfig = new PrimaryObjectStoreConfig($this->config, $this->appManager); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + private function getUser(string $uid): IUser { |
|
| 57 | + $user = $this->createMock(IUser::class); |
|
| 58 | + $user->method('getUID') |
|
| 59 | + ->willReturn($uid); |
|
| 60 | + return $user; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + private function setConfig(string $key, $value) { |
|
| 64 | + $this->systemConfig[$key] = $value; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + public function testNewUserGetsDefault() { |
|
| 68 | + $this->setConfig('objectstore', [ |
|
| 69 | + 'default' => 'server1', |
|
| 70 | + 'server1' => [ |
|
| 71 | + 'class' => StorageObjectStore::class, |
|
| 72 | + 'arguments' => [ |
|
| 73 | + 'host' => 'server1', |
|
| 74 | + ], |
|
| 75 | + ], |
|
| 76 | + ]); |
|
| 77 | + |
|
| 78 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 79 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 80 | + |
|
| 81 | + $this->assertEquals('server1', $this->config->getUserValue('test', 'homeobjectstore', 'objectstore', null)); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function testExistingUserKeepsStorage() { |
|
| 85 | + // setup user with `server1` as storage |
|
| 86 | + $this->testNewUserGetsDefault(); |
|
| 87 | + |
|
| 88 | + $this->setConfig('objectstore', [ |
|
| 89 | + 'default' => 'server2', |
|
| 90 | + 'server1' => [ |
|
| 91 | + 'class' => StorageObjectStore::class, |
|
| 92 | + 'arguments' => [ |
|
| 93 | + 'host' => 'server1', |
|
| 94 | + ], |
|
| 95 | + ], |
|
| 96 | + 'server2' => [ |
|
| 97 | + 'class' => StorageObjectStore::class, |
|
| 98 | + 'arguments' => [ |
|
| 99 | + 'host' => 'server2', |
|
| 100 | + ], |
|
| 101 | + ], |
|
| 102 | + ]); |
|
| 103 | + |
|
| 104 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 105 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 106 | + |
|
| 107 | + $this->assertEquals('server1', $this->config->getUserValue('test', 'homeobjectstore', 'objectstore', null)); |
|
| 108 | + |
|
| 109 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('other-user')); |
|
| 110 | + $this->assertEquals('server2', $result['arguments']['host']); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function testNestedAliases() { |
|
| 114 | + $this->setConfig('objectstore', [ |
|
| 115 | + 'default' => 'a1', |
|
| 116 | + 'a1' => 'a2', |
|
| 117 | + 'a2' => 'server1', |
|
| 118 | + 'server1' => [ |
|
| 119 | + 'class' => StorageObjectStore::class, |
|
| 120 | + 'arguments' => [ |
|
| 121 | + 'host' => 'server1', |
|
| 122 | + ], |
|
| 123 | + ], |
|
| 124 | + ]); |
|
| 125 | + $this->assertEquals('server1', $this->objectStoreConfig->resolveAlias('default')); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function testMultibucketChangedConfig() { |
|
| 129 | + $this->setConfig('objectstore', [ |
|
| 130 | + 'default' => 'server1', |
|
| 131 | + 'server1' => [ |
|
| 132 | + 'class' => StorageObjectStore::class, |
|
| 133 | + 'arguments' => [ |
|
| 134 | + 'host' => 'server1', |
|
| 135 | + 'multibucket' => true, |
|
| 136 | + 'num_buckets' => 8, |
|
| 137 | + 'bucket' => 'bucket-' |
|
| 138 | + ], |
|
| 139 | + ], |
|
| 140 | + ]); |
|
| 141 | + |
|
| 142 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 143 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 144 | + $this->assertEquals('bucket-7', $result['arguments']['bucket']); |
|
| 145 | + |
|
| 146 | + $this->setConfig('objectstore', [ |
|
| 147 | + 'default' => 'server1', |
|
| 148 | + 'server1' => [ |
|
| 149 | + 'class' => StorageObjectStore::class, |
|
| 150 | + 'arguments' => [ |
|
| 151 | + 'host' => 'server1', |
|
| 152 | + 'multibucket' => true, |
|
| 153 | + 'num_buckets' => 64, |
|
| 154 | + 'bucket' => 'bucket-' |
|
| 155 | + ], |
|
| 156 | + ], |
|
| 157 | + ]); |
|
| 158 | + |
|
| 159 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 160 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 161 | + $this->assertEquals('bucket-7', $result['arguments']['bucket']); |
|
| 162 | + |
|
| 163 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test-foo')); |
|
| 164 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 165 | + $this->assertEquals('bucket-40', $result['arguments']['bucket']); |
|
| 166 | + |
|
| 167 | + $this->setConfig('objectstore', [ |
|
| 168 | + 'default' => 'server2', |
|
| 169 | + 'server1' => [ |
|
| 170 | + 'class' => StorageObjectStore::class, |
|
| 171 | + 'arguments' => [ |
|
| 172 | + 'host' => 'server1', |
|
| 173 | + 'multibucket' => true, |
|
| 174 | + 'num_buckets' => 64, |
|
| 175 | + 'bucket' => 'bucket-' |
|
| 176 | + ], |
|
| 177 | + ], |
|
| 178 | + 'server2' => [ |
|
| 179 | + 'class' => StorageObjectStore::class, |
|
| 180 | + 'arguments' => [ |
|
| 181 | + 'host' => 'server2', |
|
| 182 | + 'multibucket' => true, |
|
| 183 | + 'num_buckets' => 16, |
|
| 184 | + 'bucket' => 'bucket-' |
|
| 185 | + ], |
|
| 186 | + ], |
|
| 187 | + ]); |
|
| 188 | + |
|
| 189 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 190 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 191 | + $this->assertEquals('bucket-7', $result['arguments']['bucket']); |
|
| 192 | + |
|
| 193 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test-bar')); |
|
| 194 | + $this->assertEquals('server2', $result['arguments']['host']); |
|
| 195 | + $this->assertEquals('bucket-4', $result['arguments']['bucket']); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + public function testMultibucketOldConfig() { |
|
| 199 | + $this->setConfig('objectstore_multibucket', [ |
|
| 200 | + 'class' => StorageObjectStore::class, |
|
| 201 | + 'arguments' => [ |
|
| 202 | + 'host' => 'server1', |
|
| 203 | + 'multibucket' => true, |
|
| 204 | + 'num_buckets' => 8, |
|
| 205 | + 'bucket' => 'bucket-' |
|
| 206 | + ], |
|
| 207 | + ]); |
|
| 208 | + $configs = $this->objectStoreConfig->getObjectStoreConfigs(); |
|
| 209 | + $this->assertEquals([ |
|
| 210 | + 'default' => 'server1', |
|
| 211 | + 'root' => 'server1', |
|
| 212 | + 'server1' => [ |
|
| 213 | + 'class' => StorageObjectStore::class, |
|
| 214 | + 'arguments' => [ |
|
| 215 | + 'host' => 'server1', |
|
| 216 | + 'multibucket' => true, |
|
| 217 | + 'num_buckets' => 8, |
|
| 218 | + 'bucket' => 'bucket-' |
|
| 219 | + ], |
|
| 220 | + ], |
|
| 221 | + ], $configs); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + public function testSingleObjectStore() { |
|
| 225 | + $this->setConfig('objectstore', [ |
|
| 226 | + 'class' => StorageObjectStore::class, |
|
| 227 | + 'arguments' => [ |
|
| 228 | + 'host' => 'server1', |
|
| 229 | + ], |
|
| 230 | + ]); |
|
| 231 | + $configs = $this->objectStoreConfig->getObjectStoreConfigs(); |
|
| 232 | + $this->assertEquals([ |
|
| 233 | + 'default' => 'server1', |
|
| 234 | + 'root' => 'server1', |
|
| 235 | + 'server1' => [ |
|
| 236 | + 'class' => StorageObjectStore::class, |
|
| 237 | + 'arguments' => [ |
|
| 238 | + 'host' => 'server1', |
|
| 239 | + 'multibucket' => false, |
|
| 240 | + ], |
|
| 241 | + ], |
|
| 242 | + ], $configs); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + public function testRoot() { |
|
| 246 | + $this->setConfig('objectstore', [ |
|
| 247 | + 'default' => 'server1', |
|
| 248 | + 'server1' => [ |
|
| 249 | + 'class' => StorageObjectStore::class, |
|
| 250 | + 'arguments' => [ |
|
| 251 | + 'host' => 'server1', |
|
| 252 | + ], |
|
| 253 | + ], |
|
| 254 | + 'server2' => [ |
|
| 255 | + 'class' => StorageObjectStore::class, |
|
| 256 | + 'arguments' => [ |
|
| 257 | + 'host' => 'server2', |
|
| 258 | + ], |
|
| 259 | + ], |
|
| 260 | + ]); |
|
| 261 | + |
|
| 262 | + $result = $this->objectStoreConfig->getObjectStoreConfigForRoot(); |
|
| 263 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 264 | + |
|
| 265 | + $this->setConfig('objectstore', [ |
|
| 266 | + 'default' => 'server1', |
|
| 267 | + 'root' => 'server2', |
|
| 268 | + 'server1' => [ |
|
| 269 | + 'class' => StorageObjectStore::class, |
|
| 270 | + 'arguments' => [ |
|
| 271 | + 'host' => 'server1', |
|
| 272 | + ], |
|
| 273 | + ], |
|
| 274 | + 'server2' => [ |
|
| 275 | + 'class' => StorageObjectStore::class, |
|
| 276 | + 'arguments' => [ |
|
| 277 | + 'host' => 'server2', |
|
| 278 | + ], |
|
| 279 | + ], |
|
| 280 | + ]); |
|
| 281 | + |
|
| 282 | + $result = $this->objectStoreConfig->getObjectStoreConfigForRoot(); |
|
| 283 | + $this->assertEquals('server2', $result['arguments']['host']); |
|
| 284 | + } |
|
| 285 | 285 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $this->config = $this->createMock(IConfig::class); |
| 31 | 31 | $this->appManager = $this->createMock(IAppManager::class); |
| 32 | 32 | $this->config->method('getSystemValue') |
| 33 | - ->willReturnCallback(function ($key, $default = '') { |
|
| 33 | + ->willReturnCallback(function($key, $default = '') { |
|
| 34 | 34 | if (isset($this->systemConfig[$key])) { |
| 35 | 35 | return $this->systemConfig[$key]; |
| 36 | 36 | } else { |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | }); |
| 40 | 40 | $this->config->method('getUserValue') |
| 41 | - ->willReturnCallback(function ($userId, $appName, $key, $default = '') { |
|
| 41 | + ->willReturnCallback(function($userId, $appName, $key, $default = '') { |
|
| 42 | 42 | if (isset($this->userConfig[$userId][$appName][$key])) { |
| 43 | 43 | return $this->userConfig[$userId][$appName][$key]; |
| 44 | 44 | } else { |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | }); |
| 48 | 48 | $this->config->method('setUserValue') |
| 49 | - ->willReturnCallback(function ($userId, $appName, $key, $value): void { |
|
| 49 | + ->willReturnCallback(function($userId, $appName, $key, $value): void { |
|
| 50 | 50 | $this->userConfig[$userId][$appName][$key] = $value; |
| 51 | 51 | }); |
| 52 | 52 | |
@@ -23,421 +23,421 @@ |
||
| 23 | 23 | * @group DB |
| 24 | 24 | */ |
| 25 | 25 | class FileAccessTest extends TestCase { |
| 26 | - private IDBConnection $dbConnection; |
|
| 27 | - private FileAccess $fileAccess; |
|
| 28 | - |
|
| 29 | - protected function setUp(): void { |
|
| 30 | - parent::setUp(); |
|
| 31 | - |
|
| 32 | - // Setup the actual database connection (assume the database is configured properly in PHPUnit setup) |
|
| 33 | - $this->dbConnection = Server::get(IDBConnection::class); |
|
| 34 | - |
|
| 35 | - // Ensure FileAccess is instantiated with the real connection |
|
| 36 | - $this->fileAccess = new FileAccess( |
|
| 37 | - $this->dbConnection, |
|
| 38 | - Server::get(SystemConfig::class), |
|
| 39 | - Server::get(LoggerInterface::class), |
|
| 40 | - Server::get(FilesMetadataManager::class), |
|
| 41 | - Server::get(IMimeTypeLoader::class) |
|
| 42 | - ); |
|
| 43 | - |
|
| 44 | - // Clear and prepare `filecache` table for tests |
|
| 45 | - $queryBuilder = $this->dbConnection->getQueryBuilder()->runAcrossAllShards(); |
|
| 46 | - $queryBuilder->delete('filecache')->executeStatement(); |
|
| 47 | - |
|
| 48 | - // Clean up potential leftovers from other tests |
|
| 49 | - $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 50 | - $queryBuilder->delete('mounts')->executeStatement(); |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - $this->setUpTestDatabaseForGetDistinctMounts(); |
|
| 54 | - $this->setUpTestDatabaseForGetByAncestorInStorage(); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - private function setUpTestDatabaseForGetDistinctMounts(): void { |
|
| 58 | - $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 59 | - |
|
| 60 | - // Insert test data |
|
| 61 | - $queryBuilder->insert('mounts') |
|
| 62 | - ->values([ |
|
| 63 | - 'storage_id' => $queryBuilder->createNamedParameter(1, IQueryBuilder::PARAM_INT), |
|
| 64 | - 'root_id' => $queryBuilder->createNamedParameter(10, IQueryBuilder::PARAM_INT), |
|
| 65 | - 'mount_provider_class' => $queryBuilder->createNamedParameter('TestProviderClass1'), |
|
| 66 | - 'mount_point' => $queryBuilder->createNamedParameter('/files'), |
|
| 67 | - 'user_id' => $queryBuilder->createNamedParameter('test'), |
|
| 68 | - ]) |
|
| 69 | - ->executeStatement(); |
|
| 70 | - |
|
| 71 | - $queryBuilder->insert('mounts') |
|
| 72 | - ->values([ |
|
| 73 | - 'storage_id' => $queryBuilder->createNamedParameter(3, IQueryBuilder::PARAM_INT), |
|
| 74 | - 'root_id' => $queryBuilder->createNamedParameter(30, IQueryBuilder::PARAM_INT), |
|
| 75 | - 'mount_provider_class' => $queryBuilder->createNamedParameter('TestProviderClass1'), |
|
| 76 | - 'mount_point' => $queryBuilder->createNamedParameter('/documents'), |
|
| 77 | - 'user_id' => $queryBuilder->createNamedParameter('test'), |
|
| 78 | - ]) |
|
| 79 | - ->executeStatement(); |
|
| 80 | - |
|
| 81 | - $queryBuilder->insert('mounts') |
|
| 82 | - ->values([ |
|
| 83 | - 'storage_id' => $queryBuilder->createNamedParameter(4, IQueryBuilder::PARAM_INT), |
|
| 84 | - 'root_id' => $queryBuilder->createNamedParameter(31, IQueryBuilder::PARAM_INT), |
|
| 85 | - 'mount_provider_class' => $queryBuilder->createNamedParameter('TestProviderClass2'), |
|
| 86 | - 'mount_point' => $queryBuilder->createNamedParameter('/foobar'), |
|
| 87 | - 'user_id' => $queryBuilder->createNamedParameter('test'), |
|
| 88 | - ]) |
|
| 89 | - ->executeStatement(); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Test that getDistinctMounts returns all mounts without filters |
|
| 94 | - */ |
|
| 95 | - public function testGetDistinctMountsWithoutFilters(): void { |
|
| 96 | - $result = iterator_to_array($this->fileAccess->getDistinctMounts([], false)); |
|
| 97 | - |
|
| 98 | - $this->assertCount(3, $result); |
|
| 99 | - |
|
| 100 | - $this->assertEquals([ |
|
| 101 | - 'storage_id' => 1, |
|
| 102 | - 'root_id' => 10, |
|
| 103 | - 'overridden_root' => 10, |
|
| 104 | - ], $result[0]); |
|
| 105 | - |
|
| 106 | - $this->assertEquals([ |
|
| 107 | - 'storage_id' => 3, |
|
| 108 | - 'root_id' => 30, |
|
| 109 | - 'overridden_root' => 30, |
|
| 110 | - ], $result[1]); |
|
| 111 | - |
|
| 112 | - $this->assertEquals([ |
|
| 113 | - 'storage_id' => 4, |
|
| 114 | - 'root_id' => 31, |
|
| 115 | - 'overridden_root' => 31, |
|
| 116 | - ], $result[2]); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Test that getDistinctMounts applies filtering by mount providers |
|
| 121 | - */ |
|
| 122 | - public function testGetDistinctMountsWithMountProviderFilter(): void { |
|
| 123 | - $result = iterator_to_array($this->fileAccess->getDistinctMounts(['TestProviderClass1'], false)); |
|
| 124 | - |
|
| 125 | - $this->assertCount(2, $result); |
|
| 126 | - |
|
| 127 | - $this->assertEquals([ |
|
| 128 | - 'storage_id' => 1, |
|
| 129 | - 'root_id' => 10, |
|
| 130 | - 'overridden_root' => 10, |
|
| 131 | - ], $result[0]); |
|
| 132 | - |
|
| 133 | - $this->assertEquals([ |
|
| 134 | - 'storage_id' => 3, |
|
| 135 | - 'root_id' => 30, |
|
| 136 | - 'overridden_root' => 30, |
|
| 137 | - ], $result[1]); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Test that getDistinctMounts rewrites home directory paths |
|
| 142 | - */ |
|
| 143 | - public function testGetDistinctMountsWithRewriteHomeDirectories(): void { |
|
| 144 | - // Add additional test data for a home directory mount |
|
| 145 | - $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 146 | - $queryBuilder->insert('mounts') |
|
| 147 | - ->values([ |
|
| 148 | - 'storage_id' => $queryBuilder->createNamedParameter(4, IQueryBuilder::PARAM_INT), |
|
| 149 | - 'root_id' => $queryBuilder->createNamedParameter(40, IQueryBuilder::PARAM_INT), |
|
| 150 | - 'mount_provider_class' => $queryBuilder->createNamedParameter(LocalHomeMountProvider::class), |
|
| 151 | - 'mount_point' => $queryBuilder->createNamedParameter('/home/user'), |
|
| 152 | - 'user_id' => $queryBuilder->createNamedParameter('test'), |
|
| 153 | - ]) |
|
| 154 | - ->executeStatement(); |
|
| 155 | - |
|
| 156 | - // Add a mount that is mounted in the home directory |
|
| 157 | - $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 158 | - $queryBuilder->insert('mounts') |
|
| 159 | - ->values([ |
|
| 160 | - 'storage_id' => $queryBuilder->createNamedParameter(5, IQueryBuilder::PARAM_INT), |
|
| 161 | - 'root_id' => $queryBuilder->createNamedParameter(41, IQueryBuilder::PARAM_INT), |
|
| 162 | - 'mount_provider_class' => $queryBuilder->createNamedParameter('TestMountProvider3'), |
|
| 163 | - 'mount_point' => $queryBuilder->createNamedParameter('/test/files/foobar'), |
|
| 164 | - 'user_id' => $queryBuilder->createNamedParameter('test'), |
|
| 165 | - ]) |
|
| 166 | - ->executeStatement(); |
|
| 167 | - |
|
| 168 | - // Simulate adding a "files" directory to the filecache table |
|
| 169 | - $queryBuilder = $this->dbConnection->getQueryBuilder()->runAcrossAllShards(); |
|
| 170 | - $queryBuilder->delete('filecache')->executeStatement(); |
|
| 171 | - $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 172 | - $queryBuilder->insert('filecache') |
|
| 173 | - ->values([ |
|
| 174 | - 'fileid' => $queryBuilder->createNamedParameter(99, IQueryBuilder::PARAM_INT), |
|
| 175 | - 'storage' => $queryBuilder->createNamedParameter(4, IQueryBuilder::PARAM_INT), |
|
| 176 | - 'parent' => $queryBuilder->createNamedParameter(40), |
|
| 177 | - 'name' => $queryBuilder->createNamedParameter('files'), |
|
| 178 | - 'path' => $queryBuilder->createNamedParameter('files'), |
|
| 179 | - 'path_hash' => $queryBuilder->createNamedParameter(md5('files')), |
|
| 180 | - ]) |
|
| 181 | - ->executeStatement(); |
|
| 182 | - |
|
| 183 | - $result = iterator_to_array($this->fileAccess->getDistinctMounts()); |
|
| 184 | - |
|
| 185 | - $this->assertCount(2, $result); |
|
| 186 | - |
|
| 187 | - $this->assertEquals([ |
|
| 188 | - 'storage_id' => 4, |
|
| 189 | - 'root_id' => 40, |
|
| 190 | - 'overridden_root' => 99, |
|
| 191 | - ], $result[0]); |
|
| 192 | - |
|
| 193 | - $this->assertEquals([ |
|
| 194 | - 'storage_id' => 5, |
|
| 195 | - 'root_id' => 41, |
|
| 196 | - 'overridden_root' => 41, |
|
| 197 | - ], $result[1]); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - private function setUpTestDatabaseForGetByAncestorInStorage(): void { |
|
| 201 | - // prepare `filecache` table for tests |
|
| 202 | - $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 203 | - |
|
| 204 | - $queryBuilder->insert('filecache') |
|
| 205 | - ->values([ |
|
| 206 | - 'fileid' => 1, |
|
| 207 | - 'parent' => 0, |
|
| 208 | - 'path' => $queryBuilder->createNamedParameter('files'), |
|
| 209 | - 'path_hash' => $queryBuilder->createNamedParameter(md5('files')), |
|
| 210 | - 'storage' => $queryBuilder->createNamedParameter(1), |
|
| 211 | - 'name' => $queryBuilder->createNamedParameter('files'), |
|
| 212 | - 'mimetype' => 1, |
|
| 213 | - 'encrypted' => 0, |
|
| 214 | - ]) |
|
| 215 | - ->executeStatement(); |
|
| 216 | - |
|
| 217 | - $queryBuilder->insert('filecache') |
|
| 218 | - ->values([ |
|
| 219 | - 'fileid' => 2, |
|
| 220 | - 'parent' => 1, |
|
| 221 | - 'path' => $queryBuilder->createNamedParameter('files/documents'), |
|
| 222 | - 'path_hash' => $queryBuilder->createNamedParameter(md5('files/documents')), |
|
| 223 | - 'storage' => $queryBuilder->createNamedParameter(1), |
|
| 224 | - 'name' => $queryBuilder->createNamedParameter('documents'), |
|
| 225 | - 'mimetype' => 2, |
|
| 226 | - 'encrypted' => 1, |
|
| 227 | - ]) |
|
| 228 | - ->executeStatement(); |
|
| 229 | - |
|
| 230 | - $queryBuilder->insert('filecache') |
|
| 231 | - ->values([ |
|
| 232 | - 'fileid' => 3, |
|
| 233 | - 'parent' => 1, |
|
| 234 | - 'path' => $queryBuilder->createNamedParameter('files/photos'), |
|
| 235 | - 'path_hash' => $queryBuilder->createNamedParameter(md5('files/photos')), |
|
| 236 | - 'storage' => $queryBuilder->createNamedParameter(1), |
|
| 237 | - 'name' => $queryBuilder->createNamedParameter('photos'), |
|
| 238 | - 'mimetype' => 3, |
|
| 239 | - 'encrypted' => 1, |
|
| 240 | - ]) |
|
| 241 | - ->executeStatement(); |
|
| 242 | - |
|
| 243 | - $queryBuilder->insert('filecache') |
|
| 244 | - ->values([ |
|
| 245 | - 'fileid' => 4, |
|
| 246 | - 'parent' => 3, |
|
| 247 | - 'path' => $queryBuilder->createNamedParameter('files/photos/endtoendencrypted'), |
|
| 248 | - 'path_hash' => $queryBuilder->createNamedParameter(md5('files/photos/endtoendencrypted')), |
|
| 249 | - 'storage' => $queryBuilder->createNamedParameter(1), |
|
| 250 | - 'name' => $queryBuilder->createNamedParameter('endtoendencrypted'), |
|
| 251 | - 'mimetype' => 4, |
|
| 252 | - 'encrypted' => 0, |
|
| 253 | - ]) |
|
| 254 | - ->executeStatement(); |
|
| 255 | - |
|
| 256 | - $queryBuilder->insert('filecache') |
|
| 257 | - ->values([ |
|
| 258 | - 'fileid' => 5, |
|
| 259 | - 'parent' => 1, |
|
| 260 | - 'path' => $queryBuilder->createNamedParameter('files/serversideencrypted'), |
|
| 261 | - 'path_hash' => $queryBuilder->createNamedParameter(md5('files/serversideencrypted')), |
|
| 262 | - 'storage' => $queryBuilder->createNamedParameter(1), |
|
| 263 | - 'name' => $queryBuilder->createNamedParameter('serversideencrypted'), |
|
| 264 | - 'mimetype' => 4, |
|
| 265 | - 'encrypted' => 1, |
|
| 266 | - ]) |
|
| 267 | - ->executeStatement(); |
|
| 268 | - |
|
| 269 | - $queryBuilder->insert('filecache') |
|
| 270 | - ->values([ |
|
| 271 | - 'fileid' => 6, |
|
| 272 | - 'parent' => 0, |
|
| 273 | - 'path' => $queryBuilder->createNamedParameter('files/storage2'), |
|
| 274 | - 'path_hash' => $queryBuilder->createNamedParameter(md5('files/storage2')), |
|
| 275 | - 'storage' => $queryBuilder->createNamedParameter(2), |
|
| 276 | - 'name' => $queryBuilder->createNamedParameter('storage2'), |
|
| 277 | - 'mimetype' => 5, |
|
| 278 | - 'encrypted' => 0, |
|
| 279 | - ]) |
|
| 280 | - ->executeStatement(); |
|
| 281 | - |
|
| 282 | - $queryBuilder->insert('filecache') |
|
| 283 | - ->values([ |
|
| 284 | - 'fileid' => 7, |
|
| 285 | - 'parent' => 6, |
|
| 286 | - 'path' => $queryBuilder->createNamedParameter('files/storage2/file'), |
|
| 287 | - 'path_hash' => $queryBuilder->createNamedParameter(md5('files/storage2/file')), |
|
| 288 | - 'storage' => $queryBuilder->createNamedParameter(2), |
|
| 289 | - 'name' => $queryBuilder->createNamedParameter('file'), |
|
| 290 | - 'mimetype' => 6, |
|
| 291 | - 'encrypted' => 0, |
|
| 292 | - ]) |
|
| 293 | - ->executeStatement(); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Test fetching files by ancestor in storage. |
|
| 298 | - */ |
|
| 299 | - public function testGetByAncestorInStorage(): void { |
|
| 300 | - $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 301 | - 1, // storageId |
|
| 302 | - 1, // rootId |
|
| 303 | - 0, // lastFileId |
|
| 304 | - 10, // maxResults |
|
| 305 | - [], // mimeTypes |
|
| 306 | - true, // include end-to-end encrypted files |
|
| 307 | - true, // include server-side encrypted files |
|
| 308 | - ); |
|
| 309 | - |
|
| 310 | - $result = iterator_to_array($generator); |
|
| 311 | - |
|
| 312 | - $this->assertCount(4, $result); |
|
| 313 | - |
|
| 314 | - $paths = array_map(fn (CacheEntry $entry) => $entry->getPath(), $result); |
|
| 315 | - $this->assertEquals([ |
|
| 316 | - 'files/documents', |
|
| 317 | - 'files/photos', |
|
| 318 | - 'files/photos/endtoendencrypted', |
|
| 319 | - 'files/serversideencrypted', |
|
| 320 | - ], $paths); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Test filtering by mime types. |
|
| 325 | - */ |
|
| 326 | - public function testGetByAncestorInStorageWithMimeTypes(): void { |
|
| 327 | - $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 328 | - 1, |
|
| 329 | - 1, |
|
| 330 | - 0, |
|
| 331 | - 10, |
|
| 332 | - [2], // Only include documents (mimetype=2) |
|
| 333 | - true, |
|
| 334 | - true, |
|
| 335 | - ); |
|
| 336 | - |
|
| 337 | - $result = iterator_to_array($generator); |
|
| 338 | - |
|
| 339 | - $this->assertCount(1, $result); |
|
| 340 | - $this->assertEquals('files/documents', $result[0]->getPath()); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Test excluding end-to-end encrypted files. |
|
| 345 | - */ |
|
| 346 | - public function testGetByAncestorInStorageWithoutEndToEndEncrypted(): void { |
|
| 347 | - $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 348 | - 1, |
|
| 349 | - 1, |
|
| 350 | - 0, |
|
| 351 | - 10, |
|
| 352 | - [], |
|
| 353 | - false, // exclude end-to-end encrypted files |
|
| 354 | - true, |
|
| 355 | - ); |
|
| 356 | - |
|
| 357 | - $result = iterator_to_array($generator); |
|
| 358 | - |
|
| 359 | - $this->assertCount(3, $result); |
|
| 360 | - $paths = array_map(fn (CacheEntry $entry) => $entry->getPath(), $result); |
|
| 361 | - $this->assertEquals(['files/documents', 'files/photos', 'files/serversideencrypted'], $paths); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Test excluding server-side encrypted files. |
|
| 366 | - */ |
|
| 367 | - public function testGetByAncestorInStorageWithoutServerSideEncrypted(): void { |
|
| 368 | - $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 369 | - 1, |
|
| 370 | - 1, |
|
| 371 | - 0, |
|
| 372 | - 10, |
|
| 373 | - [], |
|
| 374 | - true, |
|
| 375 | - false, // exclude server-side encrypted files |
|
| 376 | - ); |
|
| 377 | - |
|
| 378 | - $result = iterator_to_array($generator); |
|
| 379 | - |
|
| 380 | - $this->assertCount(1, $result); |
|
| 381 | - $this->assertEquals('files/photos/endtoendencrypted', $result[0]->getPath()); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Test max result limits. |
|
| 386 | - */ |
|
| 387 | - public function testGetByAncestorInStorageWithMaxResults(): void { |
|
| 388 | - $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 389 | - 1, |
|
| 390 | - 1, |
|
| 391 | - 0, |
|
| 392 | - 1, // Limit to 1 result |
|
| 393 | - [], |
|
| 394 | - true, |
|
| 395 | - true, |
|
| 396 | - ); |
|
| 397 | - |
|
| 398 | - $result = iterator_to_array($generator); |
|
| 399 | - |
|
| 400 | - $this->assertCount(1, $result); |
|
| 401 | - $this->assertEquals('files/documents', $result[0]->getPath()); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Test rootId filter |
|
| 406 | - */ |
|
| 407 | - public function testGetByAncestorInStorageWithRootIdFilter(): void { |
|
| 408 | - $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 409 | - 1, |
|
| 410 | - 3, // Filter by rootId |
|
| 411 | - 0, |
|
| 412 | - 10, |
|
| 413 | - [], |
|
| 414 | - true, |
|
| 415 | - true, |
|
| 416 | - ); |
|
| 417 | - |
|
| 418 | - $result = iterator_to_array($generator); |
|
| 419 | - |
|
| 420 | - $this->assertCount(1, $result); |
|
| 421 | - $this->assertEquals('files/photos/endtoendencrypted', $result[0]->getPath()); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Test rootId filter |
|
| 426 | - */ |
|
| 427 | - public function testGetByAncestorInStorageWithStorageFilter(): void { |
|
| 428 | - $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 429 | - 2, // Filter by storage |
|
| 430 | - 6, // and by rootId |
|
| 431 | - 0, |
|
| 432 | - 10, |
|
| 433 | - [], |
|
| 434 | - true, |
|
| 435 | - true, |
|
| 436 | - ); |
|
| 437 | - |
|
| 438 | - $result = iterator_to_array($generator); |
|
| 439 | - |
|
| 440 | - $this->assertCount(1, $result); |
|
| 441 | - $this->assertEquals('files/storage2/file', $result[0]->getPath()); |
|
| 442 | - } |
|
| 26 | + private IDBConnection $dbConnection; |
|
| 27 | + private FileAccess $fileAccess; |
|
| 28 | + |
|
| 29 | + protected function setUp(): void { |
|
| 30 | + parent::setUp(); |
|
| 31 | + |
|
| 32 | + // Setup the actual database connection (assume the database is configured properly in PHPUnit setup) |
|
| 33 | + $this->dbConnection = Server::get(IDBConnection::class); |
|
| 34 | + |
|
| 35 | + // Ensure FileAccess is instantiated with the real connection |
|
| 36 | + $this->fileAccess = new FileAccess( |
|
| 37 | + $this->dbConnection, |
|
| 38 | + Server::get(SystemConfig::class), |
|
| 39 | + Server::get(LoggerInterface::class), |
|
| 40 | + Server::get(FilesMetadataManager::class), |
|
| 41 | + Server::get(IMimeTypeLoader::class) |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + // Clear and prepare `filecache` table for tests |
|
| 45 | + $queryBuilder = $this->dbConnection->getQueryBuilder()->runAcrossAllShards(); |
|
| 46 | + $queryBuilder->delete('filecache')->executeStatement(); |
|
| 47 | + |
|
| 48 | + // Clean up potential leftovers from other tests |
|
| 49 | + $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 50 | + $queryBuilder->delete('mounts')->executeStatement(); |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + $this->setUpTestDatabaseForGetDistinctMounts(); |
|
| 54 | + $this->setUpTestDatabaseForGetByAncestorInStorage(); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + private function setUpTestDatabaseForGetDistinctMounts(): void { |
|
| 58 | + $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 59 | + |
|
| 60 | + // Insert test data |
|
| 61 | + $queryBuilder->insert('mounts') |
|
| 62 | + ->values([ |
|
| 63 | + 'storage_id' => $queryBuilder->createNamedParameter(1, IQueryBuilder::PARAM_INT), |
|
| 64 | + 'root_id' => $queryBuilder->createNamedParameter(10, IQueryBuilder::PARAM_INT), |
|
| 65 | + 'mount_provider_class' => $queryBuilder->createNamedParameter('TestProviderClass1'), |
|
| 66 | + 'mount_point' => $queryBuilder->createNamedParameter('/files'), |
|
| 67 | + 'user_id' => $queryBuilder->createNamedParameter('test'), |
|
| 68 | + ]) |
|
| 69 | + ->executeStatement(); |
|
| 70 | + |
|
| 71 | + $queryBuilder->insert('mounts') |
|
| 72 | + ->values([ |
|
| 73 | + 'storage_id' => $queryBuilder->createNamedParameter(3, IQueryBuilder::PARAM_INT), |
|
| 74 | + 'root_id' => $queryBuilder->createNamedParameter(30, IQueryBuilder::PARAM_INT), |
|
| 75 | + 'mount_provider_class' => $queryBuilder->createNamedParameter('TestProviderClass1'), |
|
| 76 | + 'mount_point' => $queryBuilder->createNamedParameter('/documents'), |
|
| 77 | + 'user_id' => $queryBuilder->createNamedParameter('test'), |
|
| 78 | + ]) |
|
| 79 | + ->executeStatement(); |
|
| 80 | + |
|
| 81 | + $queryBuilder->insert('mounts') |
|
| 82 | + ->values([ |
|
| 83 | + 'storage_id' => $queryBuilder->createNamedParameter(4, IQueryBuilder::PARAM_INT), |
|
| 84 | + 'root_id' => $queryBuilder->createNamedParameter(31, IQueryBuilder::PARAM_INT), |
|
| 85 | + 'mount_provider_class' => $queryBuilder->createNamedParameter('TestProviderClass2'), |
|
| 86 | + 'mount_point' => $queryBuilder->createNamedParameter('/foobar'), |
|
| 87 | + 'user_id' => $queryBuilder->createNamedParameter('test'), |
|
| 88 | + ]) |
|
| 89 | + ->executeStatement(); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Test that getDistinctMounts returns all mounts without filters |
|
| 94 | + */ |
|
| 95 | + public function testGetDistinctMountsWithoutFilters(): void { |
|
| 96 | + $result = iterator_to_array($this->fileAccess->getDistinctMounts([], false)); |
|
| 97 | + |
|
| 98 | + $this->assertCount(3, $result); |
|
| 99 | + |
|
| 100 | + $this->assertEquals([ |
|
| 101 | + 'storage_id' => 1, |
|
| 102 | + 'root_id' => 10, |
|
| 103 | + 'overridden_root' => 10, |
|
| 104 | + ], $result[0]); |
|
| 105 | + |
|
| 106 | + $this->assertEquals([ |
|
| 107 | + 'storage_id' => 3, |
|
| 108 | + 'root_id' => 30, |
|
| 109 | + 'overridden_root' => 30, |
|
| 110 | + ], $result[1]); |
|
| 111 | + |
|
| 112 | + $this->assertEquals([ |
|
| 113 | + 'storage_id' => 4, |
|
| 114 | + 'root_id' => 31, |
|
| 115 | + 'overridden_root' => 31, |
|
| 116 | + ], $result[2]); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Test that getDistinctMounts applies filtering by mount providers |
|
| 121 | + */ |
|
| 122 | + public function testGetDistinctMountsWithMountProviderFilter(): void { |
|
| 123 | + $result = iterator_to_array($this->fileAccess->getDistinctMounts(['TestProviderClass1'], false)); |
|
| 124 | + |
|
| 125 | + $this->assertCount(2, $result); |
|
| 126 | + |
|
| 127 | + $this->assertEquals([ |
|
| 128 | + 'storage_id' => 1, |
|
| 129 | + 'root_id' => 10, |
|
| 130 | + 'overridden_root' => 10, |
|
| 131 | + ], $result[0]); |
|
| 132 | + |
|
| 133 | + $this->assertEquals([ |
|
| 134 | + 'storage_id' => 3, |
|
| 135 | + 'root_id' => 30, |
|
| 136 | + 'overridden_root' => 30, |
|
| 137 | + ], $result[1]); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Test that getDistinctMounts rewrites home directory paths |
|
| 142 | + */ |
|
| 143 | + public function testGetDistinctMountsWithRewriteHomeDirectories(): void { |
|
| 144 | + // Add additional test data for a home directory mount |
|
| 145 | + $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 146 | + $queryBuilder->insert('mounts') |
|
| 147 | + ->values([ |
|
| 148 | + 'storage_id' => $queryBuilder->createNamedParameter(4, IQueryBuilder::PARAM_INT), |
|
| 149 | + 'root_id' => $queryBuilder->createNamedParameter(40, IQueryBuilder::PARAM_INT), |
|
| 150 | + 'mount_provider_class' => $queryBuilder->createNamedParameter(LocalHomeMountProvider::class), |
|
| 151 | + 'mount_point' => $queryBuilder->createNamedParameter('/home/user'), |
|
| 152 | + 'user_id' => $queryBuilder->createNamedParameter('test'), |
|
| 153 | + ]) |
|
| 154 | + ->executeStatement(); |
|
| 155 | + |
|
| 156 | + // Add a mount that is mounted in the home directory |
|
| 157 | + $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 158 | + $queryBuilder->insert('mounts') |
|
| 159 | + ->values([ |
|
| 160 | + 'storage_id' => $queryBuilder->createNamedParameter(5, IQueryBuilder::PARAM_INT), |
|
| 161 | + 'root_id' => $queryBuilder->createNamedParameter(41, IQueryBuilder::PARAM_INT), |
|
| 162 | + 'mount_provider_class' => $queryBuilder->createNamedParameter('TestMountProvider3'), |
|
| 163 | + 'mount_point' => $queryBuilder->createNamedParameter('/test/files/foobar'), |
|
| 164 | + 'user_id' => $queryBuilder->createNamedParameter('test'), |
|
| 165 | + ]) |
|
| 166 | + ->executeStatement(); |
|
| 167 | + |
|
| 168 | + // Simulate adding a "files" directory to the filecache table |
|
| 169 | + $queryBuilder = $this->dbConnection->getQueryBuilder()->runAcrossAllShards(); |
|
| 170 | + $queryBuilder->delete('filecache')->executeStatement(); |
|
| 171 | + $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 172 | + $queryBuilder->insert('filecache') |
|
| 173 | + ->values([ |
|
| 174 | + 'fileid' => $queryBuilder->createNamedParameter(99, IQueryBuilder::PARAM_INT), |
|
| 175 | + 'storage' => $queryBuilder->createNamedParameter(4, IQueryBuilder::PARAM_INT), |
|
| 176 | + 'parent' => $queryBuilder->createNamedParameter(40), |
|
| 177 | + 'name' => $queryBuilder->createNamedParameter('files'), |
|
| 178 | + 'path' => $queryBuilder->createNamedParameter('files'), |
|
| 179 | + 'path_hash' => $queryBuilder->createNamedParameter(md5('files')), |
|
| 180 | + ]) |
|
| 181 | + ->executeStatement(); |
|
| 182 | + |
|
| 183 | + $result = iterator_to_array($this->fileAccess->getDistinctMounts()); |
|
| 184 | + |
|
| 185 | + $this->assertCount(2, $result); |
|
| 186 | + |
|
| 187 | + $this->assertEquals([ |
|
| 188 | + 'storage_id' => 4, |
|
| 189 | + 'root_id' => 40, |
|
| 190 | + 'overridden_root' => 99, |
|
| 191 | + ], $result[0]); |
|
| 192 | + |
|
| 193 | + $this->assertEquals([ |
|
| 194 | + 'storage_id' => 5, |
|
| 195 | + 'root_id' => 41, |
|
| 196 | + 'overridden_root' => 41, |
|
| 197 | + ], $result[1]); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + private function setUpTestDatabaseForGetByAncestorInStorage(): void { |
|
| 201 | + // prepare `filecache` table for tests |
|
| 202 | + $queryBuilder = $this->dbConnection->getQueryBuilder(); |
|
| 203 | + |
|
| 204 | + $queryBuilder->insert('filecache') |
|
| 205 | + ->values([ |
|
| 206 | + 'fileid' => 1, |
|
| 207 | + 'parent' => 0, |
|
| 208 | + 'path' => $queryBuilder->createNamedParameter('files'), |
|
| 209 | + 'path_hash' => $queryBuilder->createNamedParameter(md5('files')), |
|
| 210 | + 'storage' => $queryBuilder->createNamedParameter(1), |
|
| 211 | + 'name' => $queryBuilder->createNamedParameter('files'), |
|
| 212 | + 'mimetype' => 1, |
|
| 213 | + 'encrypted' => 0, |
|
| 214 | + ]) |
|
| 215 | + ->executeStatement(); |
|
| 216 | + |
|
| 217 | + $queryBuilder->insert('filecache') |
|
| 218 | + ->values([ |
|
| 219 | + 'fileid' => 2, |
|
| 220 | + 'parent' => 1, |
|
| 221 | + 'path' => $queryBuilder->createNamedParameter('files/documents'), |
|
| 222 | + 'path_hash' => $queryBuilder->createNamedParameter(md5('files/documents')), |
|
| 223 | + 'storage' => $queryBuilder->createNamedParameter(1), |
|
| 224 | + 'name' => $queryBuilder->createNamedParameter('documents'), |
|
| 225 | + 'mimetype' => 2, |
|
| 226 | + 'encrypted' => 1, |
|
| 227 | + ]) |
|
| 228 | + ->executeStatement(); |
|
| 229 | + |
|
| 230 | + $queryBuilder->insert('filecache') |
|
| 231 | + ->values([ |
|
| 232 | + 'fileid' => 3, |
|
| 233 | + 'parent' => 1, |
|
| 234 | + 'path' => $queryBuilder->createNamedParameter('files/photos'), |
|
| 235 | + 'path_hash' => $queryBuilder->createNamedParameter(md5('files/photos')), |
|
| 236 | + 'storage' => $queryBuilder->createNamedParameter(1), |
|
| 237 | + 'name' => $queryBuilder->createNamedParameter('photos'), |
|
| 238 | + 'mimetype' => 3, |
|
| 239 | + 'encrypted' => 1, |
|
| 240 | + ]) |
|
| 241 | + ->executeStatement(); |
|
| 242 | + |
|
| 243 | + $queryBuilder->insert('filecache') |
|
| 244 | + ->values([ |
|
| 245 | + 'fileid' => 4, |
|
| 246 | + 'parent' => 3, |
|
| 247 | + 'path' => $queryBuilder->createNamedParameter('files/photos/endtoendencrypted'), |
|
| 248 | + 'path_hash' => $queryBuilder->createNamedParameter(md5('files/photos/endtoendencrypted')), |
|
| 249 | + 'storage' => $queryBuilder->createNamedParameter(1), |
|
| 250 | + 'name' => $queryBuilder->createNamedParameter('endtoendencrypted'), |
|
| 251 | + 'mimetype' => 4, |
|
| 252 | + 'encrypted' => 0, |
|
| 253 | + ]) |
|
| 254 | + ->executeStatement(); |
|
| 255 | + |
|
| 256 | + $queryBuilder->insert('filecache') |
|
| 257 | + ->values([ |
|
| 258 | + 'fileid' => 5, |
|
| 259 | + 'parent' => 1, |
|
| 260 | + 'path' => $queryBuilder->createNamedParameter('files/serversideencrypted'), |
|
| 261 | + 'path_hash' => $queryBuilder->createNamedParameter(md5('files/serversideencrypted')), |
|
| 262 | + 'storage' => $queryBuilder->createNamedParameter(1), |
|
| 263 | + 'name' => $queryBuilder->createNamedParameter('serversideencrypted'), |
|
| 264 | + 'mimetype' => 4, |
|
| 265 | + 'encrypted' => 1, |
|
| 266 | + ]) |
|
| 267 | + ->executeStatement(); |
|
| 268 | + |
|
| 269 | + $queryBuilder->insert('filecache') |
|
| 270 | + ->values([ |
|
| 271 | + 'fileid' => 6, |
|
| 272 | + 'parent' => 0, |
|
| 273 | + 'path' => $queryBuilder->createNamedParameter('files/storage2'), |
|
| 274 | + 'path_hash' => $queryBuilder->createNamedParameter(md5('files/storage2')), |
|
| 275 | + 'storage' => $queryBuilder->createNamedParameter(2), |
|
| 276 | + 'name' => $queryBuilder->createNamedParameter('storage2'), |
|
| 277 | + 'mimetype' => 5, |
|
| 278 | + 'encrypted' => 0, |
|
| 279 | + ]) |
|
| 280 | + ->executeStatement(); |
|
| 281 | + |
|
| 282 | + $queryBuilder->insert('filecache') |
|
| 283 | + ->values([ |
|
| 284 | + 'fileid' => 7, |
|
| 285 | + 'parent' => 6, |
|
| 286 | + 'path' => $queryBuilder->createNamedParameter('files/storage2/file'), |
|
| 287 | + 'path_hash' => $queryBuilder->createNamedParameter(md5('files/storage2/file')), |
|
| 288 | + 'storage' => $queryBuilder->createNamedParameter(2), |
|
| 289 | + 'name' => $queryBuilder->createNamedParameter('file'), |
|
| 290 | + 'mimetype' => 6, |
|
| 291 | + 'encrypted' => 0, |
|
| 292 | + ]) |
|
| 293 | + ->executeStatement(); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Test fetching files by ancestor in storage. |
|
| 298 | + */ |
|
| 299 | + public function testGetByAncestorInStorage(): void { |
|
| 300 | + $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 301 | + 1, // storageId |
|
| 302 | + 1, // rootId |
|
| 303 | + 0, // lastFileId |
|
| 304 | + 10, // maxResults |
|
| 305 | + [], // mimeTypes |
|
| 306 | + true, // include end-to-end encrypted files |
|
| 307 | + true, // include server-side encrypted files |
|
| 308 | + ); |
|
| 309 | + |
|
| 310 | + $result = iterator_to_array($generator); |
|
| 311 | + |
|
| 312 | + $this->assertCount(4, $result); |
|
| 313 | + |
|
| 314 | + $paths = array_map(fn (CacheEntry $entry) => $entry->getPath(), $result); |
|
| 315 | + $this->assertEquals([ |
|
| 316 | + 'files/documents', |
|
| 317 | + 'files/photos', |
|
| 318 | + 'files/photos/endtoendencrypted', |
|
| 319 | + 'files/serversideencrypted', |
|
| 320 | + ], $paths); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Test filtering by mime types. |
|
| 325 | + */ |
|
| 326 | + public function testGetByAncestorInStorageWithMimeTypes(): void { |
|
| 327 | + $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 328 | + 1, |
|
| 329 | + 1, |
|
| 330 | + 0, |
|
| 331 | + 10, |
|
| 332 | + [2], // Only include documents (mimetype=2) |
|
| 333 | + true, |
|
| 334 | + true, |
|
| 335 | + ); |
|
| 336 | + |
|
| 337 | + $result = iterator_to_array($generator); |
|
| 338 | + |
|
| 339 | + $this->assertCount(1, $result); |
|
| 340 | + $this->assertEquals('files/documents', $result[0]->getPath()); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Test excluding end-to-end encrypted files. |
|
| 345 | + */ |
|
| 346 | + public function testGetByAncestorInStorageWithoutEndToEndEncrypted(): void { |
|
| 347 | + $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 348 | + 1, |
|
| 349 | + 1, |
|
| 350 | + 0, |
|
| 351 | + 10, |
|
| 352 | + [], |
|
| 353 | + false, // exclude end-to-end encrypted files |
|
| 354 | + true, |
|
| 355 | + ); |
|
| 356 | + |
|
| 357 | + $result = iterator_to_array($generator); |
|
| 358 | + |
|
| 359 | + $this->assertCount(3, $result); |
|
| 360 | + $paths = array_map(fn (CacheEntry $entry) => $entry->getPath(), $result); |
|
| 361 | + $this->assertEquals(['files/documents', 'files/photos', 'files/serversideencrypted'], $paths); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Test excluding server-side encrypted files. |
|
| 366 | + */ |
|
| 367 | + public function testGetByAncestorInStorageWithoutServerSideEncrypted(): void { |
|
| 368 | + $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 369 | + 1, |
|
| 370 | + 1, |
|
| 371 | + 0, |
|
| 372 | + 10, |
|
| 373 | + [], |
|
| 374 | + true, |
|
| 375 | + false, // exclude server-side encrypted files |
|
| 376 | + ); |
|
| 377 | + |
|
| 378 | + $result = iterator_to_array($generator); |
|
| 379 | + |
|
| 380 | + $this->assertCount(1, $result); |
|
| 381 | + $this->assertEquals('files/photos/endtoendencrypted', $result[0]->getPath()); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Test max result limits. |
|
| 386 | + */ |
|
| 387 | + public function testGetByAncestorInStorageWithMaxResults(): void { |
|
| 388 | + $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 389 | + 1, |
|
| 390 | + 1, |
|
| 391 | + 0, |
|
| 392 | + 1, // Limit to 1 result |
|
| 393 | + [], |
|
| 394 | + true, |
|
| 395 | + true, |
|
| 396 | + ); |
|
| 397 | + |
|
| 398 | + $result = iterator_to_array($generator); |
|
| 399 | + |
|
| 400 | + $this->assertCount(1, $result); |
|
| 401 | + $this->assertEquals('files/documents', $result[0]->getPath()); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Test rootId filter |
|
| 406 | + */ |
|
| 407 | + public function testGetByAncestorInStorageWithRootIdFilter(): void { |
|
| 408 | + $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 409 | + 1, |
|
| 410 | + 3, // Filter by rootId |
|
| 411 | + 0, |
|
| 412 | + 10, |
|
| 413 | + [], |
|
| 414 | + true, |
|
| 415 | + true, |
|
| 416 | + ); |
|
| 417 | + |
|
| 418 | + $result = iterator_to_array($generator); |
|
| 419 | + |
|
| 420 | + $this->assertCount(1, $result); |
|
| 421 | + $this->assertEquals('files/photos/endtoendencrypted', $result[0]->getPath()); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Test rootId filter |
|
| 426 | + */ |
|
| 427 | + public function testGetByAncestorInStorageWithStorageFilter(): void { |
|
| 428 | + $generator = $this->fileAccess->getByAncestorInStorage( |
|
| 429 | + 2, // Filter by storage |
|
| 430 | + 6, // and by rootId |
|
| 431 | + 0, |
|
| 432 | + 10, |
|
| 433 | + [], |
|
| 434 | + true, |
|
| 435 | + true, |
|
| 436 | + ); |
|
| 437 | + |
|
| 438 | + $result = iterator_to_array($generator); |
|
| 439 | + |
|
| 440 | + $this->assertCount(1, $result); |
|
| 441 | + $this->assertEquals('files/storage2/file', $result[0]->getPath()); |
|
| 442 | + } |
|
| 443 | 443 | } |
@@ -22,46 +22,46 @@ |
||
| 22 | 22 | * @package Test\Avatar |
| 23 | 23 | */ |
| 24 | 24 | class GuestAvatarTest extends TestCase { |
| 25 | - /** |
|
| 26 | - * @var GuestAvatar |
|
| 27 | - */ |
|
| 28 | - private $guestAvatar; |
|
| 25 | + /** |
|
| 26 | + * @var GuestAvatar |
|
| 27 | + */ |
|
| 28 | + private $guestAvatar; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Setups a guest avatar instance for tests. |
|
| 32 | - * |
|
| 33 | - * @before |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public function setupGuestAvatar() { |
|
| 37 | - /* @var MockObject|LoggerInterface $logger */ |
|
| 38 | - $logger = $this->createMock(LoggerInterface::class); |
|
| 39 | - $config = $this->createMock(IConfig::class); |
|
| 40 | - $this->guestAvatar = new GuestAvatar('einstein', $config, $logger); |
|
| 41 | - } |
|
| 30 | + /** |
|
| 31 | + * Setups a guest avatar instance for tests. |
|
| 32 | + * |
|
| 33 | + * @before |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public function setupGuestAvatar() { |
|
| 37 | + /* @var MockObject|LoggerInterface $logger */ |
|
| 38 | + $logger = $this->createMock(LoggerInterface::class); |
|
| 39 | + $config = $this->createMock(IConfig::class); |
|
| 40 | + $this->guestAvatar = new GuestAvatar('einstein', $config, $logger); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Asserts that testGet() returns the expected avatar. |
|
| 45 | - * |
|
| 46 | - * For the test a static name "einstein" is used and |
|
| 47 | - * the generated image is compared with an expected one. |
|
| 48 | - */ |
|
| 49 | - public function testGet(): void { |
|
| 50 | - $this->markTestSkipped('TODO: Disable because fails on drone'); |
|
| 51 | - $avatar = $this->guestAvatar->getFile(32); |
|
| 52 | - self::assertInstanceOf(InMemoryFile::class, $avatar); |
|
| 53 | - $expectedFile = file_get_contents( |
|
| 54 | - __DIR__ . '/../../data/guest_avatar_einstein_32.png' |
|
| 55 | - ); |
|
| 56 | - self::assertEquals(trim($expectedFile), trim($avatar->getContent())); |
|
| 57 | - } |
|
| 43 | + /** |
|
| 44 | + * Asserts that testGet() returns the expected avatar. |
|
| 45 | + * |
|
| 46 | + * For the test a static name "einstein" is used and |
|
| 47 | + * the generated image is compared with an expected one. |
|
| 48 | + */ |
|
| 49 | + public function testGet(): void { |
|
| 50 | + $this->markTestSkipped('TODO: Disable because fails on drone'); |
|
| 51 | + $avatar = $this->guestAvatar->getFile(32); |
|
| 52 | + self::assertInstanceOf(InMemoryFile::class, $avatar); |
|
| 53 | + $expectedFile = file_get_contents( |
|
| 54 | + __DIR__ . '/../../data/guest_avatar_einstein_32.png' |
|
| 55 | + ); |
|
| 56 | + self::assertEquals(trim($expectedFile), trim($avatar->getContent())); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Asserts that "testIsCustomAvatar" returns false for guests. |
|
| 61 | - * |
|
| 62 | - * @return void |
|
| 63 | - */ |
|
| 64 | - public function testIsCustomAvatar(): void { |
|
| 65 | - self::assertFalse($this->guestAvatar->isCustomAvatar()); |
|
| 66 | - } |
|
| 59 | + /** |
|
| 60 | + * Asserts that "testIsCustomAvatar" returns false for guests. |
|
| 61 | + * |
|
| 62 | + * @return void |
|
| 63 | + */ |
|
| 64 | + public function testIsCustomAvatar(): void { |
|
| 65 | + self::assertFalse($this->guestAvatar->isCustomAvatar()); |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -20,76 +20,76 @@ |
||
| 20 | 20 | use Symfony\Component\Console\Output\OutputInterface; |
| 21 | 21 | |
| 22 | 22 | class Cleanup extends Base { |
| 23 | - private IAppData $appData; |
|
| 23 | + private IAppData $appData; |
|
| 24 | 24 | |
| 25 | - public function __construct( |
|
| 26 | - protected Manager $taskProcessingManager, |
|
| 27 | - private TaskMapper $taskMapper, |
|
| 28 | - private LoggerInterface $logger, |
|
| 29 | - IAppDataFactory $appDataFactory, |
|
| 30 | - ) { |
|
| 31 | - parent::__construct(); |
|
| 32 | - $this->appData = $appDataFactory->get('core'); |
|
| 33 | - } |
|
| 25 | + public function __construct( |
|
| 26 | + protected Manager $taskProcessingManager, |
|
| 27 | + private TaskMapper $taskMapper, |
|
| 28 | + private LoggerInterface $logger, |
|
| 29 | + IAppDataFactory $appDataFactory, |
|
| 30 | + ) { |
|
| 31 | + parent::__construct(); |
|
| 32 | + $this->appData = $appDataFactory->get('core'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - protected function configure() { |
|
| 36 | - $this |
|
| 37 | - ->setName('taskprocessing:task:cleanup') |
|
| 38 | - ->setDescription('cleanup old tasks') |
|
| 39 | - ->addArgument( |
|
| 40 | - 'maxAgeSeconds', |
|
| 41 | - InputArgument::OPTIONAL, |
|
| 42 | - // default is not defined as an argument default value because we want to show a nice "4 months" value |
|
| 43 | - 'delete tasks that are older than this number of seconds, defaults to ' . Manager::MAX_TASK_AGE_SECONDS . ' (4 months)', |
|
| 44 | - ); |
|
| 45 | - parent::configure(); |
|
| 46 | - } |
|
| 35 | + protected function configure() { |
|
| 36 | + $this |
|
| 37 | + ->setName('taskprocessing:task:cleanup') |
|
| 38 | + ->setDescription('cleanup old tasks') |
|
| 39 | + ->addArgument( |
|
| 40 | + 'maxAgeSeconds', |
|
| 41 | + InputArgument::OPTIONAL, |
|
| 42 | + // default is not defined as an argument default value because we want to show a nice "4 months" value |
|
| 43 | + 'delete tasks that are older than this number of seconds, defaults to ' . Manager::MAX_TASK_AGE_SECONDS . ' (4 months)', |
|
| 44 | + ); |
|
| 45 | + parent::configure(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 49 | - $maxAgeSeconds = $input->getArgument('maxAgeSeconds') ?? Manager::MAX_TASK_AGE_SECONDS; |
|
| 50 | - $output->writeln('<comment>Cleanup up tasks older than ' . $maxAgeSeconds . ' seconds and the related output files</comment>'); |
|
| 48 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 49 | + $maxAgeSeconds = $input->getArgument('maxAgeSeconds') ?? Manager::MAX_TASK_AGE_SECONDS; |
|
| 50 | + $output->writeln('<comment>Cleanup up tasks older than ' . $maxAgeSeconds . ' seconds and the related output files</comment>'); |
|
| 51 | 51 | |
| 52 | - $taskIdsToCleanup = []; |
|
| 53 | - try { |
|
| 54 | - $fileCleanupGenerator = $this->taskProcessingManager->cleanupTaskProcessingTaskFiles($maxAgeSeconds); |
|
| 55 | - foreach ($fileCleanupGenerator as $cleanedUpEntry) { |
|
| 56 | - $output->writeln( |
|
| 57 | - "<info>\t - " . 'Deleted appData/core/TaskProcessing/' . $cleanedUpEntry['file_name'] |
|
| 58 | - . ' (fileId: ' . $cleanedUpEntry['file_id'] . ', taskId: ' . $cleanedUpEntry['task_id'] . ')</info>' |
|
| 59 | - ); |
|
| 60 | - } |
|
| 61 | - $taskIdsToCleanup = $fileCleanupGenerator->getReturn(); |
|
| 62 | - } catch (\Exception $e) { |
|
| 63 | - $this->logger->warning('Failed to delete stale task processing tasks files', ['exception' => $e]); |
|
| 64 | - $output->writeln('<warning>Failed to delete stale task processing tasks files</warning>'); |
|
| 65 | - } |
|
| 66 | - try { |
|
| 67 | - $deletedTaskCount = $this->taskMapper->deleteOlderThan($maxAgeSeconds); |
|
| 68 | - foreach ($taskIdsToCleanup as $taskId) { |
|
| 69 | - $output->writeln("<info>\t - " . 'Deleted task ' . $taskId . ' from the database</info>'); |
|
| 70 | - } |
|
| 71 | - $output->writeln("<comment>\t - " . 'Deleted ' . $deletedTaskCount . ' tasks from the database</comment>'); |
|
| 72 | - } catch (\OCP\DB\Exception $e) { |
|
| 73 | - $this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]); |
|
| 74 | - $output->writeln('<warning>Failed to delete stale task processing tasks</warning>'); |
|
| 75 | - } |
|
| 76 | - try { |
|
| 77 | - $textToImageDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('text2image'), $maxAgeSeconds); |
|
| 78 | - foreach ($textToImageDeletedFileNames as $entry) { |
|
| 79 | - $output->writeln("<info>\t - " . 'Deleted appData/core/text2image/' . $entry . '</info>'); |
|
| 80 | - } |
|
| 81 | - } catch (NotFoundException $e) { |
|
| 82 | - // noop |
|
| 83 | - } |
|
| 84 | - try { |
|
| 85 | - $audioToTextDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('audio2text'), $maxAgeSeconds); |
|
| 86 | - foreach ($audioToTextDeletedFileNames as $entry) { |
|
| 87 | - $output->writeln("<info>\t - " . 'Deleted appData/core/audio2text/' . $entry . '</info>'); |
|
| 88 | - } |
|
| 89 | - } catch (NotFoundException $e) { |
|
| 90 | - // noop |
|
| 91 | - } |
|
| 52 | + $taskIdsToCleanup = []; |
|
| 53 | + try { |
|
| 54 | + $fileCleanupGenerator = $this->taskProcessingManager->cleanupTaskProcessingTaskFiles($maxAgeSeconds); |
|
| 55 | + foreach ($fileCleanupGenerator as $cleanedUpEntry) { |
|
| 56 | + $output->writeln( |
|
| 57 | + "<info>\t - " . 'Deleted appData/core/TaskProcessing/' . $cleanedUpEntry['file_name'] |
|
| 58 | + . ' (fileId: ' . $cleanedUpEntry['file_id'] . ', taskId: ' . $cleanedUpEntry['task_id'] . ')</info>' |
|
| 59 | + ); |
|
| 60 | + } |
|
| 61 | + $taskIdsToCleanup = $fileCleanupGenerator->getReturn(); |
|
| 62 | + } catch (\Exception $e) { |
|
| 63 | + $this->logger->warning('Failed to delete stale task processing tasks files', ['exception' => $e]); |
|
| 64 | + $output->writeln('<warning>Failed to delete stale task processing tasks files</warning>'); |
|
| 65 | + } |
|
| 66 | + try { |
|
| 67 | + $deletedTaskCount = $this->taskMapper->deleteOlderThan($maxAgeSeconds); |
|
| 68 | + foreach ($taskIdsToCleanup as $taskId) { |
|
| 69 | + $output->writeln("<info>\t - " . 'Deleted task ' . $taskId . ' from the database</info>'); |
|
| 70 | + } |
|
| 71 | + $output->writeln("<comment>\t - " . 'Deleted ' . $deletedTaskCount . ' tasks from the database</comment>'); |
|
| 72 | + } catch (\OCP\DB\Exception $e) { |
|
| 73 | + $this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]); |
|
| 74 | + $output->writeln('<warning>Failed to delete stale task processing tasks</warning>'); |
|
| 75 | + } |
|
| 76 | + try { |
|
| 77 | + $textToImageDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('text2image'), $maxAgeSeconds); |
|
| 78 | + foreach ($textToImageDeletedFileNames as $entry) { |
|
| 79 | + $output->writeln("<info>\t - " . 'Deleted appData/core/text2image/' . $entry . '</info>'); |
|
| 80 | + } |
|
| 81 | + } catch (NotFoundException $e) { |
|
| 82 | + // noop |
|
| 83 | + } |
|
| 84 | + try { |
|
| 85 | + $audioToTextDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('audio2text'), $maxAgeSeconds); |
|
| 86 | + foreach ($audioToTextDeletedFileNames as $entry) { |
|
| 87 | + $output->writeln("<info>\t - " . 'Deleted appData/core/audio2text/' . $entry . '</info>'); |
|
| 88 | + } |
|
| 89 | + } catch (NotFoundException $e) { |
|
| 90 | + // noop |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return 0; |
|
| 94 | - } |
|
| 93 | + return 0; |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -40,22 +40,22 @@ discard block |
||
| 40 | 40 | 'maxAgeSeconds', |
| 41 | 41 | InputArgument::OPTIONAL, |
| 42 | 42 | // default is not defined as an argument default value because we want to show a nice "4 months" value |
| 43 | - 'delete tasks that are older than this number of seconds, defaults to ' . Manager::MAX_TASK_AGE_SECONDS . ' (4 months)', |
|
| 43 | + 'delete tasks that are older than this number of seconds, defaults to '.Manager::MAX_TASK_AGE_SECONDS.' (4 months)', |
|
| 44 | 44 | ); |
| 45 | 45 | parent::configure(); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | protected function execute(InputInterface $input, OutputInterface $output): int { |
| 49 | 49 | $maxAgeSeconds = $input->getArgument('maxAgeSeconds') ?? Manager::MAX_TASK_AGE_SECONDS; |
| 50 | - $output->writeln('<comment>Cleanup up tasks older than ' . $maxAgeSeconds . ' seconds and the related output files</comment>'); |
|
| 50 | + $output->writeln('<comment>Cleanup up tasks older than '.$maxAgeSeconds.' seconds and the related output files</comment>'); |
|
| 51 | 51 | |
| 52 | 52 | $taskIdsToCleanup = []; |
| 53 | 53 | try { |
| 54 | 54 | $fileCleanupGenerator = $this->taskProcessingManager->cleanupTaskProcessingTaskFiles($maxAgeSeconds); |
| 55 | 55 | foreach ($fileCleanupGenerator as $cleanedUpEntry) { |
| 56 | 56 | $output->writeln( |
| 57 | - "<info>\t - " . 'Deleted appData/core/TaskProcessing/' . $cleanedUpEntry['file_name'] |
|
| 58 | - . ' (fileId: ' . $cleanedUpEntry['file_id'] . ', taskId: ' . $cleanedUpEntry['task_id'] . ')</info>' |
|
| 57 | + "<info>\t - ".'Deleted appData/core/TaskProcessing/'.$cleanedUpEntry['file_name'] |
|
| 58 | + . ' (fileId: '.$cleanedUpEntry['file_id'].', taskId: '.$cleanedUpEntry['task_id'].')</info>' |
|
| 59 | 59 | ); |
| 60 | 60 | } |
| 61 | 61 | $taskIdsToCleanup = $fileCleanupGenerator->getReturn(); |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | try { |
| 67 | 67 | $deletedTaskCount = $this->taskMapper->deleteOlderThan($maxAgeSeconds); |
| 68 | 68 | foreach ($taskIdsToCleanup as $taskId) { |
| 69 | - $output->writeln("<info>\t - " . 'Deleted task ' . $taskId . ' from the database</info>'); |
|
| 69 | + $output->writeln("<info>\t - ".'Deleted task '.$taskId.' from the database</info>'); |
|
| 70 | 70 | } |
| 71 | - $output->writeln("<comment>\t - " . 'Deleted ' . $deletedTaskCount . ' tasks from the database</comment>'); |
|
| 71 | + $output->writeln("<comment>\t - ".'Deleted '.$deletedTaskCount.' tasks from the database</comment>'); |
|
| 72 | 72 | } catch (\OCP\DB\Exception $e) { |
| 73 | 73 | $this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]); |
| 74 | 74 | $output->writeln('<warning>Failed to delete stale task processing tasks</warning>'); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | try { |
| 77 | 77 | $textToImageDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('text2image'), $maxAgeSeconds); |
| 78 | 78 | foreach ($textToImageDeletedFileNames as $entry) { |
| 79 | - $output->writeln("<info>\t - " . 'Deleted appData/core/text2image/' . $entry . '</info>'); |
|
| 79 | + $output->writeln("<info>\t - ".'Deleted appData/core/text2image/'.$entry.'</info>'); |
|
| 80 | 80 | } |
| 81 | 81 | } catch (NotFoundException $e) { |
| 82 | 82 | // noop |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | try { |
| 85 | 85 | $audioToTextDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('audio2text'), $maxAgeSeconds); |
| 86 | 86 | foreach ($audioToTextDeletedFileNames as $entry) { |
| 87 | - $output->writeln("<info>\t - " . 'Deleted appData/core/audio2text/' . $entry . '</info>'); |
|
| 87 | + $output->writeln("<info>\t - ".'Deleted appData/core/audio2text/'.$entry.'</info>'); |
|
| 88 | 88 | } |
| 89 | 89 | } catch (NotFoundException $e) { |
| 90 | 90 | // noop |