protected function runNomos($args = "", $files = array())
 {
     $sysConf = $this->testDb->getFossSysConf();
     $confFile = $sysConf . "/fossology.conf";
     system("touch " . $confFile);
     $config = "[FOSSOLOGY]\ndepth = 0\npath = {$sysConf}/repo\n";
     file_put_contents($confFile, $config);
     $execDir = $this->agentDir . '/agent';
     system("install -D {$this->agentDir}/VERSION {$sysConf}/mods-enabled/nomos/VERSION");
     foreach ($files as $file) {
         $args .= " " . escapeshellarg($file);
     }
     $pipeFd = popen("{$execDir}/nomos -c {$sysConf} {$args}", "r");
     $this->assertTrue($pipeFd !== false, 'running nomos failed');
     $output = "";
     while (($buffer = fgets($pipeFd, 4096)) !== false) {
         $output .= $buffer;
     }
     $retCode = pclose($pipeFd);
     unlink("{$sysConf}/mods-enabled/nomos/VERSION");
     //unlink("$sysConf/mods-enabled/nomos");
     //rmdir("$sysConf/mods-enabled");
     unlink($confFile);
     return array($output, $retCode);
 }
 protected function tearDown()
 {
     return;
     $this->testInstaller->clear();
     $this->testDb->fullDestruct();
     $this->testDb = null;
 }
 protected function setUp()
 {
     $this->dbManager = M::mock(DbManager::classname());
     $this->logger = M::mock('Monolog\\Logger');
     $this->testDb = new TestPgDb();
     $this->dbManager =& $this->testDb->getDbManager();
     $this->agent = new AgentRef($this->agentId, $this->agentName, $this->agentRev);
     $this->olderAgent = new AgentRef($this->olderAgentId, $this->agentName, $this->olderAgentRev);
     $this->otherAgent = new AgentRef($this->otherAgentId, $this->otherAgentName, $this->otherAgentRev);
     $this->incompleteAgent = new AgentRef($this->incompleteAgentId, $this->agentName, $this->incompleteAgentRev);
     $this->testDb->createPlainTables(array('agent'));
     $agentArray = array(array($this->olderAgentId, $this->agentName, $this->olderAgentRev, $this->agentDesc, $this->dbManager->booleanToDb($this->agentEnabled)), array($this->otherAgentId, $this->otherAgentName, $this->otherAgentRev, $this->otherAgentDesc, $this->dbManager->booleanToDb($this->agentEnabled)), array($this->agentId, $this->agentName, $this->agentRev, $this->agentDesc, $this->dbManager->booleanToDb($this->agentEnabled)), array($this->incompleteAgentId, $this->agentName, $this->incompleteAgentRev, $this->agentDesc, $this->dbManager->booleanToDb($this->agentEnabled)));
     foreach ($agentArray as $agentRow) {
         $this->dbManager->insertInto('agent', 'agent_pk, agent_name, agent_rev, agent_desc, agent_enabled', $agentRow);
     }
     $this->agentsDao = new AgentDao($this->dbManager, $this->logger);
     $arsTableName = $this->agentName . AgentDao::ARS_TABLE_SUFFIX;
     $this->dbManager->queryOnce("create table " . $arsTableName . " (ars_pk int, agent_fk int, upload_fk int, ars_success bool)");
     $arsArray = array(array(1, $this->olderAgentId, $this->uploadId, $this->dbManager->booleanToDb(true)), array(2, $this->agentId, $this->uploadId, $this->dbManager->booleanToDb(true)), array(3, $this->incompleteAgentId, $this->uploadId, $this->dbManager->booleanToDb(false)));
     foreach ($arsArray as $arsRow) {
         $this->dbManager->insertInto($arsTableName, 'ars_pk, agent_fk, upload_fk, ars_success', $arsRow);
     }
     $arsTableName = $this->otherAgentName . AgentDao::ARS_TABLE_SUFFIX;
     $this->dbManager->queryOnce("create table " . $arsTableName . " (ars_pk int, agent_fk int, upload_fk int, ars_success bool)");
     $arsArray = array(array(1, $this->otherAgentId, $this->uploadId, $this->dbManager->booleanToDb(true)));
     foreach ($arsArray as $arsRow) {
         $this->dbManager->insertInto($arsTableName, 'ars_pk, agent_fk, upload_fk, ars_success', $arsRow);
     }
 }
