48 use Slim\Psr7\Factory\StreamFactory;
49 use Slim\Psr7\Headers;
50 use Slim\Psr7\Request;
53 function TryToDelete($uploadpk, $user_pk, $group_pk, $uploadDao)
56 $group_pk, $uploadDao);
166 private $copyrightPlugin;
171 private $downloadPlugin;
182 $container = M::mock(
'ContainerBuilder');
183 self::$functions = M::mock();
184 $this->dbHelper = M::mock(DbHelper::class);
185 $this->
dbManager = M::mock(DbManager::class);
186 $this->restHelper = M::mock(RestHelper::class);
187 $this->uploadDao = M::mock(UploadDao::class);
188 $this->folderDao = M::mock(FolderDao::class);
189 $this->agentDao = M::mock(AgentDao::class);
190 $this->userDao = M::mock(UserDao::class);
191 $this->clearingDao = M::mock(ClearingDao::class);
192 $this->licenseDao = M::mock(LicenseDao::class);
193 $this->reuseReportProcess = M::mock(ReuseReportProcessor::class);
194 $this->uploadPermissionDao = M::mock(UploadPermissionDao::class);
195 $this->downloadPlugin = M::mock(
"download");
197 $this->
dbManager->shouldReceive(
'getSingleRow')
198 ->withArgs([M::any(), [$this->groupId, UploadStatus::OPEN,
200 $this->dbHelper->shouldReceive(
'getDbManager')->andReturn($this->
dbManager);
202 $this->restHelper->shouldReceive(
'getDbHelper')->andReturn($this->dbHelper);
203 $this->restHelper->shouldReceive(
'getGroupId')->andReturn($this->groupId);
204 $this->restHelper->shouldReceive(
'getUserId')->andReturn($this->userId);
205 $this->restHelper->shouldReceive(
'getPlugin')->withArgs(array(
"download"))->andReturn($this->downloadPlugin);
206 $this->restHelper->shouldReceive(
'getUploadDao')
207 ->andReturn($this->uploadDao);
208 $this->restHelper->shouldReceive(
'getFolderDao')
209 ->andReturn($this->folderDao);
210 $this->restHelper->shouldReceive(
'getUserDao')
211 ->andReturn($this->userDao);
212 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn(
214 $container->shouldReceive(
'get')->withArgs(array(
215 'dao.clearing'))->andReturn($this->clearingDao);
216 $container->shouldReceive(
'get')->withArgs(array(
217 'helper.restHelper'))->andReturn($this->restHelper);
218 $container->shouldReceive(
'get')->withArgs(array(
219 'dao.agent'))->andReturn($this->agentDao);
220 $container->shouldReceive(
'get')->withArgs(array(
221 'dao.upload'))->andReturn($this->uploadDao);
222 $container->shouldReceive(
'get')->withArgs(
223 [
'db.manager'])->andReturn($this->
dbManager);
224 $container->shouldReceive(
'get')->withArgs(array(
'dao.license'))->andReturn($this->licenseDao);
225 $container->shouldReceive(
'get')->withArgs(array(
226 'businessrules.reusereportprocessor'))->andReturn($this->reuseReportProcess);
228 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
229 $this->streamFactory =
new StreamFactory();
238 $this->addToAssertionCount(
239 \Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
251 $response->getBody()->seek(0);
252 return json_decode($response->getBody()->getContents(),
true);
265 $itemId = ($id * 100) + 1;
266 $left = ($id * 100) + 2;
267 $right = ($id * 100) + 50;
268 return new ItemTreeBounds($itemId,
'uploadtree_a', $id, $left, $right);
286 $uploadName =
"top$id";
287 $uploadDate =
"01-01-2020";
291 $uploadName =
"child$id";
292 $uploadDate =
"02-01-2020";
296 $uploadName =
"child$id";
297 $uploadDate =
"03-01-2020";
303 $hash =
new Hash(
'sha1checksum',
'md5checksum',
'sha256checksum', $fileSize);
304 return new Upload($folderId, $folderName, $id, $description,
305 $uploadName, $uploadDate,
null, $hash);
343 $requestHeaders =
new Headers();
344 $body = $this->streamFactory->createStream();
345 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
346 "/uploads/$uploadId"), $requestHeaders, [], [], $body);
347 if ($version == ApiVersion::V2) {
348 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
351 $this->dbHelper->shouldReceive(
'doesIdExist')
352 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
353 $this->uploadDao->shouldReceive(
'isAccessible')
354 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
355 $this->uploadDao->shouldReceive(
'getParentItemBounds')
357 $this->dbHelper->shouldReceive(
'getUploads')
358 ->withArgs([$this->userId, $this->groupId, 100, 1, $uploadId, $options,
359 true, $version])->andReturn([1, [$upload->getArray()]]);
360 $expectedResponse = (
new ResponseHelper())->withJson($upload->getArray(), 200);
361 $actualResponse = $this->uploadController->getUploads($request,
363 $this->assertEquals($expectedResponse->getStatusCode(),
364 $actualResponse->getStatusCode());
377 $requestHeaders =
new Headers();
378 $body = $this->streamFactory->createStream();
379 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
380 "/uploads/$uploadId"), $requestHeaders, [], [], $body);
381 $this->dbHelper->shouldReceive(
'doesIdExist')
382 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
383 $this->uploadDao->shouldReceive(
'isAccessible')
384 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
385 $this->expectException(HttpForbiddenException::class);
387 $this->uploadController->getUploads($request,
new ResponseHelper(),
388 [
'id' => $uploadId]);
400 $this->testGetUploadWithFilters(ApiVersion::V1);
411 $this->testGetUploadWithFilters(ApiVersion::V2);
414 private function testGetUploadWithFilters($version)
426 $folderOptions = $options;
427 $folderOptions[
"folderId"] = $folderId;
428 $requestHeaders =
new Headers();
429 $body = $this->streamFactory->createStream();
430 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
432 $requestHeaders, [], [], $body);
433 if ($version == ApiVersion::V2) {
434 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
437 $this->folderDao->shouldReceive(
'isFolderAccessible')
438 ->withArgs([$folderId, $this->userId])->andReturn(
true)->once();
439 $this->dbHelper->shouldReceive(
'getUploads')
440 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $folderOptions,
441 true, $version])->andReturn([1, []])->once();
442 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
446 $nameOptions = $options;
447 $nameOptions[
"name"] = $name;
448 $requestHeaders =
new Headers();
449 $body = $this->streamFactory->createStream();
450 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
453 if ($version == ApiVersion::V2) {
454 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
457 $this->dbHelper->shouldReceive(
'getUploads')
458 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $nameOptions,
459 true, $version])->andReturn([1, []])->once();
460 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
463 $statusString =
"InProgress";
464 $status = UploadStatus::IN_PROGRESS;
465 $statusOptions = $options;
466 $statusOptions[
"status"] = $status;
467 $requestHeaders =
new Headers();
468 $body = $this->streamFactory->createStream();
469 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
471 $requestHeaders, [], [], $body);
472 if ($version == ApiVersion::V2) {
473 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
476 $this->dbHelper->shouldReceive(
'getUploads')
477 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $statusOptions,
478 true, $version])->andReturn([1, []])->once();
479 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
483 $assigneeOptions = $options;
485 $requestHeaders =
new Headers();
486 $body = $this->streamFactory->createStream();
487 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
489 $requestHeaders, [], [], $body);
490 if ($version == ApiVersion::V2) {
491 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
494 $this->dbHelper->shouldReceive(
'getUploads')
495 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $assigneeOptions,
496 true, $version])->andReturn([1, []])->once();
497 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
500 $since =
"2021-02-28";
501 $sinceOptions = $options;
502 $sinceOptions[
"since"] = strtotime($since);
503 $requestHeaders =
new Headers();
504 $body = $this->streamFactory->createStream();
505 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
507 $requestHeaders, [], [], $body);
508 if ($version == ApiVersion::V2) {
509 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
512 $this->dbHelper->shouldReceive(
'getUploads')
513 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $sinceOptions,
514 true, $version])->andReturn([1, []])->once();
515 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
518 $statusString =
"Open";
519 $status = UploadStatus::OPEN;
520 $since =
"2021-02-28";
521 $combOptions = $options;
522 $combOptions[
"since"] = strtotime($since);
523 $combOptions[
"status"] = $status;
524 $requestHeaders =
new Headers();
525 $body = $this->streamFactory->createStream();
526 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
529 $requestHeaders, [], [], $body);
530 if ($version == ApiVersion::V2) {
531 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
534 $this->dbHelper->shouldReceive(
'getUploads')
535 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $combOptions,
536 true, $version])->andReturn([1, []])->once();
537 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
546 $this->testGetUploads(ApiVersion::V1);
554 $this->testGetUploads(ApiVersion::V2);
556 private function testGetUploads($version)
570 $requestHeaders =
new Headers();
571 $body = $this->streamFactory->createStream();
572 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
573 "/uploads/"), $requestHeaders, [], [], $body);
574 if ($version == ApiVersion::V2) {
575 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
578 $this->dbHelper->shouldReceive(
'getUploads')
579 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $options,
true, $version])
580 ->andReturn([1, $uploads]);
581 $expectedResponse = (
new ResponseHelper())->withJson($uploads, 200);
582 $actualResponse = $this->uploadController->getUploads($request,
584 $this->assertEquals($expectedResponse->getStatusCode(),
585 $actualResponse->getStatusCode());
599 $requestHeaders =
new Headers();
600 $body = $this->streamFactory->createStream();
601 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
602 "/uploads/"), $requestHeaders, [], [], $body);
603 $this->dbHelper->shouldReceive(
'doesIdExist')
604 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
605 $this->uploadDao->shouldReceive(
'isAccessible')
606 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
607 $this->uploadDao->shouldReceive(
'getParentItemBounds')
608 ->withArgs([$uploadId])->andReturn(
false);
609 $this->expectException(HttpServiceUnavailableException::class);
611 $this->uploadController->getUploads($request,
new ResponseHelper(),
612 [
'id' => $uploadId]);
642 $info =
new Info(202,
"Upload $uploadId will be copied to folder $folderId",
645 $this->restHelper->shouldReceive(
'copyUpload')
646 ->withArgs([$uploadId, $folderId,
true])->andReturn($info);
647 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
650 $requestHeaders =
new Headers();
651 $body = $this->streamFactory->createStream();
653 if($version==ApiVersion::V1){
654 $requestHeaders->setHeader(
'folderId', $folderId);
655 $requestHeaders->setHeader(
'action',
'copy');
656 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
657 $requestHeaders, [], [], $body);
658 $actualResponse = $this->uploadController->moveUpload($request,
662 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
663 $requestHeaders, [], [], $body);
664 if ($version == ApiVersion::V2) {
665 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
668 $actualResponse = $this->uploadController->moveUpload($request->withUri($request->getUri()->withQuery(
"folderId=$folderId&action=copy")),
671 $this->assertEquals($expectedResponse->getStatusCode(),
672 $actualResponse->getStatusCode());
706 $requestHeaders =
new Headers();
707 $requestHeaders->setHeader(
'folderId',
'alpha');
708 $requestHeaders->setHeader(
'action',
'move');
709 $body = $this->streamFactory->createStream();
710 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
711 $requestHeaders, [], [], $body);
712 if ($version==ApiVersion::V2) {
713 $request = $request->withQueryParams([
'folderId' =>
'alpha',
'action' =>
'move']);
715 $request = $request->withHeader(
"folderId",
"alpha")
716 ->withHeader(
"action",
"move");
718 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
719 $this->expectException(HttpBadRequestException::class);
721 $this->uploadController->moveUpload($request,
new ResponseHelper(),
722 [
'id' => $uploadId]);
757 $uploadDescription =
"Test Upload";
759 $requestHeaders =
new Headers();
760 $requestHeaders->setHeader(
'Content-Type',
'application/json');
761 if ($version == ApiVersion::V2) {
763 "location" =>
"data",
764 "folderId" => $folderId,
765 "uploadDescription" => $uploadDescription,
766 "ignoreScm" =>
"true",
767 "scanOptions" =>
"scanOptions",
768 "uploadType" =>
"vcs",
769 "excludeFolder" =>
"false"
773 "location" =>
"data",
774 "scanOptions" =>
"scanOptions"
776 $requestHeaders->setHeader(
'folderId', $folderId);
777 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
778 $requestHeaders->setHeader(
'ignoreScm',
'true');
779 $requestHeaders->setHeader(
'Content-Type',
'application/json');
780 $requestHeaders->setHeader(
'uploadType',
'vcs');
783 $body = $this->streamFactory->createStream(json_encode(
786 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
787 $requestHeaders, [], [], $body);
788 if ($version == ApiVersion::V2) {
789 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
792 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
793 if ($version == ApiVersion::V2) {
794 $uploadHelper->shouldReceive(
'createNewUpload')
795 ->withArgs([$reqBody[
"location"], $folderId, $uploadDescription,
'protected',
'true',
796 'vcs',
false,
false])
797 ->andReturn([
true,
'',
'', $uploadId]);
799 $uploadHelper->shouldReceive(
'createNewUpload')
800 ->withArgs([$reqBody[
"location"], $folderId, $uploadDescription,
'protected',
'true',
802 ->andReturn([
true,
'',
'', $uploadId]);
805 $info =
new Info(201, intval(20), InfoType::INFO);
807 $uploadHelper->shouldReceive(
'handleScheduleAnalysis')->withArgs([$uploadId,$folderId,$reqBody[
"scanOptions"],
false])
810 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
811 $this->folderDao->shouldReceive(
'isFolderAccessible')
812 ->withArgs([$folderId, $this->userId])->andReturn(
true);
814 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
816 $actualResponse = $this->uploadController->postUpload($request,
818 $this->assertEquals($expectedResponse->getStatusCode(),
819 $actualResponse->getStatusCode());
833 $requestHeaders =
new Headers();
834 $requestHeaders->setHeader(
'Content-Type',
'application/json');
836 $body = $this->streamFactory->createStream(json_encode([
837 "location" =>
"vcsData",
838 "folderId" => $folderId,
839 "uploadDescription" =>
"Test Upload",
840 "ignoreScm" =>
"true",
841 "scanOptions" =>
"scanOptions",
842 "uploadType" =>
"vcs"
845 $request =
new Request(
847 new Uri(
"HTTP",
"localhost"),
854 $request = $request->withAttribute(
855 ApiVersion::ATTRIBUTE_NAME,
859 M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
861 $this->expectException(HttpBadRequestException::class);
863 $this->uploadController->postUpload($request,
new ResponseHelper(), []);
896 $uploadDescription =
"Test Upload";
898 $requestHeaders =
new Headers();
899 $requestHeaders->setHeader(
'Content-type',
'application/json');
900 if ($version == ApiVersion::V2) {
901 $body = $this->streamFactory->createStream(json_encode([
902 "location" =>
"data",
903 "folderId" => $folderId,
904 "uploadDescription" => $uploadDescription,
905 "ignoreScm" =>
"true",
906 "scanOptions" =>
"scanOptions",
907 "uploadType" =>
"vcs"
910 $body = $this->streamFactory->createStream(json_encode([
911 "location" =>
"data",
912 "scanOptions" =>
"scanOptions"
914 $requestHeaders->setHeader(
'folderId', $folderId);
915 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
916 $requestHeaders->setHeader(
'ignoreScm',
'true');
917 $requestHeaders->setHeader(
'Content-Type',
'application/json');
918 $requestHeaders->setHeader(
'uploadType',
'vcs');
920 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
921 $requestHeaders, [], [], $body);
922 if ($version == ApiVersion::V2) {
923 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
927 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
929 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
930 $this->folderDao->shouldReceive(
'isFolderAccessible')
931 ->withArgs([$folderId, $this->userId])->andReturn(
false);
932 $this->expectException(HttpForbiddenException::class);
934 $this->uploadController->postUpload($request,
new ResponseHelper(),
969 $uploadDescription =
"Test Upload";
971 $requestHeaders =
new Headers();
972 $requestHeaders->setHeader(
'Content-type',
'application/json');
973 if ($version == ApiVersion::V2) {
974 $body = $this->streamFactory->createStream(json_encode([
975 "location" =>
"vcsData",
976 "folderId" => $folderId,
977 "uploadDescription" => $uploadDescription,
978 "ignoreScm" =>
"true",
979 "scanOptions" =>
"scanOptions",
980 "uploadType" =>
"vcs"
983 $body = $this->streamFactory->createStream(json_encode([
984 "location" =>
"vcsData",
985 "scanOptions" =>
"scanOptions"
987 $requestHeaders->setHeader(
'folderId', $folderId);
988 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
989 $requestHeaders->setHeader(
'ignoreScm',
'true');
990 $requestHeaders->setHeader(
'Content-Type',
'application/json');
991 $requestHeaders->setHeader(
'uploadType',
'vcs');
993 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
994 $requestHeaders, [], [], $body);
995 if ($version == ApiVersion::V2) {
996 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
1000 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
1002 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
1003 $this->expectException(HttpNotFoundException::class);
1005 $this->uploadController->postUpload($request,
new ResponseHelper(),
1040 $uploadDescription =
"Test Upload";
1041 $errorMessage =
"Failed to insert upload record";
1044 $requestHeaders =
new Headers();
1045 $requestHeaders->setHeader(
'Content-type',
'application/json');
1046 if ($version == ApiVersion::V2) {
1047 $body = $this->streamFactory->createStream(json_encode([
1048 "location" =>
"vcsData",
1049 "folderId" => $folderId,
1050 "uploadDescription" => $uploadDescription,
1051 "ignoreScm" =>
"true",
1052 "scanOptions" =>
"scanOptions",
1053 "uploadType" =>
"vcs",
1054 "excludeFolder" =>
"false"
1057 $body = $this->streamFactory->createStream(json_encode([
1058 "location" =>
"vcsData",
1059 "scanOptions" =>
"scanOptions"
1061 $requestHeaders->setHeader(
'folderId', $folderId);
1062 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
1063 $requestHeaders->setHeader(
'ignoreScm',
'true');
1064 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1065 $requestHeaders->setHeader(
'uploadType',
'vcs');
1068 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1069 $requestHeaders, [], [], $body);
1070 if ($version == ApiVersion::V2) {
1071 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
1075 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
1076 if ($version == ApiVersion::V2) {
1077 $uploadHelper->shouldReceive(
'createNewUpload')
1078 ->withArgs([
'vcsData', $folderId, $uploadDescription,
'protected',
'true',
1079 'vcs',
false,
false])
1080 ->andReturn([
false, $errorMessage, $errorDesc, [-1]]);
1082 $uploadHelper->shouldReceive(
'createNewUpload')
1083 ->withArgs([
'vcsData', $folderId, $uploadDescription,
'protected',
'true',
1085 ->andReturn([
false, $errorMessage, $errorDesc, [-1]]);
1088 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
1089 $this->folderDao->shouldReceive(
'isFolderAccessible')
1090 ->withArgs([$folderId, $this->userId])->andReturn(
true);
1091 $this->expectException(HttpInternalServerErrorException::class);
1093 $this->uploadController->postUpload($request,
new ResponseHelper(), []);
1105 $this->testGetUploadLicenses(ApiVersion::V1);
1116 $this->testGetUploadLicenses(ApiVersion::V2);
1118 private function testGetUploadLicenses($version)
1122 [
'agentName' =>
'nomos',
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1123 [
'agentName' =>
'monk',
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1125 $licenseResponse = [
1126 [
'filePath' =>
'filea',
'agentFindings' =>
'MIT',
'conclusions' =>
'MIT'],
1127 [
'filePath' =>
'fileb',
'agentFindings' =>
'MIT',
1128 'conclusions' =>
'No_license_found']
1131 $requestHeaders =
new Headers();
1132 $body = $this->streamFactory->createStream();
1133 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1135 "=nomos,monk&containers=false"),
1136 $requestHeaders, [], [], $body);
1137 if ($version == ApiVersion::V2) {
1138 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
1141 $this->dbHelper->shouldReceive(
'doesIdExist')
1142 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1143 $this->uploadDao->shouldReceive(
'isAccessible')
1144 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1145 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1146 ->withArgs([$uploadId])->andReturn($this->
getUploadBounds($uploadId));
1147 $this->agentDao->shouldReceive(
'arsTableExists')
1148 ->withArgs([M::anyOf(
'nomos',
'monk')])->andReturn(
true);
1150 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1151 $scanJobProxy->shouldReceive(
'createAgentStatus')
1152 ->withArgs([[
'nomos',
'monk']])
1153 ->andReturn($agentsRun);
1155 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
1156 $uploadHelper->shouldReceive(
'getUploadLicenseList')
1157 ->withArgs([$uploadId, [
'nomos',
'monk'],
false,
true,
false, 0, 50, $version])
1158 ->andReturn(([[$licenseResponse], 1]));
1160 $expectedResponse = (
new ResponseHelper())->withJson($licenseResponse, 200);
1162 $actualResponse = $this->uploadController->getUploadLicenses($request,
1164 $this->assertEquals($expectedResponse->getStatusCode(),
1165 $actualResponse->getStatusCode());
1168 $this->assertEquals(
'1',
1169 $actualResponse->getHeaderLine(
'X-Total-Pages'));
1204 [
'agentName' =>
'nomos',
'currentAgentId' => 2,
'isAgentRunning' =>
true],
1205 [
'agentName' =>
'monk',
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1208 $requestHeaders =
new Headers();
1209 $body = $this->streamFactory->createStream();
1210 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1212 "=nomos,monk&containers=false"),
1213 $requestHeaders, [], [], $body);
1214 if ($version == ApiVersion::V2) {
1215 $request = $request->withQueryParams([
'page' => 1,
'limit' => 2,
"agent" =>
"nomos,monk" ]);
1217 $request = $request->withHeader(
"limit",2)
1218 ->withHeader(
"page",1);
1220 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
1222 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1223 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agentsRun]);
1224 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1225 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1226 $this->dbHelper->shouldReceive(
'doesIdExist')
1227 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1228 $this->uploadDao->shouldReceive(
'isAccessible')
1229 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1230 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1231 ->withArgs([$uploadId])->andReturn($this->
getUploadBounds($uploadId));
1232 $this->agentDao->shouldReceive(
'arsTableExists')
1233 ->withArgs([M::anyOf(
'nomos',
'monk')])->andReturn(
true);
1235 $scanJobProxy->shouldReceive(
'createAgentStatus')
1236 ->withArgs([[
'nomos',
'monk']])
1237 ->andReturn($agentsRun);
1238 $this->expectException(HttpServiceUnavailableException::class);
1240 $this->uploadController->getUploadLicenses($request,
new ResponseHelper(),
1241 [
'id' => $uploadId]);
1253 $status = UploadStatus::REJECTED;
1254 $comment =
"Not helpful";
1256 $resource = fopen(
'data://text/plain;base64,' .
1257 base64_encode($comment),
'r+');
1258 $body = $this->streamFactory->createStreamFromResource($resource);
1259 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1262 new Headers(), [], [], $body);
1264 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
1265 ->withArgs([$this->userId, $this->groupId])
1267 $this->userDao->shouldReceive(
'getUserChoices')
1268 ->withArgs([$this->groupId])
1269 ->andReturn([$this->userId =>
"fossy", $assignee =>
"friendly-fossy"]);
1270 $this->
dbManager->shouldReceive(
'getSingleRow')
1271 ->withArgs([M::any(), [$assignee, $this->groupId, $upload], M::any()]);
1272 $this->
dbManager->shouldReceive(
'getSingleRow')
1273 ->withArgs([M::any(), [$status, $comment, $this->groupId, $upload],
1275 $this->
dbManager->shouldReceive(
'getSingleRow')
1276 ->withArgs([M::any(), [$upload], M::any()])
1277 ->andReturn([
"exists" =>
""]);
1279 $info =
new Info(202,
"Upload updated successfully.", InfoType::INFO);
1280 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
1282 $actualResponse = $this->uploadController->updateUpload($request,
1284 $this->assertEquals($expectedResponse->getStatusCode(),
1285 $actualResponse->getStatusCode());
1299 $comment =
"Not helpful";
1301 $resource = fopen(
'data://text/plain;base64,' .
1302 base64_encode($comment),
'r+');
1303 $body = $this->streamFactory->createStreamFromResource($resource);
1304 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1307 new Headers(), [], [], $body);
1309 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
1310 ->withArgs([$this->userId, $this->groupId])
1312 $this->expectException(HttpForbiddenException::class);
1314 $this->uploadController->updateUpload($request,
new ResponseHelper(),
1326 $licenseIds = array();
1328 $licenseIds[$licenseId] = $licenseId;
1329 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
1332 $this->uploadDao->shouldReceive(
'isAccessible')
1333 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1334 $this->dbHelper->shouldReceive(
'doesIdExist')
1335 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1336 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1337 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
false])->andReturn([]);
1338 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
true])->andReturn([]);
1339 $this->licenseDao->shouldReceive(
'getLicenseById')->withArgs([$licenseId, $this->groupId])->andReturn($license);
1341 $licenses[] = $license->getArray();
1342 $expectedResponse = (
new ResponseHelper())->withJson($licenses, 200);
1343 $actualResponse = $this->uploadController->getMainLicenses(
null,
new ResponseHelper(), [
'id' => $uploadId]);
1344 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
1360 "shortName" => $shortName,
1362 $license =
new License(2, $shortName,
"MIT License",
"risk",
"texts", [],
1364 $licenseIds[$licenseId] = $licenseId;
1365 $this->uploadDao->shouldReceive(
'isAccessible')
1366 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1367 $this->uploadDao->shouldReceive(
'isEditable')
1368 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1369 $this->dbHelper->shouldReceive(
'doesIdExist')
1370 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1371 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1372 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1373 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1374 $this->clearingDao->shouldReceive(
'makeMainLicense')
1375 ->withArgs([$uploadId, $this->groupId, $license->getId()])->andReturn(
null);
1377 $info =
new Info(200,
"Successfully added new main license", InfoType::INFO);
1379 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1380 $reqBody = $this->streamFactory->createStream(json_encode(
1383 $requestHeaders =
new Headers();
1384 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1385 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1386 $requestHeaders, [], [], $reqBody);
1388 $actualResponse = $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1390 $this->assertEquals($expectedResponse->getStatusCode(),
1391 $actualResponse->getStatusCode());
1407 "shortName" => $shortName,
1409 $license =
new License($licenseId, $shortName,
"MIT License",
"risk",
"texts", [],
1411 $licenseIds[$licenseId] = $licenseId;
1412 $this->uploadDao->shouldReceive(
'isAccessible')
1413 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1414 $this->uploadDao->shouldReceive(
'isEditable')
1415 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1416 $this->dbHelper->shouldReceive(
'doesIdExist')
1417 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1418 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1419 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1420 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1421 $this->clearingDao->shouldReceive(
'makeMainLicense')
1422 ->withArgs([$uploadId, $this->groupId, $license->getId()])->andReturn(
null);
1424 $reqBody = $this->streamFactory->createStream(json_encode(
1427 $requestHeaders =
new Headers();
1428 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1429 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1430 $requestHeaders, [], [], $reqBody);
1431 $this->expectException(HttpBadRequestException::class);
1433 $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1445 "shortName" =>
"MIT",
1447 $this->uploadDao->shouldReceive(
'isAccessible')
1448 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1449 $this->uploadDao->shouldReceive(
'isEditable')
1450 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
1451 $this->dbHelper->shouldReceive(
'doesIdExist')
1452 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1454 $reqBody = $this->streamFactory->createStream(json_encode($rq));
1455 $requestHeaders =
new Headers();
1456 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1457 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1458 $requestHeaders, [], [], $reqBody);
1460 $this->expectException(HttpForbiddenException::class);
1461 $this->expectExceptionMessage(
1462 "You do not have write permission on this upload.");
1463 $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1476 $license =
new License($licenseId, $shortName,
"MIT License",
"risk",
"texts", [],
1478 $licenseIds[$licenseId] = $licenseId;
1480 $this->uploadDao->shouldReceive(
'isAccessible')
1481 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1482 $this->uploadDao->shouldReceive(
'isEditable')
1483 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1484 $this->dbHelper->shouldReceive(
'doesIdExist')
1485 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1486 $this->dbHelper->shouldReceive(
'doesIdExist')
1487 ->withArgs([
"license_ref",
"rf_pk", $licenseId])->andReturn(
true);
1488 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1490 $this->clearingDao->shouldReceive(
'removeMainLicense')->withArgs([$uploadId, $this->groupId, $licenseId])->andReturn(
null);
1491 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1492 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1494 $info =
new Info(200,
"Main license removed successfully.", InfoType::INFO);
1495 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
1497 $actualResponse = $this->uploadController->removeMainLicense(
null,
1498 new ResponseHelper(), [
'id' => $uploadId,
'shortName' => $shortName]);
1499 $this->assertEquals($expectedResponse->getStatusCode(),
1500 $actualResponse->getStatusCode());
1514 $this->uploadDao->shouldReceive(
'isAccessible')
1515 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1516 $this->uploadDao->shouldReceive(
'isEditable')
1517 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
1518 $this->dbHelper->shouldReceive(
'doesIdExist')
1519 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1521 $this->expectException(HttpForbiddenException::class);
1522 $this->expectExceptionMessage(
1523 "You do not have write permission on this upload.");
1524 $this->uploadController->removeMainLicense(
null,
new ResponseHelper(),
1525 [
'id' => $uploadId,
'shortName' => $shortName]);
1536 $this->uploadDao->shouldReceive(
'isAccessible')
1537 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1538 $this->dbHelper->shouldReceive(
'doesIdExist')
1539 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1540 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1541 $this->uploadDao->shouldReceive(
"getGlobalDecisionSettingsFromInfo")->andReturn(
false);
1542 $this->agentDao->shouldReceive(
"arsTableExists")->andReturn(
true);
1543 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->andReturn([[
'agent_id' => 1,
'agent_rev' => 1]]);
1544 $this->agentDao->shouldReceive(
"getCurrentAgentRef")->andReturn(
new AgentRef(1,
"agent", 1));
1545 $this->
dbManager->shouldReceive(
"getSingleRow")
1546 ->withArgs([M::any(), [],
'no_license_uploadtree' . $uploadId])
1547 ->andReturn([
'count' => 1]);
1548 $this->
dbManager->shouldReceive(
"getSingleRow")
1549 ->withArgs([M::any(), [],
'already_cleared_uploadtree' . $uploadId])
1550 ->andReturn([
'count' => 0]);
1551 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1552 ->withArgs([
'No_license_found'])->andReturn(
null);
1553 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1554 ->withArgs([
'Void'])->andReturn(
null);
1556 "totalFilesOfInterest" => 1,
1557 "totalFilesCleared" => 1,
1560 $actualResponse = $this->uploadController->getClearingProgressInfo(
null,
1562 $this->assertEquals($expectedResponse->getStatusCode(),
1563 $actualResponse->getStatusCode());
1575 $reuseReportSummary = [
1576 'declearedLicense' =>
"",
1577 'clearedLicense' =>
"MIT, BSD-3-Clause",
1578 'usedLicense' =>
"",
1579 'unusedLicense' =>
"",
1580 'missingLicense' =>
"MIT, BSD-3-Clause",
1582 $this->uploadDao->shouldReceive(
'isAccessible')
1583 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1584 $this->dbHelper->shouldReceive(
'doesIdExist')
1585 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1586 $this->reuseReportProcess->shouldReceive(
'getReuseSummary')
1587 ->withArgs([$uploadId])->andReturn($reuseReportSummary);
1589 $expectedResponse = (
new ResponseHelper())->withJson($reuseReportSummary,
1591 $actualResponse = $this->uploadController->getReuseReportSummary(
1593 $this->assertEquals($expectedResponse->getStatusCode(),
1594 $actualResponse->getStatusCode());
1612 $this->uploadDao->shouldReceive(
'isAccessible')
1613 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1614 $this->dbHelper->shouldReceive(
'doesIdExist')
1615 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1617 $this->restHelper->shouldReceive(
'getUploadPermissionDao')->andReturn($this->uploadPermissionDao);
1618 $this->uploadPermissionDao->shouldReceive(
"getPublicPermission")->withAnyArgs()->andReturn($publicPerm);
1619 $this->uploadPermissionDao->shouldReceive(
"getPermissionGroups")->withAnyArgs()->andReturn([]);
1620 $this->restHelper->shouldReceive(
"getGroupId")->andReturn($this->groupId);
1621 $this->restHelper->shouldReceive(
"getUserId")->andReturn($this->userId);
1622 $this->restHelper->shouldReceive(
"getUploadDao")->andReturn($this->uploadDao);
1624 $body = $this->streamFactory->createStream();
1625 $requestHeaders =
new Headers();
1626 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1627 $requestHeaders, [], [], $body);
1629 $actualResponse = $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1630 $this->assertEquals(200,$actualResponse->getStatusCode());
1643 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1645 $this->dbHelper->shouldReceive(
'doesIdExist')
1646 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1647 $body = $this->streamFactory->createStream();
1648 $requestHeaders =
new Headers();
1649 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1650 $requestHeaders, [], [], $body);
1652 $this->expectException(HttpNotFoundException::class);
1653 $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1665 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1666 $this->uploadDao->shouldReceive(
'isAccessible')->withAnyArgs()->andReturn(
false);
1668 $body = $this->streamFactory->createStream();
1669 $requestHeaders =
new Headers();
1670 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1671 $requestHeaders, [], [], $body);
1673 $this->expectException(HttpForbiddenException::class);
1674 $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1687 [
"uploadId" => $uploadId,
'agentName' =>
'nomos',
'successfulAgents'=> [],
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1688 [
"uploadId" => $uploadId,
'agentName' =>
'monk',
"successfulAgents" => [],
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1691 $this->restHelper->shouldReceive(
"getGroupId")->andReturn(
$groupId);
1692 $this->agentDao->shouldReceive(
"getCurrentAgentRef")->withAnyArgs()->andReturn(
new AgentRef($uploadId,
"momoa",45));
1694 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1695 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1696 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1697 $scanJobProxy->shouldReceive(
'createAgentStatus')
1699 ->andReturn($agentsRun);
1700 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1701 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agentsRun]);
1702 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1704 $body = $this->streamFactory->createStream();
1705 $requestHeaders =
new Headers();
1706 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1707 $requestHeaders, [], [], $body);
1709 $actualResponse = $this->uploadController->getAllAgents($request,
new ResponseHelper(),[
"id"=>$uploadId]);
1710 $this->assertEquals(200,$actualResponse->getStatusCode());
1722 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1723 $this->dbHelper->shouldReceive(
'doesIdExist')
1724 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1726 $this->expectException(HttpNotFoundException::class);
1727 $this->uploadController->getAllAgents(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1740 $this->uploadDao->shouldReceive(
'isAccessible')
1741 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
1742 $this->dbHelper->shouldReceive(
'doesIdExist')
1743 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1745 $this->expectException(HttpForbiddenException::class);
1746 $this->uploadController->getAllAgents(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1760 $uploadName =
"Testing name";
1761 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1763 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1764 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1765 $this->restHelper->shouldReceive(
'getUploadDao')->andReturn($this->uploadDao);
1766 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn($uploadName);
1767 $this->clearingDao->shouldReceive(
"getClearedLicenseIdAndMultiplicities")->withAnyArgs()->andReturn([]);
1769 $actualResponse = $this->uploadController->getEditedLicenses(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1770 $this->assertEquals(200,$actualResponse->getStatusCode());
1783 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1785 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1786 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1788 $this->expectException(HttpNotFoundException::class);
1802 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1804 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
false);
1805 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1807 $this->expectException(HttpForbiddenException::class);
1823 $this->uploadDao->shouldReceive(
'isAccessible')
1824 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1825 $this->dbHelper->shouldReceive(
'doesIdExist')
1826 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1827 $this->restHelper->shouldReceive(
'getUploadDao')->andReturn($this->uploadDao);
1828 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")
1829 ->withArgs([$uploadId])->andReturn(
"uploadtree");
1830 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1833 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1834 $scanJobProxy->shouldReceive(
'createAgentStatus')->withAnyArgs()->andReturn($agentsRun);
1835 $scanJobProxy->shouldReceive(
'getLatestSuccessfulAgentIds')->andReturn([2]);
1842 'spdx_id' =>
'GPL-2.0-only',
1845 $this->licenseDao->shouldReceive(
'getLicenseHistogram')
1846 ->withAnyArgs()->andReturn($histogram);
1848 $body = $this->streamFactory->createStream();
1849 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1850 new Headers(), [], [], $body);
1852 $actualResponse = $this->uploadController->getScannedLicenses(
1855 $this->assertEquals(200, $actualResponse->getStatusCode());
1857 $this->assertCount(1, $responseBody);
1858 $this->assertEquals(2, $responseBody[0][
'id']);
1859 $this->assertEquals(
'GPL-2.0-only', $responseBody[0][
'shortname']);
1860 $this->assertEquals(10, $responseBody[0][
'occurence']);
1861 $this->assertEquals(5, $responseBody[0][
'unique']);
1877 $this->uploadDao->shouldReceive(
'isAccessible')
1878 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1879 $this->dbHelper->shouldReceive(
'doesIdExist')
1880 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1881 $this->restHelper->shouldReceive(
'getUploadDao')->andReturn($this->uploadDao);
1882 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")
1883 ->withArgs([$uploadId])->andReturn(
"uploadtree");
1884 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1887 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1888 $scanJobProxy->shouldReceive(
'createAgentStatus')->withAnyArgs()->andReturn($agentsRun);
1889 $scanJobProxy->shouldReceive(
'getLatestSuccessfulAgentIds')->andReturn([2]);
1898 LicenseDao::NO_LICENSE_FOUND => [
1902 'spdx_id' => LicenseDao::NO_LICENSE_FOUND,
1905 $this->licenseDao->shouldReceive(
'getLicenseHistogram')
1906 ->withAnyArgs()->andReturn($histogram);
1908 $body = $this->streamFactory->createStream();
1909 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1910 new Headers(), [], [], $body);
1912 $actualResponse = $this->uploadController->getScannedLicenses(
1915 $this->assertEquals(200, $actualResponse->getStatusCode());
1917 $this->assertCount(2, $responseBody);
1919 $noLicenseEntry = array_values(array_filter($responseBody,
function ($e) {
1920 return $e[
'shortname'] === LicenseDao::NO_LICENSE_FOUND;
1922 $this->assertEquals(0, $noLicenseEntry[
'id']);
1923 $this->assertEquals(7, $noLicenseEntry[
'occurence']);
1935 $this->uploadDao->shouldReceive(
'isAccessible')
1936 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1937 $this->dbHelper->shouldReceive(
'doesIdExist')
1938 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1940 $body = $this->streamFactory->createStream();
1941 $requestHeaders =
new Headers();
1942 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1943 $requestHeaders, [], [], $body);
1945 $this->expectException(HttpNotFoundException::class);
1946 $this->uploadController->getScannedLicenses($request,
new ResponseHelper(),[
"id"=>$uploadId]);
1960 [
"uploadId" => $uploadId,
'agentName' =>
'nomos',
'successfulAgents'=> [],
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1961 [
"uploadId" => $uploadId,
'agentName' =>
'monk',
"successfulAgents" => [],
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1963 $agent =
new Agent([],$uploadId,
"MOMO agent",45,
"4.4.0.37.072417",
false,
"");
1965 $this->uploadDao->shouldReceive(
'isAccessible')
1966 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1967 $this->dbHelper->shouldReceive(
'doesIdExist')
1968 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1969 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1971 $scanJobProxy->shouldReceive(
'createAgentStatus')
1973 ->andReturn($agentsRun);
1974 $scanJobProxy->shouldReceive(
"getSuccessfulAgents")->andReturn($agent);
1975 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1976 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1977 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agent]);
1979 $actualResponse = $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1980 $this->assertEquals(200,$actualResponse->getStatusCode());
1993 $this->dbHelper->shouldReceive(
'doesIdExist')
1994 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1996 $this->expectException(HttpNotFoundException::class);
1997 $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
2010 $this->uploadDao->shouldReceive(
'isAccessible')
2011 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
2012 $this->dbHelper->shouldReceive(
'doesIdExist')
2013 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
2015 $this->expectException(HttpForbiddenException::class);
2016 $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
2029 $this->dbHelper->shouldReceive(
'doesIdExist')
2030 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
2031 $this->uploadDao->shouldReceive(
'getParentItemBounds')
2033 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
2035 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
2037 $info =
new Info(200, $itemTreeBounds->getItemId(), InfoType::INFO);
2038 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
2040 $this->assertEquals($expectedResponse->getStatusCode(),$actualResponse->getStatusCode());
2054 $this->dbHelper->shouldReceive(
'doesIdExist')
2055 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
2057 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
2058 $info =
new Info(404,
"Upload does not exist", InfoType::ERROR);
2059 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
2060 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
2076 $this->dbHelper->shouldReceive(
'doesIdExist')
2077 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
2078 $this->uploadDao->shouldReceive(
'getParentItemBounds')
2080 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
2082 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
2085 $this->assertEquals(500,$actualResponse->getStatusCode());
2097 $this->dbHelper->shouldReceive(
'doesIdExist')
2098 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
2099 $this->uploadDao->shouldReceive(
'isAccessible')
2100 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
2101 $this->uploadDao->shouldReceive(
'getParentItemBounds')
2102 ->withArgs([$uploadId])->andReturn(
false);
2103 $this->expectException(HttpServiceUnavailableException::class);
2105 $this->uploadController->uploadDownload(
null,
new ResponseHelper(),
2106 [
'id' => $uploadId]);
2119 $uploadTreeTableName =
"uploadtree";
2121 $this->dbHelper->shouldReceive(
'doesIdExist')
2122 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
2123 $this->uploadDao->shouldReceive(
'isAccessible')
2124 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
2125 $this->uploadDao->shouldReceive(
'getParentItemBounds')
2126 ->withAnyArgs()->andReturn($itemTreeBounds);
2127 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')
2128 ->withArgs([$uploadId])->andReturn($uploadTreeTableName);
2129 $this->
dbManager->shouldReceive(
'getSingleRow')
2130 ->withArgs([M::on(
function ($sql) use ($uploadTreeTableName) {
2131 return strpos($sql,
"FROM $uploadTreeTableName WHERE") !==
false;
2132 }), [$itemTreeBounds->getItemId()], M::any()])
2133 ->once()->andReturn(
false);
2134 $this->expectException(HttpNotFoundException::class);
2136 $this->uploadController->uploadDownload(
null,
new ResponseHelper(),
2137 [
'id' => $uploadId]);
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)
testGetScannedLicensesWithNoLicenseFound()
testSetGroupsWithPermissions()
testGetUploadLicensesPendingScanV2()
testGetUploadWithFiltersV2()
testGetUploadLicensesV1()
testAgentsRevisionForbidden()
testRemoveMainLicense_forbiddenForReadOnlyUser()
testSetGroupsWithPermissionsUploadNotAccessible()
testGetAllAgentsUploadNotFound()
testUploadDownloadFileNotFound()
testPostUploadFolderNotAccessibleV2()
testPostUploadInternalErrorV2()
testPostUploadNegativeFolderIdV2()
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()
testUploadDownloadNotUnpacked()
testPostUploadFolderNotFoundV1()
testGetTopItemInternalServerError()
testGetEditedLicensesNotFound()
testSetMainLicense_forbiddenForReadOnlyUser()
fo_dbManager * dbManager
fo_dbManager object