function Output() { if ($this->State != PLUGIN_STATE_READY) { return 0; } $licenseShortname = GetParm("lic", PARM_TEXT); $licenseId = GetParm("rf", PARM_NUMBER); $groupId = $_SESSION[Auth::GROUP_ID]; if (empty($licenseShortname) && empty($licenseId)) { return; } if ($licenseId) { $license = $this->licenseDao->getLicenseById($licenseId, $groupId); } else { $license = $this->licenseDao->getLicenseByShortName($licenseShortname, $groupId); } if ($license === null) { return; } $this->vars['shortName'] = $license->getShortName(); $this->vars['fullName'] = $license->getFullName(); $parent = $this->licenseDao->getLicenseParentById($license->getId()); if ($parent !== null) { $this->vars['parentId'] = $parent->getId(); $this->vars['parentShortName'] = $parent->getShortName(); } $licenseUrl = $license->getUrl(); if (strtolower($licenseUrl) == 'none') { $licenseUrl = NULL; } $this->vars['url'] = $licenseUrl; $this->vars['text'] = $license->getText(); $this->vars['risk'] = $license->getRisk(); return $this->render('popup_license.html.twig'); }
private function runnerDeciderRealShouldMakeNoDecisionForIrrelevantFiles($runner) { $this->setUpTables(); $this->setUpRepo(); $monkAgentId = 5; $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef(); $licId1 = $licenseRef1->getId(); $pfile = 4; $jobId = 16; $groupId = 2; $userId = 2; $itemId = 7; $itemTreeBounds = new ItemTreeBounds($itemId, 'uploadtree_a', $uploadId = 1, 15, 16); $this->dbManager->queryOnce("DELETE FROM license_file"); /* insert NoLicenseKnown decisions */ $this->dbManager->queryOnce("INSERT INTO clearing_decision (clearing_decision_pk, uploadtree_fk, pfile_fk, user_fk, group_fk, decision_type, scope, date_added)" . " VALUES (2, {$itemId}, {$pfile}, {$userId}, {$groupId}, " . DecisionTypes::IRRELEVANT . ", " . DecisionScopes::ITEM . ", '2015-05-04 11:43:18.276425+02')"); $lastDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId); $lastClearingId = $lastDecision->getClearingId(); $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,{$licId1},{$pfile},{$monkAgentId})"); $this->dbManager->queryOnce("INSERT INTO jobqueue (jq_pk, jq_job_fk, jq_type, jq_args, jq_starttime, jq_endtime, jq_endtext, jq_end_bits, jq_schedinfo, jq_itemsprocessed, jq_log, jq_runonpfile, jq_host, jq_cmd_args)" . " VALUES ({$jobId}, 2, 'decider', '2', '2015-06-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, '-r8')"); list($success, $output, $retCode) = $runner->run($uploadId, $userId, $groupId, $jobId, ''); $this->assertTrue($success, 'cannot run runner'); $this->assertEquals($retCode, 0, 'decider failed (did you make test?): ' . $output); $newDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId); assertThat($newDecision->getClearingId(), equalTo($lastClearingId)); $this->rmRepo(); }
public function testGetLicenseByShortName() { $this->testDb->createPlainTables(array('license_ref')); $this->testDb->insertData_license_ref($limit = 3); $licDao = new LicenseDao($this->dbManager); $lic0 = $this->dbManager->getSingleRow("Select rf_shortname from license_ref limit 1"); $sname = $lic0['rf_shortname']; $lic = $licDao->getLicenseByShortName($sname); $this->assertInstanceOf('Fossology\\Lib\\Data\\License', $lic); $this->assertEquals($sname, $lic->getShortName()); $sname = "Self-destructing license"; $lic = $licDao->getLicenseByShortName($sname); $this->assertNull($lic); }
protected function insertDecisionFromTwoEvents($scope = DecisionScopes::ITEM, $originallyClearedItemId = 23) { $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef(); $licenseRef2 = $this->licenseDao->getLicenseByShortName("3DFX")->getRef(); $addedLicenses = array($licenseRef1, $licenseRef2); assertThat($addedLicenses, not(arrayContaining(null))); $clearingLicense1 = new ClearingLicense($licenseRef1, false, ClearingEventTypes::USER, "42", "44"); $clearingLicense2 = new ClearingLicense($licenseRef2, true, ClearingEventTypes::USER, "-42", "-44"); $eventId1 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, $this->userId, $this->groupId, $licenseRef1->getId(), $clearingLicense1->isRemoved(), $clearingLicense1->getType(), $clearingLicense1->getReportinfo(), $clearingLicense1->getComment()); $eventId2 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, 5, $this->groupId, $licenseRef2->getId(), $clearingLicense2->isRemoved(), $clearingLicense2->getType(), $clearingLicense2->getReportinfo(), $clearingLicense2->getComment()); $addedEventIds = array($eventId1, $eventId2); $this->clearingDao->createDecisionFromEvents($originallyClearedItemId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $scope, $addedEventIds); return array($clearingLicense1, $clearingLicense2, $addedEventIds); }
private function runnerDeciderScanWithForceDecision($runner) { $this->setUpTables(); $this->setUpRepo(); $jobId = 42; $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef(); $licenseRef2 = $this->licenseDao->getLicenseByShortName("3DFX")->getRef(); $agentLicId = $this->licenseDao->getLicenseByShortName("Adaptec")->getRef()->getId(); $addedLicenses = array($licenseRef1, $licenseRef2); assertThat($addedLicenses, not(arrayContaining(null))); $agentId = 5; $pfile = 4; $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,{$agentLicId},{$pfile},{$agentId})"); $itemTreeBounds = $this->uploadDao->getItemTreeBounds($itemId = 23); assertThat($this->agentLicenseEventProcessor->getScannerEvents($itemTreeBounds), is(not(emptyArray()))); $eventId1 = $this->clearingDao->insertClearingEvent($itemId, $userId = 2, $groupId = 3, $licenseRef1->getId(), false); $eventId2 = $this->clearingDao->insertClearingEvent($itemId, 5, $groupId, $licenseRef2->getId(), true); $this->dbManager->queryOnce("UPDATE clearing_event SET job_fk={$jobId}"); $addedEventIds = array($eventId1, $eventId2); list($success, $output, $retCode) = $runner->run($uploadId = 2, $userId, $groupId, $jobId, $args = "-k1"); $this->assertTrue($success, 'cannot run runner'); $this->assertEquals($retCode, 0, 'decider failed: ' . $output); assertThat($this->getHeartCount($output), equalTo(1)); $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId); $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId); assertThat($decisions, is(arrayWithSize(1))); /** @var ClearingDecision $deciderMadeDecision */ $deciderMadeDecision = $decisions[0]; $eventIds = array(); foreach ($deciderMadeDecision->getClearingEvents() as $event) { $eventIds[] = $event->getEventId(); } assertThat($eventIds, arrayValue($addedEventIds[0])); assertThat($eventIds, arrayValue($addedEventIds[1])); assertThat($eventIds, arrayWithSize(1 + count($addedEventIds))); $this->rmRepo(); }