Exemple #4
0
 public function testIt()
 {
     $sysConf = $this->testDb->getFossSysConf();
     $returnCode = 0;
     $lines = array();
     exec("./testlibs " . $sysConf . "/Db.conf", $lines, $returnCode);
     $this->assertEquals($expected = 0, $returnCode, "error: " . implode("\n", $lines));
 }
 public function testNullFile()
 {
     global $TEST_DATA_PATH;
     global $TEST_RESULT_PATH;
     $fossology_testconfig = $this->testDb->getFossSysConf();
     $UNUNPACK_CMD = $this->agentDir . "/agent/ununpack";
     if (!empty($TEST_RESULT_PATH)) {
         exec("/bin/rm -rf {$TEST_RESULT_PATH}");
     }
     $command = "{$UNUNPACK_CMD} -qCR {$TEST_DATA_PATH}/null-file -d {$TEST_RESULT_PATH} -c {$fossology_testconfig} > /dev/null 2>&1";
     $last = exec($command, $usageOut, $rtn);
     $this->assertNotEquals($rtn, 0);
     $this->assertFileNotExists("{$TEST_RESULT_PATH}/null-file.dir/");
 }
 private function setUpClearingTables()
 {
     $this->testDb->createPlainTables(array('copyright', 'copyright_audit', 'uploadtree', 'copyright_decision'));
     $this->testDb->createInheritedTables(array('uploadtree_a'));
     $this->testDb->insertData(array('copyright', 'uploadtree_a'));
     $this->testDb->createSequences(array('copyright_ct_pk_seq', 'copyright_decision_pk_seq'));
     $this->testDb->alterTables(array('copyright', 'copyright_decision'));
 }
 private function setUpTables()
 {
     $this->testDb->createPlainTables(array('agent', 'uploadtree', 'upload', 'pfile', 'users', 'bucketpool', 'mimetype', 'ars_master'));
     $this->testDb->createSequences(array('agent_agent_pk_seq', 'upload_upload_pk_seq', 'pfile_pfile_pk_seq', 'users_user_pk_seq', 'nomos_ars_ars_pk_seq'));
     $this->testDb->createConstraints(array('agent_pkey', 'upload_pkey_idx', 'pfile_pkey', 'user_pkey'));
     $this->testDb->alterTables(array('agent', 'pfile', 'upload', 'ars_master', 'users'));
     $this->testDb->createInheritedTables(array('uploadtree_a'));
     $this->testDb->insertData(array('upload', 'pfile', 'uploadtree_a', 'bucketpool', 'mimetype', 'users'), false);
 }
 function setUp()
 {
     global $TEST_DATA_PATH;
     global $TEST_RESULT_PATH;
     if (empty($TEST_DATA_PATH) || empty($TEST_RESULT_PATH)) {
         $this->markTestSkipped();
     }
     $this->testDb = new TestPgDb('ununpackNormal');
     $this->agentDir = dirname(dirname(__DIR__)) . "/";
     $this->ununpack = $this->agentDir . "/agent/ununpack";
     $sysConf = $this->testDb->getFossSysConf();
     $this->testInstaller = new TestInstaller($sysConf);
     $this->testInstaller->init();
     $this->testInstaller->install($this->agentDir);
     $this->testDb->createSequences(array(), true);
     $this->testDb->createPlainTables(array(), true);
     $this->testDb->alterTables(array(), true);
 }
 public function testGetUploadHashes()
 {
     $this->testDb->createPlainTables(array('pfile'));
     $this->dbManager->queryOnce('TRUNCATE upload');
     $this->testDb->insertData(array('upload', 'pfile'));
     // (pfile_pk, pfile_md5, pfile_sha1, pfile_size) := (9, 'F703E0197FB6C5BD0C8DFDCC115A0231', '5DAFC9C82988A81413B995210B668CF5CF5975FF', 16845)
     $hashes = $this->uploadDao->getUploadHashes(2);
     assertThat($hashes, equalTo(array('md5' => 'F703E0197FB6C5BD0C8DFDCC115A0231', 'sha1' => '5DAFC9C82988A81413B995210B668CF5CF5975FF')));
 }
