FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
cliParamsTest4UnunpackNormal.php
Go to the documentation of this file.
1 <?php
2 /*
3  Copyright (C) 2010-2012 Hewlett-Packard Development Company, L.P.
4  Copyright (C) 2015 Siemens AG
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
27 require_once './utility.php';
28 
31 
36 class cliParamsTest4Ununpack extends \PHPUnit\Framework\TestCase
37 {
41  private $agentDir;
45  private $ununpack;
46 
50  private $testDb;
54  private $testInstaller;
55 
60  function setUp()
61  {
62  global $TEST_DATA_PATH;
63  global $TEST_RESULT_PATH;
64 
65  if (empty($TEST_DATA_PATH) || empty($TEST_RESULT_PATH))
66  $this->markTestSkipped();
67 
68  $this->testDb = new TestPgDb('ununpackNormal');
69  $this->agentDir = dirname(dirname(__DIR__))."/";
70 
71  $sysConf = $this->testDb->getFossSysConf();
72 
73  $this->ununpack = $this->agentDir . "/agent/ununpack -c " . $sysConf;
74  $this->testInstaller = new TestInstaller($sysConf);
75  $this->testInstaller->init();
76  $this->testInstaller->install($this->agentDir);
77 
78  $this->testDb->createSequences(array(), true);
79  $this->testDb->createPlainTables(array(), true);
80  $this->testDb->createInheritedTables(array());
81  $this->testDb->alterTables(array(), true);
82  }
83 
88  public function tearDown()
89  {
90  $this->testInstaller->uninstall($this->agentDir);
91  $this->testInstaller->clear();
92  $this->testInstaller->rmRepo();
93  $this->testDb = null;
94 
95  global $TEST_RESULT_PATH;
96 
97  if (!empty($TEST_RESULT_PATH));
98  exec("/bin/rm -rf $TEST_RESULT_PATH");
99  }
100 
107  function testNormalParamI(){
108 
109  $command = $this->ununpack." -i";
110  $last = exec($command, $usageOut, $rtn);
111  $this->assertEquals($rtn, 0);
112  }
113 
122  function testNormalIso1(){
123 
124  global $TEST_DATA_PATH;
125  global $TEST_RESULT_PATH;
126 
127  $command = $this->ununpack." -qCR $TEST_DATA_PATH/test.iso -d $TEST_RESULT_PATH";
128  exec($command);
129  /* check if the result is ok? Larry think the file & dir name should be not changed, even just to uppercase */
130  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/test1.zip.dir/test.dir/test.zip.dir/ununpack");
131  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/test1.zip.dir/test.dir/test.jar.dir/ununpack");
132  }
133 
143  function testNormalParamL(){
144  global $TEST_DATA_PATH;
145  global $TEST_RESULT_PATH;
146 
147  $command = $this->ununpack." -qCR $TEST_DATA_PATH/test.iso -d $TEST_RESULT_PATH -L $TEST_RESULT_PATH/log";
148  exec($command);
149  /* check if the result is ok? Larry think the file & dir name should be not changed, even just to uppercase */
150  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/test1.zip.dir/test.dir/test.zip.dir/ununpack");
151  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/test1.zip.dir/test.dir/test.zip.dir/ununpack");
152  /* check if the log file generated? */
153  $this->assertFileExists("$TEST_RESULT_PATH/log");
154  }
155 
164  function testNormalParamx(){
165 
166  global $TEST_DATA_PATH;
167  global $TEST_RESULT_PATH;
168 
169  $command = $this->ununpack." -qCR $TEST_DATA_PATH/test.zip -d $TEST_RESULT_PATH -x";
170  exec($command);
171  $isDir = is_dir($TEST_RESULT_PATH . "/test.zip.dir");
172  $this->assertTrue(!$isDir);
173  }
174 
183  function testNormalParamr(){
184 
185  global $TEST_DATA_PATH;
186  global $TEST_RESULT_PATH;
187 
188  $command = $this->ununpack." -qC -r 0 $TEST_DATA_PATH/testtwo.zip -d $TEST_RESULT_PATH";
189  exec($command);
190  $this->assertFileExists("$TEST_RESULT_PATH/testtwo.zip.dir/test.zip");
191  $isDir = is_dir("$TEST_RESULT_PATH/testtwo.zip.dir/test.zip.dir/");
192  $this->assertTrue(!$isDir);
193  }
194 
201  function testNormalIso2(){
202  global $TEST_DATA_PATH;
203  global $TEST_RESULT_PATH;
204 
205  $command = $this->ununpack." -qCR $TEST_DATA_PATH/test.iso -d $TEST_RESULT_PATH";
206  exec($command);
207 
208  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/test1.zip");
209  }
210 
217  function testNormalRpm(){
218  global $TEST_DATA_PATH;
219  global $TEST_RESULT_PATH;
220 
221  /* the first rpm package */
222  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
223  "test.rpm -d $TEST_RESULT_PATH";
224  exec($command);
225  $this->assertFileExists("$TEST_RESULT_PATH/test.rpm.unpacked.dir/".
226  "usr/share/fossology/bsam/VERSION");
227  $this->assertFileExists("$TEST_RESULT_PATH/test.rpm.unpacked.dir/".
228  "usr/share/fossology/bsam/ui/ui-license.php");
229  }
230 
237  function testNormalTar(){
238  global $TEST_DATA_PATH;
239  global $TEST_RESULT_PATH;
240 
241  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
242  "emptydirs.tar -d $TEST_RESULT_PATH";
243  exec($command);
244  /* check if the result is ok? Select some files to confirm */
245  $this->assertFileExists("$TEST_RESULT_PATH/emptydirs.tar.dir/emptydirs/dir2/zerolenfile");
246  }
247 
255  /*
256  function testNormalRarWin(){
257  global $TEST_DATA_PATH;
258  global $TEST_RESULT_PATH;
259 
260  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
261  "test.rar -d $TEST_RESULT_PATH";
262  exec($command);
263  /* check if the result is ok? select one file to confirm *\/
264  $this->assertFileExists("$TEST_RESULT_PATH/test.rar.dir/dir1/ununpack");
265  } */
266 
267 
276  /*
277  function testNormalAr(){
278  global $TEST_DATA_PATH;
279  global $TEST_RESULT_PATH;
280 
281  /* archive file *\/
282  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
283  "test.ar -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.ar.dir/test.tar");
287 
288  // delete the directory ./test_result
289  exec("/bin/rm -rf $TEST_RESULT_PATH");
290  $isDir = is_dir($TEST_RESULT_PATH);
291  $this->assertTrue(!$isDir);
292  /* deb file *\/
293  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
294  "test.deb -d $TEST_RESULT_PATH";
295  exec($command);
296  /* check if the result is ok? select one file to confirm *\/
297  $this->assertFileExists("$TEST_RESULT_PATH/test.deb.dir/".
298  "control.tar.gz.dir/control.tar.dir/md5sums");
299  } */
300 
307  function testNormalJar(){
308  global $TEST_DATA_PATH;
309  global $TEST_RESULT_PATH;
310 
311  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
312  "test.jar -d $TEST_RESULT_PATH";
313  exec($command);
314  /* check if the result is ok? select one file to confirm */
315  $this->assertFileExists("$TEST_RESULT_PATH/test.jar.dir/ununpack");
316  }
317 
324  function testNormalZip(){
325  global $TEST_DATA_PATH;
326  global $TEST_RESULT_PATH;
327 
328  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
329  "testthree.zip -d $TEST_RESULT_PATH";
330  exec($command);
331  /* check if the result is ok? select some files to confirm */
332  $this->assertFileExists("$TEST_RESULT_PATH/testthree.zip.dir/testtwo.zip.dir/test.zip.dir/".
333  "ununpack");
334  }
335 
343  /*
344  function testNormalCatMsi(){
345  global $TEST_DATA_PATH;
346  global $TEST_RESULT_PATH;
347 
348  /* cab file *\/
349  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
350  "test.cab -d $TEST_RESULT_PATH";
351  exec($command);
352  /* check if the result is ok? select one file to confirm *\/
353  $this->assertFileExists("$TEST_RESULT_PATH/test.cab.dir/dir1/ununpack");
354 
355  // delete the directory ./test_result
356  exec("/bin/rm -rf $TEST_RESULT_PATH");
357  $isDir = is_dir($TEST_RESULT_PATH);
358  $this->assertTrue(!$isDir);
359 
360  /* msi file *\/
361  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
362  "test.msi -d $TEST_RESULT_PATH";
363  exec($command);
364  /* check if the result is ok? select one file to confirm *\/
365  $this->assertFileExists("$TEST_RESULT_PATH/test.msi.dir/ununpack");
366  } */
367 
374  function testNormalDsc(){
375  global $TEST_DATA_PATH;
376  global $TEST_RESULT_PATH;
377 
378  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
379  "test_1-1.dsc -d $TEST_RESULT_PATH";
380  exec($command);
381  /* check if the result is ok? select one file to confirm */
382  $this->assertFileExists("$TEST_RESULT_PATH/test_1-1.dsc.unpacked/debian/README.Debian");
383  }
384 
385 
393  global $TEST_DATA_PATH;
394  global $TEST_RESULT_PATH;
395 
396  /* .Z file */
397  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
398  "test.z -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/test.z.dir/test");
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  /* .gz file */
408  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
409  "testdir.tar.gz -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/testdir.tar.gz.dir/testdir.tar");
413 
414  // delete the directory ./test_result
415  exec("/bin/rm -rf $TEST_RESULT_PATH");
416  $isDir = is_dir($TEST_RESULT_PATH);
417  $this->assertTrue(!$isDir);
418  /* .bz2 file */
419  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
420  "fossI16L335U29.tar.bz2 -d $TEST_RESULT_PATH";
421  exec($command);
422  /* check if the result is ok? select one file to confirm */
423  $this->assertFileExists("$TEST_RESULT_PATH/fossI16L335U29.tar.bz2.dir/fossI16L335U29.tar.dir/fossology/README");
424  }
425 
432  function testNormalTarball(){
433  global $TEST_DATA_PATH;
434  global $TEST_RESULT_PATH;
435 
436  /* .Z tarball*/
437  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
438  "test.tar.Z -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/test.tar.Z.dir/test.tar.dir/dir1/ununpack");
442 
443  // delete the directory ./test_result
444  exec("/bin/rm -rf $TEST_RESULT_PATH");
445  $isDir = is_dir($TEST_RESULT_PATH);
446  $this->assertTrue(!$isDir);
447  /* .bz2 tarball*/
448  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
449  "fossI16L335U29.tar.bz2 -d $TEST_RESULT_PATH";
450  exec($command);
451  /* check if the result is ok? select one file to confirm */
452  $this->assertFileExists("$TEST_RESULT_PATH/fossI16L335U29.tar.bz2.dir/fossI16L335U29.tar.dir/fossology/README");
453  }
454 
461  function testNormalPdf(){
462  global $TEST_DATA_PATH;
463  global $TEST_RESULT_PATH;
464 
465  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
466  "test.pdf -d $TEST_RESULT_PATH";
467  exec($command);
468  /* check if the result is ok? select one file to confirm. */
469  $this->assertFileExists("$TEST_RESULT_PATH/test.pdf.dir/test");
470  }
471 
479  function testNormalUpx(){
480  global $TEST_DATA_PATH;
481  global $TEST_RESULT_PATH;
482 
483  //$command = "$this->UNUNPACK_PATH -qCR $TEST_DATA_PATH/".
484  // " -d $TEST_RESULT_PATH";
485  //exec($command);
486  //$this->assertFileExists("$TEST_RESULT_PATH/");
487  }
488 
495  function testNormalFsImage(){
496  global $TEST_DATA_PATH;
497  global $TEST_RESULT_PATH;
498 
499  /* ext2 image */
500  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
501  "ext2file.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/ext2file.fs.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  /* ext3 image */
511  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
512  "ext3file.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/ext3file.fs.dir/test.zip.dir/ununpack");
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  /* fat image */
522  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
523  "fatfile.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/fatfile.fs.dir/testtwo.zip");
527 
528  // delete the directory ./test_result
529  exec("/bin/rm -rf $TEST_RESULT_PATH");
530  $isDir = is_dir($TEST_RESULT_PATH);
531  $this->assertTrue(!$isDir);
532  /* ntfs image */
533  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
534  "ntfsfile.fs -d $TEST_RESULT_PATH";
535  exec($command);
536  /* check if the result is ok? select one file to confirm */
537  $this->assertFileExists("$TEST_RESULT_PATH/ntfsfile.fs.dir/test.zip.dir/ununpack");
538  }
539 
540  /* unpack boot x-x86_boot image, to-do, do not confirm
541  how is the boot x-x86 boot image like */
542 
543  /*function testNormalBootImage(){
544  global $TEST_DATA_PATH;
545  global $TEST_RESULT_PATH;
546 
547  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
548  "vmlinuz-2.6.26-2-686 -d $TEST_RESULT_PATH";
549  exec($command);
550  // check if the result is ok? select one file to confirm
551  // now, can not confirm this assertion is valid, need to confirm
552  $this->assertFileExists("$TEST_RESULT_PATH/vmlinuz-2.6.26-2-686.dir/Partition_0000");
553  }*/
554 
564  global $TEST_DATA_PATH;
565  global $TEST_RESULT_PATH;
566 
567  $command = $this->ununpack." -qCR -m 10 $TEST_DATA_PATH/".
568  "test.iso -d $TEST_RESULT_PATH";
569  exec($command);
570  /* check if the result is ok? select some files to confirm */
571  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/"
572  ."test1.zip.dir/test.dir/test.cpio");
573  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/"
574  ."test1.zip.dir/test.dir/test.cpio.dir/ununpack");
575  $this->assertFileExists("$TEST_RESULT_PATH/test.iso.dir/test1.zip.tar.dir/"
576  ."test1.zip.dir/test.dir/test.jar.dir/ununpack");
577 
578  }
579 
586  function testNormalEXE(){
587  global $TEST_DATA_PATH;
588  global $TEST_RESULT_PATH;
589 
590  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
591  "test.exe -d $TEST_RESULT_PATH";
592  exec($command);
593  /* check if the result is ok? select one file to confirm.
594  */
595  $isDir = is_dir($TEST_RESULT_PATH . "/test.ext.dir");
596  $this->assertTrue(!$isDir);
597  }
598 
605  function testNormalcpio(){
606  global $TEST_DATA_PATH;
607  global $TEST_RESULT_PATH;
608 
609  $command = $this->ununpack." -qCR $TEST_DATA_PATH/".
610  "test.cpio -d $TEST_RESULT_PATH";
611  exec($command);
612  /* check if the result is ok? */
613  $this->assertFileExists("$TEST_RESULT_PATH/test.cpio.dir/ununpack");
614  }
615 }
testNormalTarball()
Check for Z, GZ and BZ2 tarballs.
testNormalRpm()
Check for RPM files.
testNormalIso1()
Pass an iso to agent.
testNormalParamL()
Pass a log file to the agent.
testNormalCompressedFile()
Check for Z, GZ and BZ2 files.
testNormalUpx()
Check for UPX files.
testNormalMultyProcess()
Check for multi process flag.
testNormalEXE()
Check for EXE files.
tearDown()
Teardown test repo and db.
testNormalIso2()
Pass an iso to agent.
testNormalDsc()
Check for CAB and MSI files.
testNormalFsImage()
Check for disk images (file systems)
setUp()
Setup test repo and db.
Test the ununpack agent cli parameters. (Normal)
testNormalParamr()
Check recurse flag.
testNormalcpio()
Check for CPIO files.
testNormalZip()
Check for ZIP files.
testNormalJar()
Check for RAR files compressed on Windows systems.
testNormalTar()
Check for TAR files.
testNormalPdf()
Check for PDF files.
testNormalParamI()
Call agent with -i flag.