FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ft_DelagentTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2012 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/cli/tests/test_common.php');
9 require_once (__DIR__ . "/../../../testing/db/createEmptyTestEnvironment.php");
10 
16 class ft_DelagentTest extends \PHPUnit\Framework\TestCase {
17 
18  public $SYSCONF_DIR;
19  public $DB_NAME;
20  public $PG_CONN;
21  public $DB_COMMAND;
22 
27  function upload_testdata(){
28  global $SYSCONF_DIR;
29  $auth = "--user fossy --password fossy -c $SYSCONF_DIR";
31  $out = "";
32  $pos = 0;
33  $upload_path = "upload_path";
34  $command = "cp2foss $auth ../../../pkgagent/agent_tests/testdata/fossology-1.2.0-1.el5.i386.rpm -f $upload_path -d upload_des -q all -v";
35  $last = exec("$command 2>&1", $out, $rtn);
36  sleep(10);
37  $repo_string = "Uploading to folder: '/$upload_path'";
38  $repo_pos = strpos($out[7], $repo_string);
39  $output_msg_count = count($out);
40  $this->assertGreaterThan(0, $repo_pos);
41  $scheduled_agent_info_1 = "agent_pkgagent is queued to run on";
42  $scheduled_agent_info_2 = "agent_nomos is queued to run on";
43  $scheduled_agent_info_3 = "agent_mimetype is queued to run on";
44  $scheduled_agent_info_4 = "agent_copyright is queued to run on";
45  $pos = false;
46  $pos = strpos($out[$output_msg_count - 1], $scheduled_agent_info_1);
47  $this->assertEquals(0, $pos);
48  $pos = false;
49  $pos = strpos($out[$output_msg_count - 2], $scheduled_agent_info_2);
50  $this->assertEquals(0, $pos);
51  $pos = false;
52  $pos = strpos($out[$output_msg_count - 3], $scheduled_agent_info_3);
53  $this->assertEquals(0, $pos);
54  $pos = false;
55  $pos = strpos($out[$output_msg_count - 4], $scheduled_agent_info_4);
56  $this->assertEquals(0, $pos);
57  $upload_id = 0;
59  if ($out && $out[11]) {
60  $upload_id = get_upload_id($out[11]);
61  } else {
62  $this->assertFalse(true);
63  }
64  $agent_status = 0;
65  $agent_status = check_agent_status("ununpack", $upload_id);
66  $this->assertEquals(1, $agent_status);
67  $agent_status = 0;
68  $agent_status = check_agent_status("copyright", $upload_id);
69  $this->assertEquals(1, $agent_status);
70  $agent_status = 0;
71  $agent_status = check_agent_status("nomos", $upload_id);
72  $this->assertEquals(1, $agent_status);
73  $agent_status = 0;
74  $agent_status = check_agent_status("mimetype", $upload_id);
75  $this->assertEquals(1, $agent_status);
76  $agent_status = 0;
77  $agent_status = check_agent_status("pkgagent", $upload_id);
78  $this->assertEquals(1, $agent_status);
79  }
80 
81  /* initialization */
82  protected function setUp() : void {
83  global $SYSCONF_DIR;
84  global $DB_COMMAND;
85  global $DB_NAME;
86  global $REPO_NAME;
87 
88  $cwd = getcwd();
89  list($test_name, $SYSCONF_DIR, $DB_NAME, $PG_CONN) = setupTestEnv($cwd, "delagent", false);
90 
91  $REPO_NAME = "testDbRepo".$test_name;
92  add_user();
93  replace_repo();
94  scheduler_operation();
95  $this->upload_testdata();
96  }
97 
105  function test_delagentu(){
106  global $EXE_PATH;
107  global $PG_CONN;
108 
109  $expected = "";
110 
111  $sql = "SELECT upload_pk, upload_filename FROM upload ORDER BY upload_pk;";
112  $result = pg_query($PG_CONN, $sql);
113  if (pg_num_rows($result) > 0){
114  $row = pg_fetch_assoc($result);
115  $expected = $row["upload_pk"] . " :: ". $row["upload_filename"];
116  }
117  pg_free_result($result);
118  /* the file is one executable file */
119  $command = "$EXE_PATH -u -n fossy -p fossy";
120  exec($command, $out, $rtn);
121  //print_r($out);
122  $this->assertStringStartsWith($expected, $out[1]);
123  }
124 
133  global $EXE_PATH;
134  global $PG_CONN;
135 
136  $expected = "";
137 
138  add_user("testuser", "testuser");
139  $sql = "SELECT upload_pk, upload_filename FROM upload ORDER BY upload_pk;";
140  $result = pg_query($PG_CONN, $sql);
141  if (pg_num_rows($result) > 0){
142  $row = pg_fetch_assoc($result);
143  $expected = $row["upload_pk"] . " :: ". $row["upload_filename"];
144  }
145  pg_free_result($result);
146  /* the file is one executable file */
147  $command = "$EXE_PATH -u -n testuser -p testuser";
148  exec($command, $out, $rtn);
149  //print_r($out);
150  $this->assertStringStartsWith($expected, $out[1]);
151  }
152 
156  protected function tearDown() : void {
157  rollback_repo(); // rollback the repo dir in ununpack.conf and wget_agent.conf to the default
158  drop_db();
159  print "End up functional test for cp2foss \n";
160  }
161 
162 }
163 
164 
test delagent cli
test_delagentu()
test delagent -u
tearDown()
clean the env
upload_testdata()
upload testdata prepare testdata for delagent, upload one tar file and schedule all agents
test_delagentu_wronguser()
test delagent -u with wrong user
add_user($User, $Desc, $Hash, $Perm, $Email, $Email_notify, $Upload_visibility, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.
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:308