Exemple #10
0
 public function testGetUploadHashes()
 {
     $this->testDb->createPlainTables(array('pfile'));
     $this->dbManager->queryOnce('ALTER TABLE uploadtree RENAME TO uploadtree_a');
     $this->testDb->insertData(array('uploadtree_a', 'pfile'));
     // (pfile_pk, pfile_md5, pfile_sha1, pfile_size) := (4, '59CACDFCE5051CD8A1D8A1F2DCCE40A5', '04621571BCBABCE75C4DD1C6445B87DEC0995734', 12320);
     $hashes = $this->treeDao->getItemHashes(7, 'uploadtree_a');
     assertThat($hashes, equalTo(array('md5' => '59CACDFCE5051CD8A1D8A1F2DCCE40A5', 'sha1' => '04621571BCBABCE75C4DD1C6445B87DEC0995734')));
 }
Exemple #11
0
 private function setUpTables()
 {
     $this->testDb->createPlainTables(array(), true);
     $this->testDb->createInheritedTables();
     $this->dbManager->queryOnce("CREATE TABLE copyright_ars () INHERITS (ars_master)");
     $this->testDb->createSequences(array('agent_agent_pk_seq', 'pfile_pfile_pk_seq', 'upload_upload_pk_seq', 'nomos_ars_ars_pk_seq', 'license_file_fl_pk_seq', 'license_ref_rf_pk_seq', 'license_ref_bulk_lrb_pk_seq', 'clearing_decision_clearing_decision_pk_seq', 'clearing_event_clearing_event_pk_seq'));
     $this->testDb->createConstraints(array('agent_pkey', 'pfile_pkey', 'upload_pkey_idx', 'FileLicense_pkey', 'clearing_event_pkey'));
     $this->testDb->alterTables(array('agent', 'pfile', 'upload', 'ars_master', 'license_ref_bulk', 'license_set_bulk', 'clearing_event', 'clearing_decision', 'license_file', 'highlight'));
     $this->testDb->insertData(array('mimetype_ars', 'pkgagent_ars', 'ununpack_ars', 'decider_ars'), true, __DIR__ . '/fo_report.sql');
     $this->testDb->resetSequenceAsMaxOf('agent_agent_pk_seq', 'agent', 'agent_pk');
 }
