FOSSology  4.4.0
Open Source License Compliance by Open Source Software
cliParamsTest4UnunpackNormal.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2010-2012 Hewlett-Packard Development Company, L.P.
4  SPDX-FileCopyrightText: © 2015 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
16 require_once __DIR__.'/utility.php';
17 
20 
25 class cliParamsTest4Ununpack extends \PHPUnit\Framework\TestCase
26 {
30  private $agentDir;
34  private $ununpack;
35 
39  private $testDb;
43  private $testInstaller;
44 
49  function setUp() : void
50  {
51  global $TEST_DATA_PATH;
52  global $TEST_RESULT_PATH;
53 
54  if (empty($TEST_DATA_PATH) || empty($TEST_RESULT_PATH))
55  $this->markTestSkipped();
56 
57  $this->testDb = new TestPgDb('ununpackNormal');
58  $this->agentDir = dirname(__DIR__, 4)."/build/src/ununpack";
59 
60  $sysConf = $this->testDb->getFossSysConf();
61 
62  $this->ununpack = $this->agentDir . "/agent/ununpack -c " . $sysConf;
63  $this->testInstaller = new TestInstaller($sysConf);
64  $this->testInstaller->init();
65  $this->testInstaller->install($this->agentDir);
66 
67  $this->testDb->createSequences(array(), true);
68  $this->testDb->createPlainTables(array(), true);
69  $this->testDb->createInheritedTables(array());
70  $this->testDb->alterTables(array(), true);
71  }
72 
77  public function tearDown() : void
78  {
79  $this->testInstaller->uninstall($this->agentDir);
80  $this->testInstaller->clear();
81  $this->testInstaller->rmRepo();
82  $this->testDb = null;
83 
84  global $TEST_RESULT_PATH;
85 
86  if (!empty($TEST_RESULT_PATH));
87  exec("/bin/rm -rf $TEST_RESULT_PATH");
88  }
89 
96  function testNormalParamI(){
97 
98  $command = $this->ununpack." -i";
99  $last = exec($command, $usageOut, $rtn);
100  $this->assertEquals($rtn, 0);
101  }
102 
111  function testNormalIso1(){
112 
113  global $TEST_DATA_PATH;
114  global $TEST_RESULT_PATH;
115 
116  $command = $this->ununpack." -qCR $TEST_DATA_PATH/test.iso -d $TEST_RESULT_PATH";
117  exec($command);
118  /* check if the result is ok? Larry think the file & dir name should be not changed, even just to uppercase */
119  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/test1.zip.dir/test.dir/test.zip.dir/ununpack");
120  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/test1.zip.dir/test.dir/test.jar.dir/ununpack");
121  }
122 
132  function testNormalParamL(){
133  global $TEST_DATA_PATH;
134  global $TEST_RESULT_PATH;
135 
136  $command = $this->ununpack." -qCR $TEST_DATA_PATH/test.iso -d $TEST_RESULT_PATH -L $TEST_RESULT_PATH/log";
137  exec($command);
138  /* check if the result is ok? Larry think the file & dir name should be not changed, even just to uppercase */
139  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/test1.zip.dir/test.dir/test.zip.dir/ununpack");
140  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/test1.zip.dir/test.dir/test.zip.dir/ununpack");
141  /* check if the log file generated? */
142  $this->assertFileExists("$TEST_RESULT_PATH/log");
143  }
144 
153  function testNormalParamx(){
154 
155  global $TEST_DATA_PATH;
156  global $TEST_RESULT_PATH;
157 
158  $command = $this->ununpack." -qCR $TEST_DATA_PATH/test.zip -d $TEST_RESULT_PATH -x";
159  exec($command);
160  $isDir = is_dir($TEST_RESULT_PATH . "/test.zip.dir");
161  $this->assertTrue(!$isDir);
162  }
163 
172  function testNormalParamr(){
173 
174  global $TEST_DATA_PATH;
175  global $TEST_RESULT_PATH;
176 
177  $command = $this->ununpack." -qC -r 0 $TEST_DATA_PATH/testtwo.zip -d $TEST_RESULT_PATH";
178  exec($command);
179  $this->assertFileExists("$TEST_RESULT_PATH/testtwo.zip.dir/test.zip");
180  $isDir = is_dir("$TEST_RESULT_PATH/testtwo.zip.dir/test.zip.dir/");
181  $this->assertTrue(!$isDir);
182  }
183 
190  function testNormalIso2(){
191  global $TEST_DATA_PATH;
192  global $TEST_RESULT_PATH;
193 
194  $command = $this->ununpack." -qCR $TEST_DATA_PATH/test.iso -d $TEST_RESULT_PATH";
195  exec($command);
196 
197  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/test1.zip");
198  }
199 
206  function testNormalRpm(){
207  global $TEST_DATA_PATH;
208  global $TEST_RESULT_PATH;
209 
210  /* the first rpm package */
211  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
212  "test.rpm -d $TEST_RESULT_PATH";
213  exec($command);
214  $this->assertFileExists("$TEST_RESULT_PATH/test.rpm.unpacked.dir/".
215  "usr/share/fossology/bsam/VERSION");
216  $this->assertFileExists("$TEST_RESULT_PATH/test.rpm.unpacked.dir/".
217  "usr/share/fossology/bsam/ui/ui-license.php");
218  }
219 
226  function testNormalTar(){
227  global $TEST_DATA_PATH;
228  global $TEST_RESULT_PATH;
229 
230  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
231  "emptydirs.tar -d $TEST_RESULT_PATH";
232  exec($command);
233  /* check if the result is ok? Select some files to confirm */
234  $this->assertFileExists("$TEST_RESULT_PATH/emptydirs.tar.dir/emptydirs/dir2/zerolenfile");
235  }
236 
244  /*
245  function testNormalRarWin(){
246  global $TEST_DATA_PATH;
247  global $TEST_RESULT_PATH;
248 
249  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
250  "test.rar -d $TEST_RESULT_PATH";
251  exec($command);
252  /* check if the result is ok? select one file to confirm *\/
253  $this->assertFileExists("$TEST_RESULT_PATH/test.rar.dir/dir1/ununpack");
254  } */
255 
256 
265  /*
266  function testNormalAr(){
267  global $TEST_DATA_PATH;
268  global $TEST_RESULT_PATH;
269 
270  /* archive file *\/
271  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
272  "test.ar -d $TEST_RESULT_PATH";
273  exec($command);
274  /* check if the result is ok? select one file to confirm *\/
275  $this->assertFileExists("$TEST_RESULT_PATH/test.ar.dir/test.tar");
276 
277  // delete the directory ./test_result
278  exec("/bin/rm -rf $TEST_RESULT_PATH");
279  $isDir = is_dir($TEST_RESULT_PATH);
280  $this->assertTrue(!$isDir);
281  /* deb file *\/
282  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
283  "test.deb -d $TEST_RESULT_PATH";
284  exec($command);
285  /* check if the result is ok? select one file to confirm *\/
286  $this->assertFileExists("$TEST_RESULT_PATH/test.deb.dir/".
287  "control.tar.gz.dir/control.tar.dir/md5sums");
288  } */
289 
296  function testNormalJar(){
297  global $TEST_DATA_PATH;
298  global $TEST_RESULT_PATH;
299 
300  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
301  "test.jar -d $TEST_RESULT_PATH";
302  exec($command);
303  /* check if the result is ok? select one file to confirm */
304  $this->assertFileExists("$TEST_RESULT_PATH/test.jar.dir/ununpack");
305  }
306 
313  function testNormalZip(){
314  global $TEST_DATA_PATH;
315  global $TEST_RESULT_PATH;
316 
317  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
318  "testthree.zip -d $TEST_RESULT_PATH";
319  exec($command);
320  /* check if the result is ok? select some files to confirm */
321  $this->assertFileExists("$TEST_RESULT_PATH/testthree.zip.dir/testtwo.zip.dir/test.zip.dir/".
322  "ununpack");
323  }
324 
332  /*
333  function testNormalCatMsi(){
334  global $TEST_DATA_PATH;
335  global $TEST_RESULT_PATH;
336 
337  /* cab file *\/
338  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
339  "test.cab -d $TEST_RESULT_PATH";
340  exec($command);
341  /* check if the result is ok? select one file to confirm *\/
342  $this->assertFileExists("$TEST_RESULT_PATH/test.cab.dir/dir1/ununpack");
343 
344  // delete the directory ./test_result
345  exec("/bin/rm -rf $TEST_RESULT_PATH");
346  $isDir = is_dir($TEST_RESULT_PATH);
347  $this->assertTrue(!$isDir);
348 
349  /* msi file *\/
350  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
351  "test.msi -d $TEST_RESULT_PATH";
352  exec($command);
353  /* check if the result is ok? select one file to confirm *\/
354  $this->assertFileExists("$TEST_RESULT_PATH/test.msi.dir/ununpack");
355  } */
356 
363  function testNormalDsc(){
364  global $TEST_DATA_PATH;
365  global $TEST_RESULT_PATH;
366 
367  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
368  "test_1-1.dsc -d $TEST_RESULT_PATH";
369  exec($command);
370  /* check if the result is ok? select one file to confirm */
371  $this->assertFileExists("$TEST_RESULT_PATH/test_1-1.dsc.unpacked/debian/README.Debian");
372  }
373 
374 
382  global $TEST_DATA_PATH;
383  global $TEST_RESULT_PATH;
384 
385  /* .Z file */
386  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
387  "test.z -d $TEST_RESULT_PATH";
388  exec($command);
389  /* check if the result is ok? select one file to confirm */
390  $this->assertFileExists("$TEST_RESULT_PATH/test.z.dir/test");
391 
392  // delete the directory ./test_result
393  exec("/bin/rm -rf $TEST_RESULT_PATH");
394  $isDir = is_dir($TEST_RESULT_PATH);
395  $this->assertTrue(!$isDir);
396  /* .gz file */
397  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
398  "testdir.tar.gz -d $TEST_RESULT_PATH";
399  exec($command);
400  /* check if the result is ok? select one file to confirm */
401  $this->assertFileExists("$TEST_RESULT_PATH/testdir.tar.gz.dir/testdir.tar");
402 
403  // delete the directory ./test_result
404  exec("/bin/rm -rf $TEST_RESULT_PATH");
405  $isDir = is_dir($TEST_RESULT_PATH);
406  $this->assertTrue(!$isDir);
407  /* .bz2 file */
408  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
409  "fossI16L335U29.tar.bz2 -d $TEST_RESULT_PATH";
410  exec($command);
411  /* check if the result is ok? select one file to confirm */
412  $this->assertFileExists("$TEST_RESULT_PATH/fossI16L335U29.tar.bz2.dir/fossI16L335U29.tar.dir/fossology/README");
413  }
414 
421  function testNormalTarball(){
422  global $TEST_DATA_PATH;
423  global $TEST_RESULT_PATH;
424 
425  /* .Z tarball*/
426  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
427  "test.tar.Z -d $TEST_RESULT_PATH";
428  exec($command);
429  /* check if the result is ok? select one file to confirm */
430  $this->assertFileExists("$TEST_RESULT_PATH/test.tar.Z.dir/test.tar.dir/dir1/ununpack");
431 
432  // delete the directory ./test_result
433  exec("/bin/rm -rf $TEST_RESULT_PATH");
434  $isDir = is_dir($TEST_RESULT_PATH);
435  $this->assertTrue(!$isDir);
436  /* .bz2 tarball*/
437  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
438  "fossI16L335U29.tar.bz2 -d $TEST_RESULT_PATH";
439  exec($command);
440  /* check if the result is ok? select one file to confirm */
441  $this->assertFileExists("$TEST_RESULT_PATH/fossI16L335U29.tar.bz2.dir/fossI16L335U29.tar.dir/fossology/README");
442  }
443 
450  function testNormalPdf(){
451  global $TEST_DATA_PATH;
452  global $TEST_RESULT_PATH;
453 
454  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
455  "test.pdf -d $TEST_RESULT_PATH";
456  exec($command);
457  /* check if the result is ok? select one file to confirm. */
458  $this->assertFileExists("$TEST_RESULT_PATH/test.pdf.dir/test");
459  }
460 
468 // function testNormalUpx(){
469 // global $TEST_DATA_PATH;
470 // global $TEST_RESULT_PATH;
471 
472  //$command = "$this->UNUNPACK_PATH -qCR $TEST_DATA_PATH/".
473  // " -d $TEST_RESULT_PATH";
474  //exec($command);
475  //$this->assertFileExists("$TEST_RESULT_PATH/");
476 // }
477 
484  function testNormalFsImage(){
485  global $TEST_DATA_PATH;
486  global $TEST_RESULT_PATH;
487 
488  /* ext2 image */
489  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
490  "ext2file.fs -d $TEST_RESULT_PATH";
491  exec($command);
492  /* check if the result is ok? select one file to confirm */
493  $this->assertFileExists("$TEST_RESULT_PATH/ext2file.fs.dir/testtwo.zip.dir/test.zip.dir/ununpack");
494 
495  // delete the directory ./test_result
496  exec("/bin/rm -rf $TEST_RESULT_PATH");
497  $isDir = is_dir($TEST_RESULT_PATH);
498  $this->assertTrue(!$isDir);
499  /* ext3 image */
500  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
501  "ext3file.fs -d $TEST_RESULT_PATH";
502  exec($command);
503  /* check if the result is ok? select one file to confirm */
504  $this->assertFileExists("$TEST_RESULT_PATH/ext3file.fs.dir/testtwo.zip.dir/test.zip.dir/ununpack");
505 
506  // delete the directory ./test_result
507  exec("/bin/rm -rf $TEST_RESULT_PATH");
508  $isDir = is_dir($TEST_RESULT_PATH);
509  $this->assertTrue(!$isDir);
510  /* fat image */
511  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
512  "fatfile.fs -d $TEST_RESULT_PATH";
513  exec($command);
514  /* check if the result is ok? select one file to confirm */
515  $this->assertFileExists("$TEST_RESULT_PATH/fatfile.fs.dir/testtwo.zip");
516 
517  // delete the directory ./test_result
518  exec("/bin/rm -rf $TEST_RESULT_PATH");
519  $isDir = is_dir($TEST_RESULT_PATH);
520  $this->assertTrue(!$isDir);
521  /* ntfs image */
522  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
523  "ntfsfile.fs -d $TEST_RESULT_PATH";
524  exec($command);
525  /* check if the result is ok? select one file to confirm */
526  $this->assertFileExists("$TEST_RESULT_PATH/ntfsfile.fs.dir/testtwo.zip.dir/test.zip.dir/ununpack");
527  }
528 
529  /* unpack boot x-x86_boot image, to-do, do not confirm
530  how is the boot x-x86 boot image like */
531 
532  /*function testNormalBootImage(){
533  global $TEST_DATA_PATH;
534  global $TEST_RESULT_PATH;
535 
536  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
537  "vmlinuz-2.6.26-2-686 -d $TEST_RESULT_PATH";
538  exec($command);
539  // check if the result is ok? select one file to confirm
540  // now, can not confirm this assertion is valid, need to confirm
541  $this->assertFileExists("$TEST_RESULT_PATH/vmlinuz-2.6.26-2-686.dir/Partition_0000");
542  }*/
543 
553  global $TEST_DATA_PATH;
554  global $TEST_RESULT_PATH;
555 
556  $command = $this->ununpack." -qCR -m 10 $TEST_DATA_PATH/".
557  "test.iso -d $TEST_RESULT_PATH";
558  exec($command);
559  /* check if the result is ok? select some files to confirm */
560  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/"
561  ."test1.zip.dir/test.dir/test.cpio");
562  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/"
563  ."test1.zip.dir/test.dir/test.cpio.dir/ununpack");
564  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/"
565  ."test1.zip.dir/test.dir/test.jar.dir/ununpack");
566 
567  }
568 
575  function testNormalEXE(){
576  global $TEST_DATA_PATH;
577  global $TEST_RESULT_PATH;
578 
579  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
580  "test.exe -d $TEST_RESULT_PATH";
581  exec($command);
582  /* check if the result is ok? select one file to confirm.
583  */
584  $isDir = is_dir($TEST_RESULT_PATH . "/test.ext.dir");
585  $this->assertTrue(!$isDir);
586  }
587 
594  function testNormalcpio(){
595  global $TEST_DATA_PATH;
596  global $TEST_RESULT_PATH;
597 
598  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
599  "test.cpio -d $TEST_RESULT_PATH";
600  exec($command);
601  /* check if the result is ok? */
602  $this->assertFileExists("$TEST_RESULT_PATH/test.cpio.dir/ununpack");
603  }
604 
612  function testNormalZst(){
613  global $TEST_DATA_PATH;
614  global $TEST_RESULT_PATH;
615 
616  /* archive file */
617  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
618  "test.zst -d $TEST_RESULT_PATH";
619  exec($command);
620  /* check if the result is ok? select one file to confirm */
621  $this->assertFileExists("$TEST_RESULT_PATH/test.zst.dir/test.tar");
622 
623  // delete the directory ./test_result
624  exec("/bin/rm -rf $TEST_RESULT_PATH");
625  $isDir = is_dir($TEST_RESULT_PATH);
626  $this->assertTrue(!$isDir);
627  }
628 
636  function testNormalLz4(){
637  global $TEST_DATA_PATH;
638  global $TEST_RESULT_PATH;
639 
640  /* archive file */
641  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
642  "test.lz4 -d $TEST_RESULT_PATH";
643  exec($command);
644  /* check if the result is ok? select one file to confirm */
645  $this->assertFileExists("$TEST_RESULT_PATH/test.lz4.dir/test.tar");
646 
647  // delete the directory ./test_result
648  exec("/bin/rm -rf $TEST_RESULT_PATH");
649  $isDir = is_dir($TEST_RESULT_PATH);
650  $this->assertTrue(!$isDir);
651  }
652 
660  function testNormalLzma(){
661  global $TEST_DATA_PATH;
662  global $TEST_RESULT_PATH;
663 
664  /* archive file */
665  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
666  "test.lzma -d $TEST_RESULT_PATH";
667  exec($command);
668  /* check if the result is ok? select one file to confirm */
669  $this->assertFileExists("$TEST_RESULT_PATH/test.lzma.dir/test.tar");
670 
671  // delete the directory ./test_result
672  exec("/bin/rm -rf $TEST_RESULT_PATH");
673  $isDir = is_dir($TEST_RESULT_PATH);
674  $this->assertTrue(!$isDir);
675  }
676 }
Test the ununpack agent cli parameters. (Normal)
testNormalJar()
Check for RAR files compressed on Windows systems.
testNormalDsc()
Check for CAB and MSI files.
testNormalMultyProcess()
Check for multi process flag.
testNormalIso1()
Pass an iso to agent.
testNormalCompressedFile()
Check for Z, GZ and BZ2 files.
testNormalParamI()
Call agent with -i flag.
tearDown()
Teardown test repo and db.
testNormalIso2()
Pass an iso to agent.
testNormalTarball()
Check for Z, GZ and BZ2 tarballs.
testNormalcpio()
Check for CPIO files.
testNormalFsImage()
Check for UPX files.
setUp()
Setup test repo and db.
testNormalParamL()
Pass a log file to the agent.