FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
cliParamsTest4WgetAgent.php
1 <?php
2 
3 /*
4  Copyright (C) 2011-2014 Hewlett-Packard Development Company, L.P.
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 
29 require_once (__DIR__ . "/../../../testing/db/createEmptyTestEnvironment.php");
30 
31 $TEST_RESULT_PATH = "./test_result";
32 
37 class cliParamsTest4Wget extends \PHPUnit\Framework\TestCase {
38 
39  public $WGET_PATH = "";
40  public $DB_COMMAND = "";
41  public $DB_NAME = "";
42  public $SYSCONF_DIR = "";
43 
48  protected function setUp() {
49  global $WGET_PATH;
50  global $DB_COMMAND;
51  global $DB_NAME;
52  global $db_conf;
53  global $REPO_NAME;
54  global $SYSCONF_DIR;
55 
56  $db_conf = "";
57 
58  $cwd = getcwd();
59  list($test_name, $db_conf, $DB_NAME, $PG_CONN) = setupTestEnv($cwd, "wget_agent");
60 
61  $REPO_NAME = "testDbRepo".$test_name;
62 
63  $WGET_PATH = '../../agent/wget_agent';
64  $usage= "";
65  if(file_exists($WGET_PATH))
66  {
67  $usage = 'Usage: ../../agent/wget_agent [options] [OBJ]';
68  }
69  else
70  {
71  $this->assertFileExists($WGET_PATH,
72  $message = 'FATAL: cannot find executable file, stop testing\n');
73  }
74  // run it
75  $WGET_PATH = $WGET_PATH." -C -c $db_conf";
76  $last = exec("$WGET_PATH -h 2>&1", $out, $rtn);
77  $this->assertEquals($usage, $out[0]); // check if executable file wget_agent is exited
78  }
79 
92  global $TEST_RESULT_PATH;
93  global $WGET_PATH;
94  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
95 
96  $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";
97  exec($command);
98  $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");
99  $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");
100  $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");
101  }
102 
115  global $TEST_RESULT_PATH;
116  global $WGET_PATH;
117  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
118 
119  $command = "$WGET_PATH https://mirrors.kernel.org/fossology/releases/3.0.0/debian/7.0/ -A deb -R fossology-* -d $TEST_RESULT_PATH";
120  //print "command is:$command\n";
121  exec($command);
122  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/3.0.0/debian/7.0/fossology_3.0.0-1_i386.deb");
123  $this->assertFileNotExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/3.0.0/debian/7.0/fossology-ununpack_3.0.0-1_amd64.deb");
124  }
125 
138  global $TEST_RESULT_PATH;
139  global $WGET_PATH;
140  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
141 
142  $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";
143  //print "command is:$command\n";
144  exec($command);
145  $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");
146  $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");
147  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386");
148  $this->assertFileExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/x86_64");
149  }
150 
160  global $TEST_RESULT_PATH;
161  global $WGET_PATH;
162  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
163 
164  $command = "$WGET_PATH https://mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386/fossology-db-2.0.0-1.fc15.i386.rpm";
165  //print "command is:$command\n";
166  exec($command);
167  $this->assertFileExists("mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386/fossology-db-2.0.0-1.fc15.i386.rpm");
168  exec("/bin/rm -rf 'mirrors.kernel.org'");
169  }
170 
182  global $WGET_PATH;
183  return;
184 
185  $command = "$WGET_PATH 'http://www.fossology.org/~vincent/test/test%20dir(special)/WINKERS%20-%20Final_tcm19-16386.doc' -d './test result(special)'";
186  //print "command is:$command\n";
187  exec($command);
188  $this->assertFileExists("test result(special)/www.fossology.org/~vincent/test/test dir(special)/WINKERS - Final_tcm19-16386.doc");
189  exec("/bin/rm -rf 'test result(special)'");
190  }
191 
202  global $TEST_RESULT_PATH;
203  global $WGET_PATH;
204  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
205 
206  $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";
207  //print "command is:$command\n";
208  exec($command);
209  $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");
210  $this->assertFileNotExists("$TEST_RESULT_PATH/mirrors.kernel.org/fossology/releases/2.0.0/Fedora/15/i386/fossology-2.0.0-1.fc15.src.rpm");
211  }
212 
223  global $TEST_RESULT_PATH;
224  global $WGET_PATH;
225  //$this->change_proxy('http_proxy', 'web-proxy.cce.hp.com:8088');
226 
227  $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";
228  //print "command is:$command\n";
229  exec($command);
230  $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");
231  $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");
232  }
233 
237  function preparations() {
238  global $REPO_NAME;
239  global $db_conf;
240 
241  if (is_dir("/srv/fossology/$REPO_NAME")) {
242  exec("sudo chmod 2770 /srv/fossology/$REPO_NAME"); // change mode to 2770
243  exec("sudo chown fossy /srv/fossology/$REPO_NAME -R"); // change owner of REPO to fossy
244  exec("sudo chgrp fossy /srv/fossology/$REPO_NAME -R"); // change grp of REPO to fossy
245  }
246  if (is_dir($db_conf)) {
247  exec("sudo chown fossy $SYSCONF_DIR -R"); // change owner of sysconfdir to fossy
248  exec("sudo chgrp fossy $SYSCONF_DIR -R"); // change grp of sysconfdir to fossy
249  }
250  }
251 
252 
256  function change_proxy($proxy_type, $porxy) {
257  global $db_conf;
258 
259  $foss_conf = $db_conf."/fossology.conf";
260  exec("sudo sed 's/.$proxy_type.*=.*/$proxy_type=$porxy/' $foss_conf >/tmp/fossology.conf");
261  exec("sudo mv /tmp/fossology.conf $foss_conf");
262  }
263 
271  function test_proxy_ftp() {
272  global $db_conf;
273  global $TEST_RESULT_PATH;
274  global $WGET_PATH;
275  return; // TODO ignore this test case, because it is flaky on travis
276  // ftp_proxy
277  //$this->change_proxy("ftp_proxy", "web-proxy.cce.hp.com:8088");
278  $command = "$WGET_PATH ftp://releases.ubuntu.com/releases/trusty/SHA1SUMS -d $TEST_RESULT_PATH";
279  exec($command);
280  $this->assertFileExists("$TEST_RESULT_PATH/releases.ubuntu.com/releases/trusty/SHA1SUMS");
281  }
282 
290  function test_proxy_http() {
291  global $db_conf;
292  global $TEST_RESULT_PATH;
293  global $WGET_PATH;
294  // http_proxy
295  //$this->change_proxy("http_proxy", "web-proxy.cce.hp.com:8088");
296  $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";
297  exec($command);
298  $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");
299 
300  // no proxy
301  //$this->change_proxy("no_proxy", "fossology.org");
302  $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";
303  exec($command);
304  //$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");
305  }
306 
314  function test_proxy_https() {
315  global $db_conf;
316  global $TEST_RESULT_PATH;
317  global $WGET_PATH;
318 
319  // https_proxy
320  //$this->change_proxy("https_proxy", "web-proxy.cce.hp.com:8088");
321  $command = "$WGET_PATH https://www.google.com/images/srpr/nav_logo80.png -l 1 -d $TEST_RESULT_PATH";
322  exec($command);
323  $this->assertFileExists("$TEST_RESULT_PATH/www.google.com/images/srpr/nav_logo80.png");
324  }
325 
330  protected function tearDown() {
331  global $TEST_RESULT_PATH;
332  global $DB_COMMAND;
333  global $DB_NAME;
334  global $SYSCONF_DIR;
335 
336  // delete the directory ./test_result
337  exec("/bin/rm -rf $TEST_RESULT_PATH $SYSCONF_DIR");
338  // remove the sysconf/db/repo
339  if (!empty($DB_COMMAND) && !empty($DB_NAME)) {
340  exec("$DB_COMMAND -d $DB_NAME");
341  }
342  }
343 }
344 
345 ?>
test_proxy_ftp()
Test proxy ftp.
test_proxy_http()
Test proxy http and no proxy.
test_proxy_https()
Test proxy https.
testDownloadDirCurrentDirLevel0()
Download one file(one url)
change_proxy($proxy_type, $porxy)
Change proxy to test.
testDownloadAcceptRejectType1()
download one dir(one url)
preparations()
Replace default repo with new repo.
testDownloadDirHasNoChildDirLevel0()
Download one dir(one url)
testDownloadDirHasChildDirLevel0()
download one dir(one url)
testtDownloadAcceptRejectType2()
download one dir(one url)
testDownloadDirHasChildDirLevel1()
Download one dir(one url)
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:321
testDownloadURLDesAbnormal()
download one file(one url)