FOSSology  4.4.0
Open Source License Compliance by Open Source Software
cliParamsTest4WgetAgent.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2011-2014 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
18 $TEST_RESULT_PATH = "./test_result";
19 
22 
27 class cliParamsTest4Wget extends \PHPUnit\Framework\TestCase {
28 
29  public $WGET_PATH = "";
30 
32  private $testDb;
33 
38  protected function setUp() : void {
39  global $WGET_PATH;
40  global $db_conf;
41  $db_conf = "";
42 
43  $cwd = dirname(__DIR__, 4).'/build/src/wget_agent';
44 
45  $this->testDb = new TestPgDb("fosswgetagenttest");
46  $db_conf = $this->testDb->getFossSysConf();
47  $this->testInstaller = new TestInstaller($db_conf);
48  $this->testInstaller->init();
49  $this->testInstaller->cpRepo();
50  $this->testInstaller->install($cwd);
51  $WGET_PATH = $cwd . '/agent/wget_agent';
52  $usage= "";
53  if(file_exists($WGET_PATH))
54  {
55  $usage = "Usage: $WGET_PATH [options] [OBJ]";
56  }
57  else
58  {
59  $this->assertFileExists($WGET_PATH,
60  $message = 'FATAL: cannot find executable file, stop testing\n');
61  }
62  // run it
63  $WGET_PATH .= " -C -c $db_conf";
64  $last = exec("$WGET_PATH -h 2>&1", $out, $rtn);
65  $this->assertEquals($usage, $out[0]); // check if executable file wget_agent is exited
66  }
67 
80  global $TEST_RESULT_PATH;
81  global $WGET_PATH;
82  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
83 
84  $command = "$WGET_PATH https://mirrors.kernel.org/fossology/releases/3.0.0/fedora/20/x86_64/ -A rpm -R fossology-common-3.0.0-1.fc20.x86_64.rpm,fossology-debuginfo-3.0.0-1.fc20.x86_64.rpm,fossology-web-3.0.0-1.fc20.x86_64.rpm,fossology-3.0.0-1.fc20.src.rpm -d $TEST_RESULT_PATH";
85  exec($command);
86  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/3.0.0/fedora/20/x86_64/fossology-3.0.0-1.fc20.x86_64.rpm");
87  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/3.0.0/fedora/20/x86_64/fossology-wgetagent-3.0.0-1.fc20.x86_64.rpm");
88  $this->assertFileNotExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/3.0.0/fedora/20/x86_64/fossology-debuginfo-3.0.0-1.fc20.x86_64.rpm");
89  }
90 
103  global $TEST_RESULT_PATH;
104  global $WGET_PATH;
105  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
106 
107  $command = "$WGET_PATH https://mirrors.kernel.org/fossology/releases/3.0.0/debian/7.0/ -A deb -R fossology-* -d $TEST_RESULT_PATH";
108  //print "command is:$command\n";
109  exec($command);
110  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/3.0.0/debian/7.0/fossology_3.0.0-1_i386.deb");
111  $this->assertFileNotExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/3.0.0/debian/7.0/fossology-ununpack_3.0.0-1_amd64.deb");
112  }
113 
126  global $TEST_RESULT_PATH;
127  global $WGET_PATH;
128  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
129 
130  $command = "$WGET_PATH https://mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/ -A rpm -R fossology-2.0.0-1.fc15.src.rpm,fossology-common-2.0.0-1.fc15.x86_64.rpm -l 1 -d $TEST_RESULT_PATH";
131  //print "command is:$command\n";
132  exec($command);
133  $this->assertFileNotExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386/fossology-common-2.0.0-1.fc15.x86_64.rpm");
134  $this->assertFileNotExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/x86_64/fossology-common-2.0.0-1.fc15.x86_64.rpm");
135  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386");
136  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/x86_64");
137  }
138 
148  global $TEST_RESULT_PATH;
149  global $WGET_PATH;
150  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
151 
152  $command = "$WGET_PATH https://mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386/fossology-db-2.0.0-1.fc15.i386.rpm";
153  //print "command is:$command\n";
154  exec($command);
155  $this->assertFileExists("mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386/fossology-db-2.0.0-1.fc15.i386.rpm");
156  exec("/bin/rm -rf 'mirrors.kernel.org'");
157  }
158 
170  global $WGET_PATH;
171  return;
172 
173  $command = "$WGET_PATH 'http://www.fossology.org/~vincent/test/test%20dir(special)/WINKERS%20-%20Final_tcm19-16386.doc' -d './test result(special)'";
174  //print "command is:$command\n";
175  exec($command);
176  $this->assertFileExists("test result(special)/www.fossology.org/~vincent/test/test dir(special)/WINKERS - Final_tcm19-16386.doc");
177  exec("/bin/rm -rf 'test result(special)'");
178  }
179 
190  global $TEST_RESULT_PATH;
191  global $WGET_PATH;
192  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
193 
194  $command = "$WGET_PATH https://mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386/ -A fossology* -R fossology-2.0.0-1.fc15.i386.rpm,fossology-2.0.0-1.fc15.src.rpm -d $TEST_RESULT_PATH -l 2";
195  //print "command is:$command\n";
196  exec($command);
197  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386/fossology-pkgagent-2.0.0-1.fc15.i386.rpm");
198  $this->assertFileNotExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386/fossology-2.0.0-1.fc15.src.rpm");
199  }
200 
211  global $TEST_RESULT_PATH;
212  global $WGET_PATH;
213  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
214 
215  $command = "$WGET_PATH https://mirrors.kernel.org/fossology/releases/2.0.0/Debian/squeeze/6.0/ -A fossology-scheduler_2.0.0* -R gz,fossology-scheduler_2.0.0-1_i386* -d $TEST_RESULT_PATH -l 1";
216  //print "command is:$command\n";
217  exec($command);
218  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Debian/squeeze/6.0/fossology-scheduler_2.0.0-1_amd64.deb");
219  $this->assertFileNotExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Debian/squeeze/6.0/fossology-scheduler_2.0.0-1_i386.deb");
220  }
221 
222 
226  function change_proxy($proxy_type, $porxy) {
227  global $db_conf;
228 
229  $foss_conf = $db_conf."/fossology.conf";
230  exec("sudo sed 's/.$proxy_type.*=.*/$proxy_type=$porxy/' $foss_conf >/tmp/fossology.conf");
231  exec("sudo mv /tmp/fossology.conf $foss_conf");
232  }
233 
241  function test_proxy_ftp() {
242  global $db_conf;
243  global $TEST_RESULT_PATH;
244  global $WGET_PATH;
245  return; // TODO ignore this test case, because it is flaky on travis
246  // ftp_proxy
247  //$this->change_proxy("ftp_proxy", "web-proxy.cce.hp.com:8088");
248  $command = "$WGET_PATH ftp://releases.ubuntu.com/releases/trusty/SHA1SUMS -d $TEST_RESULT_PATH";
249  exec($command);
250  $this->assertFileExists("$TEST_RESULT_PATH/releases.ubuntu.com/releases/trusty/SHA1SUMS");
251  }
252 
260  function test_proxy_http() {
261  global $db_conf;
262  global $TEST_RESULT_PATH;
263  global $WGET_PATH;
264  // http_proxy
265  //$this->change_proxy("http_proxy", "web-proxy.cce.hp.com:8088");
266  $command = "$WGET_PATH https://mirrors.kernel.org/fossology/releases/2.0.0/Debian/squeeze/6.0/fossology-mimetype_2.0.0-1_amd64.deb -d $TEST_RESULT_PATH";
267  exec($command);
268  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Debian/squeeze/6.0/fossology-mimetype_2.0.0-1_amd64.deb");
269 
270  // no proxy
271  //$this->change_proxy("no_proxy", "fossology.org");
272  $command = "$WGET_PATH https://mirrors.kernel.org/fossology/releases/2.0.0/Debian/squeeze/6.0/fossology-mimetype_2.0.0-1_amd64.deb -d $TEST_RESULT_PATH";
273  exec($command);
274  //$this->assertFileNotExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Debian/squeeze/6.0/fossology-mimetype_2.0.0-1_amd64.deb");
275  }
276 
284  function test_proxy_https() {
285  global $db_conf;
286  global $TEST_RESULT_PATH;
287  global $WGET_PATH;
288 
289  // https_proxy
290  //$this->change_proxy("https_proxy", "web-proxy.cce.hp.com:8088");
291  $command = "$WGET_PATH https://www.google.com/images/srpr/nav_logo80.png -l 1 -d $TEST_RESULT_PATH";
292  exec($command);
293  $this->assertFileExists("$TEST_RESULT_PATH/www.google.com/images/srpr/nav_logo80.png");
294  }
295 
300  protected function tearDown() : void {
301  if (!is_callable('pg_connect')) {
302  return;
303  }
304  $this->testDb->fullDestruct();
305  $this->testDb = null;
306  }
307 }
testDownloadDirHasChildDirLevel0()
download one dir(one url)
testDownloadAcceptRejectType1()
download one dir(one url)
change_proxy($proxy_type, $porxy)
Change proxy to test.
testtDownloadAcceptRejectType2()
download one dir(one url)
test_proxy_http()
Test proxy http and no proxy.
test_proxy_https()
Test proxy https.
testDownloadDirHasChildDirLevel1()
Download one dir(one url)
testDownloadDirCurrentDirLevel0()
Download one file(one url)
test_proxy_ftp()
Test proxy ftp.
testDownloadDirHasNoChildDirLevel0()
Download one dir(one url)
testDownloadURLDesAbnormal()
download one file(one url)
if(!preg_match("/\s$projectGroup\s/", $groups) &&(posix_getgid() !=$gInfo[ 'gid']))
get monk license list of one specified uploadtree_id
Definition: migratetest.php:33