47 use Slim\Psr7\Factory\StreamFactory;
48 use Slim\Psr7\Headers;
49 use Slim\Psr7\Request;
52 function TryToDelete($uploadpk, $user_pk, $group_pk, $uploadDao)
55 $group_pk, $uploadDao);
163 private $copyrightPlugin;
168 private $downloadPlugin;
179 $container = M::mock(
'ContainerBuilder');
180 self::$functions = M::mock();
181 $this->dbHelper = M::mock(DbHelper::class);
182 $this->
dbManager = M::mock(DbManager::class);
183 $this->restHelper = M::mock(RestHelper::class);
184 $this->uploadDao = M::mock(UploadDao::class);
185 $this->folderDao = M::mock(FolderDao::class);
186 $this->agentDao = M::mock(AgentDao::class);
187 $this->userDao = M::mock(UserDao::class);
188 $this->clearingDao = M::mock(ClearingDao::class);
189 $this->licenseDao = M::mock(LicenseDao::class);
190 $this->reuseReportProcess = M::mock(ReuseReportProcessor::class);
191 $this->uploadPermissionDao = M::mock(UploadPermissionDao::class);
192 $this->downloadPlugin = M::mock(
"download");
194 $this->
dbManager->shouldReceive(
'getSingleRow')
195 ->withArgs([M::any(), [$this->groupId, UploadStatus::OPEN,
197 $this->dbHelper->shouldReceive(
'getDbManager')->andReturn($this->
dbManager);
199 $this->restHelper->shouldReceive(
'getDbHelper')->andReturn($this->dbHelper);
200 $this->restHelper->shouldReceive(
'getGroupId')->andReturn($this->groupId);
201 $this->restHelper->shouldReceive(
'getUserId')->andReturn($this->userId);
202 $this->restHelper->shouldReceive(
'getPlugin')->withArgs(array(
"download"))->andReturn($this->downloadPlugin);
203 $this->restHelper->shouldReceive(
'getUploadDao')
204 ->andReturn($this->uploadDao);
205 $this->restHelper->shouldReceive(
'getFolderDao')
206 ->andReturn($this->folderDao);
207 $this->restHelper->shouldReceive(
'getUserDao')
208 ->andReturn($this->userDao);
209 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn(
211 $container->shouldReceive(
'get')->withArgs(array(
212 'dao.clearing'))->andReturn($this->clearingDao);
213 $container->shouldReceive(
'get')->withArgs(array(
214 'helper.restHelper'))->andReturn($this->restHelper);
215 $container->shouldReceive(
'get')->withArgs(array(
216 'dao.agent'))->andReturn($this->agentDao);
217 $container->shouldReceive(
'get')->withArgs(array(
218 'dao.upload'))->andReturn($this->uploadDao);
219 $container->shouldReceive(
'get')->withArgs(
220 [
'db.manager'])->andReturn($this->
dbManager);
221 $container->shouldReceive(
'get')->withArgs(array(
'dao.license'))->andReturn($this->licenseDao);
222 $container->shouldReceive(
'get')->withArgs(array(
223 'businessrules.reusereportprocessor'))->andReturn($this->reuseReportProcess);
225 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
226 $this->streamFactory =
new StreamFactory();
235 $this->addToAssertionCount(
236 \Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
248 $response->getBody()->seek(0);
249 return json_decode($response->getBody()->getContents(),
true);
262 $itemId = ($id * 100) + 1;
263 $left = ($id * 100) + 2;
264 $right = ($id * 100) + 50;
265 return new ItemTreeBounds($itemId,
'uploadtree_a', $id, $left, $right);
283 $uploadName =
"top$id";
284 $uploadDate =
"01-01-2020";
288 $uploadName =
"child$id";
289 $uploadDate =
"02-01-2020";
293 $uploadName =
"child$id";
294 $uploadDate =
"03-01-2020";
300 $hash =
new Hash(
'sha1checksum',
'md5checksum',
'sha256checksum', $fileSize);
301 return new Upload($folderId, $folderName, $id, $description,
302 $uploadName, $uploadDate,
null, $hash);
340 $requestHeaders =
new Headers();
341 $body = $this->streamFactory->createStream();
342 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
343 "/uploads/$uploadId"), $requestHeaders, [], [], $body);
344 if ($version == ApiVersion::V2) {
345 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
348 $this->dbHelper->shouldReceive(
'doesIdExist')
349 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
350 $this->uploadDao->shouldReceive(
'isAccessible')
351 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
352 $this->uploadDao->shouldReceive(
'getParentItemBounds')
354 $this->dbHelper->shouldReceive(
'getUploads')
355 ->withArgs([$this->userId, $this->groupId, 100, 1, $uploadId, $options,
356 true, $version])->andReturn([1, [$upload->getArray()]]);
357 $expectedResponse = (
new ResponseHelper())->withJson($upload->getArray(), 200);
358 $actualResponse = $this->uploadController->getUploads($request,
360 $this->assertEquals($expectedResponse->getStatusCode(),
361 $actualResponse->getStatusCode());
374 $requestHeaders =
new Headers();
375 $body = $this->streamFactory->createStream();
376 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
377 "/uploads/$uploadId"), $requestHeaders, [], [], $body);
378 $this->dbHelper->shouldReceive(
'doesIdExist')
379 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
380 $this->uploadDao->shouldReceive(
'isAccessible')
381 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
382 $this->expectException(HttpForbiddenException::class);
384 $this->uploadController->getUploads($request,
new ResponseHelper(),
385 [
'id' => $uploadId]);
397 $this->testGetUploadWithFilters(ApiVersion::V1);
408 $this->testGetUploadWithFilters(ApiVersion::V2);
411 private function testGetUploadWithFilters($version)
423 $folderOptions = $options;
424 $folderOptions[
"folderId"] = $folderId;
425 $requestHeaders =
new Headers();
426 $body = $this->streamFactory->createStream();
427 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
429 $requestHeaders, [], [], $body);
430 if ($version == ApiVersion::V2) {
431 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
434 $this->folderDao->shouldReceive(
'isFolderAccessible')
435 ->withArgs([$folderId, $this->userId])->andReturn(
true)->once();
436 $this->dbHelper->shouldReceive(
'getUploads')
437 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $folderOptions,
438 true, $version])->andReturn([1, []])->once();
439 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
443 $nameOptions = $options;
444 $nameOptions[
"name"] = $name;
445 $requestHeaders =
new Headers();
446 $body = $this->streamFactory->createStream();
447 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
450 if ($version == ApiVersion::V2) {
451 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
454 $this->dbHelper->shouldReceive(
'getUploads')
455 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $nameOptions,
456 true, $version])->andReturn([1, []])->once();
457 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
460 $statusString =
"InProgress";
461 $status = UploadStatus::IN_PROGRESS;
462 $statusOptions = $options;
463 $statusOptions[
"status"] = $status;
464 $requestHeaders =
new Headers();
465 $body = $this->streamFactory->createStream();
466 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
468 $requestHeaders, [], [], $body);
469 if ($version == ApiVersion::V2) {
470 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
473 $this->dbHelper->shouldReceive(
'getUploads')
474 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $statusOptions,
475 true, $version])->andReturn([1, []])->once();
476 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
480 $assigneeOptions = $options;
482 $requestHeaders =
new Headers();
483 $body = $this->streamFactory->createStream();
484 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
486 $requestHeaders, [], [], $body);
487 if ($version == ApiVersion::V2) {
488 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
491 $this->dbHelper->shouldReceive(
'getUploads')
492 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $assigneeOptions,
493 true, $version])->andReturn([1, []])->once();
494 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
497 $since =
"2021-02-28";
498 $sinceOptions = $options;
499 $sinceOptions[
"since"] = strtotime($since);
500 $requestHeaders =
new Headers();
501 $body = $this->streamFactory->createStream();
502 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
504 $requestHeaders, [], [], $body);
505 if ($version == ApiVersion::V2) {
506 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
509 $this->dbHelper->shouldReceive(
'getUploads')
510 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $sinceOptions,
511 true, $version])->andReturn([1, []])->once();
512 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
515 $statusString =
"Open";
516 $status = UploadStatus::OPEN;
517 $since =
"2021-02-28";
518 $combOptions = $options;
519 $combOptions[
"since"] = strtotime($since);
520 $combOptions[
"status"] = $status;
521 $requestHeaders =
new Headers();
522 $body = $this->streamFactory->createStream();
523 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
526 $requestHeaders, [], [], $body);
527 if ($version == ApiVersion::V2) {
528 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
531 $this->dbHelper->shouldReceive(
'getUploads')
532 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $combOptions,
533 true, $version])->andReturn([1, []])->once();
534 $this->uploadController->getUploads($request,
new ResponseHelper(), []);
543 $this->testGetUploads(ApiVersion::V1);
551 $this->testGetUploads(ApiVersion::V2);
553 private function testGetUploads($version)
567 $requestHeaders =
new Headers();
568 $body = $this->streamFactory->createStream();
569 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
570 "/uploads/"), $requestHeaders, [], [], $body);
571 if ($version == ApiVersion::V2) {
572 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
575 $this->dbHelper->shouldReceive(
'getUploads')
576 ->withArgs([$this->userId, $this->groupId, 100, 1,
null, $options,
true, $version])
577 ->andReturn([1, $uploads]);
578 $expectedResponse = (
new ResponseHelper())->withJson($uploads, 200);
579 $actualResponse = $this->uploadController->getUploads($request,
581 $this->assertEquals($expectedResponse->getStatusCode(),
582 $actualResponse->getStatusCode());
596 $requestHeaders =
new Headers();
597 $body = $this->streamFactory->createStream();
598 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
599 "/uploads/"), $requestHeaders, [], [], $body);
600 $this->dbHelper->shouldReceive(
'doesIdExist')
601 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
602 $this->uploadDao->shouldReceive(
'isAccessible')
603 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
604 $this->uploadDao->shouldReceive(
'getParentItemBounds')
605 ->withArgs([$uploadId])->andReturn(
false);
606 $this->expectException(HttpServiceUnavailableException::class);
608 $this->uploadController->getUploads($request,
new ResponseHelper(),
609 [
'id' => $uploadId]);
639 $info =
new Info(202,
"Upload $uploadId will be copied to folder $folderId",
642 $this->restHelper->shouldReceive(
'copyUpload')
643 ->withArgs([$uploadId, $folderId,
true])->andReturn($info);
644 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
647 $requestHeaders =
new Headers();
648 $body = $this->streamFactory->createStream();
650 if($version==ApiVersion::V1){
651 $requestHeaders->setHeader(
'folderId', $folderId);
652 $requestHeaders->setHeader(
'action',
'copy');
653 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
654 $requestHeaders, [], [], $body);
655 $actualResponse = $this->uploadController->moveUpload($request,
659 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
660 $requestHeaders, [], [], $body);
661 if ($version == ApiVersion::V2) {
662 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
665 $actualResponse = $this->uploadController->moveUpload($request->withUri($request->getUri()->withQuery(
"folderId=$folderId&action=copy")),
668 $this->assertEquals($expectedResponse->getStatusCode(),
669 $actualResponse->getStatusCode());
703 $requestHeaders =
new Headers();
704 $requestHeaders->setHeader(
'folderId',
'alpha');
705 $requestHeaders->setHeader(
'action',
'move');
706 $body = $this->streamFactory->createStream();
707 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
708 $requestHeaders, [], [], $body);
709 if ($version==ApiVersion::V2) {
710 $request = $request->withQueryParams([
'folderId' =>
'alpha',
'action' =>
'move']);
712 $request = $request->withHeader(
"folderId",
"alpha")
713 ->withHeader(
"action",
"move");
715 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
716 $this->expectException(HttpBadRequestException::class);
718 $this->uploadController->moveUpload($request,
new ResponseHelper(),
719 [
'id' => $uploadId]);
754 $uploadDescription =
"Test Upload";
756 $requestHeaders =
new Headers();
757 $requestHeaders->setHeader(
'Content-Type',
'application/json');
758 if ($version == ApiVersion::V2) {
760 "location" =>
"data",
761 "folderId" => $folderId,
762 "uploadDescription" => $uploadDescription,
763 "ignoreScm" =>
"true",
764 "scanOptions" =>
"scanOptions",
765 "uploadType" =>
"vcs",
766 "excludeFolder" =>
"false"
770 "location" =>
"data",
771 "scanOptions" =>
"scanOptions"
773 $requestHeaders->setHeader(
'folderId', $folderId);
774 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
775 $requestHeaders->setHeader(
'ignoreScm',
'true');
776 $requestHeaders->setHeader(
'Content-Type',
'application/json');
777 $requestHeaders->setHeader(
'uploadType',
'vcs');
780 $body = $this->streamFactory->createStream(json_encode(
783 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
784 $requestHeaders, [], [], $body);
785 if ($version == ApiVersion::V2) {
786 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
789 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
790 if ($version == ApiVersion::V2) {
791 $uploadHelper->shouldReceive(
'createNewUpload')
792 ->withArgs([$reqBody[
"location"], $folderId, $uploadDescription,
'protected',
'true',
793 'vcs',
false,
false])
794 ->andReturn([
true,
'',
'', $uploadId]);
796 $uploadHelper->shouldReceive(
'createNewUpload')
797 ->withArgs([$reqBody[
"location"], $folderId, $uploadDescription,
'protected',
'true',
799 ->andReturn([
true,
'',
'', $uploadId]);
802 $info =
new Info(201, intval(20), InfoType::INFO);
804 $uploadHelper->shouldReceive(
'handleScheduleAnalysis')->withArgs([$uploadId,$folderId,$reqBody[
"scanOptions"],
false])
807 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
808 $this->folderDao->shouldReceive(
'isFolderAccessible')
809 ->withArgs([$folderId])->andReturn(
true);
811 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
813 $actualResponse = $this->uploadController->postUpload($request,
815 $this->assertEquals($expectedResponse->getStatusCode(),
816 $actualResponse->getStatusCode());
852 $uploadDescription =
"Test Upload";
854 $requestHeaders =
new Headers();
855 $requestHeaders->setHeader(
'Content-type',
'application/json');
856 if ($version == ApiVersion::V2) {
857 $body = $this->streamFactory->createStream(json_encode([
858 "location" =>
"data",
859 "folderId" => $folderId,
860 "uploadDescription" => $uploadDescription,
861 "ignoreScm" =>
"true",
862 "scanOptions" =>
"scanOptions",
863 "uploadType" =>
"vcs"
866 $body = $this->streamFactory->createStream(json_encode([
867 "location" =>
"data",
868 "scanOptions" =>
"scanOptions"
870 $requestHeaders->setHeader(
'folderId', $folderId);
871 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
872 $requestHeaders->setHeader(
'ignoreScm',
'true');
873 $requestHeaders->setHeader(
'Content-Type',
'application/json');
874 $requestHeaders->setHeader(
'uploadType',
'vcs');
876 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
877 $requestHeaders, [], [], $body);
878 if ($version == ApiVersion::V2) {
879 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
883 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
885 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
886 $this->folderDao->shouldReceive(
'isFolderAccessible')
887 ->withArgs([$folderId])->andReturn(
false);
888 $this->expectException(HttpForbiddenException::class);
890 $this->uploadController->postUpload($request,
new ResponseHelper(),
925 $uploadDescription =
"Test Upload";
927 $requestHeaders =
new Headers();
928 $requestHeaders->setHeader(
'Content-type',
'application/json');
929 if ($version == ApiVersion::V2) {
930 $body = $this->streamFactory->createStream(json_encode([
931 "location" =>
"vcsData",
932 "folderId" => $folderId,
933 "uploadDescription" => $uploadDescription,
934 "ignoreScm" =>
"true",
935 "scanOptions" =>
"scanOptions",
936 "uploadType" =>
"vcs"
939 $body = $this->streamFactory->createStream(json_encode([
940 "location" =>
"vcsData",
941 "scanOptions" =>
"scanOptions"
943 $requestHeaders->setHeader(
'folderId', $folderId);
944 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
945 $requestHeaders->setHeader(
'ignoreScm',
'true');
946 $requestHeaders->setHeader(
'Content-Type',
'application/json');
947 $requestHeaders->setHeader(
'uploadType',
'vcs');
949 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
950 $requestHeaders, [], [], $body);
951 if ($version == ApiVersion::V2) {
952 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
956 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
958 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
959 $this->expectException(HttpNotFoundException::class);
961 $this->uploadController->postUpload($request,
new ResponseHelper(),
996 $uploadDescription =
"Test Upload";
997 $errorMessage =
"Failed to insert upload record";
1000 $requestHeaders =
new Headers();
1001 $requestHeaders->setHeader(
'Content-type',
'application/json');
1002 if ($version == ApiVersion::V2) {
1003 $body = $this->streamFactory->createStream(json_encode([
1004 "location" =>
"vcsData",
1005 "folderId" => $folderId,
1006 "uploadDescription" => $uploadDescription,
1007 "ignoreScm" =>
"true",
1008 "scanOptions" =>
"scanOptions",
1009 "uploadType" =>
"vcs",
1010 "excludeFolder" =>
"false"
1013 $body = $this->streamFactory->createStream(json_encode([
1014 "location" =>
"vcsData",
1015 "scanOptions" =>
"scanOptions"
1017 $requestHeaders->setHeader(
'folderId', $folderId);
1018 $requestHeaders->setHeader(
'uploadDescription', $uploadDescription);
1019 $requestHeaders->setHeader(
'ignoreScm',
'true');
1020 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1021 $requestHeaders->setHeader(
'uploadType',
'vcs');
1024 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1025 $requestHeaders, [], [], $body);
1026 if ($version == ApiVersion::V2) {
1027 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
1031 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
1032 if ($version == ApiVersion::V2) {
1033 $uploadHelper->shouldReceive(
'createNewUpload')
1034 ->withArgs([
'vcsData', $folderId, $uploadDescription,
'protected',
'true',
1035 'vcs',
false,
false])
1036 ->andReturn([
false, $errorMessage, $errorDesc, [-1]]);
1038 $uploadHelper->shouldReceive(
'createNewUpload')
1039 ->withArgs([
'vcsData', $folderId, $uploadDescription,
'protected',
'true',
1041 ->andReturn([
false, $errorMessage, $errorDesc, [-1]]);
1044 $this->folderDao->shouldReceive(
'getAllFolderIds')->andReturn([2,3,4]);
1045 $this->folderDao->shouldReceive(
'isFolderAccessible')
1046 ->withArgs([$folderId])->andReturn(
true);
1047 $this->expectException(HttpInternalServerErrorException::class);
1049 $this->uploadController->postUpload($request,
new ResponseHelper(), []);
1061 $this->testGetUploadLicenses(ApiVersion::V1);
1072 $this->testGetUploadLicenses(ApiVersion::V2);
1074 private function testGetUploadLicenses($version)
1078 [
'agentName' =>
'nomos',
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1079 [
'agentName' =>
'monk',
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1081 $licenseResponse = [
1082 [
'filePath' =>
'filea',
'agentFindings' =>
'MIT',
'conclusions' =>
'MIT'],
1083 [
'filePath' =>
'fileb',
'agentFindings' =>
'MIT',
1084 'conclusions' =>
'No_license_found']
1087 $requestHeaders =
new Headers();
1088 $body = $this->streamFactory->createStream();
1089 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1091 "=nomos,monk&containers=false"),
1092 $requestHeaders, [], [], $body);
1093 if ($version == ApiVersion::V2) {
1094 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,
1097 $this->dbHelper->shouldReceive(
'doesIdExist')
1098 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1099 $this->uploadDao->shouldReceive(
'isAccessible')
1100 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1101 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1102 ->withArgs([$uploadId])->andReturn($this->
getUploadBounds($uploadId));
1103 $this->agentDao->shouldReceive(
'arsTableExists')
1104 ->withArgs([M::anyOf(
'nomos',
'monk')])->andReturn(
true);
1106 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1107 $scanJobProxy->shouldReceive(
'createAgentStatus')
1108 ->withArgs([[
'nomos',
'monk']])
1109 ->andReturn($agentsRun);
1111 $uploadHelper = M::mock(
'overload:Fossology\UI\Api\Helper\UploadHelper');
1112 $uploadHelper->shouldReceive(
'getUploadLicenseList')
1113 ->withArgs([$uploadId, [
'nomos',
'monk'],
false,
true,
false, 0, 50, $version])
1114 ->andReturn(([[$licenseResponse], 1]));
1116 $expectedResponse = (
new ResponseHelper())->withJson($licenseResponse, 200);
1118 $actualResponse = $this->uploadController->getUploadLicenses($request,
1120 $this->assertEquals($expectedResponse->getStatusCode(),
1121 $actualResponse->getStatusCode());
1124 $this->assertEquals(
'1',
1125 $actualResponse->getHeaderLine(
'X-Total-Pages'));
1160 [
'agentName' =>
'nomos',
'currentAgentId' => 2,
'isAgentRunning' =>
true],
1161 [
'agentName' =>
'monk',
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1164 $requestHeaders =
new Headers();
1165 $body = $this->streamFactory->createStream();
1166 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1168 "=nomos,monk&containers=false"),
1169 $requestHeaders, [], [], $body);
1170 if ($version == ApiVersion::V2) {
1171 $request = $request->withQueryParams([
'page' => 1,
'limit' => 2,
"agent" =>
"nomos,monk" ]);
1173 $request = $request->withHeader(
"limit",2)
1174 ->withHeader(
"page",1);
1176 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
1178 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1179 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agentsRun]);
1180 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1181 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1182 $this->dbHelper->shouldReceive(
'doesIdExist')
1183 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1184 $this->uploadDao->shouldReceive(
'isAccessible')
1185 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1186 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1187 ->withArgs([$uploadId])->andReturn($this->
getUploadBounds($uploadId));
1188 $this->agentDao->shouldReceive(
'arsTableExists')
1189 ->withArgs([M::anyOf(
'nomos',
'monk')])->andReturn(
true);
1191 $scanJobProxy->shouldReceive(
'createAgentStatus')
1192 ->withArgs([[
'nomos',
'monk']])
1193 ->andReturn($agentsRun);
1194 $this->expectException(HttpServiceUnavailableException::class);
1196 $this->uploadController->getUploadLicenses($request,
new ResponseHelper(),
1197 [
'id' => $uploadId]);
1209 $status = UploadStatus::REJECTED;
1210 $comment =
"Not helpful";
1212 $resource = fopen(
'data://text/plain;base64,' .
1213 base64_encode($comment),
'r+');
1214 $body = $this->streamFactory->createStreamFromResource($resource);
1215 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1218 new Headers(), [], [], $body);
1220 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
1221 ->withArgs([$this->userId, $this->groupId])
1223 $this->userDao->shouldReceive(
'getUserChoices')
1224 ->withArgs([$this->groupId])
1225 ->andReturn([$this->userId =>
"fossy", $assignee =>
"friendly-fossy"]);
1226 $this->
dbManager->shouldReceive(
'getSingleRow')
1227 ->withArgs([M::any(), [$assignee, $this->groupId, $upload], M::any()]);
1228 $this->
dbManager->shouldReceive(
'getSingleRow')
1229 ->withArgs([M::any(), [$status, $comment, $this->groupId, $upload],
1231 $this->
dbManager->shouldReceive(
'getSingleRow')
1232 ->withArgs([M::any(), [$upload], M::any()])
1233 ->andReturn([
"exists" =>
""]);
1235 $info =
new Info(202,
"Upload updated successfully.", InfoType::INFO);
1236 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
1238 $actualResponse = $this->uploadController->updateUpload($request,
1240 $this->assertEquals($expectedResponse->getStatusCode(),
1241 $actualResponse->getStatusCode());
1255 $comment =
"Not helpful";
1257 $resource = fopen(
'data://text/plain;base64,' .
1258 base64_encode($comment),
'r+');
1259 $body = $this->streamFactory->createStreamFromResource($resource);
1260 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
1263 new Headers(), [], [], $body);
1265 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
1266 ->withArgs([$this->userId, $this->groupId])
1268 $this->expectException(HttpForbiddenException::class);
1270 $this->uploadController->updateUpload($request,
new ResponseHelper(),
1282 $licenseIds = array();
1284 $licenseIds[$licenseId] = $licenseId;
1285 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
1288 $this->uploadDao->shouldReceive(
'isAccessible')
1289 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1290 $this->dbHelper->shouldReceive(
'doesIdExist')
1291 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1292 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1293 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
false])->andReturn([]);
1294 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
true])->andReturn([]);
1295 $this->licenseDao->shouldReceive(
'getLicenseById')->withArgs([$licenseId])->andReturn($license);
1297 $licenses[] = $license->getArray();
1298 $expectedResponse = (
new ResponseHelper())->withJson($licenses, 200);
1299 $actualResponse = $this->uploadController->getMainLicenses(
null,
new ResponseHelper(), [
'id' => $uploadId]);
1300 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
1316 "shortName" => $shortName,
1318 $license =
new License(2, $shortName,
"MIT License",
"risk",
"texts", [],
1320 $licenseIds[$licenseId] = $licenseId;
1321 $this->uploadDao->shouldReceive(
'isAccessible')
1322 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1323 $this->dbHelper->shouldReceive(
'doesIdExist')
1324 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1325 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1326 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1327 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1328 $this->clearingDao->shouldReceive(
'makeMainLicense')
1329 ->withArgs([$uploadId, $this->groupId, $license->getId()])->andReturn(
null);
1331 $info =
new Info(200,
"Successfully added new main license", InfoType::INFO);
1333 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1334 $reqBody = $this->streamFactory->createStream(json_encode(
1337 $requestHeaders =
new Headers();
1338 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1339 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1340 $requestHeaders, [], [], $reqBody);
1342 $actualResponse = $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1344 $this->assertEquals($expectedResponse->getStatusCode(),
1345 $actualResponse->getStatusCode());
1361 "shortName" => $shortName,
1363 $license =
new License($licenseId, $shortName,
"MIT License",
"risk",
"texts", [],
1365 $licenseIds[$licenseId] = $licenseId;
1366 $this->uploadDao->shouldReceive(
'isAccessible')
1367 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1368 $this->dbHelper->shouldReceive(
'doesIdExist')
1369 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1370 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1371 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1372 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1373 $this->clearingDao->shouldReceive(
'makeMainLicense')
1374 ->withArgs([$uploadId, $this->groupId, $license->getId()])->andReturn(
null);
1376 $reqBody = $this->streamFactory->createStream(json_encode(
1379 $requestHeaders =
new Headers();
1380 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1381 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1382 $requestHeaders, [], [], $reqBody);
1383 $this->expectException(HttpBadRequestException::class);
1385 $this->uploadController->setMainLicense($request,
new ResponseHelper(), [
'id' => $uploadId]);
1399 $license =
new License($licenseId, $shortName,
"MIT License",
"risk",
"texts", [],
1401 $licenseIds[$licenseId] = $licenseId;
1403 $this->uploadDao->shouldReceive(
'isAccessible')
1404 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1405 $this->dbHelper->shouldReceive(
'doesIdExist')
1406 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1407 $this->dbHelper->shouldReceive(
'doesIdExist')
1408 ->withArgs([
"license_ref",
"rf_pk", $licenseId])->andReturn(
true);
1409 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->withArgs([$uploadId, $this->groupId])->andReturn($licenseIds);
1411 $this->clearingDao->shouldReceive(
'removeMainLicense')->withArgs([$uploadId, $this->groupId, $licenseId])->andReturn(
null);
1412 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1413 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1415 $info =
new Info(200,
"Main license removed successfully.", InfoType::INFO);
1416 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
1418 $actualResponse = $this->uploadController->removeMainLicense(
null,
1419 new ResponseHelper(), [
'id' => $uploadId,
'shortName' => $shortName]);
1420 $this->assertEquals($expectedResponse->getStatusCode(),
1421 $actualResponse->getStatusCode());
1434 $this->uploadDao->shouldReceive(
'isAccessible')
1435 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1436 $this->dbHelper->shouldReceive(
'doesIdExist')
1437 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1438 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1439 $this->uploadDao->shouldReceive(
"getGlobalDecisionSettingsFromInfo")->andReturn(
false);
1440 $this->agentDao->shouldReceive(
"arsTableExists")->andReturn(
true);
1441 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->andReturn([[
'agent_id' => 1,
'agent_rev' => 1]]);
1442 $this->agentDao->shouldReceive(
"getCurrentAgentRef")->andReturn(
new AgentRef(1,
"agent", 1));
1443 $this->
dbManager->shouldReceive(
"getSingleRow")
1444 ->withArgs([M::any(), [],
'no_license_uploadtree' . $uploadId])
1445 ->andReturn([
'count' => 1]);
1446 $this->
dbManager->shouldReceive(
"getSingleRow")
1447 ->withArgs([M::any(), [],
'already_cleared_uploadtree' . $uploadId])
1448 ->andReturn([
'count' => 0]);
1449 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1450 ->withArgs([
'No_license_found'])->andReturn(
null);
1451 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1452 ->withArgs([
'Void'])->andReturn(
null);
1454 "totalFilesOfInterest" => 1,
1455 "totalFilesCleared" => 1,
1458 $actualResponse = $this->uploadController->getClearingProgressInfo(
null,
1460 $this->assertEquals($expectedResponse->getStatusCode(),
1461 $actualResponse->getStatusCode());
1473 $reuseReportSummary = [
1474 'declearedLicense' =>
"",
1475 'clearedLicense' =>
"MIT, BSD-3-Clause",
1476 'usedLicense' =>
"",
1477 'unusedLicense' =>
"",
1478 'missingLicense' =>
"MIT, BSD-3-Clause",
1480 $this->uploadDao->shouldReceive(
'isAccessible')
1481 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1482 $this->dbHelper->shouldReceive(
'doesIdExist')
1483 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1484 $this->reuseReportProcess->shouldReceive(
'getReuseSummary')
1485 ->withArgs([$uploadId])->andReturn($reuseReportSummary);
1487 $expectedResponse = (
new ResponseHelper())->withJson($reuseReportSummary,
1489 $actualResponse = $this->uploadController->getReuseReportSummary(
1491 $this->assertEquals($expectedResponse->getStatusCode(),
1492 $actualResponse->getStatusCode());
1510 $this->uploadDao->shouldReceive(
'isAccessible')
1511 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1512 $this->dbHelper->shouldReceive(
'doesIdExist')
1513 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1515 $this->restHelper->shouldReceive(
'getUploadPermissionDao')->andReturn($this->uploadPermissionDao);
1516 $this->uploadPermissionDao->shouldReceive(
"getPublicPermission")->withAnyArgs()->andReturn($publicPerm);
1517 $this->uploadPermissionDao->shouldReceive(
"getPermissionGroups")->withAnyArgs()->andReturn([]);
1518 $this->restHelper->shouldReceive(
"getGroupId")->andReturn($this->groupId);
1519 $this->restHelper->shouldReceive(
"getUserId")->andReturn($this->userId);
1520 $this->restHelper->shouldReceive(
"getUploadDao")->andReturn($this->uploadDao);
1522 $body = $this->streamFactory->createStream();
1523 $requestHeaders =
new Headers();
1524 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1525 $requestHeaders, [], [], $body);
1527 $actualResponse = $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1528 $this->assertEquals(200,$actualResponse->getStatusCode());
1541 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1543 $this->dbHelper->shouldReceive(
'doesIdExist')
1544 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1545 $body = $this->streamFactory->createStream();
1546 $requestHeaders =
new Headers();
1547 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1548 $requestHeaders, [], [], $body);
1550 $this->expectException(HttpNotFoundException::class);
1551 $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1563 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1564 $this->uploadDao->shouldReceive(
'isAccessible')->withAnyArgs()->andReturn(
false);
1566 $body = $this->streamFactory->createStream();
1567 $requestHeaders =
new Headers();
1568 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost"),
1569 $requestHeaders, [], [], $body);
1571 $this->expectException(HttpForbiddenException::class);
1572 $this->uploadController->getGroupsWithPermissions($request,$response,[
"id"=>$this->groupId]);
1585 [
"uploadId" => $uploadId,
'agentName' =>
'nomos',
'successfulAgents'=> [],
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1586 [
"uploadId" => $uploadId,
'agentName' =>
'monk',
"successfulAgents" => [],
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1589 $this->restHelper->shouldReceive(
"getGroupId")->andReturn(
$groupId);
1590 $this->agentDao->shouldReceive(
"getCurrentAgentRef")->withAnyArgs()->andReturn(
new AgentRef($uploadId,
"momoa",45));
1592 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1593 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1594 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1595 $scanJobProxy->shouldReceive(
'createAgentStatus')
1597 ->andReturn($agentsRun);
1598 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1599 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agentsRun]);
1600 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1602 $body = $this->streamFactory->createStream();
1603 $requestHeaders =
new Headers();
1604 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1605 $requestHeaders, [], [], $body);
1607 $actualResponse = $this->uploadController->getAllAgents($request,
new ResponseHelper(),[
"id"=>$uploadId]);
1608 $this->assertEquals(200,$actualResponse->getStatusCode());
1620 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1621 $this->dbHelper->shouldReceive(
'doesIdExist')
1622 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1624 $this->expectException(HttpNotFoundException::class);
1625 $this->uploadController->getAllAgents(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1638 $this->uploadDao->shouldReceive(
'isAccessible')
1639 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
1640 $this->dbHelper->shouldReceive(
'doesIdExist')
1641 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1643 $this->expectException(HttpForbiddenException::class);
1644 $this->uploadController->getAllAgents(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1658 $uploadName =
"Testing name";
1659 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1661 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1662 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1663 $this->restHelper->shouldReceive(
'getUploadDao')->andReturn($this->uploadDao);
1664 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn($uploadName);
1665 $this->clearingDao->shouldReceive(
"getClearedLicenseIdAndMultiplicities")->withAnyArgs()->andReturn([]);
1667 $actualResponse = $this->uploadController->getEditedLicenses(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1668 $this->assertEquals(200,$actualResponse->getStatusCode());
1681 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1683 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
true);
1684 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
false);
1686 $this->expectException(HttpNotFoundException::class);
1700 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1702 $this->uploadDao->shouldReceive(
"isAccessible")->withAnyArgs()->andReturn(
false);
1703 $this->dbHelper->shouldReceive(
'doesIdExist')->withAnyArgs()->andReturn(
true);
1705 $this->expectException(HttpForbiddenException::class);
1718 $this->uploadDao->shouldReceive(
'isAccessible')
1719 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1720 $this->dbHelper->shouldReceive(
'doesIdExist')
1721 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1723 $body = $this->streamFactory->createStream();
1724 $requestHeaders =
new Headers();
1725 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1726 $requestHeaders, [], [], $body);
1728 $this->expectException(HttpNotFoundException::class);
1729 $this->uploadController->getScannedLicenses($request,
new ResponseHelper(),[
"id"=>$uploadId]);
1743 [
"uploadId" => $uploadId,
'agentName' =>
'nomos',
'successfulAgents'=> [],
'currentAgentId' => 2,
'isAgentRunning' =>
false],
1744 [
"uploadId" => $uploadId,
'agentName' =>
'monk',
"successfulAgents" => [],
'currentAgentId' => 3,
'isAgentRunning' =>
false]
1746 $agent =
new Agent([],$uploadId,
"MOMO agent",45,
"4.4.0.37.072417",
false,
"");
1748 $this->uploadDao->shouldReceive(
'isAccessible')
1749 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1750 $this->dbHelper->shouldReceive(
'doesIdExist')
1751 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1752 $scanJobProxy = M::mock(
'overload:Fossology\Lib\Proxy\ScanJobProxy');
1754 $scanJobProxy->shouldReceive(
'createAgentStatus')
1756 ->andReturn($agentsRun);
1757 $scanJobProxy->shouldReceive(
"getSuccessfulAgents")->andReturn($agent);
1758 $this->agentDao->shouldReceive(
"arsTableExists")->withAnyArgs()->andReturn(
true);
1759 $this->agentDao->shouldReceive(
"getSuccessfulAgentEntries")->withAnyArgs()->andReturn([]);
1760 $this->agentDao->shouldReceive(
"getRunningAgentIds")->withAnyArgs()->andReturn([$agent]);
1762 $actualResponse = $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1763 $this->assertEquals(200,$actualResponse->getStatusCode());
1776 $this->dbHelper->shouldReceive(
'doesIdExist')
1777 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1779 $this->expectException(HttpNotFoundException::class);
1780 $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1793 $this->uploadDao->shouldReceive(
'isAccessible')
1794 ->withArgs([$uploadId, $this->groupId])->andReturn(
false);
1795 $this->dbHelper->shouldReceive(
'doesIdExist')
1796 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1798 $this->expectException(HttpForbiddenException::class);
1799 $this->uploadController->getAgentsRevision(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1812 $this->dbHelper->shouldReceive(
'doesIdExist')
1813 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1814 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1816 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1818 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1820 $info =
new Info(200, $itemTreeBounds->getItemId(), InfoType::INFO);
1821 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1823 $this->assertEquals($expectedResponse->getStatusCode(),$actualResponse->getStatusCode());
1837 $this->dbHelper->shouldReceive(
'doesIdExist')
1838 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
false);
1840 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1841 $info =
new Info(404,
"Upload does not exist", InfoType::ERROR);
1842 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1843 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
1859 $this->dbHelper->shouldReceive(
'doesIdExist')
1860 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1861 $this->uploadDao->shouldReceive(
'getParentItemBounds')
1863 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1865 $actualResponse = $this->uploadController->getTopItem(
null,
new ResponseHelper(),[
"id"=>$uploadId]);
1868 $this->assertEquals(500,$actualResponse->getStatusCode());
Contains the constants and helpers for authentication of user.
Controller for Upload model.
Provides helper methods to access database for REST api.
Override Slim response for withJson function.
Provides various DAO helper functions for REST api.
Hash model holding information about file like checksums and size.
Different type of infos provided by REST.
Info model to contain general error and return values.
Model class to hold Upload info.
Unit tests for UploadController.
testSetMainLicense_exists()
testGetAllAgentsUploadNotAccessible()
getResponseJson($response)
testGetClearingProgressInfo()
testPostUploadInternalError(int $version)
tearDown()
Remove test objects.
testPostUploadInternalErrorV1()
testAgentsRevisionNotFound()
testGetSingleUpload($version)
testPostUpload(int $version)
testPostUploadFolderNotAccessible(int $version)
testSetGroupsWithPermissions()
testGetUploadLicensesPendingScanV2()
testGetUploadWithFiltersV2()
testGetUploadLicensesV1()
testAgentsRevisionForbidden()
testSetGroupsWithPermissionsUploadNotAccessible()
testGetAllAgentsUploadNotFound()
testPostUploadFolderNotAccessibleV2()
testPostUploadInternalErrorV2()
testMoveUploadInvalidFolderV1()
testPostUploadFolderNotFoundV2()
testGetUploadLicensesPendingScan($version=ApiVersion::V2)
testGetUploadLicensesPendingScanV1()
testGetEditedLicensesForbidden()
testGetUploadWithFiltersV1()
testGetSingleUploadInAccessible()
testGetTopItemUploadNotFound()
setUp()
Setup test objects.
testGetSingleUploadNotUnpacked()
testMoveUploadInvalidFolder($version=ApiVersion::V2)
testGetUploadLicensesV2()
testPostUploadFolderNotFound(int $version)
testMoveUploadInvalidFolderV2()
testGetScannedLicensesNotFound()
testSetGroupsWithPermissionsNotFound()
testGetReuseReportSummary()
testPostUploadFolderNotAccessibleV1()
testPostUploadFolderNotFoundV1()
testGetTopItemInternalServerError()
testGetEditedLicensesNotFound()
fo_dbManager * dbManager
fo_dbManager object