File tests/git2.php changed (mode: 100644) (index 48abade..6d4a7e3) |
... |
... |
$remote = 'ssh://rocketgit@' . $rg_ssh_host . ':' .$rg_ssh_port |
65 |
65 |
. '/user/' . escapeshellarg($rg_ui['username']) |
. '/user/' . escapeshellarg($rg_ui['username']) |
66 |
66 |
. '/' . escapeshellarg($repo['name']); |
. '/' . escapeshellarg($repo['name']); |
67 |
67 |
$r = rg_exec("cd git2 && git remote add origin $remote" |
$r = rg_exec("cd git2 && git remote add origin $remote" |
68 |
|
. " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2\"" |
|
|
68 |
|
. " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2 -o IdentitiesOnly=yes\"" |
69 |
69 |
. " && git push origin master", '', FALSE, FALSE); |
. " && git push origin master", '', FALSE, FALSE); |
70 |
70 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
71 |
71 |
rg_log_ml('out: ' . $r['errmsg']); |
rg_log_ml('out: ' . $r['errmsg']); |
|
... |
... |
rg_log_exit(); |
78 |
78 |
rg_log(''); |
rg_log(''); |
79 |
79 |
rg_log_enter('Trying to push tags...'); |
rg_log_enter('Trying to push tags...'); |
80 |
80 |
$r = rg_exec("cd git2" |
$r = rg_exec("cd git2" |
81 |
|
. " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2\"" |
|
|
81 |
|
. " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2 -o IdentitiesOnly=yes\"" |
82 |
82 |
. " && git push --tags origin", '', FALSE, FALSE); |
. " && git push --tags origin", '', FALSE, FALSE); |
83 |
83 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
84 |
84 |
rg_log_ml('error: ' . $r['errmsg']); |
rg_log_ml('error: ' . $r['errmsg']); |
File tests/helpers.inc.php changed (mode: 100644) (index 55c29c6..25e9608) |
... |
... |
function rg_test_create_user($db, &$rg_ui) |
12 |
12 |
global $_user_id; |
global $_user_id; |
13 |
13 |
|
|
14 |
14 |
if (!isset($_user_id)) |
if (!isset($_user_id)) |
15 |
|
$_user_id = time(); |
|
|
15 |
|
$_user_id = time() . '-' . rand(); |
16 |
16 |
|
|
17 |
17 |
if (!is_array($rg_ui)) |
if (!is_array($rg_ui)) |
18 |
18 |
$rg_ui = array(); |
$rg_ui = array(); |
|
... |
... |
function rg_test_upload_ssh_key($db, $rg_ui, $key_name, $good_sid) |
274 |
274 |
unlink('keys/' . $key_name); |
unlink('keys/' . $key_name); |
275 |
275 |
if (file_exists('keys/' . $key_name . '.pub')) |
if (file_exists('keys/' . $key_name . '.pub')) |
276 |
276 |
unlink('keys/' . $key_name . '.pub'); |
unlink('keys/' . $key_name . '.pub'); |
277 |
|
$out = shell_exec("ssh-keygen -t rsa -N '' -C \"Key for RocketGit\"" |
|
|
277 |
|
$out = shell_exec("ssh-keygen -t rsa -N '' -b 4096 -C \"Key for RocketGit\"" |
278 |
278 |
. " -f keys/" . escapeshellarg($key_name) . " </dev/null"); |
. " -f keys/" . escapeshellarg($key_name) . " </dev/null"); |
279 |
279 |
if (!file_exists("keys/" . $key_name . ".pub")) { |
if (!file_exists("keys/" . $key_name . ".pub")) { |
280 |
280 |
rg_log("Could not generate ssh key: " . $out); |
rg_log("Could not generate ssh key: " . $out); |
|
... |
... |
function rg_test_upload_ssh_key($db, $rg_ui, $key_name, $good_sid) |
286 |
286 |
rg_log("Loading ssh key form..."); |
rg_log("Loading ssh key form..."); |
287 |
287 |
$data = array(); |
$data = array(); |
288 |
288 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
289 |
|
$r = do_req($test_url . "/op/settings/keys?t=ssh2", $data, $headers); |
|
|
289 |
|
$r = do_req($test_url . "/op/settings/keys?t=load_key_form", $data, $headers); |
290 |
290 |
if ($r === FALSE) { |
if ($r === FALSE) { |
291 |
291 |
rg_log("Cannot load form!"); |
rg_log("Cannot load form!"); |
292 |
292 |
exit(1); |
exit(1); |
|
... |
... |
function rg_test_wh_add_edit($db, $rg_ui, $good_sid, $htype, $extra) |
374 |
374 |
{ |
{ |
375 |
375 |
global $test_url; |
global $test_url; |
376 |
376 |
|
|
377 |
|
rg_log("Loading webhook add form..."); |
|
|
377 |
|
rg_log_enter('Loading webhook add form...'); |
378 |
378 |
$headers = array("Cookie: sid=" . $good_sid); |
$headers = array("Cookie: sid=" . $good_sid); |
379 |
379 |
|
|
380 |
380 |
if (!isset($extra['wh::id'])) |
if (!isset($extra['wh::id'])) |
|
... |
... |
function rg_test_wh_add_edit($db, $rg_ui, $good_sid, $htype, $extra) |
411 |
411 |
rg_log('Cannot add webhook (no \'with success\' message)!'); |
rg_log('Cannot add webhook (no \'with success\' message)!'); |
412 |
412 |
exit(1); |
exit(1); |
413 |
413 |
} |
} |
|
414 |
|
|
|
415 |
|
rg_log_exit(); |
414 |
416 |
} |
} |
415 |
417 |
|
|
416 |
418 |
/* |
/* |
File tests/http_settings.php changed (mode: 100644) (index fb57f72..e4aae6e) |
... |
... |
if ($row['session_time'] != $session_time) { |
172 |
172 |
|
|
173 |
173 |
rg_log(''); |
rg_log(''); |
174 |
174 |
rg_log("Testing SSH keys"); |
rg_log("Testing SSH keys"); |
175 |
|
rg_log("Loading ssh keys form"); |
|
176 |
|
$data = array(); |
|
177 |
|
$headers = array("Cookie: sid=" . $good_sid); |
|
178 |
|
$r = do_req($test_url . "/op/settings/keys?t=load_key_form_add", $data, $headers); |
|
179 |
|
if ($r === FALSE) { |
|
180 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
181 |
|
rg_log("Cannot load form!"); |
|
182 |
|
exit(1); |
|
183 |
|
} |
|
184 |
|
if (empty($r['tokens']['keys'])) { |
|
185 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
186 |
|
rg_log("token not found!"); |
|
187 |
|
exit(1); |
|
188 |
|
} |
|
189 |
|
rg_log("Posting keys form"); |
|
190 |
|
$comment = "<xss>" . $rg_ui['uid']; |
|
191 |
|
$key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+2OHaQiZzdwV4HQF9pCBbSQFaoM5Q0YmmRYDL8BUCjwClDgOLp9lQVN5XksoBx2t9INj6XrobjNc/GUF60c1Ald0FtjRl7nIZdYvKDutlxHcGUy6MHsVnCDviXQJD9Hm9fyuBLdy3/oadSCAaQYE/Tcf9rWt1NmhQ7560bCGmh4pw8N+XXAz2nQBCqvIK8VDoBbOOgFa/HOwBrKCgaGmcTGs5wRWHbw3+h6CO1vqEYcSCSqBPMG1JOMfMTuJ0aTXXEkSNPF+TVva85L4qrQslyHbn2JU1t7/HQsFnGtgF1o2AglIR2RbyMmr6axI51Srf20EB9/c9T3auYQipbw85"; |
|
192 |
|
$data = array("add" => 1, "token" => $r['tokens']['keys'], "key" => $key . ' ' . $comment); |
|
193 |
|
$headers = array("Cookie: sid=" . $good_sid); |
|
194 |
|
$r = do_req($test_url . "/op/settings/keys?t=post_key_form_add", $data, $headers); |
|
195 |
|
if ($r === FALSE) { |
|
196 |
|
rg_log("Cannot upload key!"); |
|
197 |
|
exit(1); |
|
198 |
|
} |
|
|
175 |
|
$key = rg_test_upload_ssh_key($db, $rg_ui, "http_settings", $good_sid); |
|
176 |
|
$key = trim($key); |
199 |
177 |
// the key upload stuff will change < and > to empty. |
// the key upload stuff will change < and > to empty. |
200 |
|
$sql = "SELECT * FROM keys WHERE key = '" . $key . " " . $comment . "'"; |
|
|
178 |
|
$sql = "SELECT * FROM keys WHERE key = '" . $key . "'"; |
201 |
179 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
202 |
180 |
$rows = rg_sql_num_rows($res); |
$rows = rg_sql_num_rows($res); |
203 |
181 |
if ($rows > 0) |
if ($rows > 0) |
File tests/wh_cloud.php changed (mode: 100644) (index 1fa813a..a84f27b) |
... |
... |
rg_log_exit(); |
46 |
46 |
|
|
47 |
47 |
|
|
48 |
48 |
rg_log(''); |
rg_log(''); |
49 |
|
rg_log_enter('Registering webhook1...'); |
|
|
49 |
|
rg_log_enter('Registering webhook...'); |
50 |
50 |
$extra = array( |
$extra = array( |
51 |
51 |
'wh::htype' => 'cloud', |
'wh::htype' => 'cloud', |
52 |
|
'wh::description' => 'description1 <xss>', |
|
|
52 |
|
'wh::description' => 'description1 <xss> codedeploy', |
53 |
53 |
'wh::repo' => '', |
'wh::repo' => '', |
54 |
54 |
'wh::refname' => '', |
'wh::refname' => '', |
|
55 |
|
'wh::idata::events[P]' => 'on', |
55 |
56 |
'wh::idata::access_key_id' => $a['access_key_id'], |
'wh::idata::access_key_id' => $a['access_key_id'], |
56 |
57 |
'wh::idata::secret_access_key' => $a['secret_access_key'], |
'wh::idata::secret_access_key' => $a['secret_access_key'], |
57 |
58 |
'wh::idata::region' => 'eu-central-1', |
'wh::idata::region' => 'eu-central-1', |
|
... |
... |
$extra = array( |
61 |
62 |
'wh::idata::bucket' => 'test-deploy-500-##repo##-##branch##', |
'wh::idata::bucket' => 'test-deploy-500-##repo##-##branch##', |
62 |
63 |
'wh::idata::file' => |
'wh::idata::file' => |
63 |
64 |
'##repo##-##branch##-##hook_id##' |
'##repo##-##branch##-##hook_id##' |
64 |
|
. '-##commit##-##date##-##time##-##ip##-##timestamp##.zip', |
|
|
65 |
|
. '-##commit##-##date##-##time##-##ip##-##timestamp##.zip' |
65 |
66 |
); |
); |
66 |
67 |
rg_test_wh_add_edit($db, $rg_ui, $good_sid, 'cloud', $extra); |
rg_test_wh_add_edit($db, $rg_ui, $good_sid, 'cloud', $extra); |
67 |
68 |
rg_log_exit(); |
rg_log_exit(); |
|
... |
... |
rg_log_exit(); |
92 |
93 |
|
|
93 |
94 |
rg_log(''); |
rg_log(''); |
94 |
95 |
rg_log_enter('Creating and upload a ssh key...'); |
rg_log_enter('Creating and upload a ssh key...'); |
95 |
|
rg_test_upload_ssh_key($db, $rg_ui, "wg_cloud", $good_sid); |
|
|
96 |
|
rg_test_upload_ssh_key($db, $rg_ui, "wh_cloud", $good_sid); |
96 |
97 |
rg_log_exit(); |
rg_log_exit(); |
97 |
98 |
|
|
98 |
99 |
|
|
File tests/wh_lambda.php copied from file tests/wh_cloud.php (similarity 50%) (mode: 100644) (index 1fa813a..6e515e6) |
... |
... |
require_once($INC . "/user.inc.php"); |
9 |
9 |
require_once("helpers.inc.php"); |
require_once("helpers.inc.php"); |
10 |
10 |
require_once("http.inc.php"); |
require_once("http.inc.php"); |
11 |
11 |
|
|
12 |
|
rg_log_set_file("wh_cloud.log"); |
|
|
12 |
|
rg_log_set_file("wh_lambda.log"); |
13 |
13 |
|
|
14 |
14 |
$rg_sql = "host=localhost user=rocketgit dbname=rocketgit connect_timeout=10"; |
$rg_sql = "host=localhost user=rocketgit dbname=rocketgit connect_timeout=10"; |
15 |
15 |
$rg_no_db = TRUE; |
$rg_no_db = TRUE; |
16 |
16 |
require_once("common.php"); |
require_once("common.php"); |
17 |
17 |
|
|
18 |
|
$_testns = 'wh_cloud'; |
|
|
18 |
|
$_testns = 'wh_lambda'; |
19 |
19 |
$rg_cache_enable = TRUE; |
$rg_cache_enable = TRUE; |
20 |
20 |
$rg_cache_debug = TRUE; |
$rg_cache_debug = TRUE; |
21 |
21 |
$rg_event_socket = "/var/lib/rocketgit/sockets/event.sock"; |
$rg_event_socket = "/var/lib/rocketgit/sockets/event.sock"; |
|
... |
... |
rg_log_exit(); |
46 |
46 |
|
|
47 |
47 |
|
|
48 |
48 |
rg_log(''); |
rg_log(''); |
49 |
|
rg_log_enter('Registering webhook1...'); |
|
|
49 |
|
rg_log_enter('Registering webhook...'); |
50 |
50 |
$extra = array( |
$extra = array( |
51 |
|
'wh::htype' => 'cloud', |
|
52 |
|
'wh::description' => 'description1 <xss>', |
|
|
51 |
|
'wh::htype' => 'lambda', |
|
52 |
|
'wh::description' => 'description2 <xss> lambda', |
53 |
53 |
'wh::repo' => '', |
'wh::repo' => '', |
54 |
54 |
'wh::refname' => '', |
'wh::refname' => '', |
|
55 |
|
'wh::idata::events[P]' => 'on', |
55 |
56 |
'wh::idata::access_key_id' => $a['access_key_id'], |
'wh::idata::access_key_id' => $a['access_key_id'], |
56 |
57 |
'wh::idata::secret_access_key' => $a['secret_access_key'], |
'wh::idata::secret_access_key' => $a['secret_access_key'], |
57 |
58 |
'wh::idata::region' => 'eu-central-1', |
'wh::idata::region' => 'eu-central-1', |
58 |
|
'wh::idata::application_name' => 'DemoApplication-##repo##', |
|
59 |
|
'wh::idata::deployment_group_name' => 'DemoFleet-##repo##-##branch##', |
|
60 |
|
'wh::idata::deployment_config_name' => '', |
|
61 |
|
'wh::idata::bucket' => 'test-deploy-500-##repo##-##branch##', |
|
62 |
|
'wh::idata::file' => |
|
63 |
|
'##repo##-##branch##-##hook_id##' |
|
64 |
|
. '-##commit##-##date##-##time##-##ip##-##timestamp##.zip', |
|
|
59 |
|
'wh::idata::function' => 'test-function', |
|
60 |
|
'wh::idata::payload' => '{"key": "aaa branch=##branch## repo=##repo##"}' |
65 |
61 |
); |
); |
66 |
|
rg_test_wh_add_edit($db, $rg_ui, $good_sid, 'cloud', $extra); |
|
|
62 |
|
rg_test_wh_add_edit($db, $rg_ui, $good_sid, 'lambda', $extra); |
67 |
63 |
rg_log_exit(); |
rg_log_exit(); |
68 |
64 |
|
|
69 |
65 |
|
|
|
... |
... |
rg_log_exit(); |
92 |
88 |
|
|
93 |
89 |
rg_log(''); |
rg_log(''); |
94 |
90 |
rg_log_enter('Creating and upload a ssh key...'); |
rg_log_enter('Creating and upload a ssh key...'); |
95 |
|
rg_test_upload_ssh_key($db, $rg_ui, "wg_cloud", $good_sid); |
|
|
91 |
|
rg_test_upload_ssh_key($db, $rg_ui, "wh_cloud", $good_sid); |
96 |
92 |
rg_log_exit(); |
rg_log_exit(); |
97 |
93 |
|
|
98 |
94 |
|
|
|
... |
... |
if ($r === FALSE) { |
125 |
121 |
rg_log('Seems the event did not set the cache!'); |
rg_log('Seems the event did not set the cache!'); |
126 |
122 |
exit(1); |
exit(1); |
127 |
123 |
} |
} |
128 |
|
if (!strstr($r, '"deploymentId":"d-') && !strstr($r, 'is already deploying')) { |
|
|
124 |
|
if (strcmp($r, '"Hello from Lambda; key: aaa branch=master repo=wh-cloud"') != 0) { |
129 |
125 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
130 |
126 |
rg_log('Seems hook did not executed correctly!'); |
rg_log('Seems hook did not executed correctly!'); |
131 |
127 |
exit(1); |
exit(1); |
|
... |
... |
if (!strstr($r, '"deploymentId":"d-') && !strstr($r, 'is already deploying')) { |
133 |
129 |
rg_log_exit(); |
rg_log_exit(); |
134 |
130 |
|
|
135 |
131 |
|
|
136 |
|
rg_log(''); |
|
137 |
|
rg_log_enter('Testing the edit of webhook...'); |
|
138 |
|
$extra = array( |
|
139 |
|
'wh::id' => $wh_id, |
|
140 |
|
'wh::htype' => 'cloud', |
|
141 |
|
'wh::repo' => '.*', |
|
142 |
|
'wh::refname' => '..*', |
|
143 |
|
'wh::description' => 'desc2 <xss>', |
|
144 |
|
'wh::flags' => 'D', |
|
145 |
|
'wh::idata::access_key_id' => 'aaa', |
|
146 |
|
'wh::idata::secret_access_key' => 'bbb', |
|
147 |
|
'wh::idata::region' => 'ccc', |
|
148 |
|
'wh::idata::application_name' => 'xxx', |
|
149 |
|
'wh::idata::deployment_group_name' => 'yyy', |
|
150 |
|
'wh::idata::deployment_config_name' => 'zzz', |
|
151 |
|
'wh::idata::bucket' => 'buck', |
|
152 |
|
'wh::idata::file' => 'rrr', |
|
153 |
|
); |
|
154 |
|
rg_test_wh_add_edit($db, $rg_ui, $good_sid, 'cloud', $extra); |
|
155 |
|
$sql = "SELECT * FROM webhooks WHERE uid = " . $rg_ui['uid'] |
|
156 |
|
. " AND id = " . $wh_id; |
|
157 |
|
$res = rg_sql_query($db, $sql); |
|
158 |
|
$row = rg_sql_fetch_array($res); |
|
159 |
|
rg_sql_free_result($res); |
|
160 |
|
$row['idata'] = unserialize($row['idata']); |
|
161 |
|
$key = 'wh' . '::' . $rg_ui['uid'] . '::' . 'list' . '::' . $wh_id; |
|
162 |
|
rg_cache_core_unset($key); // else we will get previous copy! |
|
163 |
|
$c = rg_cache_get($key); |
|
164 |
|
$list = array('htype' => 'cloud', 'repo' => '.*', 'refname' => '..*', |
|
165 |
|
'description' => 'desc2 <xss>', 'flags' => 'D', |
|
166 |
|
'access_key_id' => 'aaa', |
|
167 |
|
'secret_access_key' => 'bbb', 'region' => 'ccc', |
|
168 |
|
'application_name' => 'xxx', 'deployment_group_name' => 'yyy', |
|
169 |
|
'deployment_config_name' => 'zzz', 'bucket' => 'buck', |
|
170 |
|
'file' => 'rrr'); |
|
171 |
|
foreach ($list as $k => $v) { |
|
172 |
|
if (isset($row[$k])) |
|
173 |
|
$a = $row[$k]; |
|
174 |
|
else if (isset($row['idata'][$k])) |
|
175 |
|
$a = $row['idata'][$k]; |
|
176 |
|
else { |
|
177 |
|
rg_log('Key [' . $k . '] not found! Bad!'); |
|
178 |
|
exit(1); |
|
179 |
|
} |
|
180 |
|
if (strcmp($a, $v) != 0) { |
|
181 |
|
rg_log_ml('row: ' . print_r($row, TRUE)); |
|
182 |
|
rg_log("db: Seems that [$k] has not been updated" |
|
183 |
|
. " [" . $a . "] != " . $v); |
|
184 |
|
exit(1); |
|
185 |
|
} |
|
186 |
|
|
|
187 |
|
if (isset($c[$k])) |
|
188 |
|
$a = $c[$k]; |
|
189 |
|
else |
|
190 |
|
$a = $c['idata'][$k]; |
|
191 |
|
if (strcmp($a, $v) != 0) { |
|
192 |
|
rg_log_ml('c: ' . print_r($c, TRUE)); |
|
193 |
|
rg_log("cache: Seems that [$k] has not been updated" |
|
194 |
|
. " [" . $a . "] != " . $v); |
|
195 |
|
exit(1); |
|
196 |
|
} |
|
197 |
|
} |
|
198 |
|
rg_log_exit(); |
|
199 |
|
|
|
200 |
|
|
|
201 |
132 |
rg_log("OK!"); |
rg_log("OK!"); |
202 |
133 |
?> |
?> |