44 use Slim\Psr7\Factory\StreamFactory;
45 use Slim\Psr7\Headers;
46 use Slim\Psr7\Request;
49 function TryToDelete($uploadpk, $user_pk, $group_pk, $uploadDao)
52 $group_pk, $uploadDao);
160 $container = M::mock(
'ContainerBuilder');
161 self::$functions = M::mock();
162 $this->dbHelper = M::mock(DbHelper::class);
163 $this->
dbManager = M::mock(DbManager::class);
164 $this->restHelper = M::mock(RestHelper::class);
165 $this->uploadDao = M::mock(UploadDao::class);
166 $this->folderDao = M::mock(FolderDao::class);
167 $this->agentDao = M::mock(AgentDao::class);
168 $this->userDao = M::mock(UserDao::class);
169 $this->clearingDao = M::mock(ClearingDao::class);
170 $this->licenseDao = M::mock(LicenseDao::class);
171 $this->reuseReportProcess = M::mock(ReuseReportProcessor::class);
173 $this->
dbManager->shouldReceive(
'getSingleRow')
174 ->withArgs([M::any(), [$this->groupId, UploadStatus::OPEN,
176 $this->dbHelper->shouldReceive(
'getDbManager')->andReturn($this->
dbManager);
178 $this->restHelper->shouldReceive(
'getDbHelper')->andReturn($this->dbHelper);
179 $this->restHelper->shouldReceive(
'getGroupId')->andReturn($this->groupId);
180 $this->restHelper->shouldReceive(
'getUserId')->andReturn($this->userId);
181 $this->restHelper->shouldReceive(
'getUploadDao')
182 ->andReturn($this->uploadDao);
183 $this->restHelper->shouldReceive(
'getFolderDao')
184 ->andReturn($this->folderDao);
185 $this->restHelper->shouldReceive(
'getUserDao')
186 ->andReturn($this->userDao);
187 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn(
189 $container->shouldReceive(
'get')->withArgs(array(
190 'dao.clearing'))->andReturn($this->clearingDao);
191 $container->shouldReceive(
'get')->withArgs(array(
192 'helper.restHelper'))->andReturn($this->restHelper);
193 $container->shouldReceive(
'get')->withArgs(array(
194 'dao.agent'))->andReturn($this->agentDao);
195 $container->shouldReceive(
'get')->withArgs(array(
196 'dao.upload'))->andReturn($this->uploadDao);
197 $container->shouldReceive(
'get')->withArgs(
198 [
'db.manager'])->andReturn($this->
dbManager);
199 $container->shouldReceive(
'get')->withArgs(array(
'dao.license'))->andReturn($this->licenseDao);
200 $container->shouldReceive(
'get')->withArgs(array(
201 'businessrules.reusereportprocessor'))->andReturn($this->reuseReportProcess);
203 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
204 $this->streamFactory =
new StreamFactory();
213 $this->addToAssertionCount(
214 \Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
226 $response->getBody()->seek(0);
227 return json_decode($response->getBody()->getContents(),
true);
240 $itemId = ($id * 100) + 1;
241 $left = ($id * 100) + 2;
242 $right = ($id * 100) + 50;
243 return new ItemTreeBounds($itemId,
'uploadtree_a', $id, $left, $right);
261 $uploadName =
"top$id";
262 $uploadDate =
"01-01-2020";
266 $uploadName =
"child$id";
267 $uploadDate =
"02-01-2020";
271 $uploadName =
"child$id";
272 $uploadDate =
"03-01-2020";
278 $hash =
new Hash(
'sha1checksum',
'md5checksum',
'sha256checksum', $fileSize);
279 return new Upload($folderId, $folderName, $id, $description,
280 $uploadName, $uploadDate,
null, $hash);
290 $this->testGetSingleUpload(ApiVersion::V1);
299 $this->testGetSingleUpload(ApiVersion::V2);
301 private function testGetSingleUpload($version)
312 $requestHeaders =
new Headers();
313 $body = $this->streamFactory->createStream();
314 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
315 "/uploads/$uploadId"), $requestHeaders, [], [], $body);
316 if ($version == ApiVersion::V2) {
317 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
320 $this->dbHelper->shouldReceive(
'doesIdExist')
321 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
322 $this->uploadDao->shouldReceive(
'isAccessible')
323 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
324 $this->uploadDao->shouldReceive(
'getParentItemBounds')
326 $this->dbHelper->shouldReceive(
'getUploads')
327 ->withArgs([$this->userId, $this->groupId, 100, 1, $uploadId, $options,
328 true, $version])->andReturn([1, [$upload->getArray()]]);
329 $expectedResponse = (
new ResponseHelper())->withJson($upload->getArray(), 200);
330 $actualResponse = $this->uploadController->getUploads($request,
332 $this->assertEquals($expectedResponse->getStatusCode(),
333 $actualResponse->getStatusCode());
346 $requestHeaders =
new Headers();
347 $body = $this->streamFactory->createStream();
348 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
349 "/uploads/$uploadId"), $requestHeaders, [], [], $body);
350 $this->dbHelper->shouldReceive(
'doesIdExist')
351 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
352 $this->uploadDao->shouldReceive(
'isAccessible')
353 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
354 $this->expectException(HttpForbiddenException::class);
356 $this->uploadController->getUploads($request,
new ResponseHelper(),
357 [
'id' => $uploadId]);
369 $this->testGetUploadWithFilters(ApiVersion::V1);
380 $this->testGetUploadWithFilters(ApiVersion::V2);
383 private function testGetUploadWithFilters($version)
395 $folderOptions = $options;
396 $folderOptions[
"folderId"] = $folderId;
397 $requestHeaders =
new Headers();
398 $body = $this->streamFactory->createStream();
399 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
401 $requestHeaders, [], [], $body);
402 if ($version == ApiVersion::V2) {
403 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
406 $this->folderDao->shouldReceive(
'isFolderAccessible')
407 ->withArgs([$folderId, $this->userId])->andReturn(
true)->once();
408 $this->dbHelper->shouldReceive(
'getUploads')
409 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $folderOptions,
410 true, $version])->andReturn([1, []])->once();
411 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
415 $nameOptions = $options;
416 $nameOptions[
"name"] = $name;
417 $requestHeaders =
new Headers();
418 $body = $this->streamFactory->createStream();
419 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
422 if ($version == ApiVersion::V2) {
423 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
426 $this->dbHelper->shouldReceive(
'getUploads')
427 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $nameOptions,
428 true, $version])->andReturn([1, []])->once();
429 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
432 $statusString =
"InProgress";
433 $status = UploadStatus::IN_PROGRESS;
434 $statusOptions = $options;
435 $statusOptions[
"status"] = $status;
436 $requestHeaders =
new Headers();
437 $body = $this->streamFactory->createStream();
438 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
440 $requestHeaders, [], [], $body);
441 if ($version == ApiVersion::V2) {
442 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
445 $this->dbHelper->shouldReceive(
'getUploads')
446 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $statusOptions,
447 true, $version])->andReturn([1, []])->once();
448 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
452 $assigneeOptions = $options;
454 $requestHeaders =
new Headers();
455 $body = $this->streamFactory->createStream();
456 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
458 $requestHeaders, [], [], $body);
459 if ($version == ApiVersion::V2) {
460 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
463 $this->dbHelper->shouldReceive(
'getUploads')
464 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $assigneeOptions,
465 true, $version])->andReturn([1, []])->once();
466 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
469 $since =
"2021-02-28";
470 $sinceOptions = $options;
471 $sinceOptions[
"since"] = strtotime($since);
472 $requestHeaders =
new Headers();
473 $body = $this->streamFactory->createStream();
474 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
476 $requestHeaders, [], [], $body);
477 if ($version == ApiVersion::V2) {
478 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
481 $this->dbHelper->shouldReceive(
'getUploads')
482 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $sinceOptions,
483 true, $version])->andReturn([1, []])->once();
484 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
487 $statusString =
"Open";
488 $status = UploadStatus::OPEN;
489 $since =
"2021-02-28";
490 $combOptions = $options;
491 $combOptions[
"since"] = strtotime($since);
492 $combOptions[
"status"] = $status;
493 $requestHeaders =
new Headers();
494 $body = $this->streamFactory->createStream();
495 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
498 $requestHeaders, [], [], $body);
499 if ($version == ApiVersion::V2) {
500 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
503 $this->dbHelper->shouldReceive(
'getUploads')
504 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $combOptions,
505 true, $version])->andReturn([1, []])->once();
506 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
515 $this->testGetUploads(ApiVersion::V1);
523 $this->testGetUploads(ApiVersion::V2);
525 private function testGetUploads($version)
539 $requestHeaders =
new Headers();
540 $body = $this->streamFactory->createStream();
541 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
542 "/uploads/"), $requestHeaders, [], [], $body);
543 if ($version == ApiVersion::V2) {
544 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
547 $this->dbHelper->shouldReceive(
'getUploads')
548 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $options,
true, $version])
549 ->andReturn([1, $uploads]);
550 $expectedResponse = (
new ResponseHelper())->withJson($uploads, 200);
551 $actualResponse = $this->uploadController->getUploads($request,
553 $this->assertEquals($expectedResponse->getStatusCode(),
554 $actualResponse->getStatusCode());
568 $requestHeaders =
new Headers();
569 $body = $this->streamFactory->createStream();
570 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
571 "/uploads/"), $requestHeaders, [], [], $body);
572 $this->dbHelper->shouldReceive(
'doesIdExist')
573 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
574 $this->uploadDao->shouldReceive(
'isAccessible')
575 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
576 $this->uploadDao->shouldReceive(
'getParentItemBounds')
577 ->withArgs([$uploadId])->andReturn(
false);
578 $this->expectException(HttpServiceUnavailableException::class);
580 $this->uploadController->getUploads($request,
new ResponseHelper(),
581 [
'id' => $uploadId]);
611 $info =
new Info(202,
"Upload $uploadId will be copied to folder $folderId",
614 $this->restHelper->shouldReceive(
'copyUpload')
615 ->withArgs([$uploadId, $folderId,
true])->andReturn($info);
616 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
619 $requestHeaders =
new Headers();
620 $body = $this->streamFactory->createStream();
622 if($version==ApiVersion::V1){
623 $requestHeaders->setHeader(
'folderId', $folderId);
624 $requestHeaders->setHeader(
'action',
'copy');
625 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
626 $requestHeaders, [], [], $body);
627 $actualResponse = $this->uploadController->moveUpload($request,
631 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
632 $requestHeaders, [], [], $body);
633 if ($version == ApiVersion::V2) {
634 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
637 $actualResponse = $this->uploadController->moveUpload($request->withUri($request->getUri()->withQuery(
"folderId=$folderId&action=copy")),
640 $this->assertEquals($expectedResponse->getStatusCode(),
641 $actualResponse->getStatusCode());
655 $requestHeaders =
new Headers();
656 $requestHeaders->setHeader(
'folderId',
'alpha');
657 $requestHeaders->setHeader(
'action',
'move');
658 $body = $this->streamFactory->createStream();
659 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
660 $requestHeaders, [], [], $body);
661 $this->expectException(HttpBadRequestException::class);
663 $this->uploadController->moveUpload($request,
new ResponseHelper(),
664 [
'id' => $uploadId]);
699 $uploadDescription =
"Test Upload";
701 $requestHeaders =
new Headers();
702 $requestHeaders->setHeader(
'Content-Type',
'application/json');
703 if ($version == ApiVersion::V2) {
705 "location" =>
"data",
706 "folderId" => $folderId,
707 "uploadDescription" => $uploadDescription,
708 "ignoreScm" =>
"true",
709 "scanOptions" =>
"scanOptions",
710 "uploadType" =>
"vcs"
714 "location" =>
"data",
715 "scanOptions" =>
"scanOptions"
717 $requestHeaders->setHeader(
'folderId', $folderId);
718 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
719 $requestHeaders->setHeader(
'ignoreScm',
'true');
720 $requestHeaders->setHeader(
'Content-Type',
'application/json');
721 $requestHeaders->setHeader(
'uploadType',
'vcs');
725 $body = $this->streamFactory->createStream(json_encode(
728 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
729 $requestHeaders, [], [], $body);
730 if ($version == ApiVersion::V2) {
731 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
734 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
735 $uploadHelper->shouldReceive(
'createNewUpload')
736 ->withArgs([$reqBody[
"location"], $folderId, $uploadDescription,
'protected',
'true',
738 ->andReturn([
true,
'',
'', $uploadId]);
740 $info =
new Info(201, intval(20), InfoType::INFO);
742 $uploadHelper->shouldReceive(
'handleScheduleAnalysis')->withArgs([$uploadId,$folderId,$reqBody[
"scanOptions"],
false])
745 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
746 $this->folderDao->shouldReceive(
'isFolderAccessible')
747 ->withArgs([$folderId])->andReturn(
true);
749 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
751 $actualResponse = $this->uploadController->postUpload($request,
753 $this->assertEquals($expectedResponse->getStatusCode(),
754 $actualResponse->getStatusCode());
790 $uploadDescription =
"Test Upload";
792 $requestHeaders =
new Headers();
793 $requestHeaders->setHeader(
'Content-type',
'application/json');
794 if ($version == ApiVersion::V2) {
795 $body = $this->streamFactory->createStream(json_encode([
796 "location" =>
"data",
797 "folderId" => $folderId,
798 "uploadDescription" => $uploadDescription,
799 "ignoreScm" =>
"true",
800 "scanOptions" =>
"scanOptions",
801 "uploadType" =>
"vcs"
804 $body = $this->streamFactory->createStream(json_encode([
805 "location" =>
"data",
806 "scanOptions" =>
"scanOptions"
808 $requestHeaders->setHeader(
'folderId', $folderId);
809 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
810 $requestHeaders->setHeader(
'ignoreScm',
'true');
811 $requestHeaders->setHeader(
'Content-Type',
'application/json');
812 $requestHeaders->setHeader(
'uploadType',
'vcs');
814 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
815 $requestHeaders, [], [], $body);
816 if ($version == ApiVersion::V2) {
817 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
821 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
823 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
824 $this->folderDao->shouldReceive(
'isFolderAccessible')
825 ->withArgs([$folderId])->andReturn(
false);
826 $this->expectException(HttpForbiddenException::class);
828 $this->uploadController->postUpload($request,
new ResponseHelper(),
863 $uploadDescription =
"Test Upload";
865 $requestHeaders =
new Headers();
866 $requestHeaders->setHeader(
'Content-type',
'application/json');
867 if ($version == ApiVersion::V2) {
868 $body = $this->streamFactory->createStream(json_encode([
869 "location" =>
"vcsData",
870 "folderId" => $folderId,
871 "uploadDescription" => $uploadDescription,
872 "ignoreScm" =>
"true",
873 "scanOptions" =>
"scanOptions",
874 "uploadType" =>
"vcs"
877 $body = $this->streamFactory->createStream(json_encode([
878 "location" =>
"vcsData",
879 "scanOptions" =>
"scanOptions"
881 $requestHeaders->setHeader(
'folderId', $folderId);
882 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
883 $requestHeaders->setHeader(
'ignoreScm',
'true');
884 $requestHeaders->setHeader(
'Content-Type',
'application/json');
885 $requestHeaders->setHeader(
'uploadType',
'vcs');
887 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
888 $requestHeaders, [], [], $body);
889 if ($version == ApiVersion::V2) {
890 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
894 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
896 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
897 $this->expectException(HttpNotFoundException::class);
899 $this->uploadController->postUpload($request,
new ResponseHelper(),
934 $uploadDescription =
"Test Upload";
935 $errorMessage =
"Failed to insert upload record";
939 $requestHeaders =
new Headers();
940 $requestHeaders->setHeader(
'Content-type',
'application/json');
941 if ($version == ApiVersion::V2) {
942 $body = $this->streamFactory->createStream(json_encode([
943 "location" =>
"vcsData",
944 "folderId" => $folderId,
945 "uploadDescription" => $uploadDescription,
946 "ignoreScm" =>
"true",
947 "scanOptions" =>
"scanOptions",
948 "uploadType" =>
"vcs"
951 $body = $this->streamFactory->createStream(json_encode([
952 "location" =>
"vcsData",
953 "scanOptions" =>
"scanOptions"
955 $requestHeaders->setHeader(
'folderId', $folderId);
956 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
957 $requestHeaders->setHeader(
'ignoreScm',
'true');
958 $requestHeaders->setHeader(
'Content-Type',
'application/json');
959 $requestHeaders->setHeader(
'uploadType',
'vcs');
962 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
963 $requestHeaders, [], [], $body);
964 if ($version == ApiVersion::V2) {
965 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
969 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
970 $uploadHelper->shouldReceive(
'createNewUpload')
971 ->withArgs([
'vcsData', $folderId, $uploadDescription,
'protected',
'true',
973 ->andReturn([
false, $errorMessage, $errorDesc, [-1]]);
975 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
976 $this->folderDao->shouldReceive(
'isFolderAccessible')
977 ->withArgs([$folderId])->andReturn(
true);
978 $this->expectException(HttpInternalServerErrorException::class);
980 $this->uploadController->postUpload($request,
new ResponseHelper(), []);
992 $this->testGetUploadLicenses(ApiVersion::V1);
1003 $this->testGetUploadLicenses(ApiVersion::V2);
1005 private function testGetUploadLicenses($version)
1009 [
'agentName' =>
'nomos',
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1010 [
'agentName' =>
'monk',
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1012 $licenseResponse = [
1013 [
'filePath' =>
'filea',
'agentFindings' =>
'MIT',
'conclusions' =>
'MIT'],
1014 [
'filePath' =>
'fileb',
'agentFindings' =>
'MIT',
1015 'conclusions' =>
'No_license_found']
1018 $requestHeaders =
new Headers();
1019 $body = $this->streamFactory->createStream();
1020 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1022 "=nomos,monk&containers=false"),
1023 $requestHeaders, [], [], $body);
1024 if ($version == ApiVersion::V2) {
1025 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
1028 $this->dbHelper->shouldReceive(
'doesIdExist')
1029 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1030 $this->uploadDao->shouldReceive(
'isAccessible')
1031 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1032 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1033 ->withArgs([$uploadId])->andReturn($this->
getUploadBounds($uploadId));
1034 $this->agentDao->shouldReceive(
'arsTableExists')
1035 ->withArgs([M::anyOf(
'nomos',
'monk')])->andReturn(
true);
1037 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1038 $scanJobProxy->shouldReceive(
'createAgentStatus')
1039 ->withArgs([[
'nomos',
'monk']])
1040 ->andReturn($agentsRun);
1042 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
1043 $uploadHelper->shouldReceive(
'getUploadLicenseList')
1044 ->withArgs([$uploadId, [
'nomos',
'monk'],
false,
true,
false, 0, 50, $version])
1045 ->andReturn(([[$licenseResponse], 1]));
1047 $expectedResponse = (
new ResponseHelper())->withJson($licenseResponse, 200);
1049 $actualResponse = $this->uploadController->getUploadLicenses($request,
1051 $this->assertEquals($expectedResponse->getStatusCode(),
1052 $actualResponse->getStatusCode());
1055 $this->assertEquals(
'1',
1056 $actualResponse->getHeaderLine(
'X-Total-Pages'));
1071 [
'agentName' =>
'nomos',
'currentAgentId' => 2,
'isAgentRunning' =>
true],
1072 [
'agentName' =>
'monk',
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1075 $requestHeaders =
new Headers();
1076 $body = $this->streamFactory->createStream();
1077 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1079 "=nomos,monk&containers=false"),
1080 $requestHeaders, [], [], $body);
1082 $this->dbHelper->shouldReceive(
'doesIdExist')
1083 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1084 $this->uploadDao->shouldReceive(
'isAccessible')
1085 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1086 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1087 ->withArgs([$uploadId])->andReturn($this->
getUploadBounds($uploadId));
1088 $this->agentDao->shouldReceive(
'arsTableExists')
1089 ->withArgs([M::anyOf(
'nomos',
'monk')])->andReturn(
true);
1091 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1092 $scanJobProxy->shouldReceive(
'createAgentStatus')
1093 ->withArgs([[
'nomos',
'monk']])
1094 ->andReturn($agentsRun);
1095 $this->expectException(HttpServiceUnavailableException::class);
1097 $this->uploadController->getUploadLicenses($request,
new ResponseHelper(),
1098 [
'id' => $uploadId]);
1110 $status = UploadStatus::REJECTED;
1111 $comment =
"Not helpful";
1113 $resource = fopen(
'data://text/plain;base64,' .
1114 base64_encode($comment),
'r+');
1115 $body = $this->streamFactory->createStreamFromResource($resource);
1116 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1119 new Headers(), [], [], $body);
1121 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
1122 ->withArgs([$this->userId, $this->groupId])
1124 $this->userDao->shouldReceive(
'getUserChoices')
1125 ->withArgs([$this->groupId])
1126 ->andReturn([$this->userId =>
"fossy", $assignee =>
"friendly-fossy"]);
1127 $this->
dbManager->shouldReceive(
'getSingleRow')
1128 ->withArgs([M::any(), [$assignee, $this->groupId, $upload], M::any()]);
1129 $this->
dbManager->shouldReceive(
'getSingleRow')
1130 ->withArgs([M::any(), [$status, $comment, $this->groupId, $upload],
1132 $this->
dbManager->shouldReceive(
'getSingleRow')
1133 ->withArgs([M::any(), [$upload], M::any()])
1134 ->andReturn([
"exists" =>
""]);
1136 $info =
new Info(202,
"Upload updated successfully.", InfoType::INFO);
1137 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
1139 $actualResponse = $this->uploadController->updateUpload($request,
1141 $this->assertEquals($expectedResponse->getStatusCode(),
1142 $actualResponse->getStatusCode());
1156 $comment =
"Not helpful";
1158 $resource = fopen(
'data://text/plain;base64,' .
1159 base64_encode($comment),
'r+');
1160 $body = $this->streamFactory->createStreamFromResource($resource);
1161 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1164 new Headers(), [], [], $body);
1166 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
1167 ->withArgs([$this->userId, $this->groupId])
1169 $this->expectException(HttpForbiddenException::class);
1171 $this->uploadController->updateUpload($request,
new ResponseHelper(),
1183 $licenseIds = array();
1185 $licenseIds[$licenseId] = $licenseId;
1186 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
1189 $this->uploadDao->shouldReceive(
'isAccessible')
1190 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1191 $this->dbHelper->shouldReceive(
'doesIdExist')
1192 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1193 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1194 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
false])->andReturn([]);
1195 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
true])->andReturn([]);
1196 $this->licenseDao->shouldReceive(
'getLicenseById')->withArgs([$licenseId])->andReturn($license);
1198 $licenses[] = $license->getArray();
1199 $expectedResponse = (
new ResponseHelper())->withJson($licenses, 200);
1200 $actualResponse = $this->uploadController->getMainLicenses(
null,
new ResponseHelper(), [
'id' => $uploadId]);
1201 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
1217 "shortName" => $shortName,
1219 $license =
new License(2, $shortName,
"MIT License",
"risk",
"texts", [],
1221 $licenseIds[$licenseId] = $licenseId;
1222 $this->uploadDao->shouldReceive(
'isAccessible')
1223 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1224 $this->dbHelper->shouldReceive(
'doesIdExist')
1225 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1226 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1227 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1228 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1229 $this->clearingDao->shouldReceive(
'makeMainLicense')
1230 ->withArgs([$uploadId, $this->groupId, $license->getId()])->andReturn(
null);
1232 $info =
new Info(200,
"Successfully added new main license", InfoType::INFO);
1234 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1235 $reqBody = $this->streamFactory->createStream(json_encode(
1238 $requestHeaders =
new Headers();
1239 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1240 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1241 $requestHeaders, [], [], $reqBody);
1243 $actualResponse = $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1245 $this->assertEquals($expectedResponse->getStatusCode(),
1246 $actualResponse->getStatusCode());
1262 "shortName" => $shortName,
1264 $license =
new License($licenseId, $shortName,
"MIT License",
"risk",
"texts", [],
1266 $licenseIds[$licenseId] = $licenseId;
1267 $this->uploadDao->shouldReceive(
'isAccessible')
1268 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1269 $this->dbHelper->shouldReceive(
'doesIdExist')
1270 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1271 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1272 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1273 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1274 $this->clearingDao->shouldReceive(
'makeMainLicense')
1275 ->withArgs([$uploadId, $this->groupId, $license->getId()])->andReturn(
null);
1277 $reqBody = $this->streamFactory->createStream(json_encode(
1280 $requestHeaders =
new Headers();
1281 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1282 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1283 $requestHeaders, [], [], $reqBody);
1284 $this->expectException(HttpBadRequestException::class);
1286 $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1300 $license =
new License($licenseId, $shortName,
"MIT License",
"risk",
"texts", [],
1302 $licenseIds[$licenseId] = $licenseId;
1304 $this->uploadDao->shouldReceive(
'isAccessible')
1305 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1306 $this->dbHelper->shouldReceive(
'doesIdExist')
1307 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1308 $this->dbHelper->shouldReceive(
'doesIdExist')
1309 ->withArgs([
"license_ref",
"rf_pk", $licenseId])->andReturn(
true);
1310 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1312 $this->clearingDao->shouldReceive(
'removeMainLicense')->withArgs([$uploadId, $this->groupId, $licenseId])->andReturn(
null);
1313 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1314 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1316 $info =
new Info(200,
"Main license removed successfully.", InfoType::INFO);
1317 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
1319 $actualResponse = $this->uploadController->removeMainLicense(
null,
1320 new ResponseHelper(), [
'id' => $uploadId,
'shortName' => $shortName]);
1321 $this->assertEquals($expectedResponse->getStatusCode(),
1322 $actualResponse->getStatusCode());
1335 $this->uploadDao->shouldReceive(
'isAccessible')
1336 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1337 $this->dbHelper->shouldReceive(
'doesIdExist')
1338 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1339 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1340 $this->uploadDao->shouldReceive(
"getGlobalDecisionSettingsFromInfo")->andReturn(
false);
1341 $this->agentDao->shouldReceive(
"arsTableExists")->andReturn(
true);
1342 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->andReturn([[
'agent_id' => 1,
'agent_rev' => 1]]);
1343 $this->agentDao->shouldReceive(
"getCurrentAgentRef")->andReturn(
new AgentRef(1,
"agent", 1));
1344 $this->
dbManager->shouldReceive(
"getSingleRow")
1345 ->withArgs([M::any(), [],
'no_license_uploadtree' . $uploadId])
1346 ->andReturn([
'count' => 1]);
1347 $this->
dbManager->shouldReceive(
"getSingleRow")
1348 ->withArgs([M::any(), [],
'already_cleared_uploadtree' . $uploadId])
1349 ->andReturn([
'count' => 0]);
1350 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1351 ->withArgs([
'No_license_found'])->andReturn(
null);
1352 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1353 ->withArgs([
'Void'])->andReturn(
null);
1355 "totalFilesOfInterest" => 1,
1356 "totalFilesCleared" => 1,
1359 $actualResponse = $this->uploadController->getClearingProgressInfo(
null,
1361 $this->assertEquals($expectedResponse->getStatusCode(),
1362 $actualResponse->getStatusCode());
1374 $reuseReportSummary = [
1375 'declearedLicense' =>
"",
1376 'clearedLicense' =>
"MIT, BSD-3-Clause",
1377 'usedLicense' =>
"",
1378 'unusedLicense' =>
"",
1379 'missingLicense' =>
"MIT, BSD-3-Clause",
1381 $this->uploadDao->shouldReceive(
'isAccessible')
1382 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1383 $this->dbHelper->shouldReceive(
'doesIdExist')
1384 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1385 $this->reuseReportProcess->shouldReceive(
'getReuseSummary')
1386 ->withArgs([$uploadId])->andReturn($reuseReportSummary);
1388 $expectedResponse = (
new ResponseHelper())->withJson($reuseReportSummary,
1390 $actualResponse = $this->uploadController->getReuseReportSummary(
1392 $this->assertEquals($expectedResponse->getStatusCode(),
1393 $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()
getResponseJson($response)
testGetClearingProgressInfo()
testPostUploadInternalError(int $version)
tearDown()
Remove test objects.
testPostUploadInternalErrorV1()
testPostUpload(int $version)
testPostUploadFolderNotAccessible(int $version)
testGetUploadLicensesPendingScan()
testGetUploadWithFiltersV2()
testGetUploadLicensesV1()
testPostUploadFolderNotAccessibleV2()
testPostUploadInternalErrorV2()
testPostUploadFolderNotFoundV2()
testGetUploadWithFiltersV1()
testGetSingleUploadInAccessible()
setUp()
Setup test objects.
testGetSingleUploadNotUnpacked()
testGetUploadLicensesV2()
testPostUploadFolderNotFound(int $version)
testGetReuseReportSummary()
testPostUploadFolderNotAccessibleV1()
testPostUploadFolderNotFoundV1()
testMoveUploadInvalidFolder()
fo_dbManager * dbManager
fo_dbManager object