Exemple #12
0
 private function setUpTables()
 {
     $this->testDb->createPlainTables(array('upload', 'uploadtree', 'uploadtree_a', 'license_ref', 'license_ref_bulk', 'license_set_bulk', 'clearing_event', 'clearing_decision', 'clearing_decision_event', 'license_file', 'highlight', 'highlight_bulk', 'agent', 'pfile', 'ars_master', 'users'), false);
     $this->testDb->createSequences(array('agent_agent_pk_seq', 'pfile_pfile_pk_seq', 'upload_upload_pk_seq', 'nomos_ars_ars_pk_seq', 'license_file_fl_pk_seq', 'license_ref_rf_pk_seq', 'license_ref_bulk_lrb_pk_seq', 'clearing_event_clearing_event_pk_seq', 'clearing_decision_clearing_decision_pk_seq'), false);
     $this->testDb->createViews(array('license_file_ref'), false);
     $this->testDb->createConstraints(array('agent_pkey', 'pfile_pkey', 'upload_pkey_idx', 'FileLicense_pkey', 'clearing_event_pkey', 'clearing_decision_pkey'), false);
     $this->testDb->alterTables(array('agent', 'pfile', 'upload', 'ars_master', 'license_ref_bulk', 'license_set_bulk', 'clearing_event', 'license_file', 'highlight', 'clearing_decision'), false);
     $this->testDb->createInheritedTables();
     $this->testDb->insertData(array('pfile', 'upload', 'uploadtree_a', 'users'), false);
     $this->testDb->insertData_license_ref();
 }
 public function testAccessibilityViaPublicForQualifiedUser()
 {
     $this->testDb->createPlainTables(array('perm_upload', 'groups'));
     $this->testDb->insertData(array('groups'));
     $_SESSION[Auth::USER_LEVEL] = Auth::PERM_READ;
     $accessibilityByNone = $this->uploadPermissionDao->isAccessible($uploadId = 2, $groupId = 2);
     assertThat($accessibilityByNone, equalTo(false));
     $this->uploadPermissionDao->setPublicPermission($uploadId, Auth::PERM_READ);
     $accessibilityByPublic = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
     assertThat($accessibilityByPublic, equalTo(true));
 }
 public function run($uploadId, $userId = 2, $groupId = 2, $jobId = 1, $args = "")
 {
     $sysConf = $this->testDb->getFossSysConf();
     $agentName = "spdx2";
     $agentDir = dirname(dirname(__DIR__));
     $execDir = "{$agentDir}/agent";
     $pipeFd = popen($cmd = "echo {$uploadId} | {$execDir}/{$agentName} --userID={$userId} --groupID={$groupId} --jobId={$jobId} --scheduler_start -c {$sysConf} {$args}", "r");
     $success = $pipeFd !== false;
     $output = "";
     $retCode = -1;
     if ($success) {
         while (($buffer = fgets($pipeFd, 4096)) !== false) {
             $output .= $buffer;
         }
         $retCode = pclose($pipeFd);
     } else {
         print "failed opening pipe to {$cmd}";
     }
     return array($success, $output, $retCode);
 }
 private function setUpTables()
 {
     $this->testDb->createPlainTables(array('upload', 'uploadtree', 'license_ref', 'license_file', 'highlight', 'agent', 'pfile', 'ars_master'), false);
     $this->testDb->createSequences(array('agent_agent_pk_seq', 'pfile_pfile_pk_seq', 'upload_upload_pk_seq', 'nomos_ars_ars_pk_seq', 'license_file_fl_pk_seq', 'license_ref_rf_pk_seq'), false);
     $this->testDb->createViews(array('license_file_ref'), false);
     $this->testDb->createConstraints(array('agent_pkey', 'pfile_pkey', 'upload_pkey_idx', 'FileLicense_pkey', 'rf_pkpk'), false);
     $this->testDb->alterTables(array('agent', 'pfile', 'upload', 'ars_master', 'license_file', 'highlight', 'license_ref'), false);
     $this->testDb->createInheritedTables();
     $this->testDb->insertData(array('pfile', 'upload', 'uploadtree_a'), false);
     $this->testDb->insertData_license_ref();
     $this->testDb->resetSequenceAsMaxOf('license_ref_rf_pk_seq', 'license_ref', 'rf_pk');
 }
Exemple #16
0
 public function testupdateClearingEvent()
 {
     $this->testDb->createSequences(array('clearing_event_clearing_event_pk_seq'));
     $this->testDb->createConstraints(array('clearing_event_pkey'));
     $this->dbManager->queryOnce("ALTER TABLE clearing_event ALTER COLUMN clearing_event_pk SET DEFAULT nextval('clearing_event_clearing_event_pk_seq'::regclass)");
     $this->clearingDao->updateClearingEvent($uploadTreeId = 301, $userId = 1, $groupId = 1, $licenseId = 402, $what = 'comment', $changeCom = 'abc123');
     $rowPast = $this->dbManager->getSingleRow('SELECT * FROM clearing_event WHERE uploadtree_fk=$1 AND rf_fk=$2 ORDER BY clearing_event_pk DESC LIMIT 1', array($uploadTreeId, $licenseId), __METHOD__ . 'beforeReportinfo');
     assertThat($rowPast['comment'], equalTo($changeCom));
     $this->clearingDao->updateClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, $what = 'reportinfo', $changeRep = 'def456');
     $rowFuture = $this->dbManager->getSingleRow('SELECT * FROM clearing_event WHERE uploadtree_fk=$1 AND rf_fk=$2 ORDER BY clearing_event_pk DESC LIMIT 1', array($uploadTreeId, $licenseId), __METHOD__ . 'afterReportinfo');
     assertThat($rowFuture['comment'], equalTo($changeCom));
     assertThat($rowFuture['reportinfo'], equalTo($changeRep));
 }
