File tests/git2.php changed (mode: 100644) (index 2dd0490..e03f299) |
... |
... |
require_once("common.php"); |
18 |
18 |
$_testns = 'git2'; |
$_testns = 'git2'; |
19 |
19 |
|
|
20 |
20 |
|
|
21 |
|
prepare_http(); |
|
22 |
|
|
|
23 |
21 |
system("./git2_helper.sh &>git2_helper.sh.log"); |
system("./git2_helper.sh &>git2_helper.sh.log"); |
24 |
22 |
$_err = file_get_contents('git2_helper.sh.log'); |
$_err = file_get_contents('git2_helper.sh.log'); |
25 |
23 |
@unlink('git2_helper.sh.log'); |
@unlink('git2_helper.sh.log'); |
|
... |
... |
if (strcmp($refs['branch'][0], "group1/branch1") != 0) { |
45 |
43 |
|
|
46 |
44 |
|
|
47 |
45 |
rg_test_create_user($db, $rg_ui); |
rg_test_create_user($db, $rg_ui); |
|
46 |
|
$info = array('id' => $rg_ui['username']); |
|
47 |
|
prepare_http($info); |
|
48 |
|
|
48 |
49 |
rg_test_create_repo($db, $rg_ui, $repo); |
rg_test_create_repo($db, $rg_ui, $repo); |
49 |
50 |
$r = test_login($test_url, $rg_ui); |
$r = test_login($test_url, $rg_ui); |
50 |
51 |
if ($r === FALSE) { |
if ($r === FALSE) { |
|
... |
... |
if ($r === FALSE) { |
54 |
55 |
|
|
55 |
56 |
|
|
56 |
57 |
rg_test_upload_ssh_key($db, $rg_ui, 'git2', $kn); |
rg_test_upload_ssh_key($db, $rg_ui, 'git2', $kn); |
57 |
|
putenv('GIT_SSH_COMMAND=ssh -o ControlMaster=no -o IdentityFile=' . __DIR__ . '/keys/' . $kn |
|
58 |
|
. ' -o IdentitiesOnly=yes'); |
|
|
58 |
|
|
59 |
59 |
|
|
60 |
60 |
rg_log(''); |
rg_log(''); |
61 |
61 |
rg_log_enter('Trying to push master...'); |
rg_log_enter('Trying to push master...'); |
|
... |
... |
rg_log(''); |
120 |
120 |
rg_log_enter('Checking on web that everything is OK...'); |
rg_log_enter('Checking on web that everything is OK...'); |
121 |
121 |
$data = array(); |
$data = array(); |
122 |
122 |
$headers = array(); |
$headers = array(); |
123 |
|
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username']) |
|
|
123 |
|
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username']) |
124 |
124 |
. '/' . rawurlencode($repo['name']) . '/source/log/commit/' |
. '/' . rawurlencode($repo['name']) . '/source/log/commit/' |
125 |
125 |
. $commit, $data, $headers); |
. $commit, $data, $headers); |
126 |
126 |
if ($r === FALSE) { |
if ($r === FALSE) { |
|
... |
... |
rg_log(''); |
134 |
134 |
rg_log_enter('Checking on web that tag is OK...'); |
rg_log_enter('Checking on web that tag is OK...'); |
135 |
135 |
$data = array(); |
$data = array(); |
136 |
136 |
$headers = array(); |
$headers = array(); |
137 |
|
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username']) |
|
|
137 |
|
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username']) |
138 |
138 |
. '/' . rawurlencode($repo['name']) |
. '/' . rawurlencode($repo['name']) |
139 |
139 |
. '/source/tree/tag/unannot1/blob/a', $data, $headers); |
. '/source/tree/tag/unannot1/blob/a', $data, $headers); |
140 |
140 |
if (strstr($r['body'], 'a signature') === FALSE) { |
if (strstr($r['body'], 'a signature') === FALSE) { |
|
... |
... |
if ($r['ok'] != 1) { |
167 |
167 |
} |
} |
168 |
168 |
// Now, the branch should not be visible anymore |
// Now, the branch should not be visible anymore |
169 |
169 |
$headers = array(); |
$headers = array(); |
170 |
|
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username']) |
|
|
170 |
|
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username']) |
171 |
171 |
. '/' . rawurlencode($repo['name']) . '/source', $data, $headers); |
. '/' . rawurlencode($repo['name']) . '/source', $data, $headers); |
172 |
172 |
if (strstr($r['body'], 'branch22') !== FALSE) { |
if (strstr($r['body'], 'branch22') !== FALSE) { |
173 |
173 |
rg_log_ml('Seems the branch is still on the web!'); |
rg_log_ml('Seems the branch is still on the web!'); |
|
... |
... |
if (strstr($r['body'], 'branch22') !== FALSE) { |
176 |
176 |
rg_log_exit(); |
rg_log_exit(); |
177 |
177 |
|
|
178 |
178 |
|
|
179 |
|
rg_log("OK!"); |
|
|
179 |
|
rg_log('OK!'); |
File tests/helpers.inc.php changed (mode: 100644) (index 2f8b180..a8bf5e7) |
... |
... |
function rg_test_create_user($db, &$rg_ui) |
30 |
30 |
$new['is_admin'] = 0; |
$new['is_admin'] = 0; |
31 |
31 |
$new['rights'] = 'C'; |
$new['rights'] = 'C'; |
32 |
32 |
$new['session_time'] = 3600; |
$new['session_time'] = 3600; |
33 |
|
$new['confirm_token'] = ''; |
|
|
33 |
|
$new['confirm_token'] = rg_id(20); |
34 |
34 |
$new['confirmed'] = 0; |
$new['confirmed'] = 0; |
35 |
35 |
$new['plan_id'] = 0; |
$new['plan_id'] = 0; |
36 |
36 |
$new['pass'] = 'pass-' . $_user_id . ':'; |
$new['pass'] = 'pass-' . $_user_id . ':'; |
|
... |
... |
function rg_test_create_user($db, &$rg_ui) |
60 |
60 |
} |
} |
61 |
61 |
$rg_ui['uid'] = $r; |
$rg_ui['uid'] = $r; |
62 |
62 |
|
|
|
63 |
|
$adm = ($rg_ui['is_admin'] == 1) ? 'admin' : 'not admin'; |
|
64 |
|
rg_log('Created user [' . $rg_ui['username'] . ' with uid ' . $rg_ui['uid'] |
|
65 |
|
. '; ' . $adm); |
|
66 |
|
|
63 |
67 |
// delete associated bugs |
// delete associated bugs |
64 |
68 |
$sql = "SELECT * FROM repos WHERE uid = " . $rg_ui['uid']; |
$sql = "SELECT * FROM repos WHERE uid = " . $rg_ui['uid']; |
65 |
69 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
|
... |
... |
function rg_test_create_repo($db, $rg_ui, &$extra) |
176 |
180 |
|
|
177 |
181 |
$key = 'repo_by_id' . '::' . $extra['repo_id']; |
$key = 'repo_by_id' . '::' . $extra['repo_id']; |
178 |
182 |
rg_log('Waiting for the repo git dir to be created (key [' . $key . '])...'); |
rg_log('Waiting for the repo git dir to be created (key [' . $key . '])...'); |
179 |
|
$tries = 50; |
|
|
183 |
|
$tries = 120; |
180 |
184 |
while ($tries > 0) { |
while ($tries > 0) { |
181 |
185 |
$tries--; |
$tries--; |
182 |
186 |
|
|
|
... |
... |
function rg_test_create_repo($db, $rg_ui, &$extra) |
189 |
193 |
|
|
190 |
194 |
//rg_log_ml('DEBUG: r: ' . print_r($r, TRUE)); |
//rg_log_ml('DEBUG: r: ' . print_r($r, TRUE)); |
191 |
195 |
|
|
192 |
|
if ($r['git_dir_done'] == 1) |
|
|
196 |
|
if ($r['git_dir_done'] == 1) { |
|
197 |
|
rg_log('repo created'); |
193 |
198 |
break; |
break; |
|
199 |
|
} |
194 |
200 |
|
|
195 |
201 |
sleep(1); |
sleep(1); |
196 |
202 |
} |
} |
|
... |
... |
function rg_test_upload_ssh_key($db, $rg_ui, $key_suffix, &$key_name) |
282 |
288 |
{ |
{ |
283 |
289 |
global $test_url; |
global $test_url; |
284 |
290 |
|
|
|
291 |
|
$info = array('id' => $rg_ui['username']); |
|
292 |
|
|
285 |
293 |
$key_name = $rg_ui['uid'] . $key_suffix; |
$key_name = $rg_ui['uid'] . $key_suffix; |
286 |
294 |
putenv('RG_SSH_KEY=' . $key_name); |
putenv('RG_SSH_KEY=' . $key_name); |
287 |
295 |
|
|
|
296 |
|
$ssh = 'ssh -o ControlMaster=no' |
|
297 |
|
. ' -o IdentityFile=' . __DIR__ . '/keys/' . $key_name |
|
298 |
|
. ' -o IdentitiesOnly=yes'; |
|
299 |
|
putenv('GIT_SSH_COMMAND=' . $ssh); |
|
300 |
|
|
288 |
301 |
// we must regenerate the key because else we will not be the correct user |
// we must regenerate the key because else we will not be the correct user |
289 |
302 |
rg_log_enter("Generating a SSH key [$key_name]"); |
rg_log_enter("Generating a SSH key [$key_name]"); |
290 |
303 |
if (file_exists('keys/' . $key_name)) |
if (file_exists('keys/' . $key_name)) |
|
... |
... |
function rg_test_upload_ssh_key($db, $rg_ui, $key_suffix, &$key_name) |
308 |
321 |
rg_log("Loading ssh key form..."); |
rg_log("Loading ssh key form..."); |
309 |
322 |
$data = array(); |
$data = array(); |
310 |
323 |
$headers = array(); |
$headers = array(); |
311 |
|
$r = do_req($test_url . "/op/settings/keys?t=load_key_form", $data, $headers); |
|
|
324 |
|
$r = do_req($info, $test_url . "/op/settings/keys?t=load_key_form", $data, $headers); |
312 |
325 |
if ($r === FALSE) { |
if ($r === FALSE) { |
313 |
326 |
rg_log("Cannot load form!"); |
rg_log("Cannot load form!"); |
314 |
327 |
exit(1); |
exit(1); |
|
... |
... |
function rg_test_upload_ssh_key($db, $rg_ui, $key_suffix, &$key_name) |
322 |
335 |
rg_log("Uploading the key..."); |
rg_log("Uploading the key..."); |
323 |
336 |
$data = array('add' => 1, 'token' => $r['tokens']['keys'], 'key' => $key); |
$data = array('add' => 1, 'token' => $r['tokens']['keys'], 'key' => $key); |
324 |
337 |
$headers = array(); |
$headers = array(); |
325 |
|
$r = do_req($test_url . '/op/settings/keys?t=upload_ssh_key', $data, $headers); |
|
|
338 |
|
$r = do_req($info, $test_url . '/op/settings/keys?t=upload_ssh_key', $data, $headers); |
326 |
339 |
if ($r === FALSE) { |
if ($r === FALSE) { |
327 |
340 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
328 |
341 |
rg_log_ml("Cannot upload key!"); |
rg_log_ml("Cannot upload key!"); |
|
... |
... |
function rg_test_sc_generate($db, $rg_ui) |
354 |
367 |
{ |
{ |
355 |
368 |
global $test_url; |
global $test_url; |
356 |
369 |
|
|
|
370 |
|
$info = array('id' => $rg_ui['username']); |
|
371 |
|
|
357 |
372 |
rg_log("Loading generate scratch codes form..."); |
rg_log("Loading generate scratch codes form..."); |
358 |
373 |
$data = array(); |
$data = array(); |
359 |
374 |
$headers = array(); |
$headers = array(); |
360 |
|
$r = do_req($test_url . "/op/settings/totp/sc", $data, $headers); |
|
|
375 |
|
$r = do_req($info, $test_url . '/op/settings/totp/sc', $data, $headers); |
361 |
376 |
if ($r === FALSE) { |
if ($r === FALSE) { |
362 |
377 |
rg_log("Cannot load form!"); |
rg_log("Cannot load form!"); |
363 |
378 |
exit(1); |
exit(1); |
|
... |
... |
function rg_test_sc_generate($db, $rg_ui) |
371 |
386 |
rg_log("Generating scratch codes..."); |
rg_log("Generating scratch codes..."); |
372 |
387 |
$data = array('generate' => 1, 'token' => $r['tokens']['sc']); |
$data = array('generate' => 1, 'token' => $r['tokens']['sc']); |
373 |
388 |
$headers = array(); |
$headers = array(); |
374 |
|
$r = do_req($test_url . '/op/settings/totp/sc', $data, $headers); |
|
|
389 |
|
$r = do_req($info, $test_url . '/op/settings/totp/sc', $data, $headers); |
375 |
390 |
if ($r === FALSE) { |
if ($r === FALSE) { |
376 |
391 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
377 |
392 |
rg_log_ml('Cannot generate scratch codes!'); |
rg_log_ml('Cannot generate scratch codes!'); |
|
... |
... |
function rg_test_sc_generate($db, $rg_ui) |
393 |
408 |
/* |
/* |
394 |
409 |
* Helper for adding a webhook |
* Helper for adding a webhook |
395 |
410 |
*/ |
*/ |
396 |
|
function rg_test_wh_add_edit($db, $rg_ui, $htype, $hsubtype, $extra) |
|
|
411 |
|
function rg_test_wh_add_edit($db, $rg_ui, $htype, $hsubtype, &$extra) |
397 |
412 |
{ |
{ |
398 |
413 |
global $test_url; |
global $test_url; |
399 |
414 |
|
|
400 |
415 |
rg_log_enter('Loading webhook add form...'); |
rg_log_enter('Loading webhook add form...'); |
401 |
416 |
$headers = array(); |
$headers = array(); |
402 |
417 |
|
|
|
418 |
|
$info = array('id' => $rg_ui['username']); |
|
419 |
|
|
403 |
420 |
if (!isset($extra['wh::id'])) |
if (!isset($extra['wh::id'])) |
404 |
421 |
$extra['wh::id'] = 0; |
$extra['wh::id'] = 0; |
405 |
422 |
|
|
|
423 |
|
$extra['wh::htype'] = $htype; |
|
424 |
|
$extra['wh::hsubtype'] = $hsubtype; |
|
425 |
|
|
406 |
426 |
if ($extra['wh::id'] == 0) |
if ($extra['wh::id'] == 0) |
407 |
427 |
$url = 'add/' . $htype . '/' . $hsubtype; |
$url = 'add/' . $htype . '/' . $hsubtype; |
408 |
428 |
else |
else |
409 |
429 |
$url = 'edit/' . $extra['wh::id']; |
$url = 'edit/' . $extra['wh::id']; |
410 |
|
$r = do_req($test_url . "/op/settings/wh/" . $url, $data, $headers); |
|
|
430 |
|
$r = do_req($info, $test_url . "/op/settings/wh/" . $url, $data, $headers); |
411 |
431 |
if ($r === FALSE) { |
if ($r === FALSE) { |
412 |
432 |
rg_log("Cannot load form!"); |
rg_log("Cannot load form!"); |
413 |
433 |
exit(1); |
exit(1); |
|
... |
... |
function rg_test_wh_add_edit($db, $rg_ui, $htype, $hsubtype, $extra) |
422 |
442 |
$data = array('doit' => 1, 'token' => $r['tokens']['wh_add']); |
$data = array('doit' => 1, 'token' => $r['tokens']['wh_add']); |
423 |
443 |
$data = array_merge($data, $extra); |
$data = array_merge($data, $extra); |
424 |
444 |
$headers = array(); |
$headers = array(); |
425 |
|
$r = do_req($test_url . '/op/settings/wh/' . $url, $data, $headers); |
|
|
445 |
|
$r = do_req($info, $test_url . '/op/settings/wh/' . $url, $data, $headers); |
426 |
446 |
if ($r === FALSE) { |
if ($r === FALSE) { |
427 |
447 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
428 |
448 |
rg_log_ml('Cannot add webhook!'); |
rg_log_ml('Cannot add webhook!'); |
|
... |
... |
function rg_test_wh_add_edit($db, $rg_ui, $htype, $hsubtype, $extra) |
435 |
455 |
exit(1); |
exit(1); |
436 |
456 |
} |
} |
437 |
457 |
|
|
|
458 |
|
foreach ($r['rg_debug_html']['wh'] as $k => $v) |
|
459 |
|
$extra[$k] = $v; |
|
460 |
|
|
438 |
461 |
rg_log_exit(); |
rg_log_exit(); |
439 |
462 |
} |
} |
440 |
463 |
|
|
|
... |
... |
function test_ssh($uid, $extra) |
493 |
516 |
/* |
/* |
494 |
517 |
* Wait for a value in cache |
* Wait for a value in cache |
495 |
518 |
*/ |
*/ |
496 |
|
function test_wait_cache($key) |
|
|
519 |
|
function test_wait_cache($key, $timeout) |
497 |
520 |
{ |
{ |
498 |
|
for ($i = 0; $i < 50; $i++) { |
|
|
521 |
|
$sleep = intval($timeout / 30); |
|
522 |
|
if ($sleep == 0) |
|
523 |
|
$sleep = 1; |
|
524 |
|
|
|
525 |
|
for ($i = 0; $i < $timeout; $i++) { |
499 |
526 |
rg_cache_core_unset($key); |
rg_cache_core_unset($key); |
500 |
527 |
$r = rg_cache_get($key); |
$r = rg_cache_get($key); |
501 |
528 |
if ($r !== FALSE) |
if ($r !== FALSE) |
502 |
529 |
break; |
break; |
503 |
|
sleep(1); |
|
|
530 |
|
sleep($sleep); |
|
531 |
|
} |
|
532 |
|
|
|
533 |
|
if ($r === FALSE) { |
|
534 |
|
rg_log('Could not obtain a value from cache for key' |
|
535 |
|
. ' [' . $key . '] in ' . $timeout . 's!'); |
|
536 |
|
exit(1); |
|
537 |
|
} |
|
538 |
|
|
|
539 |
|
return $r; |
|
540 |
|
} |
|
541 |
|
|
|
542 |
|
/* |
|
543 |
|
* Helper for adding a pkg_repo |
|
544 |
|
*/ |
|
545 |
|
function rg_test_pkg_repo_add_edit($db, $rg_ui, &$extra) |
|
546 |
|
{ |
|
547 |
|
global $test_url; |
|
548 |
|
|
|
549 |
|
rg_log_enter('Loading Settings -> Packages -> Repositories add form...'); |
|
550 |
|
$headers = array(); |
|
551 |
|
|
|
552 |
|
$info = array('id' => $rg_ui['username']); |
|
553 |
|
|
|
554 |
|
if (!isset($extra['pi::id'])) |
|
555 |
|
$extra['pi::id'] = 0; |
|
556 |
|
|
|
557 |
|
if ($extra['pi::id'] == 0) |
|
558 |
|
$url = 'add'; |
|
559 |
|
else |
|
560 |
|
$url = 'edit/' . $extra['pi::id']; |
|
561 |
|
$r = do_req($info, $test_url . '/op/settings/packages/repo/' . $url, $data, $headers); |
|
562 |
|
if ($r === FALSE) { |
|
563 |
|
rg_log("Cannot load form!"); |
|
564 |
|
exit(1); |
|
565 |
|
} |
|
566 |
|
if (empty($r['tokens']['pkg_repo_edit_hl'])) { |
|
567 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
568 |
|
rg_log_ml('Token not found!'); |
|
569 |
|
exit(1); |
|
570 |
|
} |
|
571 |
|
|
|
572 |
|
rg_log('Adding pkg repo...'); |
|
573 |
|
$data = array('doit' => 1, 'token' => $r['tokens']['pkg_repo_edit_hl']); |
|
574 |
|
$data = array_merge($data, $extra); |
|
575 |
|
$headers = array(); |
|
576 |
|
$r = do_req($info, $test_url . '/op/settings/packages/repo/' . $url, $data, $headers); |
|
577 |
|
if ($r === FALSE) { |
|
578 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
579 |
|
rg_log_ml('Cannot add pkg repo!'); |
|
580 |
|
exit(1); |
|
581 |
|
} |
|
582 |
|
|
|
583 |
|
if (!strstr($r['body'], 'The packages repo has been successfully added/edited.')) { |
|
584 |
|
rg_log_ml('r[body]: ' . print_r($r['body'], TRUE)); |
|
585 |
|
rg_log('Cannot add pkg repo (no \'success\' message)!'); |
|
586 |
|
exit(1); |
|
587 |
|
} |
|
588 |
|
|
|
589 |
|
foreach ($r['rg_debug_html']['pkg_repo'] as $k => $v) |
|
590 |
|
$extra[$k] = $v; |
|
591 |
|
|
|
592 |
|
// List pkg repos |
|
593 |
|
$data = array(); |
|
594 |
|
$r = do_req($info, $test_url . '/op/settings/packages/repo/list', $data, $headers); |
|
595 |
|
if ($r === FALSE) { |
|
596 |
|
rg_log('Cannot list pkg repos!'); |
|
597 |
|
exit(1); |
|
598 |
|
} |
|
599 |
|
if (!strstr($r['body'], $extra['pi::name'])) { |
|
600 |
|
rg_log('Body does not contain the name of the pkg repo!'); |
|
601 |
|
exit(1); |
|
602 |
|
} |
|
603 |
|
|
|
604 |
|
rg_log_exit(); |
|
605 |
|
} |
|
606 |
|
|
|
607 |
|
/* |
|
608 |
|
* Helper for adding a pkg_subrepo |
|
609 |
|
* @pr - obtained from the above function |
|
610 |
|
*/ |
|
611 |
|
function rg_test_pkg_subrepo_add_edit($db, $rg_ui, $pr, &$extra) |
|
612 |
|
{ |
|
613 |
|
global $test_url; |
|
614 |
|
|
|
615 |
|
rg_log_enter('Loading Settings -> Packages -> Subrepositories add form...'); |
|
616 |
|
$headers = array(); |
|
617 |
|
|
|
618 |
|
$info = array('id' => $rg_ui['username']); |
|
619 |
|
|
|
620 |
|
if (!isset($extra['sr::id'])) |
|
621 |
|
$extra['sr::id'] = 0; |
|
622 |
|
|
|
623 |
|
$extra['sr::pkg_repo_id'] = $pr['id']; |
|
624 |
|
|
|
625 |
|
if ($extra['sr::id'] == 0) |
|
626 |
|
$url = 'add'; |
|
627 |
|
else |
|
628 |
|
$url = 'edit/' . $extra['sr::id']; |
|
629 |
|
$r = do_req($info, $test_url . '/op/settings/packages/subrepo/' . $url, $data, $headers); |
|
630 |
|
if ($r === FALSE) { |
|
631 |
|
rg_log("Cannot load form!"); |
|
632 |
|
exit(1); |
|
633 |
|
} |
|
634 |
|
if (empty($r['tokens']['pkg_subrepo_edit_hl'])) { |
|
635 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
636 |
|
rg_log_ml('Token not found!'); |
|
637 |
|
exit(1); |
|
638 |
|
} |
|
639 |
|
|
|
640 |
|
rg_log('Adding pkg subrepo...'); |
|
641 |
|
$data = array('doit' => 1, 'token' => $r['tokens']['pkg_subrepo_edit_hl']); |
|
642 |
|
$data = array_merge($data, $extra); |
|
643 |
|
$headers = array(); |
|
644 |
|
$r = do_req($info, $test_url . '/op/settings/packages/subrepo/' . $url, $data, $headers); |
|
645 |
|
if ($r === FALSE) { |
|
646 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
647 |
|
rg_log_ml('Cannot add pkg subrepo!'); |
|
648 |
|
exit(1); |
|
649 |
|
} |
|
650 |
|
|
|
651 |
|
if (!strstr($r['body'], 'The packages subrepo has been successfully added/edited.')) { |
|
652 |
|
rg_log_ml('r[body]: ' . print_r($r['body'], TRUE)); |
|
653 |
|
rg_log('Cannot add pkg subrepo (no \'success\' message)!'); |
|
654 |
|
exit(1); |
|
655 |
|
} |
|
656 |
|
|
|
657 |
|
foreach ($r['rg_debug_html']['pkg_subrepo'] as $k => $v) |
|
658 |
|
$extra[$k] = $v; |
|
659 |
|
|
|
660 |
|
// List pkg subrepos |
|
661 |
|
$data = array(); |
|
662 |
|
$r = do_req($info, $test_url . '/op/settings/packages/subrepo/list', $data, $headers); |
|
663 |
|
if ($r === FALSE) { |
|
664 |
|
rg_log('Cannot list pkg subrepos!'); |
|
665 |
|
exit(1); |
|
666 |
|
} |
|
667 |
|
if (!strstr($r['body'], $pr['pi::name'])) { |
|
668 |
|
rg_log('Body does not contain the name of the pkg repo!'); |
|
669 |
|
exit(1); |
|
670 |
|
} |
|
671 |
|
if (!strstr($r['body'], $extra['sr::name'])) { |
|
672 |
|
rg_log('Body does not contain the name of the pkg subrepo!'); |
|
673 |
|
exit(1); |
|
674 |
|
} |
|
675 |
|
|
|
676 |
|
rg_log_exit(); |
|
677 |
|
} |
|
678 |
|
|
|
679 |
|
/* |
|
680 |
|
* Helper for adding a pkg mapping |
|
681 |
|
*/ |
|
682 |
|
function rg_test_pkg_map_add_edit($db, $rg_ui, &$extra) |
|
683 |
|
{ |
|
684 |
|
global $test_url; |
|
685 |
|
|
|
686 |
|
rg_log_enter('Loading Settings -> Packages -> Mappings add form...'); |
|
687 |
|
$headers = array(); |
|
688 |
|
|
|
689 |
|
$info = array('id' => $rg_ui['username']); |
|
690 |
|
|
|
691 |
|
if (!isset($extra['mi::id'])) |
|
692 |
|
$extra['mi::id'] = 0; |
|
693 |
|
|
|
694 |
|
if (!isset($extra['mi::prio'])) |
|
695 |
|
$extra['mi::prio'] = 10; |
|
696 |
|
|
|
697 |
|
if (!isset($extra['mi::repo'])) |
|
698 |
|
$extra['mi::repo'] = ''; |
|
699 |
|
|
|
700 |
|
if (!isset($extra['mi::ref'])) |
|
701 |
|
$extra['mi::ref'] = ''; |
|
702 |
|
|
|
703 |
|
if ($extra['mi::id'] == 0) |
|
704 |
|
$url = 'add'; |
|
705 |
|
else |
|
706 |
|
$url = 'edit/' . $extra['mi::id']; |
|
707 |
|
$r = do_req($info, $test_url . '/op/settings/packages/map/' . $url, $data, $headers); |
|
708 |
|
if ($r === FALSE) { |
|
709 |
|
rg_log("Cannot load form!"); |
|
710 |
|
exit(1); |
|
711 |
|
} |
|
712 |
|
if (empty($r['tokens']['pkg_maps_edit_hl'])) { |
|
713 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
714 |
|
rg_log_ml('Token not found!'); |
|
715 |
|
exit(1); |
504 |
716 |
} |
} |
505 |
717 |
|
|
|
718 |
|
rg_log('Adding pkg map...'); |
|
719 |
|
$data = array('doit' => 1, 'token' => $r['tokens']['pkg_maps_edit_hl']); |
|
720 |
|
$data = array_merge($data, $extra); |
|
721 |
|
$headers = array(); |
|
722 |
|
$r = do_req($info, $test_url . '/op/settings/packages/map/' . $url, $data, $headers); |
506 |
723 |
if ($r === FALSE) { |
if ($r === FALSE) { |
507 |
|
rg_log('Could not obtain a value from cache for key [' . $key . ']!'); |
|
|
724 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
725 |
|
rg_log_ml('Cannot add pkg map!'); |
|
726 |
|
exit(1); |
|
727 |
|
} |
|
728 |
|
|
|
729 |
|
if (!strstr($r['body'], 'The packages mapping has been successfully added/edited.')) { |
|
730 |
|
rg_log_ml('r[body]: ' . print_r($r['body'], TRUE)); |
|
731 |
|
rg_log('Cannot add pkg map (no \'success\' message)!'); |
|
732 |
|
exit(1); |
|
733 |
|
} |
|
734 |
|
|
|
735 |
|
foreach ($r['rg_debug_html']['pkg_map'] as $k => $v) |
|
736 |
|
$extra[$k] = $v; |
|
737 |
|
|
|
738 |
|
// List mappings |
|
739 |
|
$data = array(); |
|
740 |
|
$r = do_req($info, $test_url . '/op/settings/packages/map/list', $data, $headers); |
|
741 |
|
if ($r === FALSE) { |
|
742 |
|
rg_log('Cannot list pkg maps!'); |
|
743 |
|
exit(1); |
|
744 |
|
} |
|
745 |
|
|
|
746 |
|
rg_log_exit(); |
|
747 |
|
} |
|
748 |
|
|
|
749 |
|
/* |
|
750 |
|
* Helper for getting the artifacts list |
|
751 |
|
*/ |
|
752 |
|
function rg_test_artifacts_page($rg_ui, $repo, $dir) |
|
753 |
|
{ |
|
754 |
|
global $test_url; |
|
755 |
|
|
|
756 |
|
rg_log_enter('test_artifacts dir=' . $dir); |
|
757 |
|
|
|
758 |
|
$info = array('id' => $rg_ui['username']); |
|
759 |
|
|
|
760 |
|
$r = do_req($info, $test_url . '/user/' . $rg_ui['username'] |
|
761 |
|
. '/' . $repo['name'] . '/artifacts/list' . $dir, $data, $headers); |
|
762 |
|
if ($r === FALSE) { |
|
763 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
764 |
|
rg_log_ml('Cannot get artifacts page!'); |
508 |
765 |
exit(1); |
exit(1); |
509 |
766 |
} |
} |
510 |
767 |
|
|
|
768 |
|
rg_log_exit(); |
|
769 |
|
return $r; |
|
770 |
|
} |
|
771 |
|
|
|
772 |
|
/* |
|
773 |
|
* Helper for getting the one artifact file |
|
774 |
|
*/ |
|
775 |
|
function rg_test_artifacts_file($rg_ui, $repo, $file) |
|
776 |
|
{ |
|
777 |
|
global $test_url; |
|
778 |
|
|
|
779 |
|
rg_log_enter('test_packages_file file=' . $file); |
|
780 |
|
|
|
781 |
|
$info = array('id' => $rg_ui['username']); |
|
782 |
|
|
|
783 |
|
$r = do_req($info, $test_url . '/user/' . $rg_ui['username'] |
|
784 |
|
. '/' . $repo['name'] . '/artifacts/download' . $file, |
|
785 |
|
$data, $headers); |
|
786 |
|
if ($r === FALSE) { |
|
787 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
788 |
|
rg_log_ml('Cannot get artifact file!'); |
|
789 |
|
exit(1); |
|
790 |
|
} |
|
791 |
|
|
|
792 |
|
rg_log_exit(); |
|
793 |
|
return $r; |
|
794 |
|
} |
|
795 |
|
|
|
796 |
|
/* |
|
797 |
|
* Helper for getting the packages list |
|
798 |
|
*/ |
|
799 |
|
function rg_test_packages($rg_ui, $repo) |
|
800 |
|
{ |
|
801 |
|
global $test_url; |
|
802 |
|
|
|
803 |
|
rg_log_enter('test_packages'); |
|
804 |
|
|
|
805 |
|
$info = array('id' => $rg_ui['username']); |
|
806 |
|
|
|
807 |
|
$r = do_req($info, $test_url . '/user/' . $rg_ui['username'] |
|
808 |
|
. '/' . $repo['name'] . '/pkg', $data, $headers); |
|
809 |
|
if ($r === FALSE) { |
|
810 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
811 |
|
rg_log_ml('Cannot get packages page!'); |
|
812 |
|
exit(1); |
|
813 |
|
} |
|
814 |
|
|
|
815 |
|
rg_log_exit(); |
|
816 |
|
return $r; |
|
817 |
|
} |
|
818 |
|
|
|
819 |
|
/* |
|
820 |
|
* Helper for getting the rpm repomd.xml |
|
821 |
|
*/ |
|
822 |
|
function rg_test_packages_file($login_ui, $page_ui, $type, $pkg_repo_name, |
|
823 |
|
$pkg_subrepo_name, $file) |
|
824 |
|
{ |
|
825 |
|
global $test_url; |
|
826 |
|
|
|
827 |
|
rg_log_enter('test_packages_repomd'); |
|
828 |
|
|
|
829 |
|
$info = array('id' => $login_ui['username']); |
|
830 |
|
|
|
831 |
|
$url = $test_url . '/op/pkgrepo/' . $type; |
|
832 |
|
if (strcmp($type, 'user') == 0) |
|
833 |
|
$url .= '/' . $page_ui['username']; |
|
834 |
|
$url .= '/' . $pkg_repo_name |
|
835 |
|
. '/' . $pkg_subrepo_name . '/fedora/34/x86_64/' . $file; |
|
836 |
|
|
|
837 |
|
$r = do_req($info, $url, $data, $headers); |
|
838 |
|
if ($r === FALSE) { |
|
839 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
840 |
|
rg_log_ml('Cannot get packages file [' . $file . ']!'); |
|
841 |
|
exit(1); |
|
842 |
|
} |
|
843 |
|
|
|
844 |
|
rg_log_exit(); |
511 |
845 |
return $r; |
return $r; |
512 |
846 |
} |
} |
513 |
847 |
|
|
File tests/http.inc.php changed (mode: 100644) (index e565632..c8f3836) |
1 |
1 |
<?php |
<?php |
2 |
2 |
|
|
3 |
|
if (!isset($test_ua)) |
|
4 |
|
$test_ua = "curl"; |
|
5 |
|
|
|
6 |
3 |
/* |
/* |
7 |
4 |
* Clean all cookies |
* Clean all cookies |
8 |
5 |
*/ |
*/ |
9 |
|
function clean_cookies() |
|
|
6 |
|
function clean_cookies($test) |
10 |
7 |
{ |
{ |
11 |
|
global $_testns; |
|
12 |
|
|
|
13 |
8 |
$path = __DIR__ . '/jars'; |
$path = __DIR__ . '/jars'; |
14 |
9 |
if (!file_exists($path)) |
if (!file_exists($path)) |
15 |
10 |
return; |
return; |
16 |
11 |
|
|
17 |
|
rg_log('Cleaning cookies...'); |
|
18 |
|
$cookie_jar = $path . '/' . $_testns; |
|
|
12 |
|
$cookie_jar = $path . '/' . $test; |
|
13 |
|
rg_log('Cleaning cookies from [' . $cookie_jar . ']...'); |
19 |
14 |
@unlink($cookie_jar); |
@unlink($cookie_jar); |
20 |
15 |
} |
} |
21 |
16 |
|
|
22 |
17 |
/* |
/* |
23 |
18 |
* This is called at the begining of all tests |
* This is called at the begining of all tests |
24 |
19 |
*/ |
*/ |
25 |
|
function prepare_http() |
|
|
20 |
|
function prepare_http($info) |
26 |
21 |
{ |
{ |
27 |
|
clean_cookies(); |
|
|
22 |
|
clean_cookies($info['id']); |
28 |
23 |
} |
} |
29 |
24 |
|
|
30 |
25 |
/* |
/* |
31 |
26 |
* Data is an array |
* Data is an array |
32 |
27 |
*/ |
*/ |
33 |
|
function do_req($url, &$data, &$headers) |
|
|
28 |
|
function do_req($info, $url, &$data, &$headers) |
34 |
29 |
{ |
{ |
35 |
|
global $test_ua, $test_referer; |
|
36 |
30 |
global $cookie_jar; |
global $cookie_jar; |
37 |
31 |
static $http_handles = array(); |
static $http_handles = array(); |
38 |
|
global $http_client; |
|
39 |
32 |
global $_testns; |
global $_testns; |
40 |
33 |
global $rg_log_sid; |
global $rg_log_sid; |
41 |
34 |
|
|
42 |
|
if (!isset($http_client)) |
|
43 |
|
$http_client = $_testns; |
|
|
35 |
|
$id = $info['id']; |
|
36 |
|
if (!isset($info['referer'])) |
|
37 |
|
$info['referer'] = ''; |
|
38 |
|
if (!isset($info['ua'])) |
|
39 |
|
$info['ua'] = 'curl'; |
|
40 |
|
if (!isset($info['test'])) |
|
41 |
|
$info['test'] = $_testns; |
44 |
42 |
|
|
45 |
43 |
$path = __DIR__ . '/jars'; |
$path = __DIR__ . '/jars'; |
46 |
44 |
if (!file_exists($path)) |
if (!file_exists($path)) |
47 |
45 |
mkdir($path); |
mkdir($path); |
48 |
|
$cookie_jar = $path . '/' . $http_client; |
|
|
46 |
|
$cookie_jar = $path . '/' . $id; |
49 |
47 |
|
|
50 |
48 |
if (is_null($data)) |
if (is_null($data)) |
51 |
49 |
$data = array(); |
$data = array(); |
|
... |
... |
function do_req($url, &$data, &$headers) |
64 |
62 |
$url .= '&rg_log_sid=' . $rg_log_sid; |
$url .= '&rg_log_sid=' . $rg_log_sid; |
65 |
63 |
|
|
66 |
64 |
rg_log_ml('do_req url: ' . $url . "\n" |
rg_log_ml('do_req url: ' . $url . "\n" |
|
65 |
|
. 'info=' . print_r($info, TRUE) . "\n" |
67 |
66 |
. 'data=' . print_r($data, TRUE) . "\n" |
. 'data=' . print_r($data, TRUE) . "\n" |
68 |
67 |
. 'headers=' . print_r($headers, TRUE)); |
. 'headers=' . print_r($headers, TRUE)); |
69 |
68 |
|
|
70 |
69 |
$c = FALSE; |
$c = FALSE; |
71 |
|
if (isset($http_handles[$http_client])) |
|
72 |
|
$c = $http_handles[$http_client]; |
|
|
70 |
|
if (isset($http_handles[$id])) |
|
71 |
|
$c = $http_handles[$id]; |
73 |
72 |
if ($c === FALSE) { |
if ($c === FALSE) { |
74 |
73 |
$c = curl_init(); |
$c = curl_init(); |
75 |
|
$http_handles[$http_client] = $c; |
|
|
74 |
|
$http_handles[$id] = $c; |
76 |
75 |
} |
} |
77 |
76 |
|
|
78 |
77 |
curl_setopt($c, CURLOPT_URL, $url); |
curl_setopt($c, CURLOPT_URL, $url); |
|
... |
... |
function do_req($url, &$data, &$headers) |
86 |
85 |
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); |
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); |
87 |
86 |
curl_setopt($c, CURLOPT_HEADER, 1); |
curl_setopt($c, CURLOPT_HEADER, 1); |
88 |
87 |
curl_setopt($c, CURLOPT_HTTPHEADER, $headers); |
curl_setopt($c, CURLOPT_HTTPHEADER, $headers); |
89 |
|
curl_setopt($c, CURLOPT_USERAGENT, $test_ua); |
|
90 |
|
curl_setopt($c, CURLOPT_REFERER, $test_referer); |
|
|
88 |
|
curl_setopt($c, CURLOPT_USERAGENT, $info['ua']); |
|
89 |
|
curl_setopt($c, CURLOPT_REFERER, $info['referer']); |
91 |
90 |
curl_setopt($c, CURLOPT_CERTINFO, TRUE); |
curl_setopt($c, CURLOPT_CERTINFO, TRUE); |
92 |
91 |
curl_setopt($c, CURLOPT_VERBOSE, TRUE); |
curl_setopt($c, CURLOPT_VERBOSE, TRUE); |
93 |
92 |
curl_setopt($c, CURLOPT_ENCODING , 'gzip'); |
curl_setopt($c, CURLOPT_ENCODING , 'gzip'); |
|
... |
... |
function do_req($url, &$data, &$headers) |
122 |
121 |
} |
} |
123 |
122 |
|
|
124 |
123 |
$ret = array(); |
$ret = array(); |
|
124 |
|
$ret['rg_debug_html'] = array(); |
125 |
125 |
$ret['ci'] = @curl_getinfo($c); |
$ret['ci'] = @curl_getinfo($c); |
126 |
126 |
if ($ret['ci'] === FALSE) { |
if ($ret['ci'] === FALSE) { |
127 |
127 |
rg_log('Cannot call curl_getinfo!'); |
rg_log('Cannot call curl_getinfo!'); |
128 |
128 |
exit(1); |
exit(1); |
129 |
129 |
} |
} |
130 |
130 |
|
|
131 |
|
//rg_log_ml('DEBUG: ci: ' . print_r($ret['ci'], TRUE)); |
|
|
131 |
|
//rg_log_debug('ci: ' . print_r($ret['ci'], TRUE)); |
132 |
132 |
|
|
133 |
133 |
if ($ret['ci']['http_code'] == 500) |
if ($ret['ci']['http_code'] == 500) |
134 |
134 |
return $ret; |
return $ret; |
135 |
135 |
|
|
136 |
136 |
$header_size = $ret['ci']['header_size']; |
$header_size = $ret['ci']['header_size']; |
137 |
|
//rg_log('DEBUG: r (len=' . strlen($r) . '): ' . $r); |
|
138 |
|
//rg_log('DEBUG: header_size: ' . $header_size); |
|
|
137 |
|
//rg_log_debug('r (len=' . strlen($r) . '): ' . $r); |
|
138 |
|
//rg_log_debug('header_size: ' . $header_size); |
139 |
139 |
$ret['header'] = substr($r, 0, $header_size); |
$ret['header'] = substr($r, 0, $header_size); |
140 |
140 |
$ret['body'] = substr($r, $header_size); |
$ret['body'] = substr($r, $header_size); |
141 |
141 |
|
|
142 |
142 |
if ($ret['ci']['http_code'] != 200) |
if ($ret['ci']['http_code'] != 200) |
143 |
143 |
return $ret; |
return $ret; |
144 |
144 |
|
|
|
145 |
|
$x = explode(' --rg_debug_html-- ', $ret['body']); |
|
146 |
|
if (isset($x[2])) { |
|
147 |
|
$j = @json_decode($x[1], TRUE); |
|
148 |
|
if ($j === FALSE) { |
|
149 |
|
rg_log('Cannot decode rg_debug_html json: ' . $x[1]); |
|
150 |
|
exit(1); |
|
151 |
|
} |
|
152 |
|
|
|
153 |
|
$ret['rg_debug_html'] = $j; |
|
154 |
|
if (!empty($ret['rg_debug_html'])) |
|
155 |
|
rg_log_ml('rg_debug_html: ' |
|
156 |
|
. print_r($ret['rg_debug_html'], TRUE)); |
|
157 |
|
|
|
158 |
|
$ret['body'] = $x[0] . $x[2]; |
|
159 |
|
} |
|
160 |
|
|
145 |
161 |
if (stristr($ret['header'], 'Content-Type: text/html')) { |
if (stristr($ret['header'], 'Content-Type: text/html')) { |
146 |
162 |
// Check for XSS |
// Check for XSS |
147 |
163 |
if (stristr($ret['body'], '<xss>')) { |
if (stristr($ret['body'], '<xss>')) { |
|
... |
... |
function do_req($url, &$data, &$headers) |
155 |
171 |
if (stristr($ret['header'], 'Content-Disposition: attachment')) |
if (stristr($ret['header'], 'Content-Disposition: attachment')) |
156 |
172 |
return $ret; |
return $ret; |
157 |
173 |
|
|
158 |
|
if (!stristr($ret['header'], 'Content-Encoding: gzip')) { |
|
159 |
|
rg_log_ml('headers: ' . print_r($ret['header'], TRUE)); |
|
|
174 |
|
if (!stristr($ret['header'], 'X-RocketGit-skip-compression: 1') |
|
175 |
|
&& (!stristr($ret['header'], 'Content-Encoding: gzip'))) { |
160 |
176 |
rg_log('Content is not compressed!'); |
rg_log('Content is not compressed!'); |
161 |
177 |
exit(1); |
exit(1); |
162 |
178 |
} |
} |
163 |
179 |
|
|
164 |
|
if (!stristr($ret['header'], "\n" . 'ETag: ')) { |
|
165 |
|
rg_log_ml('headers: ' . print_r($ret['header'], TRUE)); |
|
|
180 |
|
if (!stristr($ret['header'], 'X-RocketGit-skip-etag: 1') |
|
181 |
|
&& (!stristr($ret['header'], "\n" . 'ETag: '))) { |
166 |
182 |
rg_log('ETag is not present!'); |
rg_log('ETag is not present!'); |
167 |
183 |
exit(1); |
exit(1); |
168 |
184 |
} |
} |
|
... |
... |
function do_req($url, &$data, &$headers) |
172 |
188 |
// do nothing |
// do nothing |
173 |
189 |
} else if (stristr($ret['header'], 'Content-Type: application/octet-stream')) { |
} else if (stristr($ret['header'], 'Content-Type: application/octet-stream')) { |
174 |
190 |
// do nothing |
// do nothing |
|
191 |
|
} else if (stristr($ret['header'], 'Content-Type: application/x-rpm')) { |
|
192 |
|
// do nothing |
|
193 |
|
} else if (stristr($ret['header'], 'Content-Type: text/xml')) { |
|
194 |
|
// do nothing - TODO: should we parse it? |
175 |
195 |
} else if (stristr($ret['header'], 'Content-Type: text/html')) { |
} else if (stristr($ret['header'], 'Content-Type: text/html')) { |
176 |
196 |
// some fixes |
// some fixes |
177 |
197 |
$ret['body'] = str_replace('autocomplete="off"', '', $ret['body']); |
$ret['body'] = str_replace('autocomplete="off"', '', $ret['body']); |
178 |
198 |
$ret['body'] = str_replace('<xss>', '|xss|', $ret['body']); |
$ret['body'] = str_replace('<xss>', '|xss|', $ret['body']); |
179 |
|
file_put_contents("http.tidy.in", $ret['body']); |
|
180 |
|
$cmd = "tidy -errors -utf8 -file http.tidy.out http.tidy.in"; |
|
|
199 |
|
|
|
200 |
|
$_tf = $_testns . '.tidy'; |
|
201 |
|
file_put_contents($_tf . '.in', $ret['body']); |
|
202 |
|
$cmd = 'tidy -errors -utf8 -file ' . escapeshellarg($_tf) |
|
203 |
|
. '.out ' . escapeshellarg($_tf) . '.in'; |
181 |
204 |
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
182 |
205 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
183 |
206 |
rg_log_ml('body: ' . $ret['body']); |
rg_log_ml('body: ' . $ret['body']); |
184 |
207 |
rg_log_ml('tidy error: ' . $r['stderr']); |
rg_log_ml('tidy error: ' . $r['stderr']); |
185 |
|
rg_log_ml(file_get_contents('http.tidy.out')); |
|
|
208 |
|
rg_log_ml(file_get_contents($_tf . '.out')); |
186 |
209 |
exit(1); |
exit(1); |
187 |
210 |
} |
} |
|
211 |
|
@unlink($_tf . '.in'); |
|
212 |
|
@unlink($_tf . '.out'); |
188 |
213 |
} else if (stristr($ret['header'], 'Content-Type: application/json')) { |
} else if (stristr($ret['header'], 'Content-Type: application/json')) { |
189 |
214 |
$ret['json'] = @json_decode($ret['body'], TRUE); |
$ret['json'] = @json_decode($ret['body'], TRUE); |
190 |
215 |
if ($ret['json'] === NULL) { |
if ($ret['json'] === NULL) { |
|
... |
... |
function do_req($url, &$data, &$headers) |
211 |
236 |
|
|
212 |
237 |
// Find cookies |
// Find cookies |
213 |
238 |
$ret['cookies'] = array(); |
$ret['cookies'] = array(); |
214 |
|
$x = preg_match_all('/Set-Cookie: (.*?)=(.*?)[;]/', |
|
|
239 |
|
$x = preg_match_all('/[sS]et-[cC]ookie: (.*?)=(.*?)[;]/', |
215 |
240 |
$ret['header'], $matches, PREG_SET_ORDER); |
$ret['header'], $matches, PREG_SET_ORDER); |
216 |
241 |
if ($x !== FALSE) { |
if ($x !== FALSE) { |
217 |
242 |
foreach ($matches as $junk => $info) { |
foreach ($matches as $junk => $info) { |
|
... |
... |
function do_req($url, &$data, &$headers) |
231 |
256 |
$ret['tokens'] = array(); |
$ret['tokens'] = array(); |
232 |
257 |
$x = preg_match_all('/ name="token" value="([a-zA-Z0-9_:]*)"/', |
$x = preg_match_all('/ name="token" value="([a-zA-Z0-9_:]*)"/', |
233 |
258 |
$ret['body'], $matches); |
$ret['body'], $matches); |
234 |
|
//rg_log_ml('DEBUG: tokens matches: ' . print_r($matches, TRUE)); |
|
|
259 |
|
//rg_log_debug('tokens matches: ' . print_r($matches, TRUE)); |
235 |
260 |
if (($x === FALSE) || (!isset($matches[1]))) { |
if (($x === FALSE) || (!isset($matches[1]))) { |
236 |
261 |
//rg_log("CHECK: no token found"); |
//rg_log("CHECK: no token found"); |
237 |
262 |
} else { |
} else { |
|
... |
... |
function do_req($url, &$data, &$headers) |
252 |
277 |
$ret['inputs'] = array(); |
$ret['inputs'] = array(); |
253 |
278 |
$x = preg_match_all('/<input .* name="(.*?)" .*value="(.*?)"/uD', |
$x = preg_match_all('/<input .* name="(.*?)" .*value="(.*?)"/uD', |
254 |
279 |
$ret['body'], $matches); |
$ret['body'], $matches); |
255 |
|
//rg_log_ml('DEBUG: inputs matches: ' . print_r($matches, TRUE)); |
|
|
280 |
|
//rg_log_debug('inputs matches: ' . print_r($matches, TRUE)); |
256 |
281 |
if (($x === FALSE) || (!isset($matches[1]))) { |
if (($x === FALSE) || (!isset($matches[1]))) { |
257 |
282 |
//rg_log("CHECK: no token found"); |
//rg_log("CHECK: no token found"); |
258 |
283 |
} else { |
} else { |
|
... |
... |
function do_req($url, &$data, &$headers) |
263 |
288 |
|
|
264 |
289 |
// find logout token |
// find logout token |
265 |
290 |
$x = preg_match('/logout\?token=([a-zA-Z0-9:]*)"/', $ret['body'], $matches); |
$x = preg_match('/logout\?token=([a-zA-Z0-9:]*)"/', $ret['body'], $matches); |
266 |
|
//rg_log_ml('DEBUG: matches[logout]: ' . print_r($matches, TRUE)); |
|
|
291 |
|
//rg_log_debug('matches[logout]: ' . print_r($matches, TRUE)); |
267 |
292 |
if (($x === FALSE) || (!isset($matches[1]))) { |
if (($x === FALSE) || (!isset($matches[1]))) { |
268 |
293 |
$ret['tokens']['logout'] = ''; |
$ret['tokens']['logout'] = ''; |
269 |
294 |
} else { |
} else { |
|
... |
... |
function do_req($url, &$data, &$headers) |
288 |
313 |
*/ |
*/ |
289 |
314 |
function test_login($url, $rg_ui) |
function test_login($url, $rg_ui) |
290 |
315 |
{ |
{ |
291 |
|
global $test_ua; |
|
|
316 |
|
$info = array('id' => $rg_ui['username']); |
292 |
317 |
|
|
293 |
318 |
// First we need to load the form so we can get the token |
// First we need to load the form so we can get the token |
294 |
319 |
$data = array(); |
$data = array(); |
295 |
|
$r = do_req($url . "/op/login", $data, $headers); |
|
|
320 |
|
$r = do_req($info, $url . "/op/login", $data, $headers); |
296 |
321 |
if ($r === FALSE) { |
if ($r === FALSE) { |
297 |
322 |
rg_log('Cannot load login form!'); |
rg_log('Cannot load login form!'); |
298 |
323 |
return FALSE; |
return FALSE; |
|
... |
... |
function test_login($url, $rg_ui) |
316 |
341 |
if (isset($rg_ui['t'])) |
if (isset($rg_ui['t'])) |
317 |
342 |
$data['t'] = $rg_ui['t']; |
$data['t'] = $rg_ui['t']; |
318 |
343 |
$headers = array(); |
$headers = array(); |
319 |
|
$r = do_req($url . "/op/login", $data, $headers); |
|
|
344 |
|
$r = do_req($info, $url . "/op/login", $data, $headers); |
320 |
345 |
if ($r === FALSE) { |
if ($r === FALSE) { |
321 |
346 |
rg_log_ml("Cannot login: " . print_r($r, TRUE)); |
rg_log_ml("Cannot login: " . print_r($r, TRUE)); |
322 |
347 |
return FALSE; |
return FALSE; |
|
... |
... |
function test_restore($db) |
353 |
378 |
rg_cache_unset('user::4::info', RG_SOCKET_NO_WAIT); |
rg_cache_unset('user::4::info', RG_SOCKET_NO_WAIT); |
354 |
379 |
} |
} |
355 |
380 |
|
|
356 |
|
/* |
|
357 |
|
* Set user agent |
|
358 |
|
*/ |
|
359 |
|
function test_set_ua($s) |
|
360 |
|
{ |
|
361 |
|
global $test_ua; |
|
362 |
|
|
|
363 |
|
$test_ua = $s; |
|
364 |
|
} |
|
365 |
|
|
|
366 |
|
/* |
|
367 |
|
* Set referer |
|
368 |
|
*/ |
|
369 |
|
function test_set_referer($s) |
|
370 |
|
{ |
|
371 |
|
global $test_referer; |
|
372 |
|
|
|
373 |
|
$test_referer = $s; |
|
374 |
|
} |
|
375 |
|
|
|
376 |
|
?> |
|
File tests/http_api.php changed (mode: 100644) (index e7317c1..617ae06) |
... |
... |
require_once('common.php'); |
18 |
18 |
|
|
19 |
19 |
$_testns = 'http_api'; |
$_testns = 'http_api'; |
20 |
20 |
|
|
21 |
|
prepare_http(); |
|
22 |
|
|
|
23 |
21 |
rg_test_create_user($db, $u); |
rg_test_create_user($db, $u); |
24 |
22 |
rg_test_create_repo_no_dir($db, $u, $repo); |
rg_test_create_repo_no_dir($db, $u, $repo); |
|
23 |
|
$info = array('id' => $u['username']); |
|
24 |
|
prepare_http($info); |
|
25 |
|
|
25 |
26 |
|
|
26 |
27 |
$r = test_login($test_url, $u); |
$r = test_login($test_url, $u); |
27 |
28 |
if ($r === FALSE) |
if ($r === FALSE) |
|
... |
... |
rg_log_enter('Loading api keys form...'); |
34 |
35 |
$url = '/op/settings/apikeys/add'; |
$url = '/op/settings/apikeys/add'; |
35 |
36 |
$headers = array(); |
$headers = array(); |
36 |
37 |
$data = array(); |
$data = array(); |
37 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
38 |
|
$r = do_req($info, $test_url . $url, $data, $headers); |
38 |
39 |
if ($r === FALSE) { |
if ($r === FALSE) { |
39 |
40 |
rg_log('Cannot load form.'); |
rg_log('Cannot load form.'); |
40 |
41 |
exit(1); |
exit(1); |
|
... |
... |
rg_log(''); |
53 |
54 |
rg_log_enter('Posting api keys add form (token=' . $token . ')...'); |
rg_log_enter('Posting api keys add form (token=' . $token . ')...'); |
54 |
55 |
$data = array('doit' => 1, 'token' => $token, |
$data = array('doit' => 1, 'token' => $token, |
55 |
56 |
'ak::name' => 'ak<xss>', 'ak::key' => $key); |
'ak::name' => 'ak<xss>', 'ak::key' => $key); |
56 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
57 |
|
$r = do_req($info, $test_url . $url, $data, $headers); |
57 |
58 |
if ($r === FALSE) { |
if ($r === FALSE) { |
58 |
59 |
rg_log('Cannot post request.'); |
rg_log('Cannot post request.'); |
59 |
60 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_enter('Calling API: user_info (without authorization)...'); |
82 |
83 |
$headers = $sh; |
$headers = $sh; |
83 |
84 |
$a = array('cmd' => 'user_info', 'user' => $u['username']); |
$a = array('cmd' => 'user_info', 'user' => $u['username']); |
84 |
85 |
$data = json_encode($a); |
$data = json_encode($a); |
85 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
86 |
|
$r = do_req($info, $test_url . $url, $data, $headers); |
86 |
87 |
if (@strcmp($r['json']['error'], 'invalid user or apikey') != 0) { |
if (@strcmp($r['json']['error'], 'invalid user or apikey') != 0) { |
87 |
88 |
rg_log('Cannot call api.'); |
rg_log('Cannot call api.'); |
88 |
89 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_enter('Calling API: invalid command...'); |
99 |
100 |
$headers = $sh; |
$headers = $sh; |
100 |
101 |
$a = array('cmd' => 'invalid command'); |
$a = array('cmd' => 'invalid command'); |
101 |
102 |
$data = json_encode($a); |
$data = json_encode($a); |
102 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
103 |
|
$r = do_req($info, $test_url . $url, $data, $headers); |
103 |
104 |
if (@strcmp($r['json']['error'], 'invalid command') != 0) { |
if (@strcmp($r['json']['error'], 'invalid command') != 0) { |
104 |
105 |
rg_log('Cannot call api.'); |
rg_log('Cannot call api.'); |
105 |
106 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_enter('Calling API: user_info (with authorization)...'); |
112 |
113 |
$headers = $sh; |
$headers = $sh; |
113 |
114 |
$a = array('cmd' => 'user_info', 'user' => $u['username']); |
$a = array('cmd' => 'user_info', 'user' => $u['username']); |
114 |
115 |
$data = json_encode($a); |
$data = json_encode($a); |
115 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
116 |
|
$r = do_req($info, $test_url . $url, $data, $headers); |
116 |
117 |
if (@strcmp($r['json']['email'], $u['email']) != 0) { |
if (@strcmp($r['json']['email'], $u['email']) != 0) { |
117 |
118 |
rg_log('E-mail ot returned for user_info?!'); |
rg_log('E-mail ot returned for user_info?!'); |
118 |
119 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_enter('Calling API: user_ssh_key_list (uid instead or user)...'); |
125 |
126 |
$headers = $sh; |
$headers = $sh; |
126 |
127 |
$a = array('cmd' => 'user_ssh_keys_list', 'uid' => $u['uid'], 'opaque' => 'abc'); |
$a = array('cmd' => 'user_ssh_keys_list', 'uid' => $u['uid'], 'opaque' => 'abc'); |
127 |
128 |
$data = json_encode($a); |
$data = json_encode($a); |
128 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
129 |
|
$r = do_req($info, $test_url . $url, $data, $headers); |
129 |
130 |
if (!isset($r['json']['list'][0]['last_use'])) { |
if (!isset($r['json']['list'][0]['last_use'])) { |
130 |
131 |
rg_log('NO last_use field for the first key!'); |
rg_log('NO last_use field for the first key!'); |
131 |
132 |
exit(1); |
exit(1); |
File tests/http_bug.php changed (mode: 100644) (index 6e83c6b..eac38a5) |
... |
... |
require_once("common.php"); |
18 |
18 |
$_testns = 'http_bug'; |
$_testns = 'http_bug'; |
19 |
19 |
|
|
20 |
20 |
|
|
21 |
|
prepare_http(); |
|
22 |
|
|
|
23 |
21 |
rg_test_create_user($db, $u1); |
rg_test_create_user($db, $u1); |
|
22 |
|
$info1 = array('id' => $u1['username']); |
|
23 |
|
prepare_http($info1); |
|
24 |
|
|
24 |
25 |
rg_test_create_user($db, $u2); |
rg_test_create_user($db, $u2); |
|
26 |
|
$info2 = array('id' => $u2['username']); |
|
27 |
|
prepare_http($info2); |
|
28 |
|
|
25 |
29 |
rg_test_create_repo($db, $u1, $repo); |
rg_test_create_repo($db, $u1, $repo); |
26 |
30 |
|
|
27 |
31 |
$r = test_login($test_url, $u1); |
$r = test_login($test_url, $u1); |
|
... |
... |
rg_log_enter("Loading bug form..."); |
34 |
38 |
$url = "/user/" . $u1['username'] . "/" . $repo['name'] . "/bug/add"; |
$url = "/user/" . $u1['username'] . "/" . $repo['name'] . "/bug/add"; |
35 |
39 |
$headers = array(); |
$headers = array(); |
36 |
40 |
$data = array(); |
$data = array(); |
37 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
41 |
|
$r = do_req($info1, $test_url . $url, $data, $headers); |
38 |
42 |
if ($r === FALSE) { |
if ($r === FALSE) { |
39 |
43 |
rg_log('Cannot load add bug form.'); |
rg_log('Cannot load add bug form.'); |
40 |
44 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_exit(); |
49 |
53 |
rg_log(''); |
rg_log(''); |
50 |
54 |
rg_log_enter("Posting bug form (token=$token)..."); |
rg_log_enter("Posting bug form (token=$token)..."); |
51 |
55 |
$labels = array('a/b', 'uu::bb', '<xss>'); sort($labels); |
$labels = array('a/b', 'uu::bb', '<xss>'); sort($labels); |
|
56 |
|
$info1['test'] = 'add bug'; |
52 |
57 |
$data = array( |
$data = array( |
53 |
58 |
'doit' => 1, |
'doit' => 1, |
54 |
59 |
'edit' => 1, |
'edit' => 1, |
|
... |
... |
$data = array( |
57 |
62 |
'body' => 'aasasasassa<xss>', |
'body' => 'aasasasassa<xss>', |
58 |
63 |
'state' => 1, |
'state' => 1, |
59 |
64 |
'assigned_to' => $u2['username'], |
'assigned_to' => $u2['username'], |
60 |
|
'labels' => implode(' ', $labels), |
|
61 |
|
'_test' => 'add bug'); |
|
62 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
65 |
|
'labels' => implode(' ', $labels)); |
|
66 |
|
$r = do_req($info1, $test_url . $url, $data, $headers); |
63 |
67 |
if ($r === FALSE) { |
if ($r === FALSE) { |
64 |
68 |
rg_log('Cannot post bug request.'); |
rg_log('Cannot post bug request.'); |
65 |
69 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_enter("Testing adding a note"); |
104 |
108 |
|
|
105 |
109 |
rg_log_enter("Loading bug/note form..."); |
rg_log_enter("Loading bug/note form..."); |
106 |
110 |
$url = "/user/" . $u1['username'] . "/" . $repo['name'] . "/bug/1"; |
$url = "/user/" . $u1['username'] . "/" . $repo['name'] . "/bug/1"; |
107 |
|
$data = array('_test' => 'adding a note'); |
|
108 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
111 |
|
$info1['test'] = 'adding a note'; |
|
112 |
|
$r = do_req($info1, $test_url . $url, $data, $headers); |
109 |
113 |
if ($r === FALSE) { |
if ($r === FALSE) { |
110 |
114 |
rg_log("Cannot load bug page."); |
rg_log("Cannot load bug page."); |
111 |
115 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_exit(); |
119 |
123 |
|
|
120 |
124 |
rg_log_enter("Posting note add form (token=$token)..."); |
rg_log_enter("Posting note add form (token=$token)..."); |
121 |
125 |
$note = 'This is a note<xss>'; |
$note = 'This is a note<xss>'; |
|
126 |
|
$info1['test'] = 'adding a note'; |
122 |
127 |
$data = array('note_add_doit' => 1, 'token' => $token, |
$data = array('note_add_doit' => 1, 'token' => $token, |
123 |
|
'note' => $note, |
|
124 |
|
'_test' => 'adding a note'); |
|
125 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
128 |
|
'note' => $note); |
|
129 |
|
$r = do_req($info1, $test_url . $url, $data, $headers); |
126 |
130 |
if ($r === FALSE) { |
if ($r === FALSE) { |
127 |
131 |
rg_log('Cannot post bug request.'); |
rg_log('Cannot post bug request.'); |
128 |
132 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_exit(); |
148 |
152 |
$token = $r['tokens']['close_reopen']; |
$token = $r['tokens']['close_reopen']; |
149 |
153 |
rg_log(''); |
rg_log(''); |
150 |
154 |
rg_log_enter("Posting close bug form (token=$token)..."); |
rg_log_enter("Posting close bug form (token=$token)..."); |
|
155 |
|
$info1['test'] = 'closing a bug'; |
151 |
156 |
$data = array('token' => $token, |
$data = array('token' => $token, |
152 |
157 |
'close_reopen' => 1, |
'close_reopen' => 1, |
153 |
|
'state' => 2, |
|
154 |
|
'_test' => 'closing a bug'); |
|
155 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
158 |
|
'state' => 2); |
|
159 |
|
$r = do_req($info1, $test_url . $url, $data, $headers); |
156 |
160 |
if ($r === FALSE) { |
if ($r === FALSE) { |
157 |
161 |
rg_log('Cannot post bug request.'); |
rg_log('Cannot post bug request.'); |
158 |
162 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_exit(); |
171 |
175 |
$token = $r['tokens']['close_reopen']; |
$token = $r['tokens']['close_reopen']; |
172 |
176 |
rg_log(''); |
rg_log(''); |
173 |
177 |
rg_log_enter("Posting re-open bug form (token=$token)..."); |
rg_log_enter("Posting re-open bug form (token=$token)..."); |
|
178 |
|
$info1['test'] = 're-opn bug'; |
174 |
179 |
$data = array('token' => $token, |
$data = array('token' => $token, |
175 |
180 |
'close_reopen' => 1, |
'close_reopen' => 1, |
176 |
|
'state'=> 1, |
|
177 |
|
'_test' => 're-opn bug'); |
|
178 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
181 |
|
'state'=> 1); |
|
182 |
|
$r = do_req($info1, $test_url . $url, $data, $headers); |
179 |
183 |
if ($r === FALSE) { |
if ($r === FALSE) { |
180 |
184 |
rg_log('Cannot post bug request (check http_bug.out for last answer).'); |
rg_log('Cannot post bug request (check http_bug.out for last answer).'); |
181 |
185 |
exit(1); |
exit(1); |
|
... |
... |
if ($row['state'] != 1) { |
193 |
197 |
rg_log_exit(); |
rg_log_exit(); |
194 |
198 |
|
|
195 |
199 |
rg_log(''); |
rg_log(''); |
196 |
|
rg_log_enter("Testing deleting a bug"); |
|
|
200 |
|
rg_log_enter('Testing deleting a bug'); |
197 |
201 |
for ($i = 0; $i <= 1; $i++) { |
for ($i = 0; $i <= 1; $i++) { |
198 |
202 |
$token = $r['tokens']['del_undel']; |
$token = $r['tokens']['del_undel']; |
199 |
203 |
rg_log("Posting delete bug form (token=$token)..."); |
rg_log("Posting delete bug form (token=$token)..."); |
|
204 |
|
$info1['test'] = 'deleting a bug (' . $i . ')'; |
200 |
205 |
$data = array('token' => $token, |
$data = array('token' => $token, |
201 |
206 |
'del_doit' => 1, |
'del_doit' => 1, |
202 |
|
'del_undel' => $i + 1, |
|
203 |
|
'_test' => 'deleting a bug (i=' . $i . ')'); |
|
204 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
207 |
|
'del_undel' => $i + 1); |
|
208 |
|
$r = do_req($info1, $test_url . $url, $data, $headers); |
205 |
209 |
if ($r === FALSE) { |
if ($r === FALSE) { |
206 |
210 |
rg_log('Cannot post bug request.'); |
rg_log('Cannot post bug request.'); |
207 |
211 |
exit(1); |
exit(1); |
|
... |
... |
if ($r === FALSE) |
236 |
240 |
exit(1); |
exit(1); |
237 |
241 |
$headers = array(); |
$headers = array(); |
238 |
242 |
|
|
239 |
|
// We are already in the watch list because the asignee is automatically added |
|
|
243 |
|
// 'u2' is already in the watch list because the asignee is automatically added |
240 |
244 |
for ($i = 0; $i <= 1; $i++) { |
for ($i = 0; $i <= 1; $i++) { |
241 |
|
rg_log("Loading bug form (i=$i)..."); |
|
242 |
|
$data = array('_test' => 'load-form-watch-' . $i); |
|
243 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
245 |
|
rg_log('Loading bug form (i=' . $i . ')...'); |
|
246 |
|
$data = array(); |
|
247 |
|
$r = do_req($info2, $test_url . $url, $data, $headers); |
244 |
248 |
if ($r === FALSE) { |
if ($r === FALSE) { |
245 |
249 |
rg_log('Cannot load bug form.'); |
rg_log('Cannot load bug form.'); |
246 |
250 |
exit(1); |
exit(1); |
247 |
251 |
} |
} |
248 |
252 |
$token = $r['tokens']['watch_bug']; |
$token = $r['tokens']['watch_bug']; |
249 |
253 |
|
|
250 |
|
rg_log("Posting (un)watch bug form..."); |
|
|
254 |
|
rg_log('Posting (un)watch bug form...'); |
251 |
255 |
$data = array('token' => $token, 'watch_type' => 'bug', |
$data = array('token' => $token, 'watch_type' => 'bug', |
252 |
|
'watch_doit' => 1, 'watch' => $i, |
|
253 |
|
'_test' => 'post-watch-' . $i); |
|
254 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
256 |
|
'watch_doit' => 1, 'watch' => $i); |
|
257 |
|
$r = do_req($info2, $test_url . $url, $data, $headers); |
255 |
258 |
if ($r === FALSE) { |
if ($r === FALSE) { |
256 |
259 |
rg_log('Cannot post watch bug request.'); |
rg_log('Cannot post watch bug request.'); |
257 |
260 |
exit(1); |
exit(1); |
258 |
261 |
} |
} |
259 |
|
$sql = 'SELECT uid FROM watch_bug WHERE repo_id = ' . $repo['repo_id'] |
|
|
262 |
|
$sql = 'SELECT DISTINCT uid FROM watch_bug' |
|
263 |
|
. ' WHERE repo_id = ' . $repo['repo_id'] |
260 |
264 |
. ' AND bug_id = 1'; |
. ' AND bug_id = 1'; |
261 |
265 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
262 |
266 |
$rows = rg_sql_num_rows($res); |
$rows = rg_sql_num_rows($res); |
|
... |
... |
for ($i = 0; $i <= 1; $i++) { |
265 |
269 |
$row[] = $r; |
$row[] = $r; |
266 |
270 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
267 |
271 |
|
|
268 |
|
if ($i == 0) { // unwatch - only rg_ui[uid] should be present |
|
|
272 |
|
if ($i == 0) { // unwatch - only u1[uid] should be present |
269 |
273 |
if (($rows != 1) || ($row[0]['uid'] != $u1['uid'])) { |
if (($rows != 1) || ($row[0]['uid'] != $u1['uid'])) { |
270 |
|
rg_log_ml('Seems we could not watch the bug; row:' |
|
|
274 |
|
rg_log_ml('Seems I could not unwatch the bug; rows: ' |
271 |
275 |
. print_r($row, TRUE)); |
. print_r($row, TRUE)); |
272 |
276 |
exit(1); |
exit(1); |
273 |
277 |
} |
} |
|
... |
... |
rg_log_exit(); |
288 |
292 |
|
|
289 |
293 |
rg_log_enter('Search bugs: loading form...'); |
rg_log_enter('Search bugs: loading form...'); |
290 |
294 |
$url = '/user/' . $u1['username'] . '/' . $repo['name'] . '/bug/search'; |
$url = '/user/' . $u1['username'] . '/' . $repo['name'] . '/bug/search'; |
|
295 |
|
$info1['test'] = 'load search bug form'; |
291 |
296 |
$headers = array(); $data = array(); |
$headers = array(); $data = array(); |
292 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
297 |
|
$r = do_req($info1, $test_url . $url, $data, $headers); |
293 |
298 |
if ($r === FALSE) { |
if ($r === FALSE) { |
294 |
299 |
rg_log('Cannot load bug search page!'); |
rg_log('Cannot load bug search page!'); |
295 |
300 |
exit(1); |
exit(1); |
|
... |
... |
if ($r === FALSE) { |
297 |
302 |
rg_log_exit(); |
rg_log_exit(); |
298 |
303 |
|
|
299 |
304 |
|
|
300 |
|
rg_log_enter('Search bugs: ad a search...'); |
|
|
305 |
|
rg_log_enter('Search bugs: add a search...'); |
301 |
306 |
$url = '/user/' . $u1['username'] . '/' . $repo['name'] . '/bug/search'; |
$url = '/user/' . $u1['username'] . '/' . $repo['name'] . '/bug/search'; |
|
307 |
|
$info1['test'] = 'search bug'; |
302 |
308 |
$headers = array(); $data = array('doit' => '1'); |
$headers = array(); $data = array('doit' => '1'); |
303 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
309 |
|
$r = do_req($info1, $test_url . $url, $data, $headers); |
304 |
310 |
if ($r === FALSE) { |
if ($r === FALSE) { |
305 |
311 |
rg_log('Cannot do bug search!'); |
rg_log('Cannot do bug search!'); |
306 |
312 |
exit(1); |
exit(1); |
File tests/http_confirm.php changed (mode: 100644) (index 9b64bf2..2759064) |
... |
... |
require_once("common.php"); |
19 |
19 |
$_testns = 'http_confirm'; |
$_testns = 'http_confirm'; |
20 |
20 |
|
|
21 |
21 |
|
|
22 |
|
prepare_http(); |
|
23 |
|
|
|
24 |
22 |
$uniq = rg_id(10); |
$uniq = rg_id(10); |
25 |
23 |
|
|
|
24 |
|
$info = array('id' => 'http_confirm'); |
|
25 |
|
prepare_http($info); |
|
26 |
|
|
|
27 |
|
|
26 |
28 |
rg_log_enter('Loading confirmation form...'); |
rg_log_enter('Loading confirmation form...'); |
27 |
29 |
// First we need to load the form so we can get the token |
// First we need to load the form so we can get the token |
28 |
|
$r = do_req($test_url . "/op/create_account", $data, $headers); |
|
|
30 |
|
$r = do_req($info, $test_url . "/op/create_account", $data, $headers); |
29 |
31 |
if ($r === FALSE) { |
if ($r === FALSE) { |
30 |
32 |
rg_log("Cannot load create_account page!"); |
rg_log("Cannot load create_account page!"); |
31 |
33 |
exit(1); |
exit(1); |
|
... |
... |
$data['gen'] = $gen; |
48 |
50 |
$data['doit'] = 1; |
$data['doit'] = 1; |
49 |
51 |
$headers = array(); |
$headers = array(); |
50 |
52 |
sleep(3); // we need to sleep, else we will trigger the bot protection |
sleep(3); // we need to sleep, else we will trigger the bot protection |
51 |
|
$r = do_req($test_url . '/op/create_account?t=create_account', $data, $headers); |
|
|
53 |
|
$r = do_req($info, $test_url . '/op/create_account?t=create_account', $data, $headers); |
52 |
54 |
if (!strstr($r['body'], 'Your account has been successfully created')) { |
if (!strstr($r['body'], 'Your account has been successfully created')) { |
53 |
55 |
rg_log_ml('body: ' . print_r($r['body'], TRUE)); |
rg_log_ml('body: ' . print_r($r['body'], TRUE)); |
54 |
56 |
rg_log('Cannot create account!'); |
rg_log('Cannot create account!'); |
|
... |
... |
rg_log_exit(); |
72 |
74 |
|
|
73 |
75 |
rg_log_enter('Finding confirmation link...'); |
rg_log_enter('Finding confirmation link...'); |
74 |
76 |
$key = 'DEBUG::' . $uid . '::mail'; |
$key = 'DEBUG::' . $uid . '::mail'; |
75 |
|
$c = test_wait_cache($key); |
|
|
77 |
|
$c = test_wait_cache($key, 50); |
76 |
78 |
rg_log_ml('c: ' . print_r($c, TRUE)); |
rg_log_ml('c: ' . print_r($c, TRUE)); |
77 |
79 |
$c = $c['mail/user/welcome']; |
$c = $c['mail/user/welcome']; |
78 |
80 |
$t = explode('below:', $c['body']); |
$t = explode('below:', $c['body']); |
|
... |
... |
rg_log_exit(); |
90 |
92 |
|
|
91 |
93 |
rg_log_enter('Trying with the wrong link...'); |
rg_log_enter('Trying with the wrong link...'); |
92 |
94 |
$data = array(); $headers = array(); |
$data = array(); $headers = array(); |
93 |
|
$r = do_req($link . 'XXX?t=http_confirm', $data, $headers); |
|
|
95 |
|
$r = do_req($info, $link . 'XXX?t=http_confirm', $data, $headers); |
94 |
96 |
if (!strstr($r['body'], 'Invalid token')) { |
if (!strstr($r['body'], 'Invalid token')) { |
95 |
97 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
96 |
98 |
rg_log('Something wrong with the token!'); |
rg_log('Something wrong with the token!'); |
|
... |
... |
rg_log_exit(); |
100 |
102 |
|
|
101 |
103 |
|
|
102 |
104 |
rg_log_enter('Trying with the good link (first time)...'); |
rg_log_enter('Trying with the good link (first time)...'); |
103 |
|
$r = do_req($link . '?t=http_confirm1', $data, $headers); |
|
|
105 |
|
$r = do_req($info, $link . '?t=http_confirm1', $data, $headers); |
104 |
106 |
if (!strstr($r['body'], 'Your e-mail is confirmed now.')) { |
if (!strstr($r['body'], 'Your e-mail is confirmed now.')) { |
105 |
107 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
106 |
108 |
rg_log('Something wrong with the token!'); |
rg_log('Something wrong with the token!'); |
|
... |
... |
rg_log_exit(); |
110 |
112 |
|
|
111 |
113 |
|
|
112 |
114 |
rg_log_enter('Trying with the good link (second time)...'); |
rg_log_enter('Trying with the good link (second time)...'); |
113 |
|
$r = do_req($link . '?t=http_confirm2', $data, $headers); |
|
|
115 |
|
$r = do_req($info, $link . '?t=http_confirm2', $data, $headers); |
114 |
116 |
if (!strstr($r['body'], 'Invalid token.')) { |
if (!strstr($r['body'], 'Invalid token.')) { |
115 |
117 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
116 |
118 |
rg_log('Reusing a confirmation token must not work!'); |
rg_log('Reusing a confirmation token must not work!'); |
|
... |
... |
rg_log_exit(); |
120 |
122 |
|
|
121 |
123 |
|
|
122 |
124 |
rg_log('OK!'); |
rg_log('OK!'); |
123 |
|
?> |
|
File tests/http_csrf.php changed (mode: 100644) (index 7cc7a9c..a2755c5) |
... |
... |
require_once("common.php"); |
18 |
18 |
|
|
19 |
19 |
$_testns = 'http_csrf'; |
$_testns = 'http_csrf'; |
20 |
20 |
|
|
21 |
|
prepare_http(); |
|
22 |
|
|
|
23 |
|
test_set_ua("user-agent-1"); |
|
24 |
21 |
rg_test_create_user($db, $rg_ui); |
rg_test_create_user($db, $rg_ui); |
|
22 |
|
$info = array('id' => $rg_ui['username'], 'ua' => 'user-agent-1'); |
|
23 |
|
prepare_http($info); |
|
24 |
|
|
25 |
25 |
$r = test_login($test_url, $rg_ui); |
$r = test_login($test_url, $rg_ui); |
26 |
26 |
if ($r === FALSE) { |
if ($r === FALSE) { |
27 |
27 |
rg_log("Cannot login!"); |
rg_log("Cannot login!"); |
|
... |
... |
if ($r === FALSE) { |
29 |
29 |
} |
} |
30 |
30 |
|
|
31 |
31 |
rg_log_enter("Loading suggestion form (referer test)"); |
rg_log_enter("Loading suggestion form (referer test)"); |
32 |
|
test_set_ua("user-agent-1"); |
|
33 |
|
test_set_referer($test_url); |
|
|
32 |
|
$info['ua'] = 'user-agent-1'; |
|
33 |
|
$info['referer'] = $test_url; |
34 |
34 |
$data = array(); |
$data = array(); |
35 |
35 |
$headers = array(); |
$headers = array(); |
36 |
|
$r = do_req($test_url . "/op/suggestion?t=load_suggestion_form_referer", $data, $headers); |
|
|
36 |
|
$r = do_req($info, $test_url . "/op/suggestion?t=load_suggestion_form_referer", $data, $headers); |
37 |
37 |
if (!stristr($r['body'], "action=\"/op/suggestion\"")) { |
if (!stristr($r['body'], "action=\"/op/suggestion\"")) { |
38 |
38 |
rg_log("Cannot load form! See above."); |
rg_log("Cannot load form! See above."); |
39 |
39 |
exit(1); |
exit(1); |
|
... |
... |
$good_logout_token = $r['tokens']['logout']; |
43 |
43 |
rg_log_exit(); |
rg_log_exit(); |
44 |
44 |
|
|
45 |
45 |
rg_log_enter("Try posting with different referer: should not work"); |
rg_log_enter("Try posting with different referer: should not work"); |
46 |
|
test_set_ua("user-agent-1"); |
|
47 |
|
test_set_referer("http://attacker.com:4000/bla"); |
|
|
46 |
|
$info['ua'] = 'user-agent-1'; |
|
47 |
|
$info['referer'] = 'http://attacker.com:4000/bla'; |
48 |
48 |
$data = array( |
$data = array( |
49 |
49 |
"doit" => 1, |
"doit" => 1, |
50 |
50 |
"token" => $good_token, |
"token" => $good_token, |
51 |
51 |
"suggestion" => "bla bla bla" |
"suggestion" => "bla bla bla" |
52 |
52 |
); |
); |
53 |
53 |
$headers = array(); |
$headers = array(); |
54 |
|
$r = do_req($test_url . "/op/suggestion?t=post_suggestion_form_diff_referer", $data, $headers); |
|
|
54 |
|
$r = do_req($info, $test_url . "/op/suggestion?t=post_suggestion_form_diff_referer", $data, $headers); |
55 |
55 |
if (!stristr($r['body'], "invalid referer")) { |
if (!stristr($r['body'], "invalid referer")) { |
56 |
56 |
rg_log_ml("Seems I could add a suggestion bypassing CSRF" |
rg_log_ml("Seems I could add a suggestion bypassing CSRF" |
57 |
57 |
. " protection based on referer! See above."); |
. " protection based on referer! See above."); |
|
... |
... |
rg_log_exit(); |
61 |
61 |
|
|
62 |
62 |
|
|
63 |
63 |
rg_log_enter("Testing logout CSRF (wrong token)..."); |
rg_log_enter("Testing logout CSRF (wrong token)..."); |
64 |
|
test_set_ua("user-agent-1"); |
|
65 |
|
test_set_referer($test_url); |
|
|
64 |
|
$info['ua'] = 'user-agent-1'; |
|
65 |
|
$info['referer'] = $test_url; |
66 |
66 |
$data['token'] = strtoupper($good_token); |
$data['token'] = strtoupper($good_token); |
67 |
67 |
$headers = array(); |
$headers = array(); |
68 |
|
$r = do_req($test_url . "/op/logout?t=wrong_token", $data, $headers); |
|
|
68 |
|
$r = do_req($info, $test_url . "/op/logout?t=wrong_token", $data, $headers); |
69 |
69 |
if (stristr($r['body'], "You are now logged out")) { |
if (stristr($r['body'], "You are now logged out")) { |
70 |
70 |
rg_log("No error on logout with wrong token?! See above."); |
rg_log("No error on logout with wrong token?! See above."); |
71 |
71 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_exit(); |
75 |
75 |
|
|
76 |
76 |
/* TODO setting cookie does not work! |
/* TODO setting cookie does not work! |
77 |
77 |
rg_log_enter("Testing logout CSRF (token passed in cookie)..."); |
rg_log_enter("Testing logout CSRF (token passed in cookie)..."); |
78 |
|
test_set_ua("user-agent-1"); |
|
79 |
|
test_set_referer($test_url); |
|
|
78 |
|
$info['ua'] = 'user-agent-1'; |
|
79 |
|
$info['referer'] = $test_url; |
80 |
80 |
$headers = array('Cookie: token=' . $good_logout_token); |
$headers = array('Cookie: token=' . $good_logout_token); |
81 |
81 |
$data = array('doit' => 1); |
$data = array('doit' => 1); |
82 |
|
$r = do_req($test_url . "/op/logout?t=token_passed_by_cookie", $data, $headers); |
|
|
82 |
|
$r = do_req($info, $test_url . "/op/logout?t=token_passed_by_cookie", $data, $headers); |
83 |
83 |
if (stristr($r['body'], "You are now logged out")) { |
if (stristr($r['body'], "You are now logged out")) { |
84 |
84 |
rg_log("No error on logout with token passed by cookie?! See above."); |
rg_log("No error on logout with token passed by cookie?! See above."); |
85 |
85 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_exit(); |
89 |
89 |
|
|
90 |
90 |
|
|
91 |
91 |
rg_log_enter("Testing logout CSRF (good token)..."); |
rg_log_enter("Testing logout CSRF (good token)..."); |
92 |
|
test_set_ua("user-agent-1"); |
|
|
92 |
|
$info['ua'] = 'user-agent-1'; |
93 |
93 |
$url = $test_url . "/op/logout?t=good_token&token=" . $good_logout_token; |
$url = $test_url . "/op/logout?t=good_token&token=" . $good_logout_token; |
94 |
94 |
$data = array(); $headers = array(); |
$data = array(); $headers = array(); |
95 |
|
$r = do_req($url, $data, $headers); |
|
|
95 |
|
$r = do_req($info, $url, $data, $headers); |
96 |
96 |
if (!stristr($r['body'], "You are now logged out")) { |
if (!stristr($r['body'], "You are now logged out")) { |
97 |
97 |
rg_log("Seems I cannot logout with a good token! See above."); |
rg_log("Seems I cannot logout with a good token! See above."); |
98 |
98 |
exit(1); |
exit(1); |
99 |
99 |
} |
} |
100 |
100 |
rg_log_exit(); |
rg_log_exit(); |
101 |
101 |
|
|
102 |
|
rg_log("OK!"); |
|
103 |
|
?> |
|
|
102 |
|
rg_log('OK!'); |
File tests/http_settings.php changed (mode: 100644) (index 533023a..2434dae) |
... |
... |
require_once("common.php"); |
19 |
19 |
$_testns = 'http_settings'; |
$_testns = 'http_settings'; |
20 |
20 |
|
|
21 |
21 |
|
|
22 |
|
prepare_http(); |
|
23 |
|
|
|
24 |
22 |
$now = time(); |
$now = time(); |
25 |
23 |
|
|
26 |
24 |
rg_log_enter("Testing if caching works: cache_enable=" . ($rg_cache_enable ? "true" : "false")); |
rg_log_enter("Testing if caching works: cache_enable=" . ($rg_cache_enable ? "true" : "false")); |
|
... |
... |
rg_log_exit(); |
43 |
41 |
test_restore($db); |
test_restore($db); |
44 |
42 |
|
|
45 |
43 |
rg_test_create_user($db, $rg_ui); |
rg_test_create_user($db, $rg_ui); |
|
44 |
|
$info = array('id' => $rg_ui['username']); |
|
45 |
|
prepare_http($info); |
|
46 |
|
|
46 |
47 |
$r = test_login($test_url, $rg_ui); |
$r = test_login($test_url, $rg_ui); |
47 |
48 |
if ($r === FALSE) { |
if ($r === FALSE) { |
48 |
49 |
rg_log("Cannot login!"); |
rg_log("Cannot login!"); |
|
... |
... |
rg_log(''); |
53 |
54 |
rg_log_enter("Loading change pass form"); |
rg_log_enter("Loading change pass form"); |
54 |
55 |
$data = array(); |
$data = array(); |
55 |
56 |
$headers = array(); |
$headers = array(); |
56 |
|
$r = do_req($test_url . "/op/settings/change_pass?t=load_change_pass_form", $data, $headers); |
|
|
57 |
|
$r = do_req($info, $test_url . "/op/settings/change_pass?t=load_change_pass_form", $data, $headers); |
57 |
58 |
if (!strstr($r['body'], "action=\"/op/settings/change_pass\"")) { |
if (!strstr($r['body'], "action=\"/op/settings/change_pass\"")) { |
58 |
59 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
59 |
60 |
rg_log("Cannot load change pass form!"); |
rg_log("Cannot load change pass form!"); |
|
... |
... |
$data = array( |
72 |
73 |
"pass2" => "bbbb" |
"pass2" => "bbbb" |
73 |
74 |
); |
); |
74 |
75 |
$headers = array(); |
$headers = array(); |
75 |
|
$r = do_req($test_url . "/op/settings/change_pass?t=post_change_pass_form", $data, $headers); |
|
|
76 |
|
$r = do_req($info, $test_url . "/op/settings/change_pass?t=post_change_pass_form", $data, $headers); |
76 |
77 |
if (!strstr($r['body'], "Password has been successfully updated")) { |
if (!strstr($r['body'], "Password has been successfully updated")) { |
77 |
78 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
78 |
79 |
rg_log("Cannot change pass!"); |
rg_log("Cannot change pass!"); |
|
... |
... |
rg_log(''); |
96 |
97 |
rg_log_enter('Change back the password'); |
rg_log_enter('Change back the password'); |
97 |
98 |
$data = array(); |
$data = array(); |
98 |
99 |
$headers = array(); |
$headers = array(); |
99 |
|
$r = do_req($test_url . "/op/settings/change_pass?t=load_change_pass_form", $data, $headers); |
|
|
100 |
|
$r = do_req($info, $test_url . "/op/settings/change_pass?t=load_change_pass_form", $data, $headers); |
100 |
101 |
if (!strstr($r['body'], "action=\"/op/settings/change_pass\"")) { |
if (!strstr($r['body'], "action=\"/op/settings/change_pass\"")) { |
101 |
102 |
rg_log("Cannot load change pass form!"); |
rg_log("Cannot load change pass form!"); |
102 |
103 |
exit(1); |
exit(1); |
|
... |
... |
$data = array( |
110 |
111 |
"pass2" => $rg_ui['pass'] |
"pass2" => $rg_ui['pass'] |
111 |
112 |
); |
); |
112 |
113 |
$headers = array(); |
$headers = array(); |
113 |
|
$r = do_req($test_url . "/op/settings/change_pass?t=change_back_the_password", $data, $headers); |
|
|
114 |
|
$r = do_req($info, $test_url . "/op/settings/change_pass?t=change_back_the_password", $data, $headers); |
114 |
115 |
if ($r === FALSE) { |
if ($r === FALSE) { |
115 |
116 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
116 |
117 |
rg_log("Cannot change back the pass to aaaa!"); |
rg_log("Cannot change back the pass to aaaa!"); |
|
... |
... |
rg_log(''); |
126 |
127 |
rg_log_enter('Loading edit info form'); |
rg_log_enter('Loading edit info form'); |
127 |
128 |
$data = array(); |
$data = array(); |
128 |
129 |
$headers = array(); |
$headers = array(); |
129 |
|
$r = do_req($test_url . "/op/settings/edit_info?t=load_edit_info_form", $data, $headers); |
|
|
130 |
|
$r = do_req($info, $test_url . "/op/settings/edit_info?t=load_edit_info_form", $data, $headers); |
130 |
131 |
if ($r === FALSE) { |
if ($r === FALSE) { |
131 |
132 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
132 |
133 |
rg_log("Cannot load form!"); |
rg_log("Cannot load form!"); |
|
... |
... |
$data = array( |
147 |
148 |
"session_time" => $session_time |
"session_time" => $session_time |
148 |
149 |
); |
); |
149 |
150 |
$headers = array(); |
$headers = array(); |
150 |
|
$r = do_req($test_url . "/op/settings/edit_info?t=post_edit_info_form", $data, $headers); |
|
|
151 |
|
$r = do_req($info, $test_url . "/op/settings/edit_info?t=post_edit_info_form", $data, $headers); |
151 |
152 |
if (!strstr($r['body'], "Information has been successfully updated")) { |
if (!strstr($r['body'], "Information has been successfully updated")) { |
152 |
153 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
153 |
154 |
rg_log("Cannot change account info!"); |
rg_log("Cannot change account info!"); |
|
... |
... |
rg_log_enter('Now, testing deletion: key_id=' . $key_id); |
206 |
207 |
rg_log("Loading ssh keys form"); |
rg_log("Loading ssh keys form"); |
207 |
208 |
$data = array(); |
$data = array(); |
208 |
209 |
$headers = array(); |
$headers = array(); |
209 |
|
$r = do_req($test_url . "/op/settings/keys?t=load_key_form_del", $data, $headers); |
|
|
210 |
|
$r = do_req($info, $test_url . "/op/settings/keys?t=load_key_form_del", $data, $headers); |
210 |
211 |
if ($r === FALSE) { |
if ($r === FALSE) { |
211 |
212 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
212 |
213 |
rg_log("Cannot load ssh key form!"); |
rg_log("Cannot load ssh key form!"); |
|
... |
... |
if ($r === FALSE) { |
215 |
216 |
rg_log("Posting delete keys form"); |
rg_log("Posting delete keys form"); |
216 |
217 |
$data = array("delete" => 1, "token" => $r['tokens']['keys'], "key_delete_ids[$key_id]" => "on"); |
$data = array("delete" => 1, "token" => $r['tokens']['keys'], "key_delete_ids[$key_id]" => "on"); |
217 |
218 |
$headers = array(); |
$headers = array(); |
218 |
|
$r = do_req($test_url . "/op/settings/keys?t=post_key_form_del", $data, $headers); |
|
|
219 |
|
$r = do_req($info, $test_url . "/op/settings/keys?t=post_key_form_del", $data, $headers); |
219 |
220 |
if (!strstr($r['body'], "success")) { |
if (!strstr($r['body'], "success")) { |
220 |
221 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
221 |
222 |
rg_log("Cannot delete key!"); |
rg_log("Cannot delete key!"); |
|
... |
... |
if ($rows == 1) { |
232 |
233 |
} |
} |
233 |
234 |
rg_log_exit(); |
rg_log_exit(); |
234 |
235 |
|
|
235 |
|
rg_log("OK!"); |
|
236 |
|
?> |
|
|
236 |
|
rg_log('OK!'); |
File tests/http_totp.php changed (mode: 100644) (index f7dd98e..8aea6ee) |
... |
... |
$_testns = 'http_totp'; |
25 |
25 |
|
|
26 |
26 |
$rg_user_max_len = 60; |
$rg_user_max_len = 60; |
27 |
27 |
|
|
28 |
|
prepare_http(); |
|
29 |
|
|
|
30 |
28 |
rg_test_create_user($db, $rg_ui); |
rg_test_create_user($db, $rg_ui); |
|
29 |
|
$info = array('id' => $rg_ui['username']); |
|
30 |
|
prepare_http($info); |
|
31 |
|
|
31 |
32 |
|
|
32 |
33 |
// Add an totp token to this account |
// Add an totp token to this account |
33 |
34 |
$key = 'ACHCBCCVQ7AK4RGM'; |
$key = 'ACHCBCCVQ7AK4RGM'; |
|
... |
... |
$lt = rg_totp_compute($key, time() / 30, 6); |
45 |
46 |
// We provide an old cookie to test if we generate a new pre-login one |
// We provide an old cookie to test if we generate a new pre-login one |
46 |
47 |
rg_log(''); |
rg_log(''); |
47 |
48 |
rg_log_enter('Loading login form...'); |
rg_log_enter('Loading login form...'); |
48 |
|
$r = do_req($test_url . "/op/login", $data, $headers); |
|
|
49 |
|
$r = do_req($info, $test_url . "/op/login", $data, $headers); |
49 |
50 |
if ($r === FALSE) { |
if ($r === FALSE) { |
50 |
51 |
rg_log("Cannot load login form."); |
rg_log("Cannot load login form."); |
51 |
52 |
exit(1); |
exit(1); |
|
... |
... |
$data = array( |
64 |
65 |
"login_token" => '', |
"login_token" => '', |
65 |
66 |
"lock_ip" => 0); |
"lock_ip" => 0); |
66 |
67 |
$headers = array(); |
$headers = array(); |
67 |
|
$r = do_req($test_url . "/op/login", $data, $headers); |
|
|
68 |
|
$r = do_req($info, $test_url . "/op/login", $data, $headers); |
68 |
69 |
if ($r === FALSE) { |
if ($r === FALSE) { |
69 |
70 |
rg_log_ml('r=' . print_r($r, TRUE)); |
rg_log_ml('r=' . print_r($r, TRUE)); |
70 |
71 |
rg_log("Cannot login!"); |
rg_log("Cannot login!"); |
|
... |
... |
$data = array( |
89 |
90 |
"login_token" => $lt, |
"login_token" => $lt, |
90 |
91 |
"lock_ip" => 0); |
"lock_ip" => 0); |
91 |
92 |
$headers = array(); |
$headers = array(); |
92 |
|
$r = do_req($test_url . "/op/login", $data, $headers); |
|
|
93 |
|
$r = do_req($info, $test_url . "/op/login", $data, $headers); |
93 |
94 |
if ($r === FALSE) { |
if ($r === FALSE) { |
94 |
95 |
rg_log_ml('r=' . print_r($r, TRUE)); |
rg_log_ml('r=' . print_r($r, TRUE)); |
95 |
96 |
rg_log("Cannot login!"); |
rg_log("Cannot login!"); |
|
... |
... |
if (strstr($r['body'], "invalid user")) { |
103 |
104 |
rg_log_exit(); |
rg_log_exit(); |
104 |
105 |
|
|
105 |
106 |
|
|
106 |
|
$r = totp_enroll($db); |
|
|
107 |
|
$r = totp_enroll($db, $info); |
107 |
108 |
if ($r['ok'] !== 1) |
if ($r['ok'] !== 1) |
108 |
109 |
exit(1); |
exit(1); |
109 |
110 |
|
|
|
... |
... |
while (($row = rg_sql_fetch_array($res))) { |
122 |
123 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
123 |
124 |
rg_log_ml('list=' . print_r($list, TRUE)); |
rg_log_ml('list=' . print_r($list, TRUE)); |
124 |
125 |
|
|
125 |
|
$r = totp_scratch_delete($list); |
|
|
126 |
|
$r = totp_scratch_delete($info, $list); |
126 |
127 |
if ($r['ok'] !== 1) |
if ($r['ok'] !== 1) |
127 |
128 |
exit(1); |
exit(1); |
128 |
129 |
$sql = "SELECT DISTINCT itime FROM scratch_codes WHERE uid = " . $rg_ui['uid']; |
$sql = "SELECT DISTINCT itime FROM scratch_codes WHERE uid = " . $rg_ui['uid']; |
|
... |
... |
if (count($list) < 2) { |
173 |
174 |
} |
} |
174 |
175 |
rg_log('Loading list devices form...'); |
rg_log('Loading list devices form...'); |
175 |
176 |
$data = array(); |
$data = array(); |
176 |
|
$r = do_req($test_url . "/op/settings/totp/list", $data, $headers); |
|
|
177 |
|
$r = do_req($info, $test_url . "/op/settings/totp/list", $data, $headers); |
177 |
178 |
if ($r === FALSE) { |
if ($r === FALSE) { |
178 |
179 |
rg_log("Cannot load list devices form."); |
rg_log("Cannot load list devices form."); |
179 |
180 |
exit(1); |
exit(1); |
|
... |
... |
$data = array( 'delete' => 1, 'token' => $good_token); |
183 |
184 |
foreach ($list as $id) |
foreach ($list as $id) |
184 |
185 |
$data['delete_list[' . $id . ']'] = 'on'; |
$data['delete_list[' . $id . ']'] = 'on'; |
185 |
186 |
$headers = array(); |
$headers = array(); |
186 |
|
$r = do_req($test_url . "/op/settings/totp/list", $data, $headers); |
|
|
187 |
|
$r = do_req($info, $test_url . "/op/settings/totp/list", $data, $headers); |
187 |
188 |
if (!strstr($r['body'], 'success')) { |
if (!strstr($r['body'], 'success')) { |
188 |
189 |
rg_log("Cannot delete login tokens!"); |
rg_log("Cannot delete login tokens!"); |
189 |
190 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_exit(); |
208 |
209 |
|
|
209 |
210 |
|
|
210 |
211 |
rg_prof_log(); |
rg_prof_log(); |
211 |
|
rg_log("OK!"); |
|
212 |
|
?> |
|
|
212 |
|
rg_log('OK!'); |
File tests/ldap.php changed (mode: 100644) (index 2d117ed..5731afe) |
... |
... |
function clean($log) |
73 |
73 |
} |
} |
74 |
74 |
|
|
75 |
75 |
|
|
76 |
|
prepare_http(); |
|
77 |
|
|
|
78 |
76 |
$rg_ui = array('is_admin' => 1); |
$rg_ui = array('is_admin' => 1); |
79 |
77 |
rg_test_create_user($db, $rg_ui); |
rg_test_create_user($db, $rg_ui); |
|
78 |
|
$info = array('id' => $rg_ui['username']); |
|
79 |
|
prepare_http($info); |
|
80 |
|
|
80 |
81 |
$r = test_login($test_url, $rg_ui); |
$r = test_login($test_url, $rg_ui); |
81 |
82 |
if ($r === FALSE) { |
if ($r === FALSE) { |
82 |
|
rg_log("Cannot login!"); |
|
|
83 |
|
rg_log('Cannot login!'); |
83 |
84 |
exit(1); |
exit(1); |
84 |
85 |
} |
} |
85 |
86 |
|
|
|
... |
... |
rg_log(''); |
134 |
135 |
rg_log_enter('Loading Admin -> LDAP -> Add...'); |
rg_log_enter('Loading Admin -> LDAP -> Add...'); |
135 |
136 |
$data = array(); |
$data = array(); |
136 |
137 |
$headers = array(); |
$headers = array(); |
137 |
|
$r = do_req($test_url . '/op/admin/ldap/add', $data, $headers); |
|
|
138 |
|
$r = do_req($info, $test_url . '/op/admin/ldap/add', $data, $headers); |
138 |
139 |
if ($r === FALSE) { |
if ($r === FALSE) { |
139 |
140 |
rg_log('Cannot load add page!'); |
rg_log('Cannot load add page!'); |
140 |
141 |
exit(1); |
exit(1); |
|
... |
... |
$data = array( |
169 |
170 |
'ldap::admin_group' => 'cn=(Admins|Admins2),ou=Group,dc=my-domain,dc=com', |
'ldap::admin_group' => 'cn=(Admins|Admins2),ou=Group,dc=my-domain,dc=com', |
170 |
171 |
'ldap::ca_cert' => '' |
'ldap::ca_cert' => '' |
171 |
172 |
); |
); |
172 |
|
$r = do_req($test_url . '/op/admin/ldap/add', $data, $headers); |
|
|
173 |
|
$r = do_req($info, $test_url . '/op/admin/ldap/add', $data, $headers); |
173 |
174 |
if (!strstr($r['body'], 'LDAP server has been successfully added/edited.')) { |
if (!strstr($r['body'], 'LDAP server has been successfully added/edited.')) { |
174 |
175 |
rg_log_ml('body: ' . $r['body']); |
rg_log_ml('body: ' . $r['body']); |
175 |
176 |
rg_log('Success message not found!'); |
rg_log('Success message not found!'); |
|
... |
... |
rg_log(''); |
182 |
183 |
rg_log_enter('Loading Admin -> LDAP -> List...'); |
rg_log_enter('Loading Admin -> LDAP -> List...'); |
183 |
184 |
$data = array(); |
$data = array(); |
184 |
185 |
$headers = array(); |
$headers = array(); |
185 |
|
$r = do_req($test_url . '/op/admin/ldap/list', $data, $headers); |
|
|
186 |
|
$r = do_req($info, $test_url . '/op/admin/ldap/list', $data, $headers); |
186 |
187 |
if ($r === FALSE) { |
if ($r === FALSE) { |
187 |
188 |
rg_log('Cannot load list page!'); |
rg_log('Cannot load list page!'); |
188 |
189 |
exit(1); |
exit(1); |
|
... |
... |
if ($r['ok'] !== 1) { |
248 |
249 |
exit(1); |
exit(1); |
249 |
250 |
} |
} |
250 |
251 |
$found = FALSE; |
$found = FALSE; |
251 |
|
foreach ($r['list'] as $id => $info) { |
|
252 |
|
if (strcmp($info['url'], 'ldap://' . $bind_addr . ':' . $bind_port) != 0) |
|
|
252 |
|
foreach ($r['list'] as $id => $i) { |
|
253 |
|
if (strcmp($i['url'], 'ldap://' . $bind_addr . ':' . $bind_port) != 0) |
253 |
254 |
continue; |
continue; |
254 |
255 |
|
|
255 |
256 |
$found = TRUE; |
$found = TRUE; |
|
... |
... |
if ($r === FALSE) { |
444 |
445 |
rg_log_exit(); |
rg_log_exit(); |
445 |
446 |
|
|
446 |
447 |
|
|
447 |
|
rg_log(''); |
|
448 |
|
rg_log_enter('Login again as the admin user...'); |
|
449 |
|
$r = test_login($test_url, $rg_ui); |
|
450 |
|
if ($r === FALSE) { |
|
451 |
|
rg_log("Cannot login!"); |
|
452 |
|
exit(1); |
|
453 |
|
} |
|
454 |
|
rg_log_exit(); |
|
455 |
|
|
|
456 |
|
|
|
457 |
448 |
rg_log(''); |
rg_log(''); |
458 |
449 |
rg_log_enter('Loading Admin -> LDAP -> List -> [Edit]...'); |
rg_log_enter('Loading Admin -> LDAP -> List -> [Edit]...'); |
459 |
450 |
$data = array(); |
$data = array(); |
460 |
451 |
$headers = array(); |
$headers = array(); |
461 |
|
$r = do_req($test_url . '/op/admin/ldap/edit/' . $id, $data, $headers); |
|
|
452 |
|
$r = do_req($info, $test_url . '/op/admin/ldap/edit/' . $id, $data, $headers); |
462 |
453 |
if ($r === FALSE) { |
if ($r === FALSE) { |
463 |
454 |
rg_log('Cannot load edit page!'); |
rg_log('Cannot load edit page!'); |
464 |
455 |
exit(1); |
exit(1); |
465 |
456 |
} |
} |
|
457 |
|
if (!isset($r['tokens']['ldap_add'])) { |
|
458 |
|
rg_log('Cannot find ldap_add token!'); |
|
459 |
|
exit(1); |
|
460 |
|
} |
466 |
461 |
$token = $r['tokens']['ldap_add']; |
$token = $r['tokens']['ldap_add']; |
467 |
462 |
rg_log_exit(); |
rg_log_exit(); |
468 |
463 |
|
|
|
... |
... |
$data = array( |
490 |
485 |
'ldap::ca_cert' => 'ca_cert' |
'ldap::ca_cert' => 'ca_cert' |
491 |
486 |
); |
); |
492 |
487 |
$headers = array(); |
$headers = array(); |
493 |
|
$r = do_req($test_url . '/op/admin/ldap/add', $data, $headers); |
|
|
488 |
|
$r = do_req($info, $test_url . '/op/admin/ldap/add', $data, $headers); |
494 |
489 |
if ($r === FALSE) { |
if ($r === FALSE) { |
495 |
490 |
rg_log('Cannot load edit page!'); |
rg_log('Cannot load edit page!'); |
496 |
491 |
exit(1); |
exit(1); |
|
... |
... |
$res = rg_sql_query($db, $sql); |
505 |
500 |
$row = rg_sql_fetch_array($res); |
$row = rg_sql_fetch_array($res); |
506 |
501 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
507 |
502 |
$key = 'ldap::list::' . $id; |
$key = 'ldap::list::' . $id; |
508 |
|
$c = test_wait_cache($key); |
|
|
503 |
|
$c = test_wait_cache($key, 50); |
509 |
504 |
foreach ($data as $k => $v) { |
foreach ($data as $k => $v) { |
510 |
505 |
// ignore some fields |
// ignore some fields |
511 |
506 |
if (strncmp($k, 'ldap::', 6) != 0) |
if (strncmp($k, 'ldap::', 6) != 0) |
|
... |
... |
rg_log(''); |
551 |
546 |
rg_log_enter('Loading Admin -> LDAP -> List (for delete)...'); |
rg_log_enter('Loading Admin -> LDAP -> List (for delete)...'); |
552 |
547 |
$data = array(); |
$data = array(); |
553 |
548 |
$headers = array(); |
$headers = array(); |
554 |
|
$r = do_req($test_url . '/op/admin/ldap/list', $data, $headers); |
|
|
549 |
|
$r = do_req($info, $test_url . '/op/admin/ldap/list', $data, $headers); |
555 |
550 |
if ($r === FALSE) { |
if ($r === FALSE) { |
556 |
551 |
rg_log('Cannot load list page!'); |
rg_log('Cannot load list page!'); |
557 |
552 |
exit(1); |
exit(1); |
|
... |
... |
$data = array( |
568 |
563 |
'delete_list[' . $id . ']' => 'on' |
'delete_list[' . $id . ']' => 'on' |
569 |
564 |
); |
); |
570 |
565 |
$headers = array(); |
$headers = array(); |
571 |
|
$r = do_req($test_url . '/op/admin/ldap/list', $data, $headers); |
|
|
566 |
|
$r = do_req($info, $test_url . '/op/admin/ldap/list', $data, $headers); |
572 |
567 |
if ($r === FALSE) { |
if ($r === FALSE) { |
573 |
568 |
rg_log('Cannot load list page!'); |
rg_log('Cannot load list page!'); |
574 |
569 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_exit(); |
582 |
577 |
|
|
583 |
578 |
|
|
584 |
579 |
rg_log('OK!'); |
rg_log('OK!'); |
585 |
|
?> |
|
File tests/mr.inc.php changed (mode: 100644) (index f597016..5e5075f) |
... |
... |
function test_mr_check($db, $t, $rg_ui, $repo, $mr_id, $mr_refname, $expect_ff) |
11 |
11 |
|
|
12 |
12 |
rg_log_enter('test_mr_check'); |
rg_log_enter('test_mr_check'); |
13 |
13 |
|
|
|
14 |
|
$info = array('id' => $rg_ui['username']); |
|
15 |
|
|
14 |
16 |
$url = '/user/' . $rg_ui['username'] . '/' . $repo['name'] . '/mr'; |
$url = '/user/' . $rg_ui['username'] . '/' . $repo['name'] . '/mr'; |
15 |
17 |
|
|
16 |
18 |
rg_log_enter('Check if merge is in db and is against correct branch...'); |
rg_log_enter('Check if merge is in db and is against correct branch...'); |
|
... |
... |
function test_mr_check($db, $t, $rg_ui, $repo, $mr_id, $mr_refname, $expect_ff) |
27 |
29 |
rg_log_enter('Loading the merge requests page - just to see it appears there'); |
rg_log_enter('Loading the merge requests page - just to see it appears there'); |
28 |
30 |
$data = array(); |
$data = array(); |
29 |
31 |
$headers = array(); |
$headers = array(); |
30 |
|
$r = do_req($test_url . $url . '?t=' . $t, $data, $headers); |
|
|
32 |
|
$r = do_req($info, $test_url . $url . '?t=' . $t, $data, $headers); |
31 |
33 |
if (!strstr($r['body'], '>' . $mri['id'] . '<')) { |
if (!strstr($r['body'], '>' . $mri['id'] . '<')) { |
32 |
34 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
33 |
35 |
rg_log('id link not found!'); |
rg_log('id link not found!'); |
|
... |
... |
function test_mr_check($db, $t, $rg_ui, $repo, $mr_id, $mr_refname, $expect_ff) |
40 |
42 |
rg_log_enter('Loading the merge request specific page...'); |
rg_log_enter('Loading the merge request specific page...'); |
41 |
43 |
$data = array(); |
$data = array(); |
42 |
44 |
$headers = array(); |
$headers = array(); |
43 |
|
$r = do_req($test_url . $url . '/' . $mri['id'] . '?t=' . $t, $data, $headers); |
|
|
45 |
|
$r = do_req($info, $test_url . $url . '/' . $mri['id'] . '?t=' . $t, $data, $headers); |
44 |
46 |
if (!strstr($r['body'], 'This merge request can be merged without conflicts')) { |
if (!strstr($r['body'], 'This merge request can be merged without conflicts')) { |
45 |
47 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
46 |
48 |
rg_log('Merge request does not appear as mergeable'); |
rg_log('Merge request does not appear as mergeable'); |
|
... |
... |
function test_mr_check($db, $t, $rg_ui, $repo, $mr_id, $mr_refname, $expect_ff) |
54 |
56 |
$mm1 = 'This is the merge message <xss>' . rg_id(8); |
$mm1 = 'This is the merge message <xss>' . rg_id(8); |
55 |
57 |
$data = array('token' => $r['tokens']['mr_merge'], |
$data = array('token' => $r['tokens']['mr_merge'], |
56 |
58 |
'merge_ff' => 0, 'merge_msg' => $mm1); |
'merge_ff' => 0, 'merge_msg' => $mm1); |
57 |
|
$r = do_req($test_url . $url . '/' . $mri['id'] . '/merge', $data, $headers); |
|
|
59 |
|
$r = do_req($info, $test_url . $url . '/' . $mri['id'] . '/merge', $data, $headers); |
58 |
60 |
if ($r === FALSE) { |
if ($r === FALSE) { |
59 |
61 |
rg_log('Cannot post merge form'); |
rg_log('Cannot post merge form'); |
60 |
62 |
exit(1); |
exit(1); |
File tests/pr_anon.php changed (mode: 100644) (index 078a698..8046a9a) |
... |
... |
require_once("common.php"); |
22 |
22 |
$_testns = 'pr_anon'; |
$_testns = 'pr_anon'; |
23 |
23 |
|
|
24 |
24 |
|
|
25 |
|
prepare_http(); |
|
26 |
|
|
|
27 |
25 |
rg_test_create_user($db, $rg_ui); |
rg_test_create_user($db, $rg_ui); |
|
26 |
|
$info = array('id' => $rg_ui['username']); |
|
27 |
|
prepare_http($info); |
28 |
28 |
|
|
29 |
29 |
|
|
30 |
30 |
rg_log(''); |
rg_log(''); |
|
... |
... |
rg_log_exit(); |
39 |
39 |
|
|
40 |
40 |
rg_test_upload_ssh_key($db, $rg_ui, 'pr_anon', $kn); |
rg_test_upload_ssh_key($db, $rg_ui, 'pr_anon', $kn); |
41 |
41 |
|
|
42 |
|
$ssh = 'ssh -o ControlMaster=no -o IdentityFile=../../keys/' . $kn |
|
43 |
|
. ' -o IdentitiesOnly=yes'; |
|
44 |
|
putenv('GIT_SSH_COMMAND=' . $ssh); |
|
45 |
42 |
|
|
46 |
43 |
rg_log(''); |
rg_log(''); |
47 |
44 |
rg_log_enter('Creating a repo'); |
rg_log_enter('Creating a repo'); |
|
... |
... |
rg_log_enter('Do a non-anonymous push...'); |
100 |
97 |
file_put_contents('temp_repos/pr_anon/change2.txt', "change2 desc\n\nthis is the body\nline 2 of body"); |
file_put_contents('temp_repos/pr_anon/change2.txt', "change2 desc\n\nthis is the body\nline 2 of body"); |
101 |
98 |
file_put_contents('temp_repos/pr_anon/change3.txt', "change3 desc\n\nthis is the body\nline 2 of body"); |
file_put_contents('temp_repos/pr_anon/change3.txt', "change3 desc\n\nthis is the body\nline 2 of body"); |
102 |
99 |
$r = rg_exec('cd temp_repos/pr_anon' |
$r = rg_exec('cd temp_repos/pr_anon' |
103 |
|
. ' && echo "change2" > a && git add a && git commit -F change2.txt' |
|
|
100 |
|
. ' && echo "change2" > a && git commit -a -F change2.txt' |
104 |
101 |
. ' && echo "change3" > a && git commit -a -F change3.txt' |
. ' && echo "change3" > a && git commit -a -F change3.txt' |
105 |
102 |
. ' && git push origin_ssh master', |
. ' && git push origin_ssh master', |
106 |
103 |
'', FALSE, FALSE, FALSE); |
'', FALSE, FALSE, FALSE); |
|
... |
... |
rg_log_exit(); |
113 |
110 |
|
|
114 |
111 |
rg_log(''); |
rg_log(''); |
115 |
112 |
rg_log_enter('Do an anonymous push into a non-empty repo...'); |
rg_log_enter('Do an anonymous push into a non-empty repo...'); |
116 |
|
putenv('GIT_SSH_COMMAND='); |
|
117 |
113 |
file_put_contents('temp_repos/pr_anon/change4.txt', "anon change4 desc\n\nthis is the body\nline 2 of body"); |
file_put_contents('temp_repos/pr_anon/change4.txt', "anon change4 desc\n\nthis is the body\nline 2 of body"); |
118 |
114 |
file_put_contents('temp_repos/pr_anon/change5.txt', "anon change5 desc\n\nthis is the body\nline 2 of body"); |
file_put_contents('temp_repos/pr_anon/change5.txt', "anon change5 desc\n\nthis is the body\nline 2 of body"); |
119 |
115 |
$r = rg_exec('cd temp_repos/pr_anon' |
$r = rg_exec('cd temp_repos/pr_anon' |
120 |
|
. ' && echo "change4" >> a && git add a' |
|
121 |
|
. ' && git commit -F change4.txt' |
|
122 |
|
. ' && echo "change5" >> a; git commit -a -F change5.txt' |
|
|
116 |
|
. ' && echo "change4" >> a && git commit -a -F change4.txt' |
|
117 |
|
. ' && echo "change5" >> a && git commit -a -F change5.txt' |
123 |
118 |
. ' && git push origin_git master', |
. ' && git push origin_git master', |
124 |
119 |
'', FALSE, FALSE, FALSE); |
'', FALSE, FALSE, FALSE); |
125 |
120 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
|
... |
... |
test_mr_check($db, $_testns, $rg_ui, $repo, 2, 'refs/heads/master', FALSE); |
133 |
128 |
|
|
134 |
129 |
|
|
135 |
130 |
rg_log(''); |
rg_log(''); |
136 |
|
rg_log_enter('Now, try to see what happens when a merge is with conflicts...'); |
|
|
131 |
|
rg_log_enter('Now, try to see what happens when a merge is with conflicts (this is mr 3)...'); |
137 |
132 |
$r = rg_exec('cd temp_repos/pr_anon' |
$r = rg_exec('cd temp_repos/pr_anon' |
138 |
|
. ' && echo "change2" > a' |
|
139 |
|
. ' && git commit -a -m "conflict1b"' |
|
|
133 |
|
. ' && echo "change2" > a && git commit -a -m "conflict1b"' |
140 |
134 |
. ' && git push origin_git master', |
. ' && git push origin_git master', |
141 |
135 |
'', FALSE, FALSE, FALSE); |
'', FALSE, FALSE, FALSE); |
142 |
136 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
143 |
137 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
144 |
|
rg_log('Could not pull/commit/push by git proto: ' . $r['errmsg'] . '!'); |
|
|
138 |
|
rg_log('Could not push by git proto: ' . $r['errmsg'] . '!'); |
145 |
139 |
exit(1); |
exit(1); |
146 |
140 |
} |
} |
147 |
|
putenv('GIT_SSH_COMMAND=' . $ssh); |
|
148 |
|
$r = rg_exec('cd temp_repos/pr_anon' |
|
149 |
|
. ' && git reset --hard HEAD^1' |
|
150 |
|
. ' && echo "change1" > a' |
|
151 |
|
. ' && echo "commit" && git commit -a -m "conflict1a"' |
|
152 |
|
. ' && echo "push" && strace -s200 -f -tt -o pr_anon.strace git push origin_ssh master', |
|
153 |
|
'', FALSE, FALSE, FALSE); |
|
154 |
|
if ($r['ok'] != 1) { |
|
155 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
156 |
|
rg_log('Could not reset/commit/push by ssh proto: ' . $r['errmsg'] . '!'); |
|
157 |
|
exit(1); |
|
|
141 |
|
chdir('temp_repos/pr_anon'); |
|
142 |
|
$list = array( |
|
143 |
|
'git reset --hard HEAD^1', |
|
144 |
|
'echo "change1" > a', |
|
145 |
|
'git commit -a -m "conflict1a"', |
|
146 |
|
'git push origin_ssh master' |
|
147 |
|
); |
|
148 |
|
foreach ($list as $cmd) { |
|
149 |
|
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
|
150 |
|
if ($r['ok'] != 1) { |
|
151 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
152 |
|
rg_log('Could not run [' . $cmd . ']: ' . $r['errmsg'] . '!'); |
|
153 |
|
exit(1); |
|
154 |
|
} |
158 |
155 |
} |
} |
|
156 |
|
chdir('../..'); |
159 |
157 |
$mri = rg_test_mr_info($db, $repo['repo_id'], 3); |
$mri = rg_test_mr_info($db, $repo['repo_id'], 3); |
160 |
158 |
$data = array(); |
$data = array(); |
161 |
159 |
$headers = array(); |
$headers = array(); |
162 |
|
$r = do_req($test_url . $url . $mri['id'] . '?t=pr_anon', $data, $headers); |
|
|
160 |
|
$r = do_req($info, $test_url . $url . $mri['id'] . '?t=pr_anon', $data, $headers); |
163 |
161 |
if (!strstr($r['body'], 'This merge request cannot be merged without conflicts')) { |
if (!strstr($r['body'], 'This merge request cannot be merged without conflicts')) { |
164 |
162 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
165 |
163 |
rg_log('Merge request appears as mergeable and should not!'); |
rg_log('Merge request appears as mergeable and should not!'); |
File tests/source.php changed (mode: 100644) (index 0f181ce..4b5906b) |
... |
... |
require_once("common.php"); |
18 |
18 |
$_testns = 'source'; |
$_testns = 'source'; |
19 |
19 |
|
|
20 |
20 |
|
|
21 |
|
prepare_http(); |
|
22 |
|
|
|
23 |
21 |
rg_test_create_user($db, $rg_ui); |
rg_test_create_user($db, $rg_ui); |
24 |
|
rg_log('Created user ' . $rg_ui['uid']); |
|
|
22 |
|
$info = array('id' => $rg_ui['username']); |
|
23 |
|
prepare_http($info); |
|
24 |
|
|
25 |
25 |
rg_test_create_repo($db, $rg_ui, $repo); |
rg_test_create_repo($db, $rg_ui, $repo); |
26 |
|
rg_log('Created repo ' . $repo['repo_id']); |
|
|
26 |
|
|
27 |
27 |
$r = test_login($test_url, $rg_ui); |
$r = test_login($test_url, $rg_ui); |
28 |
28 |
if ($r === FALSE) { |
if ($r === FALSE) { |
29 |
29 |
rg_log("Cannot login!"); |
rg_log("Cannot login!"); |
|
... |
... |
if ($r === FALSE) { |
32 |
32 |
|
|
33 |
33 |
|
|
34 |
34 |
rg_test_upload_ssh_key($db, $rg_ui, 'source', $kn); |
rg_test_upload_ssh_key($db, $rg_ui, 'source', $kn); |
35 |
|
putenv('GIT_SSH_COMMAND=ssh -v -o ControlMaster=no -o IdentityFile=../../keys/' |
|
36 |
|
. $kn . ' -o IdentitiesOnly=yes'); |
|
37 |
35 |
|
|
38 |
36 |
|
|
39 |
37 |
rg_log(''); |
rg_log(''); |
40 |
38 |
rg_log_enter('Trying to load source/log for an empty repo...'); |
rg_log_enter('Trying to load source/log for an empty repo...'); |
41 |
39 |
$data = array(); |
$data = array(); |
42 |
40 |
$headers = array(); |
$headers = array(); |
43 |
|
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username']) |
|
|
41 |
|
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username']) |
44 |
42 |
. '/' . rawurlencode($repo['name']) . '/source/log', |
. '/' . rawurlencode($repo['name']) . '/source/log', |
45 |
43 |
$data, $headers); |
$data, $headers); |
46 |
44 |
if (!strstr($r['body'], 'This repo contains no commits.')) { |
if (!strstr($r['body'], 'This repo contains no commits.')) { |
|
... |
... |
if ($r['ok'] != 1) { |
71 |
69 |
$data = array(); |
$data = array(); |
72 |
70 |
$headers = array(); |
$headers = array(); |
73 |
71 |
rg_log('Check "log" menu...'); |
rg_log('Check "log" menu...'); |
74 |
|
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username']) |
|
|
72 |
|
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username']) |
75 |
73 |
. '/' . rawurlencode($repo['name']) . '/source/log', |
. '/' . rawurlencode($repo['name']) . '/source/log', |
76 |
74 |
$data, $headers); |
$data, $headers); |
77 |
75 |
// TODO: can func ever return FALSE? Change everywhere! |
// TODO: can func ever return FALSE? Change everywhere! |
|
... |
... |
if (!strstr($r['body'], $cmsg)) { |
85 |
83 |
exit(1); |
exit(1); |
86 |
84 |
} |
} |
87 |
85 |
rg_log('Check "Tree" menu...'); |
rg_log('Check "Tree" menu...'); |
88 |
|
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username']) |
|
|
86 |
|
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username']) |
89 |
87 |
. '/' . rawurlencode($repo['name']) . '/source/tree', |
. '/' . rawurlencode($repo['name']) . '/source/tree', |
90 |
88 |
$data, $headers); |
$data, $headers); |
91 |
89 |
if ($r === FALSE) { |
if ($r === FALSE) { |
|
... |
... |
if ($r['ok'] != 1) { |
122 |
120 |
$data = array(); |
$data = array(); |
123 |
121 |
$headers = array(); |
$headers = array(); |
124 |
122 |
rg_log('Check "Tree" menu...'); |
rg_log('Check "Tree" menu...'); |
125 |
|
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username']) |
|
|
123 |
|
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username']) |
126 |
124 |
. '/' . rawurlencode($repo['name']) . '/source/tree', |
. '/' . rawurlencode($repo['name']) . '/source/tree', |
127 |
125 |
$data, $headers); |
$data, $headers); |
128 |
126 |
if ($r === FALSE) { |
if ($r === FALSE) { |
|
... |
... |
$url = substr($_x[0], $p + 9, -1); |
151 |
149 |
$data = array(); |
$data = array(); |
152 |
150 |
$headers = array(); |
$headers = array(); |
153 |
151 |
rg_log('Check "Tree" menu (dir ' . $d . ')...'); |
rg_log('Check "Tree" menu (dir ' . $d . ')...'); |
154 |
|
$r = do_req($test_url . $url, $data, $headers); |
|
|
152 |
|
$r = do_req($info, $test_url . $url, $data, $headers); |
155 |
153 |
if ($r === FALSE) { |
if ($r === FALSE) { |
156 |
154 |
rg_log('Cannot load source/tree page!'); |
rg_log('Cannot load source/tree page!'); |
157 |
155 |
exit(1); |
exit(1); |
|
... |
... |
rg_log(''); |
168 |
166 |
rg_log_enter('Loading blob page...'); |
rg_log_enter('Loading blob page...'); |
169 |
167 |
$data = array(); |
$data = array(); |
170 |
168 |
$headers = array(); |
$headers = array(); |
171 |
|
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username']) |
|
|
169 |
|
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username']) |
172 |
170 |
. '/' . rawurlencode($repo['name']) . '/source/tree/branch/master' |
. '/' . rawurlencode($repo['name']) . '/source/tree/branch/master' |
173 |
171 |
. '/blob/' . rawurlencode($d) . '/' . rawurlencode($f), |
. '/blob/' . rawurlencode($d) . '/' . rawurlencode($f), |
174 |
172 |
$data, $headers); |
$data, $headers); |
|
... |
... |
if (!strstr($r['body'], 'aÈ™')) { |
185 |
183 |
rg_log_enter('Downloading blob...'); |
rg_log_enter('Downloading blob...'); |
186 |
184 |
$data = array(); |
$data = array(); |
187 |
185 |
$headers = array(); |
$headers = array(); |
188 |
|
$r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username']) |
|
|
186 |
|
$r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username']) |
189 |
187 |
. '/' . rawurlencode($repo['name']) . '/source/tree/branch/master' |
. '/' . rawurlencode($repo['name']) . '/source/tree/branch/master' |
190 |
188 |
. '/blob_download/' . rawurlencode($d) . '/' . rawurlencode($f) . '?format=raw', |
. '/blob_download/' . rawurlencode($d) . '/' . rawurlencode($f) . '?format=raw', |
191 |
189 |
$data, $headers); |
$data, $headers); |
File tests/wh_http.php changed (mode: 100644) (index 7a25a0a..b0079b7) |
... |
... |
require_once("common.php"); |
18 |
18 |
$_testns = 'wh_http'; |
$_testns = 'wh_http'; |
19 |
19 |
|
|
20 |
20 |
|
|
21 |
|
$port1 = 64000 + (rand(0, 100000) + time()) % 1000; |
|
22 |
|
$port2 = $port1 + 1; |
|
23 |
|
$port3 = $port2 + 1; |
|
24 |
|
rg_log('port1=' . $port1 . ' port2=' . $port2 . ' port3=' . $port3); |
|
|
21 |
|
$ports = array(); |
|
22 |
|
$ports[1] = 64000 + (rand(0, 100000) + time()) % 1000; |
|
23 |
|
$ports[2] = $ports[1] + 1; |
|
24 |
|
$ports[3] = $ports[2] + 1; |
|
25 |
|
rg_log('ports=' . rg_array2string($ports)); |
25 |
26 |
|
|
26 |
27 |
function clean() |
function clean() |
27 |
28 |
{ |
{ |
|
... |
... |
function clean() |
30 |
31 |
rg_exec('fuser -k -9 wh-stunnel-' . $id . '.log', '', FALSE, FALSE, FALSE); |
rg_exec('fuser -k -9 wh-stunnel-' . $id . '.log', '', FALSE, FALSE, FALSE); |
31 |
32 |
} |
} |
32 |
33 |
|
|
33 |
|
prepare_http(); |
|
34 |
|
|
|
35 |
34 |
rg_log(''); |
rg_log(''); |
36 |
35 |
rg_log('Generating certificates...'); |
rg_log('Generating certificates...'); |
37 |
36 |
$r = rg_exec('./ca.sh wh', '', FALSE, FALSE, FALSE); |
$r = rg_exec('./ca.sh wh', '', FALSE, FALSE, FALSE); |
|
... |
... |
if ($x === FALSE) { |
50 |
49 |
exit(1); |
exit(1); |
51 |
50 |
} |
} |
52 |
51 |
|
|
53 |
|
$y = str_replace('@@port@@', $port1, $x); |
|
54 |
|
$y = str_replace('@@verify@@', '2', $y); |
|
55 |
|
$y = str_replace('@@id@@', '1', $y); |
|
56 |
|
$y = str_replace('@@cwd@@', __DIR__, $y); |
|
57 |
|
file_put_contents('wh-stunnel.conf-1.tmp', $y); |
|
58 |
|
|
|
59 |
|
$y = str_replace('@@port@@', $port2, $x); |
|
60 |
|
$y = str_replace('@@verify@@', '2', $y); |
|
61 |
|
$y = str_replace('@@id@@', '2', $y); |
|
62 |
|
$y = str_replace('@@cwd@@', __DIR__, $y); |
|
63 |
|
file_put_contents('wh-stunnel.conf-2.tmp', $y); |
|
64 |
|
|
|
65 |
|
$y = str_replace('@@port@@', $port3, $x); |
|
66 |
|
$y = str_replace('@@verify@@', '0', $y); |
|
67 |
|
$y = str_replace('@@id@@', '3', $y); |
|
68 |
|
$y = str_replace('@@cwd@@', __DIR__, $y); |
|
69 |
|
file_put_contents('wh-stunnel.conf-3.tmp', $y); |
|
70 |
|
|
|
71 |
52 |
|
|
72 |
53 |
rg_log(''); |
rg_log(''); |
73 |
|
rg_log('Starting stunnel1...'); |
|
74 |
|
$pid = pcntl_fork(); |
|
75 |
|
if ($pid == -1) { |
|
76 |
|
rg_log('Cannot fork'); |
|
77 |
|
exit(1); |
|
78 |
|
} |
|
79 |
|
if ($pid == 0) { //child |
|
80 |
|
rg_log_set_file('wh-stunnel-1-rg.log'); |
|
81 |
|
rg_exec('stunnel wh-stunnel.conf-1.tmp 1>wh-stunnel-1-1.log 2>wh-stunnel-1-2.log', |
|
82 |
|
'', FALSE, FALSE, FALSE); |
|
83 |
|
exit(0); |
|
84 |
|
} |
|
85 |
|
rg_log('Started stunnel with pid ' . $pid); |
|
86 |
|
|
|
87 |
|
|
|
88 |
|
rg_log(''); |
|
89 |
|
rg_log('Starting stunnel2...'); |
|
90 |
|
$pid = pcntl_fork(); |
|
91 |
|
if ($pid == -1) { |
|
92 |
|
rg_log('Cannot fork'); |
|
93 |
|
exit(1); |
|
94 |
|
} |
|
95 |
|
if ($pid == 0) { //child |
|
96 |
|
rg_log_set_file('wh-stunnel-2-rg.log'); |
|
97 |
|
rg_exec('stunnel wh-stunnel.conf-2.tmp 1>wh-stunnel-2-1.log 2>wh-stunnel-2-2.log', |
|
98 |
|
'', FALSE, FALSE, FALSE); |
|
99 |
|
exit(0); |
|
100 |
|
} |
|
101 |
|
rg_log('Started stunnel with pid ' . $pid); |
|
102 |
|
|
|
103 |
|
|
|
104 |
|
rg_log(''); |
|
105 |
|
rg_log('Starting stunnel3...'); |
|
106 |
|
$pid = pcntl_fork(); |
|
107 |
|
if ($pid == -1) { |
|
108 |
|
rg_log('Cannot fork'); |
|
109 |
|
exit(1); |
|
110 |
|
} |
|
111 |
|
if ($pid == 0) { //child |
|
112 |
|
rg_log_set_file('wh-stunnel-3-rg.log'); |
|
113 |
|
rg_exec('stunnel wh-stunnel.conf-3.tmp 1>wh-stunnel-3-1.log 2>wh-stunnel-3-2.log', |
|
|
54 |
|
rg_log_enter('starting stunnels...'); |
|
55 |
|
for ($i = 1; $i <= 3; $i++) { |
|
56 |
|
rg_log('Starting stunnel' . $i . '..'); |
|
57 |
|
|
|
58 |
|
// Only stunnel 3 verify the cert |
|
59 |
|
$verify = ($i == 3) ? 0 : 2; |
|
60 |
|
|
|
61 |
|
$y = str_replace('@@port@@', $ports[$i], $x); |
|
62 |
|
$y = str_replace('@@verify@@', $verify, $y); |
|
63 |
|
$y = str_replace('@@id@@', $i, $y); |
|
64 |
|
$y = str_replace('@@cwd@@', __DIR__, $y); |
|
65 |
|
file_put_contents('wh-stunnel.conf-' . $i . '.tmp', $y); |
|
66 |
|
|
|
67 |
|
$pid = pcntl_fork(); |
|
68 |
|
if ($pid == -1) { |
|
69 |
|
rg_log('Cannot fork'); |
|
70 |
|
exit(1); |
|
71 |
|
} |
|
72 |
|
if ($pid == 0) { //child |
|
73 |
|
rg_log_set_file('wh-stunnel-' . $i . '-rg.log'); |
|
74 |
|
rg_exec('stunnel wh-stunnel.conf-' . $i . '.tmp' |
|
75 |
|
. ' 1>wh-stunnel-' . $i . '-1.log' |
|
76 |
|
. ' 2>wh-stunnel-' . $i . '-2.log', |
114 |
77 |
'', FALSE, FALSE, FALSE); |
'', FALSE, FALSE, FALSE); |
115 |
|
exit(0); |
|
|
78 |
|
exit(0); |
|
79 |
|
} |
|
80 |
|
rg_log('Started stunnel with pid ' . $pid); |
116 |
81 |
} |
} |
117 |
|
rg_log('Started stunnel with pid ' . $pid); |
|
118 |
|
|
|
|
82 |
|
rg_log_exit(); |
119 |
83 |
|
|
120 |
84 |
register_shutdown_function('clean'); |
register_shutdown_function('clean'); |
121 |
85 |
|
|
122 |
86 |
rg_log(''); |
rg_log(''); |
123 |
|
rg_log("Creating a user..."); |
|
|
87 |
|
$rg_ui = array('confirmed' => 20); |
124 |
88 |
rg_test_create_user($db, $rg_ui); |
rg_test_create_user($db, $rg_ui); |
125 |
|
$key1 = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $port1; |
|
126 |
|
$key2 = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $port2; |
|
127 |
|
$key3 = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $port3; |
|
|
89 |
|
$info = array('id' => $rg_ui['username']); |
|
90 |
|
prepare_http($info); |
|
91 |
|
|
|
92 |
|
|
|
93 |
|
$key1 = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $ports[1]; |
|
94 |
|
$key2 = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $ports[2]; |
|
95 |
|
$key3 = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $ports[3]; |
128 |
96 |
|
|
129 |
97 |
|
|
130 |
98 |
rg_log(''); |
rg_log(''); |
|
... |
... |
if ($r === FALSE) { |
139 |
107 |
rg_log(''); |
rg_log(''); |
140 |
108 |
rg_log('Registering webhook1...'); |
rg_log('Registering webhook1...'); |
141 |
109 |
$extra = array( |
$extra = array( |
142 |
|
'wh::htype' => 'http', |
|
143 |
|
'wh::hsubtype' => 'generic', |
|
144 |
110 |
'wh::description' => 'description1 <xss>', |
'wh::description' => 'description1 <xss>', |
145 |
111 |
'wh::repo' => '', |
'wh::repo' => '', |
146 |
112 |
'wh::refname' => '', |
'wh::refname' => '', |
147 |
|
'wh::idata::url' => 'https://localhost:' . $port1 . '/wh.html', |
|
|
113 |
|
'wh::idata::url' => 'https://localhost:' . $ports[1] . '/wh.html', |
148 |
114 |
'wh::idata::events[C]' => 'on', |
'wh::idata::events[C]' => 'on', |
149 |
115 |
'wh::idata::events[P]' => 'on', |
'wh::idata::events[P]' => 'on', |
150 |
116 |
'wh::idata::events[B]' => 'on', |
'wh::idata::events[B]' => 'on', |
151 |
117 |
'wh::idata::key' => 'key1 <xss>', |
'wh::idata::key' => 'key1 <xss>', |
152 |
|
'wh::idata::opaque' => $port1, |
|
|
118 |
|
'wh::idata::opaque' => $ports[1], |
153 |
119 |
'wh::idata::client_cert' => '', |
'wh::idata::client_cert' => '', |
154 |
120 |
'wh::idata::itype' => 0, |
'wh::idata::itype' => 0, |
155 |
121 |
'wh::idata::client_ca_cert' => file_get_contents('ca/wh/certs/cacert.pem') |
'wh::idata::client_ca_cert' => file_get_contents('ca/wh/certs/cacert.pem') |
|
... |
... |
$extra = array( |
165 |
131 |
'wh::description' => 'description1 <xss>', |
'wh::description' => 'description1 <xss>', |
166 |
132 |
'wh::repo' => '', |
'wh::repo' => '', |
167 |
133 |
'wh::refname' => '', |
'wh::refname' => '', |
168 |
|
'wh::idata::url' => 'https://localhost:' . $port2 . '/wh.html', |
|
|
134 |
|
'wh::idata::url' => 'https://localhost:' . $ports[2] . '/wh.html', |
169 |
135 |
'wh::idata::events[C]' => 'on', |
'wh::idata::events[C]' => 'on', |
170 |
136 |
'wh::idata::events[P]' => 'on', |
'wh::idata::events[P]' => 'on', |
171 |
137 |
'wh::idata::events[B]' => 'on', |
'wh::idata::events[B]' => 'on', |
172 |
138 |
'wh::idata::key' => 'key2 <xss>', |
'wh::idata::key' => 'key2 <xss>', |
173 |
|
'wh::idata::opaque' => $port2, |
|
|
139 |
|
'wh::idata::opaque' => $ports[2], |
174 |
140 |
'wh::idata::itype' => 1, |
'wh::idata::itype' => 1, |
175 |
141 |
'wh::idata::client_cert' => file_get_contents('ca/wh/certs/client.pem') |
'wh::idata::client_cert' => file_get_contents('ca/wh/certs/client.pem') |
176 |
142 |
. file_get_contents('ca/wh/private/client.key'), |
. file_get_contents('ca/wh/private/client.key'), |
|
... |
... |
rg_test_wh_add_edit($db, $rg_ui, 'http', 'generic', $extra); |
182 |
148 |
rg_log(''); |
rg_log(''); |
183 |
149 |
rg_log('Registering webhook3...'); |
rg_log('Registering webhook3...'); |
184 |
150 |
$extra = array( |
$extra = array( |
185 |
|
'wh::htype' => 'http', |
|
186 |
|
'wh::hsubtype' => 'generic', |
|
187 |
151 |
'wh::description' => 'description1 <xss>', |
'wh::description' => 'description1 <xss>', |
188 |
152 |
'wh::repo' => '', |
'wh::repo' => '', |
189 |
153 |
'wh::refname' => '', |
'wh::refname' => '', |
190 |
|
'wh::idata::url' => 'https://localhost:' . $port3 . '/wh.html', |
|
|
154 |
|
'wh::idata::url' => 'https://localhost:' . $ports[3] . '/wh.html', |
191 |
155 |
'wh::idata::events[C]' => 'on', |
'wh::idata::events[C]' => 'on', |
192 |
156 |
'wh::idata::events[P]' => 'on', |
'wh::idata::events[P]' => 'on', |
193 |
157 |
'wh::idata::events[B]' => 'on', |
'wh::idata::events[B]' => 'on', |
194 |
158 |
'wh::idata::key' => 'key2 <xss>', |
'wh::idata::key' => 'key2 <xss>', |
195 |
|
'wh::idata::opaque' => $port3, |
|
|
159 |
|
'wh::idata::opaque' => $ports[3], |
196 |
160 |
'wh::idata::itype' => 2, |
'wh::idata::itype' => 2, |
197 |
161 |
'wh::idata::custom_body' => 'This is the custom_body commit=##commit## ip=##ip##', |
'wh::idata::custom_body' => 'This is the custom_body commit=##commit## ip=##ip##', |
198 |
162 |
'wh::idata::client_cert' => '', |
'wh::idata::client_cert' => '', |
|
... |
... |
rg_test_wh_add_edit($db, $rg_ui, 'http', 'generic', $extra); |
202 |
166 |
|
|
203 |
167 |
|
|
204 |
168 |
rg_log('Finding out the ids...'); |
rg_log('Finding out the ids...'); |
205 |
|
$r = test_wait_cache('wh' . '::' . $rg_ui['uid']); |
|
|
169 |
|
$r = test_wait_cache('wh' . '::' . $rg_ui['uid'], 50); |
206 |
170 |
rg_log_ml('r=' . print_r($r, TRUE)); |
rg_log_ml('r=' . print_r($r, TRUE)); |
207 |
171 |
$t = array_keys($r['list']); |
$t = array_keys($r['list']); |
208 |
172 |
if (count($t) != 3) { |
if (count($t) != 3) { |
|
... |
... |
rg_test_create_repo($db, $rg_ui, $repo); |
225 |
189 |
|
|
226 |
190 |
rg_log(''); |
rg_log(''); |
227 |
191 |
rg_log_enter('Testing if the curl posted with success (wh1) (should not work)'); |
rg_log_enter('Testing if the curl posted with success (wh1) (should not work)'); |
228 |
|
$r = test_wait_cache($key1 . '::' . $wh_id1); |
|
|
192 |
|
$r = test_wait_cache($key1 . '::' . $wh_id1, 50); |
229 |
193 |
if (strcmp($r, "BAD") != 0) { |
if (strcmp($r, "BAD") != 0) { |
230 |
194 |
$_k = 'wh::' . $rg_ui['uid'] . '::list::' . $wh_id1 . '::last_output'; |
$_k = 'wh::' . $rg_ui['uid'] . '::list::' . $wh_id1 . '::last_output'; |
231 |
|
$_e = test_wait_cache($_k); |
|
|
195 |
|
$_e = test_wait_cache($_k, 50); |
232 |
196 |
rg_log_ml('_e:' . $_e); |
rg_log_ml('_e:' . $_e); |
233 |
197 |
rg_log('Seems wh1 executed correctly without client' |
rg_log('Seems wh1 executed correctly without client' |
234 |
198 |
. ' cert (r=' . $r . ')!'); |
. ' cert (r=' . $r . ')!'); |
|
... |
... |
rg_log_exit(); |
239 |
203 |
|
|
240 |
204 |
rg_log(''); |
rg_log(''); |
241 |
205 |
rg_log_enter('Testing if the curl posted with success (wh2) (should work)'); |
rg_log_enter('Testing if the curl posted with success (wh2) (should work)'); |
242 |
|
$r = test_wait_cache($key2 . '::' . $wh_id2); |
|
|
206 |
|
$r = test_wait_cache($key2 . '::' . $wh_id2, 50); |
243 |
207 |
if (strcmp($r, "OK") != 0) { |
if (strcmp($r, "OK") != 0) { |
244 |
208 |
$_k = 'wh::' . $rg_ui['uid'] . '::list::' . $wh_id2 . '::last_output'; |
$_k = 'wh::' . $rg_ui['uid'] . '::list::' . $wh_id2 . '::last_output'; |
245 |
|
$_e = test_wait_cache($_k); |
|
|
209 |
|
$_e = test_wait_cache($_k, 50); |
246 |
210 |
rg_log_ml('_e:' . $_e); |
rg_log_ml('_e:' . $_e); |
247 |
211 |
rg_log('Seems wh2 did not returned success' |
rg_log('Seems wh2 did not returned success' |
248 |
212 |
. ' (r=' . $r . ')!'); |
. ' (r=' . $r . ')!'); |
|
... |
... |
rg_log_exit(); |
253 |
217 |
|
|
254 |
218 |
rg_log(''); |
rg_log(''); |
255 |
219 |
rg_log_enter('Testing if the curl posted with success (wh3) (should work)'); |
rg_log_enter('Testing if the curl posted with success (wh3) (should work)'); |
256 |
|
$r = test_wait_cache($key3 . '::' . $wh_id3); |
|
|
220 |
|
$r = test_wait_cache($key3 . '::' . $wh_id3, 50); |
257 |
221 |
if (strcmp($r, "OK") != 0) { |
if (strcmp($r, "OK") != 0) { |
258 |
222 |
$_k = 'wh::' . $rg_ui['uid'] . '::list::' . $wh_id3 . '::last_output'; |
$_k = 'wh::' . $rg_ui['uid'] . '::list::' . $wh_id3 . '::last_output'; |
259 |
|
$_e = test_wait_cache($_k); |
|
|
223 |
|
$_e = test_wait_cache($_k, 50); |
260 |
224 |
rg_log_ml('_e:' . $_e); |
rg_log_ml('_e:' . $_e); |
261 |
225 |
rg_log('Seems wh3 did not returned success' |
rg_log('Seems wh3 did not returned success' |
262 |
226 |
. ' (r=' . $r . ')!'); |
. ' (r=' . $r . ')!'); |
|
... |
... |
rg_log(''); |
269 |
233 |
rg_log_enter('Testing the edit of webhook1...'); |
rg_log_enter('Testing the edit of webhook1...'); |
270 |
234 |
$extra = array( |
$extra = array( |
271 |
235 |
'wh::id' => $wh_id1, |
'wh::id' => $wh_id1, |
272 |
|
'wh::htype' => 'http', |
|
273 |
|
'wh::hsubtype' => 'generic', |
|
274 |
236 |
'wh::description' => 'desc2 <xss>', |
'wh::description' => 'desc2 <xss>', |
275 |
237 |
'wh::repo' => '.*', |
'wh::repo' => '.*', |
276 |
238 |
'wh::refname' => '..*', |
'wh::refname' => '..*', |
277 |
239 |
'wh::flags[D]' => 'on', |
'wh::flags[D]' => 'on', |
278 |
|
'wh::idata::url' => 'https://localhost:' . $port1 . '/wh.html', |
|
|
240 |
|
'wh::idata::url' => 'https://localhost:' . $ports[1] . '/wh.html', |
279 |
241 |
'wh::idata::events[C]' => 'on', |
'wh::idata::events[C]' => 'on', |
280 |
242 |
'wh::idata::events[B]' => 'on', |
'wh::idata::events[B]' => 'on', |
281 |
243 |
'wh::idata::key' => 'another key <xss>', |
'wh::idata::key' => 'another key <xss>', |
|
... |
... |
$row = rg_sql_fetch_array($res); |
296 |
258 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
297 |
259 |
$row['idata'] = rg_unserialize($row['idata']); |
$row['idata'] = rg_unserialize($row['idata']); |
298 |
260 |
$key = 'wh' . '::' . $rg_ui['uid'] . '::' . 'list' . '::' . $wh_id1; |
$key = 'wh' . '::' . $rg_ui['uid'] . '::' . 'list' . '::' . $wh_id1; |
299 |
|
$c = test_wait_cache($key); |
|
|
261 |
|
$c = test_wait_cache($key, 50); |
300 |
262 |
$list = array('htype' => 'http', 'events' => 'CB', 'repo' => '.*', |
$list = array('htype' => 'http', 'events' => 'CB', 'repo' => '.*', |
301 |
263 |
'refname' => '..*', |
'refname' => '..*', |
302 |
264 |
'description' => 'desc2 <xss>', 'key' => 'another key <xss>', |
'description' => 'desc2 <xss>', 'key' => 'another key <xss>', |
|
... |
... |
rg_log(''); |
336 |
298 |
rg_log_enter('Testing the delete - loading form...'); |
rg_log_enter('Testing the delete - loading form...'); |
337 |
299 |
$data = array(); |
$data = array(); |
338 |
300 |
$headers = array(); |
$headers = array(); |
339 |
|
$r = do_req($test_url . "/op/settings/wh/list", $data, $headers); |
|
|
301 |
|
$r = do_req($info, $test_url . "/op/settings/wh/list", $data, $headers); |
340 |
302 |
if ($r === FALSE) { |
if ($r === FALSE) { |
341 |
303 |
rg_log("Cannot load list form."); |
rg_log("Cannot load list form."); |
342 |
304 |
exit(1); |
exit(1); |
|
... |
... |
$good_token = $r['tokens']['wh_list']; |
350 |
312 |
$data = array( 'delete' => 1, |
$data = array( 'delete' => 1, |
351 |
313 |
'token' => $good_token, |
'token' => $good_token, |
352 |
314 |
'delete_list[' . $wh_id1 . ']' => 'on'); |
'delete_list[' . $wh_id1 . ']' => 'on'); |
353 |
|
$r = do_req($test_url . "/op/settings/wh/list", $data, $headers); |
|
|
315 |
|
$r = do_req($info, $test_url . "/op/settings/wh/list", $data, $headers); |
354 |
316 |
if (!strstr($r['body'], 'success')) { |
if (!strstr($r['body'], 'success')) { |
355 |
317 |
rg_log_ml('r[body]: ' . print_r($r['body'], TRUE)); |
rg_log_ml('r[body]: ' . print_r($r['body'], TRUE)); |
356 |
318 |
rg_log("Cannot delete webhook!"); |
rg_log("Cannot delete webhook!"); |