46 use Slim\Psr7\Factory\StreamFactory;
47 use Slim\Psr7\Headers;
48 use Slim\Psr7\Request;
51 function TryToDelete($uploadpk, $user_pk, $group_pk, $uploadDao)
54 $group_pk, $uploadDao);
162 private $copyrightPlugin;
167 private $downloadPlugin;
178 $container = M::mock(
'ContainerBuilder');
179 self::$functions = M::mock();
180 $this->dbHelper = M::mock(DbHelper::class);
181 $this->
dbManager = M::mock(DbManager::class);
182 $this->restHelper = M::mock(RestHelper::class);
183 $this->uploadDao = M::mock(UploadDao::class);
184 $this->folderDao = M::mock(FolderDao::class);
185 $this->agentDao = M::mock(AgentDao::class);
186 $this->userDao = M::mock(UserDao::class);
187 $this->clearingDao = M::mock(ClearingDao::class);
188 $this->licenseDao = M::mock(LicenseDao::class);
189 $this->reuseReportProcess = M::mock(ReuseReportProcessor::class);
190 $this->uploadPermissionDao = M::mock(UploadPermissionDao::class);
191 $this->downloadPlugin = M::mock(
"download");
193 $this->
dbManager->shouldReceive(
'getSingleRow')
194 ->withArgs([M::any(), [$this->groupId, UploadStatus::OPEN,
196 $this->dbHelper->shouldReceive(
'getDbManager')->andReturn($this->
dbManager);
198 $this->restHelper->shouldReceive(
'getDbHelper')->andReturn($this->dbHelper);
199 $this->restHelper->shouldReceive(
'getGroupId')->andReturn($this->groupId);
200 $this->restHelper->shouldReceive(
'getUserId')->andReturn($this->userId);
201 $this->restHelper->shouldReceive(
'getPlugin')->withArgs(array(
"download"))->andReturn($this->downloadPlugin);
202 $this->restHelper->shouldReceive(
'getUploadDao')
203 ->andReturn($this->uploadDao);
204 $this->restHelper->shouldReceive(
'getFolderDao')
205 ->andReturn($this->folderDao);
206 $this->restHelper->shouldReceive(
'getUserDao')
207 ->andReturn($this->userDao);
208 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn(
210 $container->shouldReceive(
'get')->withArgs(array(
211 'dao.clearing'))->andReturn($this->clearingDao);
212 $container->shouldReceive(
'get')->withArgs(array(
213 'helper.restHelper'))->andReturn($this->restHelper);
214 $container->shouldReceive(
'get')->withArgs(array(
215 'dao.agent'))->andReturn($this->agentDao);
216 $container->shouldReceive(
'get')->withArgs(array(
217 'dao.upload'))->andReturn($this->uploadDao);
218 $container->shouldReceive(
'get')->withArgs(
219 [
'db.manager'])->andReturn($this->
dbManager);
220 $container->shouldReceive(
'get')->withArgs(array(
'dao.license'))->andReturn($this->licenseDao);
221 $container->shouldReceive(
'get')->withArgs(array(
222 'businessrules.reusereportprocessor'))->andReturn($this->reuseReportProcess);
224 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
225 $this->streamFactory =
new StreamFactory();
234 $this->addToAssertionCount(
235 \Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
247 $response->getBody()->seek(0);
248 return json_decode($response->getBody()->getContents(),
true);
261 $itemId = ($id * 100) + 1;
262 $left = ($id * 100) + 2;
263 $right = ($id * 100) + 50;
264 return new ItemTreeBounds($itemId,
'uploadtree_a', $id, $left, $right);
282 $uploadName =
"top$id";
283 $uploadDate =
"01-01-2020";
287 $uploadName =
"child$id";
288 $uploadDate =
"02-01-2020";
292 $uploadName =
"child$id";
293 $uploadDate =
"03-01-2020";
299 $hash =
new Hash(
'sha1checksum',
'md5checksum',
'sha256checksum', $fileSize);
300 return new Upload($folderId, $folderName, $id, $description,
301 $uploadName, $uploadDate,
null, $hash);
339 $requestHeaders =
new Headers();
340 $body = $this->streamFactory->createStream();
341 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
342 "/uploads/$uploadId"), $requestHeaders, [], [], $body);
343 if ($version == ApiVersion::V2) {
344 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
347 $this->dbHelper->shouldReceive(
'doesIdExist')
348 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
349 $this->uploadDao->shouldReceive(
'isAccessible')
350 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
351 $this->uploadDao->shouldReceive(
'getParentItemBounds')
353 $this->dbHelper->shouldReceive(
'getUploads')
354 ->withArgs([$this->userId, $this->groupId, 100, 1, $uploadId, $options,
355 true, $version])->andReturn([1, [$upload->getArray()]]);
356 $expectedResponse = (
new ResponseHelper())->withJson($upload->getArray(), 200);
357 $actualResponse = $this->uploadController->getUploads($request,
359 $this->assertEquals($expectedResponse->getStatusCode(),
360 $actualResponse->getStatusCode());
373 $requestHeaders =
new Headers();
374 $body = $this->streamFactory->createStream();
375 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
376 "/uploads/$uploadId"), $requestHeaders, [], [], $body);
377 $this->dbHelper->shouldReceive(
'doesIdExist')
378 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
379 $this->uploadDao->shouldReceive(
'isAccessible')
380 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
381 $this->expectException(HttpForbiddenException::class);
383 $this->uploadController->getUploads($request,
new ResponseHelper(),
384 [
'id' => $uploadId]);
396 $this->testGetUploadWithFilters(ApiVersion::V1);
407 $this->testGetUploadWithFilters(ApiVersion::V2);
410 private function testGetUploadWithFilters($version)
422 $folderOptions = $options;
423 $folderOptions[
"folderId"] = $folderId;
424 $requestHeaders =
new Headers();
425 $body = $this->streamFactory->createStream();
426 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
428 $requestHeaders, [], [], $body);
429 if ($version == ApiVersion::V2) {
430 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
433 $this->folderDao->shouldReceive(
'isFolderAccessible')
434 ->withArgs([$folderId, $this->userId])->andReturn(
true)->once();
435 $this->dbHelper->shouldReceive(
'getUploads')
436 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $folderOptions,
437 true, $version])->andReturn([1, []])->once();
438 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
442 $nameOptions = $options;
443 $nameOptions[
"name"] = $name;
444 $requestHeaders =
new Headers();
445 $body = $this->streamFactory->createStream();
446 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
449 if ($version == ApiVersion::V2) {
450 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
453 $this->dbHelper->shouldReceive(
'getUploads')
454 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $nameOptions,
455 true, $version])->andReturn([1, []])->once();
456 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
459 $statusString =
"InProgress";
460 $status = UploadStatus::IN_PROGRESS;
461 $statusOptions = $options;
462 $statusOptions[
"status"] = $status;
463 $requestHeaders =
new Headers();
464 $body = $this->streamFactory->createStream();
465 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
467 $requestHeaders, [], [], $body);
468 if ($version == ApiVersion::V2) {
469 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
472 $this->dbHelper->shouldReceive(
'getUploads')
473 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $statusOptions,
474 true, $version])->andReturn([1, []])->once();
475 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
479 $assigneeOptions = $options;
481 $requestHeaders =
new Headers();
482 $body = $this->streamFactory->createStream();
483 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
485 $requestHeaders, [], [], $body);
486 if ($version == ApiVersion::V2) {
487 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
490 $this->dbHelper->shouldReceive(
'getUploads')
491 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $assigneeOptions,
492 true, $version])->andReturn([1, []])->once();
493 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
496 $since =
"2021-02-28";
497 $sinceOptions = $options;
498 $sinceOptions[
"since"] = strtotime($since);
499 $requestHeaders =
new Headers();
500 $body = $this->streamFactory->createStream();
501 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
503 $requestHeaders, [], [], $body);
504 if ($version == ApiVersion::V2) {
505 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
508 $this->dbHelper->shouldReceive(
'getUploads')
509 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $sinceOptions,
510 true, $version])->andReturn([1, []])->once();
511 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
514 $statusString =
"Open";
515 $status = UploadStatus::OPEN;
516 $since =
"2021-02-28";
517 $combOptions = $options;
518 $combOptions[
"since"] = strtotime($since);
519 $combOptions[
"status"] = $status;
520 $requestHeaders =
new Headers();
521 $body = $this->streamFactory->createStream();
522 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
525 $requestHeaders, [], [], $body);
526 if ($version == ApiVersion::V2) {
527 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
530 $this->dbHelper->shouldReceive(
'getUploads')
531 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $combOptions,
532 true, $version])->andReturn([1, []])->once();
533 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
542 $this->testGetUploads(ApiVersion::V1);
550 $this->testGetUploads(ApiVersion::V2);
552 private function testGetUploads($version)
566 $requestHeaders =
new Headers();
567 $body = $this->streamFactory->createStream();
568 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
569 "/uploads/"), $requestHeaders, [], [], $body);
570 if ($version == ApiVersion::V2) {
571 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
574 $this->dbHelper->shouldReceive(
'getUploads')
575 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $options,
true, $version])
576 ->andReturn([1, $uploads]);
577 $expectedResponse = (
new ResponseHelper())->withJson($uploads, 200);
578 $actualResponse = $this->uploadController->getUploads($request,
580 $this->assertEquals($expectedResponse->getStatusCode(),
581 $actualResponse->getStatusCode());
595 $requestHeaders =
new Headers();
596 $body = $this->streamFactory->createStream();
597 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
598 "/uploads/"), $requestHeaders, [], [], $body);
599 $this->dbHelper->shouldReceive(
'doesIdExist')
600 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
601 $this->uploadDao->shouldReceive(
'isAccessible')
602 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
603 $this->uploadDao->shouldReceive(
'getParentItemBounds')
604 ->withArgs([$uploadId])->andReturn(
false);
605 $this->expectException(HttpServiceUnavailableException::class);
607 $this->uploadController->getUploads($request,
new ResponseHelper(),
608 [
'id' => $uploadId]);
638 $info =
new Info(202,
"Upload $uploadId will be copied to folder $folderId",
641 $this->restHelper->shouldReceive(
'copyUpload')
642 ->withArgs([$uploadId, $folderId,
true])->andReturn($info);
643 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
646 $requestHeaders =
new Headers();
647 $body = $this->streamFactory->createStream();
649 if($version==ApiVersion::V1){
650 $requestHeaders->setHeader(
'folderId', $folderId);
651 $requestHeaders->setHeader(
'action',
'copy');
652 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
653 $requestHeaders, [], [], $body);
654 $actualResponse = $this->uploadController->moveUpload($request,
658 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
659 $requestHeaders, [], [], $body);
660 if ($version == ApiVersion::V2) {
661 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
664 $actualResponse = $this->uploadController->moveUpload($request->withUri($request->getUri()->withQuery(
"folderId=$folderId&action=copy")),
667 $this->assertEquals($expectedResponse->getStatusCode(),
668 $actualResponse->getStatusCode());
702 $requestHeaders =
new Headers();
703 $requestHeaders->setHeader(
'folderId',
'alpha');
704 $requestHeaders->setHeader(
'action',
'move');
705 $body = $this->streamFactory->createStream();
706 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
707 $requestHeaders, [], [], $body);
708 if ($version==ApiVersion::V2) {
709 $request = $request->withQueryParams([
'folderId' =>
'alpha',
'action' =>
'move']);
711 $request = $request->withHeader(
"folderId",
"alpha")
712 ->withHeader(
"action",
"move");
714 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
715 $this->expectException(HttpBadRequestException::class);
717 $this->uploadController->moveUpload($request,
new ResponseHelper(),
718 [
'id' => $uploadId]);
753 $uploadDescription =
"Test Upload";
755 $requestHeaders =
new Headers();
756 $requestHeaders->setHeader(
'Content-Type',
'application/json');
757 if ($version == ApiVersion::V2) {
759 "location" =>
"data",
760 "folderId" => $folderId,
761 "uploadDescription" => $uploadDescription,
762 "ignoreScm" =>
"true",
763 "scanOptions" =>
"scanOptions",
764 "uploadType" =>
"vcs"
768 "location" =>
"data",
769 "scanOptions" =>
"scanOptions"
771 $requestHeaders->setHeader(
'folderId', $folderId);
772 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
773 $requestHeaders->setHeader(
'ignoreScm',
'true');
774 $requestHeaders->setHeader(
'Content-Type',
'application/json');
775 $requestHeaders->setHeader(
'uploadType',
'vcs');
779 $body = $this->streamFactory->createStream(json_encode(
782 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
783 $requestHeaders, [], [], $body);
784 if ($version == ApiVersion::V2) {
785 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
788 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
789 $uploadHelper->shouldReceive(
'createNewUpload')
790 ->withArgs([$reqBody[
"location"], $folderId, $uploadDescription,
'protected',
'true',
792 ->andReturn([
true,
'',
'', $uploadId]);
794 $info =
new Info(201, intval(20), InfoType::INFO);
796 $uploadHelper->shouldReceive(
'handleScheduleAnalysis')->withArgs([$uploadId,$folderId,$reqBody[
"scanOptions"],
false])
799 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
800 $this->folderDao->shouldReceive(
'isFolderAccessible')
801 ->withArgs([$folderId])->andReturn(
true);
803 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
805 $actualResponse = $this->uploadController->postUpload($request,
807 $this->assertEquals($expectedResponse->getStatusCode(),
808 $actualResponse->getStatusCode());
844 $uploadDescription =
"Test Upload";
846 $requestHeaders =
new Headers();
847 $requestHeaders->setHeader(
'Content-type',
'application/json');
848 if ($version == ApiVersion::V2) {
849 $body = $this->streamFactory->createStream(json_encode([
850 "location" =>
"data",
851 "folderId" => $folderId,
852 "uploadDescription" => $uploadDescription,
853 "ignoreScm" =>
"true",
854 "scanOptions" =>
"scanOptions",
855 "uploadType" =>
"vcs"
858 $body = $this->streamFactory->createStream(json_encode([
859 "location" =>
"data",
860 "scanOptions" =>
"scanOptions"
862 $requestHeaders->setHeader(
'folderId', $folderId);
863 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
864 $requestHeaders->setHeader(
'ignoreScm',
'true');
865 $requestHeaders->setHeader(
'Content-Type',
'application/json');
866 $requestHeaders->setHeader(
'uploadType',
'vcs');
868 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
869 $requestHeaders, [], [], $body);
870 if ($version == ApiVersion::V2) {
871 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
875 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
877 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
878 $this->folderDao->shouldReceive(
'isFolderAccessible')
879 ->withArgs([$folderId])->andReturn(
false);
880 $this->expectException(HttpForbiddenException::class);
882 $this->uploadController->postUpload($request,
new ResponseHelper(),
917 $uploadDescription =
"Test Upload";
919 $requestHeaders =
new Headers();
920 $requestHeaders->setHeader(
'Content-type',
'application/json');
921 if ($version == ApiVersion::V2) {
922 $body = $this->streamFactory->createStream(json_encode([
923 "location" =>
"vcsData",
924 "folderId" => $folderId,
925 "uploadDescription" => $uploadDescription,
926 "ignoreScm" =>
"true",
927 "scanOptions" =>
"scanOptions",
928 "uploadType" =>
"vcs"
931 $body = $this->streamFactory->createStream(json_encode([
932 "location" =>
"vcsData",
933 "scanOptions" =>
"scanOptions"
935 $requestHeaders->setHeader(
'folderId', $folderId);
936 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
937 $requestHeaders->setHeader(
'ignoreScm',
'true');
938 $requestHeaders->setHeader(
'Content-Type',
'application/json');
939 $requestHeaders->setHeader(
'uploadType',
'vcs');
941 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
942 $requestHeaders, [], [], $body);
943 if ($version == ApiVersion::V2) {
944 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
948 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
950 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
951 $this->expectException(HttpNotFoundException::class);
953 $this->uploadController->postUpload($request,
new ResponseHelper(),
988 $uploadDescription =
"Test Upload";
989 $errorMessage =
"Failed to insert upload record";
993 $requestHeaders =
new Headers();
994 $requestHeaders->setHeader(
'Content-type',
'application/json');
995 if ($version == ApiVersion::V2) {
996 $body = $this->streamFactory->createStream(json_encode([
997 "location" =>
"vcsData",
998 "folderId" => $folderId,
999 "uploadDescription" => $uploadDescription,
1000 "ignoreScm" =>
"true",
1001 "scanOptions" =>
"scanOptions",
1002 "uploadType" =>
"vcs"
1005 $body = $this->streamFactory->createStream(json_encode([
1006 "location" =>
"vcsData",
1007 "scanOptions" =>
"scanOptions"
1009 $requestHeaders->setHeader(
'folderId', $folderId);
1010 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
1011 $requestHeaders->setHeader(
'ignoreScm',
'true');
1012 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1013 $requestHeaders->setHeader(
'uploadType',
'vcs');
1016 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1017 $requestHeaders, [], [], $body);
1018 if ($version == ApiVersion::V2) {
1019 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
1023 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
1024 $uploadHelper->shouldReceive(
'createNewUpload')
1025 ->withArgs([
'vcsData', $folderId, $uploadDescription,
'protected',
'true',
1027 ->andReturn([
false, $errorMessage, $errorDesc, [-1]]);
1029 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
1030 $this->folderDao->shouldReceive(
'isFolderAccessible')
1031 ->withArgs([$folderId])->andReturn(
true);
1032 $this->expectException(HttpInternalServerErrorException::class);
1034 $this->uploadController->postUpload($request,
new ResponseHelper(), []);
1046 $this->testGetUploadLicenses(ApiVersion::V1);
1057 $this->testGetUploadLicenses(ApiVersion::V2);
1059 private function testGetUploadLicenses($version)
1063 [
'agentName' =>
'nomos',
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1064 [
'agentName' =>
'monk',
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1066 $licenseResponse = [
1067 [
'filePath' =>
'filea',
'agentFindings' =>
'MIT',
'conclusions' =>
'MIT'],
1068 [
'filePath' =>
'fileb',
'agentFindings' =>
'MIT',
1069 'conclusions' =>
'No_license_found']
1072 $requestHeaders =
new Headers();
1073 $body = $this->streamFactory->createStream();
1074 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1076 "=nomos,monk&containers=false"),
1077 $requestHeaders, [], [], $body);
1078 if ($version == ApiVersion::V2) {
1079 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
1082 $this->dbHelper->shouldReceive(
'doesIdExist')
1083 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1084 $this->uploadDao->shouldReceive(
'isAccessible')
1085 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1086 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1087 ->withArgs([$uploadId])->andReturn($this->
getUploadBounds($uploadId));
1088 $this->agentDao->shouldReceive(
'arsTableExists')
1089 ->withArgs([M::anyOf(
'nomos',
'monk')])->andReturn(
true);
1091 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1092 $scanJobProxy->shouldReceive(
'createAgentStatus')
1093 ->withArgs([[
'nomos',
'monk']])
1094 ->andReturn($agentsRun);
1096 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
1097 $uploadHelper->shouldReceive(
'getUploadLicenseList')
1098 ->withArgs([$uploadId, [
'nomos',
'monk'],
false,
true,
false, 0, 50, $version])
1099 ->andReturn(([[$licenseResponse], 1]));
1101 $expectedResponse = (
new ResponseHelper())->withJson($licenseResponse, 200);
1103 $actualResponse = $this->uploadController->getUploadLicenses($request,
1105 $this->assertEquals($expectedResponse->getStatusCode(),
1106 $actualResponse->getStatusCode());
1109 $this->assertEquals(
'1',
1110 $actualResponse->getHeaderLine(
'X-Total-Pages'));
1145 [
'agentName' =>
'nomos',
'currentAgentId' => 2,
'isAgentRunning' =>
true],
1146 [
'agentName' =>
'monk',
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1149 $requestHeaders =
new Headers();
1150 $body = $this->streamFactory->createStream();
1151 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1153 "=nomos,monk&containers=false"),
1154 $requestHeaders, [], [], $body);
1155 if ($version == ApiVersion::V2) {
1156 $request = $request->withQueryParams([
'page' => 1,
'limit' => 2,
"agent" =>
"nomos,monk" ]);
1158 $request = $request->withHeader(
"limit",2)
1159 ->withHeader(
"page",1);
1161 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
1163 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1164 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agentsRun]);
1165 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1166 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1167 $this->dbHelper->shouldReceive(
'doesIdExist')
1168 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1169 $this->uploadDao->shouldReceive(
'isAccessible')
1170 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1171 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1172 ->withArgs([$uploadId])->andReturn($this->
getUploadBounds($uploadId));
1173 $this->agentDao->shouldReceive(
'arsTableExists')
1174 ->withArgs([M::anyOf(
'nomos',
'monk')])->andReturn(
true);
1176 $scanJobProxy->shouldReceive(
'createAgentStatus')
1177 ->withArgs([[
'nomos',
'monk']])
1178 ->andReturn($agentsRun);
1179 $this->expectException(HttpServiceUnavailableException::class);
1181 $this->uploadController->getUploadLicenses($request,
new ResponseHelper(),
1182 [
'id' => $uploadId]);
1194 $status = UploadStatus::REJECTED;
1195 $comment =
"Not helpful";
1197 $resource = fopen(
'data://text/plain;base64,' .
1198 base64_encode($comment),
'r+');
1199 $body = $this->streamFactory->createStreamFromResource($resource);
1200 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1203 new Headers(), [], [], $body);
1205 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
1206 ->withArgs([$this->userId, $this->groupId])
1208 $this->userDao->shouldReceive(
'getUserChoices')
1209 ->withArgs([$this->groupId])
1210 ->andReturn([$this->userId =>
"fossy", $assignee =>
"friendly-fossy"]);
1211 $this->
dbManager->shouldReceive(
'getSingleRow')
1212 ->withArgs([M::any(), [$assignee, $this->groupId, $upload], M::any()]);
1213 $this->
dbManager->shouldReceive(
'getSingleRow')
1214 ->withArgs([M::any(), [$status, $comment, $this->groupId, $upload],
1216 $this->
dbManager->shouldReceive(
'getSingleRow')
1217 ->withArgs([M::any(), [$upload], M::any()])
1218 ->andReturn([
"exists" =>
""]);
1220 $info =
new Info(202,
"Upload updated successfully.", InfoType::INFO);
1221 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
1223 $actualResponse = $this->uploadController->updateUpload($request,
1225 $this->assertEquals($expectedResponse->getStatusCode(),
1226 $actualResponse->getStatusCode());
1240 $comment =
"Not helpful";
1242 $resource = fopen(
'data://text/plain;base64,' .
1243 base64_encode($comment),
'r+');
1244 $body = $this->streamFactory->createStreamFromResource($resource);
1245 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1248 new Headers(), [], [], $body);
1250 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
1251 ->withArgs([$this->userId, $this->groupId])
1253 $this->expectException(HttpForbiddenException::class);
1255 $this->uploadController->updateUpload($request,
new ResponseHelper(),
1267 $licenseIds = array();
1269 $licenseIds[$licenseId] = $licenseId;
1270 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
1273 $this->uploadDao->shouldReceive(
'isAccessible')
1274 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1275 $this->dbHelper->shouldReceive(
'doesIdExist')
1276 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1277 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1278 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
false])->andReturn([]);
1279 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
true])->andReturn([]);
1280 $this->licenseDao->shouldReceive(
'getLicenseById')->withArgs([$licenseId])->andReturn($license);
1282 $licenses[] = $license->getArray();
1283 $expectedResponse = (
new ResponseHelper())->withJson($licenses, 200);
1284 $actualResponse = $this->uploadController->getMainLicenses(
null,
new ResponseHelper(), [
'id' => $uploadId]);
1285 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
1301 "shortName" => $shortName,
1303 $license =
new License(2, $shortName,
"MIT License",
"risk",
"texts", [],
1305 $licenseIds[$licenseId] = $licenseId;
1306 $this->uploadDao->shouldReceive(
'isAccessible')
1307 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1308 $this->dbHelper->shouldReceive(
'doesIdExist')
1309 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1310 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1311 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1312 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1313 $this->clearingDao->shouldReceive(
'makeMainLicense')
1314 ->withArgs([$uploadId, $this->groupId, $license->getId()])->andReturn(
null);
1316 $info =
new Info(200,
"Successfully added new main license", InfoType::INFO);
1318 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1319 $reqBody = $this->streamFactory->createStream(json_encode(
1322 $requestHeaders =
new Headers();
1323 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1324 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1325 $requestHeaders, [], [], $reqBody);
1327 $actualResponse = $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1329 $this->assertEquals($expectedResponse->getStatusCode(),
1330 $actualResponse->getStatusCode());
1346 "shortName" => $shortName,
1348 $license =
new License($licenseId, $shortName,
"MIT License",
"risk",
"texts", [],
1350 $licenseIds[$licenseId] = $licenseId;
1351 $this->uploadDao->shouldReceive(
'isAccessible')
1352 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1353 $this->dbHelper->shouldReceive(
'doesIdExist')
1354 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1355 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1356 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1357 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1358 $this->clearingDao->shouldReceive(
'makeMainLicense')
1359 ->withArgs([$uploadId, $this->groupId, $license->getId()])->andReturn(
null);
1361 $reqBody = $this->streamFactory->createStream(json_encode(
1364 $requestHeaders =
new Headers();
1365 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1366 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1367 $requestHeaders, [], [], $reqBody);
1368 $this->expectException(HttpBadRequestException::class);
1370 $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1384 $license =
new License($licenseId, $shortName,
"MIT License",
"risk",
"texts", [],
1386 $licenseIds[$licenseId] = $licenseId;
1388 $this->uploadDao->shouldReceive(
'isAccessible')
1389 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1390 $this->dbHelper->shouldReceive(
'doesIdExist')
1391 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1392 $this->dbHelper->shouldReceive(
'doesIdExist')
1393 ->withArgs([
"license_ref",
"rf_pk", $licenseId])->andReturn(
true);
1394 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1396 $this->clearingDao->shouldReceive(
'removeMainLicense')->withArgs([$uploadId, $this->groupId, $licenseId])->andReturn(
null);
1397 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1398 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1400 $info =
new Info(200,
"Main license removed successfully.", InfoType::INFO);
1401 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
1403 $actualResponse = $this->uploadController->removeMainLicense(
null,
1404 new ResponseHelper(), [
'id' => $uploadId,
'shortName' => $shortName]);
1405 $this->assertEquals($expectedResponse->getStatusCode(),
1406 $actualResponse->getStatusCode());
1419 $this->uploadDao->shouldReceive(
'isAccessible')
1420 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1421 $this->dbHelper->shouldReceive(
'doesIdExist')
1422 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1423 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1424 $this->uploadDao->shouldReceive(
"getGlobalDecisionSettingsFromInfo")->andReturn(
false);
1425 $this->agentDao->shouldReceive(
"arsTableExists")->andReturn(
true);
1426 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->andReturn([[
'agent_id' => 1,
'agent_rev' => 1]]);
1427 $this->agentDao->shouldReceive(
"getCurrentAgentRef")->andReturn(
new AgentRef(1,
"agent", 1));
1428 $this->
dbManager->shouldReceive(
"getSingleRow")
1429 ->withArgs([M::any(), [],
'no_license_uploadtree' . $uploadId])
1430 ->andReturn([
'count' => 1]);
1431 $this->
dbManager->shouldReceive(
"getSingleRow")
1432 ->withArgs([M::any(), [],
'already_cleared_uploadtree' . $uploadId])
1433 ->andReturn([
'count' => 0]);
1434 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1435 ->withArgs([
'No_license_found'])->andReturn(
null);
1436 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1437 ->withArgs([
'Void'])->andReturn(
null);
1439 "totalFilesOfInterest" => 1,
1440 "totalFilesCleared" => 1,
1443 $actualResponse = $this->uploadController->getClearingProgressInfo(
null,
1445 $this->assertEquals($expectedResponse->getStatusCode(),
1446 $actualResponse->getStatusCode());
1458 $reuseReportSummary = [
1459 'declearedLicense' =>
"",
1460 'clearedLicense' =>
"MIT, BSD-3-Clause",
1461 'usedLicense' =>
"",
1462 'unusedLicense' =>
"",
1463 'missingLicense' =>
"MIT, BSD-3-Clause",
1465 $this->uploadDao->shouldReceive(
'isAccessible')
1466 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1467 $this->dbHelper->shouldReceive(
'doesIdExist')
1468 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1469 $this->reuseReportProcess->shouldReceive(
'getReuseSummary')
1470 ->withArgs([$uploadId])->andReturn($reuseReportSummary);
1472 $expectedResponse = (
new ResponseHelper())->withJson($reuseReportSummary,
1474 $actualResponse = $this->uploadController->getReuseReportSummary(
1476 $this->assertEquals($expectedResponse->getStatusCode(),
1477 $actualResponse->getStatusCode());
1495 $this->uploadDao->shouldReceive(
'isAccessible')
1496 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1497 $this->dbHelper->shouldReceive(
'doesIdExist')
1498 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1500 $this->restHelper->shouldReceive(
'getUploadPermissionDao')->andReturn($this->uploadPermissionDao);
1501 $this->uploadPermissionDao->shouldReceive(
"getPublicPermission")->withAnyArgs()->andReturn($publicPerm);
1502 $this->uploadPermissionDao->shouldReceive(
"getPermissionGroups")->withAnyArgs()->andReturn([]);
1503 $this->restHelper->shouldReceive(
"getGroupId")->andReturn($this->groupId);
1504 $this->restHelper->shouldReceive(
"getUserId")->andReturn($this->userId);
1505 $this->restHelper->shouldReceive(
"getUploadDao")->andReturn($this->uploadDao);
1507 $body = $this->streamFactory->createStream();
1508 $requestHeaders =
new Headers();
1509 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1510 $requestHeaders, [], [], $body);
1512 $actualResponse = $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1513 $this->assertEquals(200,$actualResponse->getStatusCode());
1526 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1528 $this->dbHelper->shouldReceive(
'doesIdExist')
1529 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1530 $body = $this->streamFactory->createStream();
1531 $requestHeaders =
new Headers();
1532 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1533 $requestHeaders, [], [], $body);
1535 $this->expectException(HttpNotFoundException::class);
1536 $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1548 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1549 $this->uploadDao->shouldReceive(
'isAccessible')->withAnyArgs()->andReturn(
false);
1551 $body = $this->streamFactory->createStream();
1552 $requestHeaders =
new Headers();
1553 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1554 $requestHeaders, [], [], $body);
1556 $this->expectException(HttpForbiddenException::class);
1557 $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1570 [
"uploadId" => $uploadId,
'agentName' =>
'nomos',
'successfulAgents'=> [],
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1571 [
"uploadId" => $uploadId,
'agentName' =>
'monk',
"successfulAgents" => [],
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1574 $this->restHelper->shouldReceive(
"getGroupId")->andReturn(
$groupId);
1575 $this->agentDao->shouldReceive(
"getCurrentAgentRef")->withAnyArgs()->andReturn(
new AgentRef($uploadId,
"momoa",45));
1577 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1578 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1579 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1580 $scanJobProxy->shouldReceive(
'createAgentStatus')
1582 ->andReturn($agentsRun);
1583 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1584 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agentsRun]);
1585 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1587 $body = $this->streamFactory->createStream();
1588 $requestHeaders =
new Headers();
1589 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1590 $requestHeaders, [], [], $body);
1592 $actualResponse = $this->uploadController->getAllAgents($request,
new ResponseHelper(),[
"id"=>$uploadId]);
1593 $this->assertEquals(200,$actualResponse->getStatusCode());
1605 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1606 $this->dbHelper->shouldReceive(
'doesIdExist')
1607 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1609 $this->expectException(HttpNotFoundException::class);
1610 $this->uploadController->getAllAgents(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1623 $this->uploadDao->shouldReceive(
'isAccessible')
1624 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
1625 $this->dbHelper->shouldReceive(
'doesIdExist')
1626 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1628 $this->expectException(HttpForbiddenException::class);
1629 $this->uploadController->getAllAgents(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1643 $uploadName =
"Testing name";
1644 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1646 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1647 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1648 $this->restHelper->shouldReceive(
'getUploadDao')->andReturn($this->uploadDao);
1649 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withAnyArgs()->andReturn($uploadName);
1650 $this->clearingDao->shouldReceive(
"getClearedLicenseIdAndMultiplicities")->withAnyArgs()->andReturn([]);
1652 $actualResponse = $this->uploadController->getEditedLicenses(
null,
new ResponseHelper(),[
"id"=>
$groupId]);
1653 $this->assertEquals(200,$actualResponse->getStatusCode());
1666 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1668 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1669 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1671 $this->expectException(HttpNotFoundException::class);
1685 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1687 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
false);
1688 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1690 $this->expectException(HttpForbiddenException::class);
1703 $this->uploadDao->shouldReceive(
'isAccessible')
1704 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1705 $this->dbHelper->shouldReceive(
'doesIdExist')
1706 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1708 $body = $this->streamFactory->createStream();
1709 $requestHeaders =
new Headers();
1710 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1711 $requestHeaders, [], [], $body);
1713 $this->expectException(HttpNotFoundException::class);
1714 $this->uploadController->getScannedLicenses($request,
new ResponseHelper(),[
"id"=>$uploadId]);
1728 [
"uploadId" => $uploadId,
'agentName' =>
'nomos',
'successfulAgents'=> [],
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1729 [
"uploadId" => $uploadId,
'agentName' =>
'monk',
"successfulAgents" => [],
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1731 $agent =
new Agent([],$uploadId,
"MOMO agent",45,
"4.4.0.37.072417",
false,
"");
1733 $this->uploadDao->shouldReceive(
'isAccessible')
1734 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1735 $this->dbHelper->shouldReceive(
'doesIdExist')
1736 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1737 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1739 $scanJobProxy->shouldReceive(
'createAgentStatus')
1741 ->andReturn($agentsRun);
1742 $scanJobProxy->shouldReceive(
"getSuccessfulAgents")->andReturn($agent);
1743 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1744 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1745 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agent]);
1747 $actualResponse = $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1748 $this->assertEquals(200,$actualResponse->getStatusCode());
1761 $this->dbHelper->shouldReceive(
'doesIdExist')
1762 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1764 $this->expectException(HttpNotFoundException::class);
1765 $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1778 $this->uploadDao->shouldReceive(
'isAccessible')
1779 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
1780 $this->dbHelper->shouldReceive(
'doesIdExist')
1781 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1783 $this->expectException(HttpForbiddenException::class);
1784 $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1797 $this->dbHelper->shouldReceive(
'doesIdExist')
1798 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1799 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1801 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1803 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1805 $info =
new Info(200, $itemTreeBounds->getItemId(), InfoType::INFO);
1806 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1808 $this->assertEquals($expectedResponse->getStatusCode(),$actualResponse->getStatusCode());
1822 $this->dbHelper->shouldReceive(
'doesIdExist')
1823 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1825 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1826 $info =
new Info(404,
"Upload does not exist", InfoType::ERROR);
1827 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1828 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
1844 $this->dbHelper->shouldReceive(
'doesIdExist')
1845 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1846 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1848 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1850 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1853 $this->assertEquals(500,$actualResponse->getStatusCode());
Contains the constants and helpers for authentication of user.
Controller for Upload model.
Provides helper methods to access database for REST api.
Override Slim response for withJson function.
Provides various DAO helper functions for REST api.
Hash model holding information about file like checksums and size.
Different type of infos provided by REST.
Info model to contain general error and return values.
Model class to hold Upload info.
Unit tests for UploadController.
testSetMainLicense_exists()
testGetAllAgentsUploadNotAccessible()
getResponseJson($response)
testGetClearingProgressInfo()
testPostUploadInternalError(int $version)
tearDown()
Remove test objects.
testPostUploadInternalErrorV1()
testAgentsRevisionNotFound()
testGetSingleUpload($version)
testPostUpload(int $version)
testPostUploadFolderNotAccessible(int $version)
testSetGroupsWithPermissions()
testGetUploadLicensesPendingScanV2()
testGetUploadWithFiltersV2()
testGetUploadLicensesV1()
testAgentsRevisionForbidden()
testSetGroupsWithPermissionsUploadNotAccessible()
testGetAllAgentsUploadNotFound()
testPostUploadFolderNotAccessibleV2()
testPostUploadInternalErrorV2()
testMoveUploadInvalidFolderV1()
testPostUploadFolderNotFoundV2()
testGetUploadLicensesPendingScan($version=ApiVersion::V2)
testGetUploadLicensesPendingScanV1()
testGetEditedLicensesForbidden()
testGetUploadWithFiltersV1()
testGetSingleUploadInAccessible()
testGetTopItemUploadNotFound()
setUp()
Setup test objects.
testGetSingleUploadNotUnpacked()
testMoveUploadInvalidFolder($version=ApiVersion::V2)
testGetUploadLicensesV2()
testPostUploadFolderNotFound(int $version)
testMoveUploadInvalidFolderV2()
testGetScannedLicensesNotFound()
testSetGroupsWithPermissionsNotFound()
testGetReuseReportSummary()
testPostUploadFolderNotAccessibleV1()
testPostUploadFolderNotFoundV1()
testGetTopItemInternalServerError()
testGetEditedLicensesNotFound()
fo_dbManager * dbManager
fo_dbManager object