Exemple #17
0
 private function setUpTables()
 {
     $this->testDb->createPlainTables(array('upload', 'upload_reuse', 'uploadtree', 'uploadtree_a', 'license_ref', 'license_ref_bulk', 'license_set_bulk', 'clearing_decision', 'clearing_decision_event', 'clearing_event', 'license_file', 'highlight', 'highlight_keyword', 'agent', 'pfile', 'ars_master', 'users', 'group_user_member', 'license_map', 'jobqueue', 'job'), false);
     $this->testDb->createSequences(array('agent_agent_pk_seq', 'pfile_pfile_pk_seq', 'upload_upload_pk_seq', 'nomos_ars_ars_pk_seq', 'license_file_fl_pk_seq', 'license_ref_rf_pk_seq', 'license_ref_bulk_lrb_pk_seq', 'clearing_decision_clearing_decision_pk_seq', 'clearing_event_clearing_event_pk_seq', 'FileLicense_pkey', 'jobqueue_jq_pk_seq'), false);
     $this->testDb->createViews(array('license_file_ref'), false);
     $this->testDb->createConstraints(array('agent_pkey', 'pfile_pkey', 'upload_pkey_idx', 'clearing_event_pkey', 'jobqueue_pkey'), false);
     $this->testDb->alterTables(array('agent', 'pfile', 'upload', 'ars_master', 'license_ref_bulk', 'license_set_bulk', 'clearing_event', 'clearing_decision', 'license_file', 'highlight', 'jobqueue'), false);
     $this->testDb->createInheritedTables();
     $this->testDb->createInheritedArsTables(array('nomos', 'monk', 'copyright'));
     $this->testDb->insertData(array('pfile', 'upload', 'uploadtree_a', 'users', 'group_user_member', 'agent', 'license_file', 'nomos_ars', 'monk_ars', 'copyright_ars'), false);
     $this->testDb->insertData_license_ref(80);
     $this->testDb->resetSequenceAsMaxOf('agent_agent_pk_seq', 'agent', 'agent_pk');
 }
 protected function setUp()
 {
     $this->testDb = new TestPgDb();
     $this->dbManager =& $this->testDb->getDbManager();
     $this->testDb->createPlainTables(array('upload', 'uploadtree', 'job', 'perm_upload', 'jobqueue', 'jobdepends'));
     $this->testDb->createInheritedTables(array('uploadtree_a'));
     $uploadArray = array(array('upload_pk' => 1, 'uploadtree_tablename' => 'uploadtree'), array('upload_pk' => 2, 'uploadtree_tablename' => 'uploadtree_a'));
     foreach ($uploadArray as $uploadEntry) {
         $this->dbManager->insertTableRow('upload', $uploadEntry);
     }
     $this->dbManager->prepare($stmt = 'insert.job', "INSERT INTO job (job_pk, job_queued, job_name, job_upload_fk, job_user_fk) VALUES (\$1, \$2, \$3, \$4, \$5)");
     $jobArray = array(array(1, date('c', time() - 5), "FCKeditor_2.6.4.zip", 1, 1), array(2, date('c'), "zlib_1.2.8.zip", 2, 2));
     foreach ($jobArray as $uploadEntry) {
         $this->dbManager->freeResult($this->dbManager->execute($stmt, $uploadEntry));
     }
     $logger = M::mock('Monolog\\Logger');
     $logger->shouldReceive('debug');
     $this->uploadPermissionDao = M::mock('Fossology\\Lib\\Dao\\UploadPermissionDao');
     $this->uploadDao = new UploadDao($this->dbManager, $logger, $this->uploadPermissionDao);
     $this->showJobsDao = new ShowJobsDao($this->dbManager, $this->uploadDao);
     $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
 }
 private function runnerReuserScanWithARepoClearingEnhanced($runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     $originallyClearedItemId = 23;
     /* upload 3 in the test db is the same as upload 2 -> items 13-24 in upload 2 correspond to 33-44 */
     $reusingUploadItemShift = 20;
     $this->dbManager->queryOnce("UPDATE uploadtree_a SET pfile_fk=351 WHERE uploadtree_pk={$originallyClearedItemId}+{$reusingUploadItemShift}", __METHOD__ . '.minorChange');
     $this->uploadDao->addReusedUpload($uploadId = 3, $reusedUpload = 2, $this->groupId, $this->groupId, $reuseMode = 1);
     $repoPath = $this->testDb->getFossSysConf() . '/repo/files/';
     $this->treeDao->shouldReceive('getRepoPathOfPfile')->with(4)->andReturn($repoPath . '04621571bcbabce75c4dd1c6445b87dec0995734.59cacdfce5051cd8a1d8a1f2dcce40a5.12320');
     $this->treeDao->shouldReceive('getRepoPathOfPfile')->with(351)->andReturn($repoPath . 'c518ce1658140b65fa0132ad1130cb91512416bf.8e913e594d24ff3aeabe350107d97815.35829');
     list($clearingLicense1, $clearingLicense2, $addedEventIds) = $this->insertDecisionFromTwoEvents(DecisionScopes::REPO, $originallyClearedItemId);
     $clearingLicenses = array($clearingLicense1, $clearingLicense2);
     list($success, $output, $retCode) = $runner->run($uploadId, $this->userId, $this->groupId);
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'reuser failed: ' . $output);
     $newUploadClearings = $this->getFilteredClearings($uploadId, $this->groupId);
     $potentiallyReusableClearings = $this->getFilteredClearings($reusedUpload, $this->groupId);
     assertThat($newUploadClearings, is(arrayWithSize(1)));
     assertThat($potentiallyReusableClearings, is(arrayWithSize(1)));
     /** @var ClearingDecision */
     $potentiallyReusableClearing = $potentiallyReusableClearings[0];
     /** @var ClearingDecision */
     $newClearing = $newUploadClearings[0];
     /* they are actually the same ClearingDecision
      * only sameFolder and sameUpload are different */
     assertThat($newClearing, not(equalTo($potentiallyReusableClearing)));
     assertThat($newClearing->getClearingLicenses(), arrayContainingInAnyOrder($clearingLicenses));
     assertThat($newClearing->getType(), equalTo($potentiallyReusableClearing->getType()));
     assertThat($newClearing->getScope(), equalTo($potentiallyReusableClearing->getScope()));
     assertThat($newClearing->getUploadTreeId(), equalTo($potentiallyReusableClearing->getUploadTreeId() + $reusingUploadItemShift));
     /* reuser should have not created a correct local event history */
     $bounds = $this->uploadDao->getItemTreeBounds($originallyClearedItemId + $reusingUploadItemShift);
     $newEvents = $this->clearingDao->getRelevantClearingEvents($bounds, $this->groupId);
     assertThat($newEvents, is(arrayWithSize(count($clearingLicenses))));
     /** @var ClearingEvent $newEvent */
     foreach ($newEvents as $newEvent) {
         assertThat($newEvent->getEventId(), anyOf($addedEventIds));
         assertThat($newEvent->getClearingLicense(), anyOf($clearingLicenses));
     }
     $this->rmRepo();
 }
 public function testHasTopLevelFolder_yes()
 {
     $this->testDb->insertData(array('folder'));
     $htlf = $this->folderDao->hasTopLevelFolder();
     assertThat($htlf, is(TRUE));
 }
Exemple #21
0
 private function setUpTables()
 {
     $this->testDb->createPlainTables(array('license_ref'), false);
     $this->testDb->createSequences(array('license_ref_rf_pk_seq'), false);
     $this->testDb->insertData_license_ref(1 << 10);
 }