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);
164 private $copyrightPlugin;
169 private $downloadPlugin;
180 $container = M::mock(
'ContainerBuilder');
181 self::$functions = M::mock();
182 $this->dbHelper = M::mock(DbHelper::class);
183 $this->
dbManager = M::mock(DbManager::class);
184 $this->restHelper = M::mock(RestHelper::class);
185 $this->uploadDao = M::mock(UploadDao::class);
186 $this->folderDao = M::mock(FolderDao::class);
187 $this->agentDao = M::mock(AgentDao::class);
188 $this->userDao = M::mock(UserDao::class);
189 $this->clearingDao = M::mock(ClearingDao::class);
190 $this->licenseDao = M::mock(LicenseDao::class);
191 $this->reuseReportProcess = M::mock(ReuseReportProcessor::class);
192 $this->uploadPermissionDao = M::mock(UploadPermissionDao::class);
193 $this->downloadPlugin = M::mock(
"download");
195 $this->
dbManager->shouldReceive(
'getSingleRow')
196 ->withArgs([M::any(), [$this->groupId, UploadStatus::OPEN,
198 $this->dbHelper->shouldReceive(
'getDbManager')->andReturn($this->
dbManager);
200 $this->restHelper->shouldReceive(
'getDbHelper')->andReturn($this->dbHelper);
201 $this->restHelper->shouldReceive(
'getGroupId')->andReturn($this->groupId);
202 $this->restHelper->shouldReceive(
'getUserId')->andReturn($this->userId);
203 $this->restHelper->shouldReceive(
'getPlugin')->withArgs(array(
"download"))->andReturn($this->downloadPlugin);
204 $this->restHelper->shouldReceive(
'getUploadDao')
205 ->andReturn($this->uploadDao);
206 $this->restHelper->shouldReceive(
'getFolderDao')
207 ->andReturn($this->folderDao);
208 $this->restHelper->shouldReceive(
'getUserDao')
209 ->andReturn($this->userDao);
210 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn(
212 $container->shouldReceive(
'get')->withArgs(array(
213 'dao.clearing'))->andReturn($this->clearingDao);
214 $container->shouldReceive(
'get')->withArgs(array(
215 'helper.restHelper'))->andReturn($this->restHelper);
216 $container->shouldReceive(
'get')->withArgs(array(
217 'dao.agent'))->andReturn($this->agentDao);
218 $container->shouldReceive(
'get')->withArgs(array(
219 'dao.upload'))->andReturn($this->uploadDao);
220 $container->shouldReceive(
'get')->withArgs(
221 [
'db.manager'])->andReturn($this->
dbManager);
222 $container->shouldReceive(
'get')->withArgs(array(
'dao.license'))->andReturn($this->licenseDao);
223 $container->shouldReceive(
'get')->withArgs(array(
224 'businessrules.reusereportprocessor'))->andReturn($this->reuseReportProcess);
226 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
227 $this->streamFactory =
new StreamFactory();
236 $this->addToAssertionCount(
237 \Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
249 $response->getBody()->seek(0);
250 return json_decode($response->getBody()->getContents(),
true);
263 $itemId = ($id * 100) + 1;
264 $left = ($id * 100) + 2;
265 $right = ($id * 100) + 50;
266 return new ItemTreeBounds($itemId,
'uploadtree_a', $id, $left, $right);
284 $uploadName =
"top$id";
285 $uploadDate =
"01-01-2020";
289 $uploadName =
"child$id";
290 $uploadDate =
"02-01-2020";
294 $uploadName =
"child$id";
295 $uploadDate =
"03-01-2020";
301 $hash =
new Hash(
'sha1checksum',
'md5checksum',
'sha256checksum', $fileSize);
302 return new Upload($folderId, $folderName, $id, $description,
303 $uploadName, $uploadDate,
null, $hash);
341 $requestHeaders =
new Headers();
342 $body = $this->streamFactory->createStream();
343 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
344 "/uploads/$uploadId"), $requestHeaders, [], [], $body);
345 if ($version == ApiVersion::V2) {
346 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
349 $this->dbHelper->shouldReceive(
'doesIdExist')
350 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
351 $this->uploadDao->shouldReceive(
'isAccessible')
352 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
353 $this->uploadDao->shouldReceive(
'getParentItemBounds')
355 $this->dbHelper->shouldReceive(
'getUploads')
356 ->withArgs([$this->userId, $this->groupId, 100, 1, $uploadId, $options,
357 true, $version])->andReturn([1, [$upload->getArray()]]);
358 $expectedResponse = (
new ResponseHelper())->withJson($upload->getArray(), 200);
359 $actualResponse = $this->uploadController->getUploads($request,
361 $this->assertEquals($expectedResponse->getStatusCode(),
362 $actualResponse->getStatusCode());
375 $requestHeaders =
new Headers();
376 $body = $this->streamFactory->createStream();
377 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
378 "/uploads/$uploadId"), $requestHeaders, [], [], $body);
379 $this->dbHelper->shouldReceive(
'doesIdExist')
380 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
381 $this->uploadDao->shouldReceive(
'isAccessible')
382 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
383 $this->expectException(HttpForbiddenException::class);
385 $this->uploadController->getUploads($request,
new ResponseHelper(),
386 [
'id' => $uploadId]);
398 $this->testGetUploadWithFilters(ApiVersion::V1);
409 $this->testGetUploadWithFilters(ApiVersion::V2);
412 private function testGetUploadWithFilters($version)
424 $folderOptions = $options;
425 $folderOptions[
"folderId"] = $folderId;
426 $requestHeaders =
new Headers();
427 $body = $this->streamFactory->createStream();
428 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
430 $requestHeaders, [], [], $body);
431 if ($version == ApiVersion::V2) {
432 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
435 $this->folderDao->shouldReceive(
'isFolderAccessible')
436 ->withArgs([$folderId, $this->userId])->andReturn(
true)->once();
437 $this->dbHelper->shouldReceive(
'getUploads')
438 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $folderOptions,
439 true, $version])->andReturn([1, []])->once();
440 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
444 $nameOptions = $options;
445 $nameOptions[
"name"] = $name;
446 $requestHeaders =
new Headers();
447 $body = $this->streamFactory->createStream();
448 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
451 if ($version == ApiVersion::V2) {
452 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
455 $this->dbHelper->shouldReceive(
'getUploads')
456 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $nameOptions,
457 true, $version])->andReturn([1, []])->once();
458 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
461 $statusString =
"InProgress";
462 $status = UploadStatus::IN_PROGRESS;
463 $statusOptions = $options;
464 $statusOptions[
"status"] = $status;
465 $requestHeaders =
new Headers();
466 $body = $this->streamFactory->createStream();
467 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
469 $requestHeaders, [], [], $body);
470 if ($version == ApiVersion::V2) {
471 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
474 $this->dbHelper->shouldReceive(
'getUploads')
475 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $statusOptions,
476 true, $version])->andReturn([1, []])->once();
477 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
481 $assigneeOptions = $options;
483 $requestHeaders =
new Headers();
484 $body = $this->streamFactory->createStream();
485 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
487 $requestHeaders, [], [], $body);
488 if ($version == ApiVersion::V2) {
489 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
492 $this->dbHelper->shouldReceive(
'getUploads')
493 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $assigneeOptions,
494 true, $version])->andReturn([1, []])->once();
495 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
498 $since =
"2021-02-28";
499 $sinceOptions = $options;
500 $sinceOptions[
"since"] = strtotime($since);
501 $requestHeaders =
new Headers();
502 $body = $this->streamFactory->createStream();
503 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
505 $requestHeaders, [], [], $body);
506 if ($version == ApiVersion::V2) {
507 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
510 $this->dbHelper->shouldReceive(
'getUploads')
511 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $sinceOptions,
512 true, $version])->andReturn([1, []])->once();
513 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
516 $statusString =
"Open";
517 $status = UploadStatus::OPEN;
518 $since =
"2021-02-28";
519 $combOptions = $options;
520 $combOptions[
"since"] = strtotime($since);
521 $combOptions[
"status"] = $status;
522 $requestHeaders =
new Headers();
523 $body = $this->streamFactory->createStream();
524 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
527 $requestHeaders, [], [], $body);
528 if ($version == ApiVersion::V2) {
529 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
532 $this->dbHelper->shouldReceive(
'getUploads')
533 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $combOptions,
534 true, $version])->andReturn([1, []])->once();
535 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
544 $this->testGetUploads(ApiVersion::V1);
552 $this->testGetUploads(ApiVersion::V2);
554 private function testGetUploads($version)
568 $requestHeaders =
new Headers();
569 $body = $this->streamFactory->createStream();
570 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
571 "/uploads/"), $requestHeaders, [], [], $body);
572 if ($version == ApiVersion::V2) {
573 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
576 $this->dbHelper->shouldReceive(
'getUploads')
577 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $options,
true, $version])
578 ->andReturn([1, $uploads]);
579 $expectedResponse = (
new ResponseHelper())->withJson($uploads, 200);
580 $actualResponse = $this->uploadController->getUploads($request,
582 $this->assertEquals($expectedResponse->getStatusCode(),
583 $actualResponse->getStatusCode());
597 $requestHeaders =
new Headers();
598 $body = $this->streamFactory->createStream();
599 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
600 "/uploads/"), $requestHeaders, [], [], $body);
601 $this->dbHelper->shouldReceive(
'doesIdExist')
602 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
603 $this->uploadDao->shouldReceive(
'isAccessible')
604 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
605 $this->uploadDao->shouldReceive(
'getParentItemBounds')
606 ->withArgs([$uploadId])->andReturn(
false);
607 $this->expectException(HttpServiceUnavailableException::class);
609 $this->uploadController->getUploads($request,
new ResponseHelper(),
610 [
'id' => $uploadId]);
640 $info =
new Info(202,
"Upload $uploadId will be copied to folder $folderId",
643 $this->restHelper->shouldReceive(
'copyUpload')
644 ->withArgs([$uploadId, $folderId,
true])->andReturn($info);
645 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
648 $requestHeaders =
new Headers();
649 $body = $this->streamFactory->createStream();
651 if($version==ApiVersion::V1){
652 $requestHeaders->setHeader(
'folderId', $folderId);
653 $requestHeaders->setHeader(
'action',
'copy');
654 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
655 $requestHeaders, [], [], $body);
656 $actualResponse = $this->uploadController->moveUpload($request,
660 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
661 $requestHeaders, [], [], $body);
662 if ($version == ApiVersion::V2) {
663 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
666 $actualResponse = $this->uploadController->moveUpload($request->withUri($request->getUri()->withQuery(
"folderId=$folderId&action=copy")),
669 $this->assertEquals($expectedResponse->getStatusCode(),
670 $actualResponse->getStatusCode());
704 $requestHeaders =
new Headers();
705 $requestHeaders->setHeader(
'folderId',
'alpha');
706 $requestHeaders->setHeader(
'action',
'move');
707 $body = $this->streamFactory->createStream();
708 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
709 $requestHeaders, [], [], $body);
710 if ($version==ApiVersion::V2) {
711 $request = $request->withQueryParams([
'folderId' =>
'alpha',
'action' =>
'move']);
713 $request = $request->withHeader(
"folderId",
"alpha")
714 ->withHeader(
"action",
"move");
716 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
717 $this->expectException(HttpBadRequestException::class);
719 $this->uploadController->moveUpload($request,
new ResponseHelper(),
720 [
'id' => $uploadId]);
755 $uploadDescription =
"Test Upload";
757 $requestHeaders =
new Headers();
758 $requestHeaders->setHeader(
'Content-Type',
'application/json');
759 if ($version == ApiVersion::V2) {
761 "location" =>
"data",
762 "folderId" => $folderId,
763 "uploadDescription" => $uploadDescription,
764 "ignoreScm" =>
"true",
765 "scanOptions" =>
"scanOptions",
766 "uploadType" =>
"vcs",
767 "excludeFolder" =>
"false"
771 "location" =>
"data",
772 "scanOptions" =>
"scanOptions"
774 $requestHeaders->setHeader(
'folderId', $folderId);
775 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
776 $requestHeaders->setHeader(
'ignoreScm',
'true');
777 $requestHeaders->setHeader(
'Content-Type',
'application/json');
778 $requestHeaders->setHeader(
'uploadType',
'vcs');
781 $body = $this->streamFactory->createStream(json_encode(
784 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
785 $requestHeaders, [], [], $body);
786 if ($version == ApiVersion::V2) {
787 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
790 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
791 if ($version == ApiVersion::V2) {
792 $uploadHelper->shouldReceive(
'createNewUpload')
793 ->withArgs([$reqBody[
"location"], $folderId, $uploadDescription,
'protected',
'true',
794 'vcs',
false,
false])
795 ->andReturn([
true,
'',
'', $uploadId]);
797 $uploadHelper->shouldReceive(
'createNewUpload')
798 ->withArgs([$reqBody[
"location"], $folderId, $uploadDescription,
'protected',
'true',
800 ->andReturn([
true,
'',
'', $uploadId]);
803 $info =
new Info(201, intval(20), InfoType::INFO);
805 $uploadHelper->shouldReceive(
'handleScheduleAnalysis')->withArgs([$uploadId,$folderId,$reqBody[
"scanOptions"],
false])
808 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
809 $this->folderDao->shouldReceive(
'isFolderAccessible')
810 ->withArgs([$folderId])->andReturn(
true);
812 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
814 $actualResponse = $this->uploadController->postUpload($request,
816 $this->assertEquals($expectedResponse->getStatusCode(),
817 $actualResponse->getStatusCode());
853 $uploadDescription =
"Test Upload";
855 $requestHeaders =
new Headers();
856 $requestHeaders->setHeader(
'Content-type',
'application/json');
857 if ($version == ApiVersion::V2) {
858 $body = $this->streamFactory->createStream(json_encode([
859 "location" =>
"data",
860 "folderId" => $folderId,
861 "uploadDescription" => $uploadDescription,
862 "ignoreScm" =>
"true",
863 "scanOptions" =>
"scanOptions",
864 "uploadType" =>
"vcs"
867 $body = $this->streamFactory->createStream(json_encode([
868 "location" =>
"data",
869 "scanOptions" =>
"scanOptions"
871 $requestHeaders->setHeader(
'folderId', $folderId);
872 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
873 $requestHeaders->setHeader(
'ignoreScm',
'true');
874 $requestHeaders->setHeader(
'Content-Type',
'application/json');
875 $requestHeaders->setHeader(
'uploadType',
'vcs');
877 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
878 $requestHeaders, [], [], $body);
879 if ($version == ApiVersion::V2) {
880 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
884 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
886 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
887 $this->folderDao->shouldReceive(
'isFolderAccessible')
888 ->withArgs([$folderId])->andReturn(
false);
889 $this->expectException(HttpForbiddenException::class);
891 $this->uploadController->postUpload($request,
new ResponseHelper(),
926 $uploadDescription =
"Test Upload";
928 $requestHeaders =
new Headers();
929 $requestHeaders->setHeader(
'Content-type',
'application/json');
930 if ($version == ApiVersion::V2) {
931 $body = $this->streamFactory->createStream(json_encode([
932 "location" =>
"vcsData",
933 "folderId" => $folderId,
934 "uploadDescription" => $uploadDescription,
935 "ignoreScm" =>
"true",
936 "scanOptions" =>
"scanOptions",
937 "uploadType" =>
"vcs"
940 $body = $this->streamFactory->createStream(json_encode([
941 "location" =>
"vcsData",
942 "scanOptions" =>
"scanOptions"
944 $requestHeaders->setHeader(
'folderId', $folderId);
945 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
946 $requestHeaders->setHeader(
'ignoreScm',
'true');
947 $requestHeaders->setHeader(
'Content-Type',
'application/json');
948 $requestHeaders->setHeader(
'uploadType',
'vcs');
950 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
951 $requestHeaders, [], [], $body);
952 if ($version == ApiVersion::V2) {
953 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
957 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
959 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
960 $this->expectException(HttpNotFoundException::class);
962 $this->uploadController->postUpload($request,
new ResponseHelper(),
997 $uploadDescription =
"Test Upload";
998 $errorMessage =
"Failed to insert upload record";
1001 $requestHeaders =
new Headers();
1002 $requestHeaders->setHeader(
'Content-type',
'application/json');
1003 if ($version == ApiVersion::V2) {
1004 $body = $this->streamFactory->createStream(json_encode([
1005 "location" =>
"vcsData",
1006 "folderId" => $folderId,
1007 "uploadDescription" => $uploadDescription,
1008 "ignoreScm" =>
"true",
1009 "scanOptions" =>
"scanOptions",
1010 "uploadType" =>
"vcs",
1011 "excludeFolder" =>
"false"
1014 $body = $this->streamFactory->createStream(json_encode([
1015 "location" =>
"vcsData",
1016 "scanOptions" =>
"scanOptions"
1018 $requestHeaders->setHeader(
'folderId', $folderId);
1019 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
1020 $requestHeaders->setHeader(
'ignoreScm',
'true');
1021 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1022 $requestHeaders->setHeader(
'uploadType',
'vcs');
1025 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1026 $requestHeaders, [], [], $body);
1027 if ($version == ApiVersion::V2) {
1028 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
1032 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
1033 if ($version == ApiVersion::V2) {
1034 $uploadHelper->shouldReceive(
'createNewUpload')
1035 ->withArgs([
'vcsData', $folderId, $uploadDescription,
'protected',
'true',
1036 'vcs',
false,
false])
1037 ->andReturn([
false, $errorMessage, $errorDesc, [-1]]);
1039 $uploadHelper->shouldReceive(
'createNewUpload')
1040 ->withArgs([
'vcsData', $folderId, $uploadDescription,
'protected',
'true',
1042 ->andReturn([
false, $errorMessage, $errorDesc, [-1]]);
1045 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
1046 $this->folderDao->shouldReceive(
'isFolderAccessible')
1047 ->withArgs([$folderId])->andReturn(
true);
1048 $this->expectException(HttpInternalServerErrorException::class);
1050 $this->uploadController->postUpload($request,
new ResponseHelper(), []);
1062 $this->testGetUploadLicenses(ApiVersion::V1);
1073 $this->testGetUploadLicenses(ApiVersion::V2);
1075 private function testGetUploadLicenses($version)
1079 [
'agentName' =>
'nomos',
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1080 [
'agentName' =>
'monk',
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1082 $licenseResponse = [
1083 [
'filePath' =>
'filea',
'agentFindings' =>
'MIT',
'conclusions' =>
'MIT'],
1084 [
'filePath' =>
'fileb',
'agentFindings' =>
'MIT',
1085 'conclusions' =>
'No_license_found']
1088 $requestHeaders =
new Headers();
1089 $body = $this->streamFactory->createStream();
1090 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1092 "=nomos,monk&containers=false"),
1093 $requestHeaders, [], [], $body);
1094 if ($version == ApiVersion::V2) {
1095 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
1098 $this->dbHelper->shouldReceive(
'doesIdExist')
1099 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1100 $this->uploadDao->shouldReceive(
'isAccessible')
1101 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1102 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1103 ->withArgs([$uploadId])->andReturn($this->
getUploadBounds($uploadId));
1104 $this->agentDao->shouldReceive(
'arsTableExists')
1105 ->withArgs([M::anyOf(
'nomos',
'monk')])->andReturn(
true);
1107 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1108 $scanJobProxy->shouldReceive(
'createAgentStatus')
1109 ->withArgs([[
'nomos',
'monk']])
1110 ->andReturn($agentsRun);
1112 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
1113 $uploadHelper->shouldReceive(
'getUploadLicenseList')
1114 ->withArgs([$uploadId, [
'nomos',
'monk'],
false,
true,
false, 0, 50, $version])
1115 ->andReturn(([[$licenseResponse], 1]));
1117 $expectedResponse = (
new ResponseHelper())->withJson($licenseResponse, 200);
1119 $actualResponse = $this->uploadController->getUploadLicenses($request,
1121 $this->assertEquals($expectedResponse->getStatusCode(),
1122 $actualResponse->getStatusCode());
1125 $this->assertEquals(
'1',
1126 $actualResponse->getHeaderLine(
'X-Total-Pages'));
1161 [
'agentName' =>
'nomos',
'currentAgentId' => 2,
'isAgentRunning' =>
true],
1162 [
'agentName' =>
'monk',
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1165 $requestHeaders =
new Headers();
1166 $body = $this->streamFactory->createStream();
1167 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1169 "=nomos,monk&containers=false"),
1170 $requestHeaders, [], [], $body);
1171 if ($version == ApiVersion::V2) {
1172 $request = $request->withQueryParams([
'page' => 1,
'limit' => 2,
"agent" =>
"nomos,monk" ]);
1174 $request = $request->withHeader(
"limit",2)
1175 ->withHeader(
"page",1);
1177 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
1179 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1180 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agentsRun]);
1181 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1182 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1183 $this->dbHelper->shouldReceive(
'doesIdExist')
1184 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1185 $this->uploadDao->shouldReceive(
'isAccessible')
1186 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1187 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1188 ->withArgs([$uploadId])->andReturn($this->
getUploadBounds($uploadId));
1189 $this->agentDao->shouldReceive(
'arsTableExists')
1190 ->withArgs([M::anyOf(
'nomos',
'monk')])->andReturn(
true);
1192 $scanJobProxy->shouldReceive(
'createAgentStatus')
1193 ->withArgs([[
'nomos',
'monk']])
1194 ->andReturn($agentsRun);
1195 $this->expectException(HttpServiceUnavailableException::class);
1197 $this->uploadController->getUploadLicenses($request,
new ResponseHelper(),
1198 [
'id' => $uploadId]);
1210 $status = UploadStatus::REJECTED;
1211 $comment =
"Not helpful";
1213 $resource = fopen(
'data://text/plain;base64,' .
1214 base64_encode($comment),
'r+');
1215 $body = $this->streamFactory->createStreamFromResource($resource);
1216 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1219 new Headers(), [], [], $body);
1221 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
1222 ->withArgs([$this->userId, $this->groupId])
1224 $this->userDao->shouldReceive(
'getUserChoices')
1225 ->withArgs([$this->groupId])
1226 ->andReturn([$this->userId =>
"fossy", $assignee =>
"friendly-fossy"]);
1227 $this->
dbManager->shouldReceive(
'getSingleRow')
1228 ->withArgs([M::any(), [$assignee, $this->groupId, $upload], M::any()]);
1229 $this->
dbManager->shouldReceive(
'getSingleRow')
1230 ->withArgs([M::any(), [$status, $comment, $this->groupId, $upload],
1232 $this->
dbManager->shouldReceive(
'getSingleRow')
1233 ->withArgs([M::any(), [$upload], M::any()])
1234 ->andReturn([
"exists" =>
""]);
1236 $info =
new Info(202,
"Upload updated successfully.", InfoType::INFO);
1237 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
1239 $actualResponse = $this->uploadController->updateUpload($request,
1241 $this->assertEquals($expectedResponse->getStatusCode(),
1242 $actualResponse->getStatusCode());
1256 $comment =
"Not helpful";
1258 $resource = fopen(
'data://text/plain;base64,' .
1259 base64_encode($comment),
'r+');
1260 $body = $this->streamFactory->createStreamFromResource($resource);
1261 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1264 new Headers(), [], [], $body);
1266 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
1267 ->withArgs([$this->userId, $this->groupId])
1269 $this->expectException(HttpForbiddenException::class);
1271 $this->uploadController->updateUpload($request,
new ResponseHelper(),
1283 $licenseIds = array();
1285 $licenseIds[$licenseId] = $licenseId;
1286 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
1289 $this->uploadDao->shouldReceive(
'isAccessible')
1290 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1291 $this->dbHelper->shouldReceive(
'doesIdExist')
1292 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1293 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1294 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
false])->andReturn([]);
1295 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
true])->andReturn([]);
1296 $this->licenseDao->shouldReceive(
'getLicenseById')->withArgs([$licenseId])->andReturn($license);
1298 $licenses[] = $license->getArray();
1299 $expectedResponse = (
new ResponseHelper())->withJson($licenses, 200);
1300 $actualResponse = $this->uploadController->getMainLicenses(
null,
new ResponseHelper(), [
'id' => $uploadId]);
1301 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
1317 "shortName" => $shortName,
1319 $license =
new License(2, $shortName,
"MIT License",
"risk",
"texts", [],
1321 $licenseIds[$licenseId] = $licenseId;
1322 $this->uploadDao->shouldReceive(
'isAccessible')
1323 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1324 $this->dbHelper->shouldReceive(
'doesIdExist')
1325 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1326 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1327 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1328 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1329 $this->clearingDao->shouldReceive(
'makeMainLicense')
1330 ->withArgs([$uploadId, $this->groupId, $license->getId()])->andReturn(
null);
1332 $info =
new Info(200,
"Successfully added new main license", InfoType::INFO);
1334 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1335 $reqBody = $this->streamFactory->createStream(json_encode(
1338 $requestHeaders =
new Headers();
1339 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1340 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1341 $requestHeaders, [], [], $reqBody);
1343 $actualResponse = $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1345 $this->assertEquals($expectedResponse->getStatusCode(),
1346 $actualResponse->getStatusCode());
1362 "shortName" => $shortName,
1364 $license =
new License($licenseId, $shortName,
"MIT License",
"risk",
"texts", [],
1366 $licenseIds[$licenseId] = $licenseId;
1367 $this->uploadDao->shouldReceive(
'isAccessible')
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 $reqBody = $this->streamFactory->createStream(json_encode(
1380 $requestHeaders =
new Headers();
1381 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1382 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1383 $requestHeaders, [], [], $reqBody);
1384 $this->expectException(HttpBadRequestException::class);
1386 $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1400 $license =
new License($licenseId, $shortName,
"MIT License",
"risk",
"texts", [],
1402 $licenseIds[$licenseId] = $licenseId;
1404 $this->uploadDao->shouldReceive(
'isAccessible')
1405 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1406 $this->dbHelper->shouldReceive(
'doesIdExist')
1407 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1408 $this->dbHelper->shouldReceive(
'doesIdExist')
1409 ->withArgs([
"license_ref",
"rf_pk", $licenseId])->andReturn(
true);
1410 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1412 $this->clearingDao->shouldReceive(
'removeMainLicense')->withArgs([$uploadId, $this->groupId, $licenseId])->andReturn(
null);
1413 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1414 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1416 $info =
new Info(200,
"Main license removed successfully.", InfoType::INFO);
1417 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
1419 $actualResponse = $this->uploadController->removeMainLicense(
null,
1420 new ResponseHelper(), [
'id' => $uploadId,
'shortName' => $shortName]);
1421 $this->assertEquals($expectedResponse->getStatusCode(),
1422 $actualResponse->getStatusCode());
1435 $this->uploadDao->shouldReceive(
'isAccessible')
1436 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1437 $this->dbHelper->shouldReceive(
'doesIdExist')
1438 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1439 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1440 $this->uploadDao->shouldReceive(
"getGlobalDecisionSettingsFromInfo")->andReturn(
false);
1441 $this->agentDao->shouldReceive(
"arsTableExists")->andReturn(
true);
1442 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->andReturn([[
'agent_id' => 1,
'agent_rev' => 1]]);
1443 $this->agentDao->shouldReceive(
"getCurrentAgentRef")->andReturn(
new AgentRef(1,
"agent", 1));
1444 $this->
dbManager->shouldReceive(
"getSingleRow")
1445 ->withArgs([M::any(), [],
'no_license_uploadtree' . $uploadId])
1446 ->andReturn([
'count' => 1]);
1447 $this->
dbManager->shouldReceive(
"getSingleRow")
1448 ->withArgs([M::any(), [],
'already_cleared_uploadtree' . $uploadId])
1449 ->andReturn([
'count' => 0]);
1450 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1451 ->withArgs([
'No_license_found'])->andReturn(
null);
1452 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1453 ->withArgs([
'Void'])->andReturn(
null);
1455 "totalFilesOfInterest" => 1,
1456 "totalFilesCleared" => 1,
1459 $actualResponse = $this->uploadController->getClearingProgressInfo(
null,
1461 $this->assertEquals($expectedResponse->getStatusCode(),
1462 $actualResponse->getStatusCode());
1474 $reuseReportSummary = [
1475 'declearedLicense' =>
"",
1476 'clearedLicense' =>
"MIT, BSD-3-Clause",
1477 'usedLicense' =>
"",
1478 'unusedLicense' =>
"",
1479 'missingLicense' =>
"MIT, BSD-3-Clause",
1481 $this->uploadDao->shouldReceive(
'isAccessible')
1482 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1483 $this->dbHelper->shouldReceive(
'doesIdExist')
1484 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1485 $this->reuseReportProcess->shouldReceive(
'getReuseSummary')
1486 ->withArgs([$uploadId])->andReturn($reuseReportSummary);
1488 $expectedResponse = (
new ResponseHelper())->withJson($reuseReportSummary,
1490 $actualResponse = $this->uploadController->getReuseReportSummary(
1492 $this->assertEquals($expectedResponse->getStatusCode(),
1493 $actualResponse->getStatusCode());
1511 $this->uploadDao->shouldReceive(
'isAccessible')
1512 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1513 $this->dbHelper->shouldReceive(
'doesIdExist')
1514 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1516 $this->restHelper->shouldReceive(
'getUploadPermissionDao')->andReturn($this->uploadPermissionDao);
1517 $this->uploadPermissionDao->shouldReceive(
"getPublicPermission")->withAnyArgs()->andReturn($publicPerm);
1518 $this->uploadPermissionDao->shouldReceive(
"getPermissionGroups")->withAnyArgs()->andReturn([]);
1519 $this->restHelper->shouldReceive(
"getGroupId")->andReturn($this->groupId);
1520 $this->restHelper->shouldReceive(
"getUserId")->andReturn($this->userId);
1521 $this->restHelper->shouldReceive(
"getUploadDao")->andReturn($this->uploadDao);
1523 $body = $this->streamFactory->createStream();
1524 $requestHeaders =
new Headers();
1525 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1526 $requestHeaders, [], [], $body);
1528 $actualResponse = $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1529 $this->assertEquals(200,$actualResponse->getStatusCode());
1542 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1544 $this->dbHelper->shouldReceive(
'doesIdExist')
1545 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1546 $body = $this->streamFactory->createStream();
1547 $requestHeaders =
new Headers();
1548 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1549 $requestHeaders, [], [], $body);
1551 $this->expectException(HttpNotFoundException::class);
1552 $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1564 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1565 $this->uploadDao->shouldReceive(
'isAccessible')->withAnyArgs()->andReturn(
false);
1567 $body = $this->streamFactory->createStream();
1568 $requestHeaders =
new Headers();
1569 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1570 $requestHeaders, [], [], $body);
1572 $this->expectException(HttpForbiddenException::class);
1573 $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1586 [
"uploadId" => $uploadId,
'agentName' =>
'nomos',
'successfulAgents'=> [],
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1587 [
"uploadId" => $uploadId,
'agentName' =>
'monk',
"successfulAgents" => [],
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1590 $this->restHelper->shouldReceive(
"getGroupId")->andReturn(
$groupId);
1591 $this->agentDao->shouldReceive(
"getCurrentAgentRef")->withAnyArgs()->andReturn(
new AgentRef($uploadId,
"momoa",45));
1593 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1594 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1595 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1596 $scanJobProxy->shouldReceive(
'createAgentStatus')
1598 ->andReturn($agentsRun);
1599 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1600 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agentsRun]);
1601 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1603 $body = $this->streamFactory->createStream();
1604 $requestHeaders =
new Headers();
1605 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1606 $requestHeaders, [], [], $body);
1608 $actualResponse = $this->uploadController->getAllAgents($request,
new ResponseHelper(),[
"id"=>$uploadId]);
1609 $this->assertEquals(200,$actualResponse->getStatusCode());
1621 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1622 $this->dbHelper->shouldReceive(
'doesIdExist')
1623 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1625 $this->expectException(HttpNotFoundException::class);
1626 $this->uploadController->getAllAgents(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1639 $this->uploadDao->shouldReceive(
'isAccessible')
1640 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
1641 $this->dbHelper->shouldReceive(
'doesIdExist')
1642 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1644 $this->expectException(HttpForbiddenException::class);
1645 $this->uploadController->getAllAgents(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1659 $uploadName =
"Testing name";
1660 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1662 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1663 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1664 $this->restHelper->shouldReceive(
'getUploadDao')->andReturn($this->uploadDao);
1665 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn($uploadName);
1666 $this->clearingDao->shouldReceive(
"getClearedLicenseIdAndMultiplicities")->withAnyArgs()->andReturn([]);
1668 $actualResponse = $this->uploadController->getEditedLicenses(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1669 $this->assertEquals(200,$actualResponse->getStatusCode());
1682 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1684 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1685 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1687 $this->expectException(HttpNotFoundException::class);
1701 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1703 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
false);
1704 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1706 $this->expectException(HttpForbiddenException::class);
1722 $this->uploadDao->shouldReceive(
'isAccessible')
1723 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1724 $this->dbHelper->shouldReceive(
'doesIdExist')
1725 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1726 $this->restHelper->shouldReceive(
'getUploadDao')->andReturn($this->uploadDao);
1727 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")
1728 ->withArgs([$uploadId])->andReturn(
"uploadtree");
1729 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1732 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1733 $scanJobProxy->shouldReceive(
'createAgentStatus')->withAnyArgs()->andReturn($agentsRun);
1734 $scanJobProxy->shouldReceive(
'getLatestSuccessfulAgentIds')->andReturn([2]);
1741 'spdx_id' =>
'GPL-2.0-only',
1744 $this->licenseDao->shouldReceive(
'getLicenseHistogram')
1745 ->withAnyArgs()->andReturn($histogram);
1747 $body = $this->streamFactory->createStream();
1748 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1749 new Headers(), [], [], $body);
1751 $actualResponse = $this->uploadController->getScannedLicenses(
1754 $this->assertEquals(200, $actualResponse->getStatusCode());
1756 $this->assertCount(1, $responseBody);
1757 $this->assertEquals(2, $responseBody[0][
'id']);
1758 $this->assertEquals(
'GPL-2.0-only', $responseBody[0][
'shortname']);
1759 $this->assertEquals(10, $responseBody[0][
'occurence']);
1760 $this->assertEquals(5, $responseBody[0][
'unique']);
1776 $this->uploadDao->shouldReceive(
'isAccessible')
1777 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1778 $this->dbHelper->shouldReceive(
'doesIdExist')
1779 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1780 $this->restHelper->shouldReceive(
'getUploadDao')->andReturn($this->uploadDao);
1781 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")
1782 ->withArgs([$uploadId])->andReturn(
"uploadtree");
1783 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1786 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1787 $scanJobProxy->shouldReceive(
'createAgentStatus')->withAnyArgs()->andReturn($agentsRun);
1788 $scanJobProxy->shouldReceive(
'getLatestSuccessfulAgentIds')->andReturn([2]);
1797 LicenseDao::NO_LICENSE_FOUND => [
1801 'spdx_id' => LicenseDao::NO_LICENSE_FOUND,
1804 $this->licenseDao->shouldReceive(
'getLicenseHistogram')
1805 ->withAnyArgs()->andReturn($histogram);
1807 $body = $this->streamFactory->createStream();
1808 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1809 new Headers(), [], [], $body);
1811 $actualResponse = $this->uploadController->getScannedLicenses(
1814 $this->assertEquals(200, $actualResponse->getStatusCode());
1816 $this->assertCount(2, $responseBody);
1818 $noLicenseEntry = array_values(array_filter($responseBody,
function ($e) {
1819 return $e[
'shortname'] === LicenseDao::NO_LICENSE_FOUND;
1821 $this->assertEquals(0, $noLicenseEntry[
'id']);
1822 $this->assertEquals(7, $noLicenseEntry[
'occurence']);
1834 $this->uploadDao->shouldReceive(
'isAccessible')
1835 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1836 $this->dbHelper->shouldReceive(
'doesIdExist')
1837 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1839 $body = $this->streamFactory->createStream();
1840 $requestHeaders =
new Headers();
1841 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1842 $requestHeaders, [], [], $body);
1844 $this->expectException(HttpNotFoundException::class);
1845 $this->uploadController->getScannedLicenses($request,
new ResponseHelper(),[
"id"=>$uploadId]);
1859 [
"uploadId" => $uploadId,
'agentName' =>
'nomos',
'successfulAgents'=> [],
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1860 [
"uploadId" => $uploadId,
'agentName' =>
'monk',
"successfulAgents" => [],
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1862 $agent =
new Agent([],$uploadId,
"MOMO agent",45,
"4.4.0.37.072417",
false,
"");
1864 $this->uploadDao->shouldReceive(
'isAccessible')
1865 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1866 $this->dbHelper->shouldReceive(
'doesIdExist')
1867 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1868 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1870 $scanJobProxy->shouldReceive(
'createAgentStatus')
1872 ->andReturn($agentsRun);
1873 $scanJobProxy->shouldReceive(
"getSuccessfulAgents")->andReturn($agent);
1874 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1875 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1876 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agent]);
1878 $actualResponse = $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1879 $this->assertEquals(200,$actualResponse->getStatusCode());
1892 $this->dbHelper->shouldReceive(
'doesIdExist')
1893 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1895 $this->expectException(HttpNotFoundException::class);
1896 $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1909 $this->uploadDao->shouldReceive(
'isAccessible')
1910 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
1911 $this->dbHelper->shouldReceive(
'doesIdExist')
1912 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1914 $this->expectException(HttpForbiddenException::class);
1915 $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1928 $this->dbHelper->shouldReceive(
'doesIdExist')
1929 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1930 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1932 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1934 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1936 $info =
new Info(200, $itemTreeBounds->getItemId(), InfoType::INFO);
1937 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1939 $this->assertEquals($expectedResponse->getStatusCode(),$actualResponse->getStatusCode());
1953 $this->dbHelper->shouldReceive(
'doesIdExist')
1954 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1956 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1957 $info =
new Info(404,
"Upload does not exist", InfoType::ERROR);
1958 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1959 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
1975 $this->dbHelper->shouldReceive(
'doesIdExist')
1976 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1977 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1979 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1981 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1984 $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)
testGetScannedLicensesWithNoLicenseFound()
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