List of commits:
Subject Hash Author Date (UTC)
Lots of tests updated 40e01f4db4d341d4e2dceb4407ea7d6ff523ac9e Catalin(ux) M. BOIE 2021-10-21 06:00:02
Big changes to add rpm packages repositories 5e07ff440d6ad7f0ef9900a634b2f39f0e7fa1e4 Catalin(ux) M. BOIE 2021-10-21 05:59:26
Cosmetic 02376344f7d7d321d824ab7978de2ad49c007167 Catalin(ux) M. BOIE 2021-05-23 12:57:06
Added FIDO2 support for SSH 04186abe13896ad4f4ea7126691d0a2b1798de1a Catalin(ux) M. BOIE 2021-05-23 12:30:43
ssh: show the id of the key both on web and when connecting ab95ccfa2819d6ac9f427209ee61c75aad8a3661 Catalin(ux) M. BOIE 2021-05-23 10:52:44
Some events are doing some queries, and we need to cover them in transaction, not only the subevents 4768ffec303961971cc0c3732a24e858f47dd381 Catalin(ux) M. BOIE 2020-12-15 07:33:36
Added rate limit for ssh and git connections b667130e6c5721a3d30193863a5defd8bbff50f1 Catalin(ux) M. BOIE 2020-11-30 10:49:27
cosmetic abe44edadda9da7c639b7bd8c9e13e6058555669 Catalin(ux) M. BOIE 2020-11-30 10:21:01
gpg functions and test ecb9e05c99a2b73edfba5014329e362d8c6e9246 Catalin(ux) M. BOIE 2020-11-09 07:38:11
Stats page is not rendered for bots. 29ca3f62ac460b64eb0a10fbb8bdfdf4a1767dc5 Catalin(ux) M. BOIE 2020-10-13 05:48:43
Added rate limit options 60e939a52577a01603f9f386ffaf1a9712f99ab6 Catalin(ux) M. BOIE 2020-10-07 05:02:25
Improved bots list and clean old entries 9da0a014040753734beabfecb298b8956fc25fe3 Catalin(ux) M. BOIE 2020-10-05 06:34:43
builder: use secrets only if available 4fe47afc60435508ad90f62c51d489ac3c20b4d0 Catalin(ux) M. BOIE 2020-08-28 07:29:14
worker: use secrets only if available 5371e918e294a46cc38c765371a1caf7a3083eef Catalin(ux) M. BOIE 2020-08-28 07:28:12
builder: do not break meta variable 1d8207b1a782ab039406dbd087cdc9bb5ea0b898 Catalin(ux) M. BOIE 2020-08-28 07:27:48
Whitespace 86086337c5323b073f517bc59c18aba0808fb4f3 Catalin(ux) M. BOIE 2020-08-24 07:22:13
Bump version to 0.73 7cac4d7a31116ac9ad86e0babeb0c1aace5dd852 Catalin(ux) M. BOIE 2020-08-23 15:32:03
duilder update f691d84aa0aa70ef60a7487f247ed1a9ab1e3ab1 Catalin(ux) M. BOIE 2020-08-23 15:31:38
Bot prevention should not be active for edit operation 371c60a486ea989fafb66266cab71ea9f7db0269 Catalin(ux) M. BOIE 2020-08-23 15:02:13
TODO update 32591f3b1cf054bd70411592e5a82f5898d7da2f Catalin(ux) M. BOIE 2020-08-23 15:01:51
Commit 40e01f4db4d341d4e2dceb4407ea7d6ff523ac9e - Lots of tests updated
Author: Catalin(ux) M. BOIE
Author date (UTC): 2021-10-21 06:00
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2021-10-21 06:00
Parent(s): 5e07ff440d6ad7f0ef9900a634b2f39f0e7fa1e4
Signer:
Signing key:
Signing status: N
Tree: e232a94d012e2d54ef69f68437ebf8dc856f8fa1
File Lines added Lines deleted
tests/.gitignore 1 1
tests/_run_tests.sh 1 1
tests/admin_set_git.php 4 5
tests/admin_set_web.php 5 5
tests/by_http.php 5 6
tests/common.php 2 1
tests/email.php 2 2
tests/git.php 11 1
tests/git2.php 8 8
tests/git_log1.expected 2 2
tests/helpers.inc.php 348 14
tests/hook_update_help.php 1 2
tests/http.inc.php 63 59
tests/http_304.php 13 4
tests/http_admin.php 7 6
tests/http_api.php 9 8
tests/http_bug.php 41 35
tests/http_confirm.php 10 9
tests/http_create_account.php 6 4
tests/http_csrf.php 18 19
tests/http_forgot.php 8 9
tests/http_keys.php 7 6
tests/http_login.php 12 17
tests/http_settings.php 12 12
tests/http_top.php 4 3
tests/http_totp.php 11 11
tests/keys.php 6 5
tests/ldap.php 18 24
tests/mr.inc.php 5 3
tests/pr_anon.php 24 26
tests/prof.php 4 4
tests/repo.php 2 2
tests/rights.php 1 1
tests/source.php 11 13
tests/ssh.php 4 2
tests/totp.inc.php 6 6
tests/user.php 1 1
tests/util.php 35 4
tests/wh_cloud.php 7 12
tests/wh_http.php 57 95
tests/wh_lambda.php 5 6
File tests/.gitignore changed (mode: 100644) (index 607c80a..5c25c77)
... ... keys/*
21 21 *.pid *.pid
22 22 ca ca
23 23 *.tmp *.tmp
24 wh_cloud.git
25 24 git_log1.final git_log1.final
26 25 hook_update_dest.git hook_update_dest.git
27 26 hook_update_src.git hook_update_src.git
 
... ... _run_tests.failed
31 30 temp_repos temp_repos
32 31 state state
33 32 jars jars
33 tmp
File tests/_run_tests.sh changed (mode: 100755) (index 483d3e2..37456df)
... ... tests="pkg_subrepo pkg_rpm gpg http_api http_304 ldap_core ldap \
9 9 http_admin http_bug http_confirm \ http_admin http_bug http_confirm \
10 10 http_create_account http_login http_settings http_csrf http_top \ http_create_account http_login http_settings http_csrf http_top \
11 11 token util log state cache prof event rights keys user repo git \ token util log state cache prof event rights keys user repo git \
12 bug hook_update git2 source"
12 bug hook_update git2 source wh_build"
13 13
14 14 ts=`date +%s` ts=`date +%s`
15 15 failed="" failed=""
File tests/admin_set_git.php changed (mode: 100644) (index 7b7a291..c25f3d4)
... ... require_once('common.php');
18 18
19 19 $_testns = 'admin_set_git'; $_testns = 'admin_set_git';
20 20
21 prepare_http();
22
23 21 $rg_ui = array('is_admin' => 1); $rg_ui = array('is_admin' => 1);
24 22 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
23 $info = array('id' => $rg_ui['username']);
24 prepare_http($info);
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!");
 
... ... rg_log('');
33 33 rg_log_enter('Loading Admin -> Settings -> Git...'); rg_log_enter('Loading Admin -> Settings -> Git...');
34 34 $data = array(); $data = array();
35 35 $headers = array(); $headers = array();
36 $r = do_req($test_url . '/op/admin/settings/git', $data, $headers);
36 $r = do_req($info, $test_url . '/op/admin/settings/git', $data, $headers);
37 37 if ($r === FALSE) { if ($r === FALSE) {
38 38 rg_log("Cannot load page!"); rg_log("Cannot load page!");
39 39 exit(1); exit(1);
 
... ... foreach ($list as $var => $def) {
64 64 else else
65 65 $data[$var] = $v; $data[$var] = $v;
66 66 } }
67 $r = do_req($test_url . '/op/admin/settings/git', $data, $headers);
67 $r = do_req($info, $test_url . '/op/admin/settings/git', $data, $headers);
68 68 if (!strstr($r['body'], 'Configuration has been successfully saved.')) { if (!strstr($r['body'], 'Configuration has been successfully saved.')) {
69 69 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
70 70 rg_log("Cannot post form (expected answer missing)!"); rg_log("Cannot post form (expected answer missing)!");
 
... ... rg_log_exit();
74 74
75 75
76 76 rg_log('OK!'); rg_log('OK!');
77 ?>
File tests/admin_set_web.php changed (mode: 100644) (index 43600cd..5a8888e)
... ... require_once('common.php');
19 19 $_testns = 'admin_set_web'; $_testns = 'admin_set_web';
20 20
21 21
22 prepare_http();
23
24 22 $rg_ui = array('is_admin' => 1); $rg_ui = array('is_admin' => 1);
25 23 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
24 $info = array('id' => $rg_ui['username']);
25 prepare_http($info);
26
26 27 $r = test_login($test_url, $rg_ui); $r = test_login($test_url, $rg_ui);
27 28 if ($r === FALSE) { if ($r === FALSE) {
28 29 rg_log("Cannot login!"); rg_log("Cannot login!");
 
... ... rg_log('');
34 35 rg_log_enter('Loading Admin -> Settings -> Web...'); rg_log_enter('Loading Admin -> Settings -> Web...');
35 36 $data = array(); $data = array();
36 37 $headers = array(); $headers = array();
37 $r = do_req($test_url . '/op/admin/settings/web', $data, $headers);
38 $r = do_req($info, $test_url . '/op/admin/settings/web', $data, $headers);
38 39 if ($r === FALSE) { if ($r === FALSE) {
39 40 rg_log("Cannot load page!"); rg_log("Cannot load page!");
40 41 exit(1); exit(1);
 
... ... foreach ($list as $var => $def) {
67 68 else else
68 69 $data[$var] = $v; $data[$var] = $v;
69 70 } }
70 $r = do_req($test_url . '/op/admin/settings/web', $data, $headers);
71 $r = do_req($info, $test_url . '/op/admin/settings/web', $data, $headers);
71 72 if (!strstr($r['body'], 'Configuration has been successfully saved.')) { if (!strstr($r['body'], 'Configuration has been successfully saved.')) {
72 73 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
73 74 rg_log("Cannot post form (expected answer missing)!"); rg_log("Cannot post form (expected answer missing)!");
 
... ... rg_log_exit();
77 78
78 79
79 80 rg_log('OK!'); rg_log('OK!');
80 ?>
File tests/by_http.php changed (mode: 100644) (index 4f9797b..4aa80be)
... ... $e_testns = escapeshellarg($_testns);
24 24 $git_push = 'git push --verbose'; $git_push = 'git push --verbose';
25 25
26 26
27 prepare_http();
28
29 27 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
30 rg_log('Created user ' . $rg_ui['uid']);
28 $info = array('id' => $rg_ui['username']);
29 prepare_http($info);
30
31 31
32 32 putenv('git_username=' . $rg_ui['username']); putenv('git_username=' . $rg_ui['username']);
33 33 putenv('git_password=' . $rg_ui['pass']); putenv('git_password=' . $rg_ui['pass']);
 
... ... if ($r['ok'] != 1) {
182 182 rg_log_exit(); rg_log_exit();
183 183
184 184
185 $r = totp_enroll($db);
185 $r = totp_enroll($db, $info);
186 186 if ($r['ok'] !== 1) if ($r['ok'] !== 1)
187 187 exit(1); exit(1);
188 188 $key = $r['key']; $key = $r['key'];
 
... ... rg_log('master from .git: ' . $commit);
250 250 rg_log_enter('Checking on web that everything is OK...'); rg_log_enter('Checking on web that everything is OK...');
251 251 $data = array(); $data = array();
252 252 $headers = array(); $headers = array();
253 $r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username'])
253 $r = do_req($info, $test_url . '/user/' . rawurlencode($rg_ui['username'])
254 254 . '/' . rawurlencode($repo['name']) . '/source/log/commit/' . '/' . rawurlencode($repo['name']) . '/source/log/commit/'
255 255 . $commit, $data, $headers); . $commit, $data, $headers);
256 256 if ($r === FALSE) { if ($r === FALSE) {
 
... ... rg_log_exit();
266 266
267 267
268 268 rg_log('OK!'); rg_log('OK!');
269 ?>
File tests/common.php changed (mode: 100644) (index 6f82cb5..60ab999)
... ... if ($db === FALSE) {
27 27 rg_cache_core_set($db, 'state::hostname', 'rg.embedromix.ro'); rg_cache_core_set($db, 'state::hostname', 'rg.embedromix.ro');
28 28 rg_cache_core_set($db, 'state::http_allow', '9002'); rg_cache_core_set($db, 'state::http_allow', '9002');
29 29 rg_cache_core_set($db, 'state::https_allow', '9003'); rg_cache_core_set($db, 'state::https_allow', '9003');
30
30 $test_url = rg_base_url($db, '', '');
31 31
32 32 // Force debug by setting the settings // Force debug by setting the settings
33 33 $r = rg_state_set($db, 'debug', '1'); $r = rg_state_set($db, 'debug', '1');
 
... ... if ($r === FALSE) {
35 35 rg_internal_error('Cannot set state (debug var)!'); rg_internal_error('Cannot set state (debug var)!');
36 36 exit(1); exit(1);
37 37 } }
38 rg_debug_set(1);
38 39
39 40
40 41 if (isset($rg_no_db) && $rg_no_db) if (isset($rg_no_db) && $rg_no_db)
File tests/email.php changed (mode: 100644) (index 7e0a958..9a39f35)
... ... rg_test_create_user($db, $rg_ui);
27 27 rg_log(''); rg_log('');
28 28 rg_log('Trying to get the cache info...'); rg_log('Trying to get the cache info...');
29 29 $key = 'DEBUG::' . $rg_ui['uid']; $key = 'DEBUG::' . $rg_ui['uid'];
30 $r = test_wait_cache($key);
30 $r = test_wait_cache($key, 50);
31 31 if (!strstr($r['mail']['body'], 'Dear ' . $rg_ui['realname'])) { if (!strstr($r['mail']['body'], 'Dear ' . $rg_ui['realname'])) {
32 32 rg_log_ml('body: ' . print_r($r['mail']['body'], TRUE)); rg_log_ml('body: ' . print_r($r['mail']['body'], TRUE));
33 33 rg_log('realname was specified bu not found in e-mail!'); rg_log('realname was specified bu not found in e-mail!');
 
... ... rg_test_create_user($db, $rg_ui);
44 44 rg_log(''); rg_log('');
45 45 rg_log('Trying to get the cache info...'); rg_log('Trying to get the cache info...');
46 46 $key = 'DEBUG::' . $rg_ui['uid']; $key = 'DEBUG::' . $rg_ui['uid'];
47 $r = test_wait_cache($key);
47 $r = test_wait_cache($key, 50);
48 48 if (!strstr($r['mail']['body'], 'Dear ' . $rg_ui['username'])) { if (!strstr($r['mail']['body'], 'Dear ' . $rg_ui['username'])) {
49 49 rg_log_ml('body: ' . print_r($r['mail']['body'], TRUE)); rg_log_ml('body: ' . print_r($r['mail']['body'], TRUE));
50 50 rg_log('realname was specified bu not found in e-mail!'); rg_log('realname was specified bu not found in e-mail!');
File tests/git.php changed (mode: 100644) (index b6b73f0..a4b691f)
... ... if (!empty($r[2]['files']['a']['chunks'])) {
232 232 rg_log('r[2][files][a][chunks] is not empty and file a has a big diff!'); rg_log('r[2][files][a][chunks] is not empty and file a has a big diff!');
233 233 exit(1); exit(1);
234 234 } }
235 system('rm -rf temp_repos/git_big_diff');
235 $r = rg_git_log2listing($r, $rg, FALSE /*commit_table*/);
236 if (!strstr($r, 'The diff for file <b>a</b> is too big (16 changes) and cannot be shown')) {
237 file_put_contents('git-big-diff.out', $r);
238 rg_log('Message about a big diff1 not found! Check git-big-diff.out file');
239 exit(1);
240 }
241 if (!strstr($r, 'The diff for file <b>a</b> is too big (18 changes) and cannot be shown')) {
242 file_put_contents('git-big-diff.out', $r);
243 rg_log('Message about a big diff2 not found! Check git-big-diff.out file');
244 exit(1);
245 }
236 246 rg_log_exit(); rg_log_exit();
237 247
238 248
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/git_log1.expected changed (mode: 100644) (index 93c2881..b85d313)
43 43 <div class="diff"> <div class="diff">
44 44 <a name="file-uniq-id-e9ead85f4cc2dfffaae3cd00d6f14cb099922f0c"></a> <a name="file-uniq-id-e9ead85f4cc2dfffaae3cd00d6f14cb099922f0c"></a>
45 45 <table class="chunk"> <table class="chunk">
46 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>\1\2\3\4\5\6\a\b\t\n\v\f\r\16\17\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37 !&quot;#$%&amp;&#039;()*+,-.0123456789:;&lt;=&gt;?</b> changed (mode: 100644) (index 72943a1..f761ec1)</td></tr>
46 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>\1\2\3\4\5\6\a\b\t\n\v\f\r\16\17\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37 !&quot;#$%&amp;&apos;()*+,-.0123456789:;&lt;=&gt;?</b> changed (mode: 100644) (index 72943a1..f761ec1)</td></tr>
47 47 1 cl-r aaa cl-e 1 cl-r aaa cl-e
48 48 1 cl-e cl-g bbb 1 cl-e cl-g bbb
49 49 </table> </table>
 
51 51 <div class="diff"> <div class="diff">
52 52 <a name="file-uniq-id-e9ead85f4cc2dfffaae3cd00d6f14cb099922f0c"></a> <a name="file-uniq-id-e9ead85f4cc2dfffaae3cd00d6f14cb099922f0c"></a>
53 53 <table class="chunk"> <table class="chunk">
54 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>\1\2\3\4\5\6\a\b\t\n\v\f\r\16\17\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37 !&quot;#$%&amp;&#039;()*+,-.0123456789:;&lt;=&gt;?</b> copied from file <b>a b c È™</b> (similarity 100%)</td></tr>
54 <tr style="border: 1px; background: #dddddd"><td colspan="4">File <b>\1\2\3\4\5\6\a\b\t\n\v\f\r\16\17\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37 !&quot;#$%&amp;&apos;()*+,-.0123456789:;&lt;=&gt;?</b> copied from file <b>a b c È™</b> (similarity 100%)</td></tr>
55 55 </table> </table>
56 56 </div> </div>
57 57 <div class="diff"> <div class="diff">
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/hook_update_help.php changed (mode: 100644) (index c4bc774..ffdc4e6)
... ... $a['who'] = 400;
51 51 $a['uid'] = $uid; $a['uid'] = $uid;
52 52 $a['rights'] = $rights; $a['rights'] = $rights;
53 53 $a['prio'] = 13; $a['prio'] = 13;
54 $a['ip'] = "";
55 54 $a['misc'] = ""; $a['misc'] = "";
56 55 $a['description'] = "desc <>"; $a['description'] = "desc <>";
56 $a['ip'] = '';
57 57
58 58 rg_log("op=$op"); rg_log("op=$op");
59 59 if (strcmp($op, "init") == 0) { if (strcmp($op, "init") == 0) {
 
... ... if (strcmp($op, "init") == 0) {
109 109
110 110 rg_sql_close($db); rg_sql_close($db);
111 111
112 ?>
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_304.php changed (mode: 100644) (index 3d99dc8..088b707)
... ... require_once('common.php');
18 18
19 19 $_testns = 'http_304'; $_testns = 'http_304';
20 20
21 prepare_http();
21 $info = array('id' => 'http_304');
22 prepare_http($info);
23
22 24
23 25 rg_log(''); rg_log('');
24 26 rg_log_enter('Loading main page to get ETag value...'); rg_log_enter('Loading main page to get ETag value...');
25 27 $data = array(); $headers = array(); $data = array(); $headers = array();
26 $r = do_req($test_url . '/', $data, $headers);
28 $r = do_req($info, $test_url . '/', $data, $headers);
27 29 rg_log_ml('Headers: ' . print_r($r['header'], TRUE)); rg_log_ml('Headers: ' . print_r($r['header'], TRUE));
28 30 $x = explode("\nETag: ", $r['header'], 2); $x = explode("\nETag: ", $r['header'], 2);
31 if (!isset($x[1]))
32 $x = explode("\netag: ", $r['header'], 2);
33 if (!isset($x[1])) {
34 rg_log('ETag/etag not found!');
35 exit(1);
36 }
29 37 $y = explode("\n", $x[1], 2); $y = explode("\n", $x[1], 2);
30 38 $etag = trim($y[0]); $etag = trim($y[0]);
31 39 rg_log_exit(); rg_log_exit();
 
... ... rg_log_exit();
34 42 rg_log(''); rg_log('');
35 43 rg_log_enter('Loading main page...'); rg_log_enter('Loading main page...');
36 44 $data = array(); $headers = array('If-None-Match: ' . $etag); $data = array(); $headers = array('If-None-Match: ' . $etag);
37 $r = do_req($test_url . '/', $data, $headers);
45 $r = do_req($info, $test_url . '/', $data, $headers);
38 46 $x = explode("\n", $r['header'], 2); $x = explode("\n", $r['header'], 2);
39 $x = trim($x[0]);
47 $x = $x[0];
40 48 if (!strstr($x, ' 304 ')) { if (!strstr($x, ' 304 ')) {
41 49 rg_log_ml('headers: ' . print_r($r['header'], TRUE)); rg_log_ml('headers: ' . print_r($r['header'], TRUE));
42 50 rg_log('We did not got 304 answer (but [' . $x . '])!'); rg_log('We did not got 304 answer (but [' . $x . '])!');
 
... ... if (!strstr($x, ' 304 ')) {
44 52 } }
45 53 rg_log_exit(); rg_log_exit();
46 54
55
47 56 rg_log('OK!'); rg_log('OK!');
File tests/http_admin.php changed (mode: 100644) (index f6b57d9..1ec41ec)
... ... $_testns = 'http_admin';
20 20
21 21 $rg_user_max_len = 60; $rg_user_max_len = 60;
22 22
23 prepare_http();
24
25 23 $rg_ui = array('is_admin' => 1); $rg_ui = array('is_admin' => 1);
26 24 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
25 $info = array('id' => $rg_ui['username']);
26 prepare_http($info);
27
27 28
28 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
29 30 // 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
30 $r = do_req($test_url . "/op/login", $data, $headers);
31 $r = do_req($info, $test_url . '/op/login', $data, $headers);
31 32 if ($r === FALSE) { if ($r === FALSE) {
32 33 rg_log("Cannot load login form."); rg_log("Cannot load login form.");
33 34 exit(1); exit(1);
 
... ... $data = array(
48 49 "pass" => $rg_ui['pass'], "pass" => $rg_ui['pass'],
49 50 "lock_ip" => 0); "lock_ip" => 0);
50 51 $headers = array(); $headers = array();
51 $r = do_req($test_url . "/op/login", $data, $headers);
52 $r = do_req($info, $test_url . "/op/login", $data, $headers);
52 53 if ($r === FALSE) { if ($r === FALSE) {
53 54 rg_log_ml("Cannot login: " . print_r($r, TRUE)); rg_log_ml("Cannot login: " . print_r($r, TRUE));
54 55 exit(1); exit(1);
 
... ... if (strstr($r['body'], "invalid user")) {
61 62 rg_log("Loading invites form..."); rg_log("Loading invites form...");
62 63 $url = "/op/admin/mails/invites"; $url = "/op/admin/mails/invites";
63 64 $data = array(); $data = array();
64 $r = do_req($test_url . $url, $data, $headers);
65 $r = do_req($info, $test_url . $url, $data, $headers);
65 66 if ($r === FALSE) { if ($r === FALSE) {
66 67 rg_log("Cannot load add bug form."); rg_log("Cannot load add bug form.");
67 68 exit(1); exit(1);
 
... ... $data = array('doit' => 1, 'token' => $token,
77 78 'inv::list' => "a@embedromix.ro|a\nb@embedromix.ro|b b2 b3<xss>\n", 'inv::list' => "a@embedromix.ro|a\nb@embedromix.ro|b b2 b3<xss>\n",
78 79 'inv::subject' => 'Invite 1 - hello {NAME}<xss>', 'inv::subject' => 'Invite 1 - hello {NAME}<xss>',
79 80 'inv::body' => "Hello {NAME}!\n\nYou are invited, {NAME}!<xss>"); 'inv::body' => "Hello {NAME}!\n\nYou are invited, {NAME}!<xss>");
80 $r = do_req($test_url . $url, $data, $headers);
81 $r = do_req($info, $test_url . $url, $data, $headers);
81 82 if ($r === FALSE) { if ($r === FALSE) {
82 83 rg_log("Cannot post bug request."); rg_log("Cannot post bug request.");
83 84 exit(1); exit(1);
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_create_account.php changed (mode: 100644) (index 80e2fd1..83a289c)
... ... require_once("common.php");
16 16
17 17 $_testns = 'http_create_account'; $_testns = 'http_create_account';
18 18
19 prepare_http();
19 $info = array('id' => 'http_create_account');
20 prepare_http($info);
20 21
21 22 rg_log("Test create account"); rg_log("Test create account");
22 23
23 24 // 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
24 $r = do_req($test_url . "/op/create_account", $data, $headers);
25 $r = do_req($info, $test_url . "/op/create_account", $data, $headers);
25 26 if ($r === FALSE) { if ($r === FALSE) {
26 27 rg_log("Cannot load create_account page!"); rg_log("Cannot load create_account page!");
27 28 exit(1); exit(1);
 
... ... $uniq = rg_id(16);
34 35 sleep(2); // bot protection sleep(2); // bot protection
35 36 rg_log('Adding an account without accepting tos...'); rg_log('Adding an account without accepting tos...');
36 37 $username = "http1-$uniq<xss>"; $username = "http1-$uniq<xss>";
38 $info = array('id' => $username);
37 39 $data = array( $data = array(
38 40 "uid" => 0, "uid" => 0,
39 41 "doit" => 1, "doit" => 1,
 
... ... $data = array(
48 50 'gen' => $gen 'gen' => $gen
49 51 ); );
50 52 $headers = array(); $headers = array();
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'], "without accepting")) { if (!strstr($r['body'], "without accepting")) {
53 55 rg_log("Seems we could create an account without accepting ToS. Bad!"); rg_log("Seems we could create an account without accepting ToS. Bad!");
54 56 exit(1); exit(1);
 
... ... rg_log('Adding an account accepting tos...');
58 60 $data['token'] = $r['tokens']['user_edit_hl']; $data['token'] = $r['tokens']['user_edit_hl'];
59 61 $data['tos'] = 1; $data['tos'] = 1;
60 62 $headers = array(); $headers = array();
61 $r = do_req($test_url . "/op/create_account?t=create_account", $data, $headers);
63 $r = do_req($info, $test_url . "/op/create_account?t=create_account", $data, $headers);
62 64 if (!strstr($r['body'], "Your account has been successfully created")) { if (!strstr($r['body'], "Your account has been successfully created")) {
63 65 rg_log_ml('body: ' . print_r($r['body'], TRUE)); rg_log_ml('body: ' . print_r($r['body'], TRUE));
64 66 rg_log("Cannot create account"); rg_log("Cannot create account");
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_forgot.php changed (mode: 100644) (index 60369fb..ee4ac9a)
... ... $_testns = 'http_forgot';
25 25
26 26 $rg_user_max_len = 60; $rg_user_max_len = 60;
27 27
28 prepare_http();
29 28 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
30
29 $info = array('id' => $rg_ui['username']);
30 prepare_http($info);
31 31
32 32 rg_log(''); rg_log('');
33 33 rg_log_enter('Loading forgot_send form...'); rg_log_enter('Loading forgot_send form...');
34 34 $data = array(); $headers = array(); $data = array(); $headers = array();
35 $r = do_req($test_url . '/op/forgot_send', $data, $headers);
35 $r = do_req($info, $test_url . '/op/forgot_send', $data, $headers);
36 36 if ($r === FALSE) { if ($r === FALSE) {
37 37 rg_log("Cannot load forgot pass page!"); rg_log("Cannot load forgot pass page!");
38 38 exit(1); exit(1);
 
... ... $data = array(
43 43 'doit' => 1 'doit' => 1
44 44 ); );
45 45 $headers = array(); $headers = array();
46 $r = do_req($test_url . '/op/forgot_send', $data, $headers);
46 $r = do_req($info, $test_url . '/op/forgot_send', $data, $headers);
47 47 if (!strstr($r['body'], 'your inbox and follow the instructions')) { if (!strstr($r['body'], 'your inbox and follow the instructions')) {
48 48 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
49 49 rg_log("Cannot post forgot pass form!"); rg_log("Cannot post forgot pass form!");
 
... ... rg_log_exit();
67 67 rg_log(''); rg_log('');
68 68 rg_log_enter('Loading token from mail...'); rg_log_enter('Loading token from mail...');
69 69 $k = 'DEBUG::0::mail::mail/user/forgot/recover'; $k = 'DEBUG::0::mail::mail/user/forgot/recover';
70 $c = test_wait_cache($k);
70 $c = test_wait_cache($k, 50);
71 71 if (!isset($c['body'])) { if (!isset($c['body'])) {
72 72 rg_log_ml(print_r($c, TRUE)); rg_log_ml(print_r($c, TRUE));
73 73 rg_log('No body in c var!'); rg_log('No body in c var!');
 
... ... $s .= 'junk';
91 91
92 92 rg_log('Loading the forgot link form...'); rg_log('Loading the forgot link form...');
93 93 $data = array(); $headers = array(); $data = array(); $headers = array();
94 $r = do_req($test_url . '/op/forgot_link/' . $s, $data, $headers);
94 $r = do_req($info, $test_url . '/op/forgot_link/' . $s, $data, $headers);
95 95 if ($r === FALSE) { if ($r === FALSE) {
96 96 rg_log("Cannot load forgot_link page!"); rg_log("Cannot load forgot_link page!");
97 97 exit(1); exit(1);
 
... ... $data = array(
107 107 'doit' => 1 'doit' => 1
108 108 ); );
109 109 $headers = array(); $headers = array();
110 $r = do_req($test_url . '/op/forgot_link', $data, $headers);
110 $r = do_req($info, $test_url . '/op/forgot_link', $data, $headers);
111 111 if (!strstr($r['body'], 'Home page of user')) { if (!strstr($r['body'], 'Home page of user')) {
112 112 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
113 113 rg_log('Cannot post forgot link form' rg_log('Cannot post forgot link form'
 
... ... rg_log_exit();
136 136
137 137
138 138 rg_prof_log(); rg_prof_log();
139 rg_log("OK!");
140 ?>
139 rg_log('OK!');
File tests/http_keys.php changed (mode: 100644) (index 8db9c89..82432e2)
... ... require_once('common.php');
19 19 $_testns = 'http_keys'; $_testns = 'http_keys';
20 20
21 21
22 prepare_http();
23
24 22 $rg_ui = array('is_admin' => 1); $rg_ui = array('is_admin' => 1);
25 23 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
24 $info = array('id' => $rg_ui['username']);
25 prepare_http($info);
26
26 27 $r = test_login($test_url, $rg_ui); $r = test_login($test_url, $rg_ui);
27 28 if ($r === FALSE) { if ($r === FALSE) {
28 29 rg_log("Cannot login!"); rg_log("Cannot login!");
 
... ... rg_log('');
34 35 rg_log_enter('Loading Admin -> Settings -> SSH...'); rg_log_enter('Loading Admin -> Settings -> SSH...');
35 36 $data = array(); $data = array();
36 37 $headers = array(); $headers = array();
37 $r = do_req($test_url . '/op/admin/settings/ssh', $data, $headers);
38 $r = do_req($info, $test_url . '/op/admin/settings/ssh', $data, $headers);
38 39 if ($r === FALSE) { if ($r === FALSE) {
39 40 rg_log("Cannot load page!"); rg_log("Cannot load page!");
40 41 exit(1); exit(1);
 
... ... $list = array(
56 57 'ssh_key_min_bits_rsa' => 2048, 'ssh_key_min_bits_rsa' => 2048,
57 58 'ssh_key_allow_dsa' => 0, 'ssh_key_allow_dsa' => 0,
58 59 'ssh_key_min_bits_ecdsa' => 256, 'ssh_key_min_bits_ecdsa' => 256,
59 'AuthorizedKeysCommand' => 1
60 'AuthorizedKeysCommand' => 1,
61 'fido2_security' => 0
60 62 ); );
61 63 foreach ($list as $var => $def) { foreach ($list as $var => $def) {
62 64 $v = rg_state_get($db, $var); $v = rg_state_get($db, $var);
 
... ... foreach ($list as $var => $def) {
69 71 else else
70 72 $data[$var] = $v; $data[$var] = $v;
71 73 } }
72 $r = do_req($test_url . '/op/admin/settings/ssh', $data, $headers);
74 $r = do_req($info, $test_url . '/op/admin/settings/ssh', $data, $headers);
73 75 if (!strstr($r['body'], 'Configuration has been successfully saved.')) { if (!strstr($r['body'], 'Configuration has been successfully saved.')) {
74 76 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
75 77 rg_log("Cannot post form (expected answer missing)!"); rg_log("Cannot post form (expected answer missing)!");
 
... ... rg_log_exit();
79 81
80 82
81 83 rg_log('OK!'); rg_log('OK!');
82 ?>
File tests/http_login.php changed (mode: 100644) (index 34d81f7..df8e5a3)
... ... require_once("common.php");
18 18 $_testns = 'http_login'; $_testns = 'http_login';
19 19
20 20
21 prepare_http();
22
23 21 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
22 $info = array('id' => $rg_ui['username']);
23 prepare_http($info);
24 24
25 $good_guy = $_testns . '-good';
26 $bad_guy = $_testns . '-bad';
25 $info_bad = array('id' => 'http_login_bad');
26 prepare_http($info_bad);
27 27
28 28 rg_log("Test login operation"); rg_log("Test login operation");
29 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
30 30 // We provide junk cookies to test if we generate a new pre-login one // We provide junk cookies to test if we generate a new pre-login one
31 31 $data = array(); $data = array();
32 32 $headers = array(); $headers = array();
33 $http_client = $good_guy;
34 $r = do_req($test_url . "/op/login", $data, $headers);
33 $r = do_req($info, $test_url . "/op/login", $data, $headers);
35 34 if ($r === FALSE) { if ($r === FALSE) {
36 35 rg_log("Cannot load login form."); rg_log("Cannot load login form.");
37 36 exit(1); exit(1);
38 37 } }
39 38 $good_sid = $r['sid']; $good_sid = $r['sid'];
40 39 $good_token = $r['tokens']['login']; $good_token = $r['tokens']['login'];
41 rg_log("good: token=$good_token");
42 if (strncmp($r['sid'], 'X', 1) != 0) {
43 rg_log('Seems we did not get a pre-login session!');
40 rg_log('good: token=' . $good_token);
41 if (strncmp($good_sid, 'X', 1) != 0) {
42 rg_log('Seems we did not get a pre-login session! sid=[' . $good_sid . ']');
44 43 exit(1); exit(1);
45 44 } }
46 45
 
... ... if (strncmp($r['sid'], 'X', 1) != 0) {
48 47 // we need a valid token of the attacker, so we do a new request // we need a valid token of the attacker, so we do a new request
49 48 $data = array(); $data = array();
50 49 $headers = array(); $headers = array();
51 $http_client = $bad_guy;
52 $r = do_req($test_url . "/op/login", $data, $headers);
50 $r = do_req($info_bad, $test_url . '/op/login', $data, $headers);
53 51 if ($r === FALSE) { if ($r === FALSE) {
54 52 rg_log("Cannot load login form."); rg_log("Cannot load login form.");
55 53 exit(1); exit(1);
 
... ... $data = array(
67 65 "lock_ip" => 1 "lock_ip" => 1
68 66 ); );
69 67 $headers = array(); $headers = array();
70 $http_client = $good_guy;
71 $r = do_req($test_url . "/op/login?t=bad_token_good_sid", $data, $headers);
68 $r = do_req($info, $test_url . "/op/login?t=bad_token_good_sid", $data, $headers);
72 69 if ($r === FALSE) { if ($r === FALSE) {
73 70 rg_log_ml(print_r($r, TRUE)); rg_log_ml(print_r($r, TRUE));
74 71 rg_log_ml("Cannot do the request. Check above."); rg_log_ml("Cannot do the request. Check above.");
 
... ... $data = array(
89 86 "lock_ip" => 1 "lock_ip" => 1
90 87 ); );
91 88 $headers = array(); $headers = array();
92 $http_client = $good_guy;
93 $r = do_req($test_url . "/op/login?t=good_sid_good_token", $data, $headers);
89 $r = do_req($info, $test_url . "/op/login?t=good_sid_good_token", $data, $headers);
94 90 if ($r === FALSE) { if ($r === FALSE) {
95 91 rg_log_ml("Cannot login: " . print_r($r, TRUE)); rg_log_ml("Cannot login: " . print_r($r, TRUE));
96 92 exit(1); exit(1);
 
... ... if ($r === FALSE) {
110 106 } }
111 107
112 108
113 rg_log("OK!");
114 ?>
109 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_top.php changed (mode: 100644) (index ac2b81b..f1e0dd5)
... ... require_once("common.php");
18 18
19 19 $_testns = 'http_top'; $_testns = 'http_top';
20 20
21
22 prepare_http();
21 $info = array('id' => 'http_top');
22 prepare_http($info);
23 23
24 24 // TODO: donate has some problems with input + border (tidy)! // TODO: donate has some problems with input + border (tidy)!
25 25 $_list = array('features', 'discover', 'download', 'pricing', 'tos', $_list = array('features', 'discover', 'download', 'pricing', 'tos',
 
... ... $_list = array('features', 'discover', 'download', 'pricing', 'tos',
27 27 'doc/demo', 'doc/thanks'); 'doc/demo', 'doc/thanks');
28 28 foreach ($_list as $op) { foreach ($_list as $op) {
29 29 rg_log("Loading $op page..."); rg_log("Loading $op page...");
30 $info = array('id' => 'http_top');
30 31 $data = array(); $data = array();
31 $r = do_req($test_url . '/op/' . $op, $data, $headers);
32 $r = do_req($info, $test_url . '/op/' . $op, $data, $headers);
32 33 } }
33 34
34 35 rg_log('OK!'); 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/keys.php changed (mode: 100644) (index 4669499..3d6177a)
2 2 error_reporting(E_ALL | E_STRICT); error_reporting(E_ALL | E_STRICT);
3 3 ini_set("track_errors", "On"); ini_set("track_errors", "On");
4 4
5 $rg_sql_debug = 1;
6 $test_normal = FALSE;
7
5 8 $INC = dirname(__FILE__) . "/../inc"; $INC = dirname(__FILE__) . "/../inc";
6 9 require_once(dirname(__FILE__) . "/config.php"); require_once(dirname(__FILE__) . "/config.php");
7 10 require_once($INC . "/init.inc.php"); require_once($INC . "/init.inc.php");
 
... ... rg_log_set_file("keys.log");
15 18
16 19 require_once("common.php"); require_once("common.php");
17 20
18 $rg_sql_debug = 1;
19
20 21 // Defaults // Defaults
21 22 $rg_admin_email = "rg@embedromix.ro"; $rg_admin_email = "rg@embedromix.ro";
22 23
 
... ... if ($key_id2 === FALSE) {
59 60
60 61 // test key file generation // test key file generation
61 62 $rg_scripts = "/a"; $rg_scripts = "/a";
62 $rg_ssh_paras = "ssh1,ssh2,ssh3";
63 $rg_ssh_paras = 'ssh1,ssh2,ssh3';
63 64 $r = rg_keys_regen($db); $r = rg_keys_regen($db);
64 65 if ($r === FALSE) { if ($r === FALSE) {
65 66 rg_log("Cannot regenerate keys (" . rg_keys_error() . ")!"); rg_log("Cannot regenerate keys (" . rg_keys_error() . ")!");
 
... ... if ($c === FALSE) {
73 74 $key1b = str_replace("\n", '', $key1); $key1b = str_replace('first_key', 'first _key', $key1b); $key1b = str_replace("\n", '', $key1); $key1b = str_replace('first_key', 'first _key', $key1b);
74 75 $e = "command=\"" $e = "command=\""
75 76 . $rg_scripts . "/scripts/remote.sh 1 $key_id1 N\"," . $rg_scripts . "/scripts/remote.sh 1 $key_id1 N\","
76 . $rg_ssh_paras . ' ' . $key1b . "\n"
77 . $rg_ssh_paras . ',no-touch-required ' . $key1b . "\n"
77 78 . "command=\"" . "command=\""
78 79 . $rg_scripts . "/scripts/remote.sh 2 $key_id2 N\"," . $rg_scripts . "/scripts/remote.sh 2 $key_id2 N\","
79 . $rg_ssh_paras . ' ' . $key2 . "\n";
80 . $rg_ssh_paras . ',no-touch-required ' . $key2 . "\n";
80 81 if (strcmp($c, $e) != 0) { if (strcmp($c, $e) != 0) {
81 82 rg_log("Generated file does not seems OK!"); rg_log("Generated file does not seems OK!");
82 83 rg_log("e: $e"); rg_log("e: $e");
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/prof.php changed (mode: 100644) (index 43529c3..41531ff)
... ... sleep(1);
32 32 rg_prof_end("label2"); rg_prof_end("label2");
33 33 rg_prof_end("label2"); rg_prof_end("label2");
34 34 $t = rg_prof_get(); $t = rg_prof_get();
35 if (($t['label2']['time_ms'] < 1800) || ($t['label2']['time_ms'] > 2200)) {
36 rg_log_ml(print_r($t, TRUE));
35 if (($t['label2']['time'] < 1800) || ($t['label2']['time'] > 2200)) {
36 rg_log_ml('t: ' . print_r($t['label2'], TRUE));
37 37 rg_log("Nested profiling is not working (time_ms). See above t."); rg_log("Nested profiling is not working (time_ms). See above t.");
38 38 exit(1); exit(1);
39 39 } }
 
... ... if ($t['label2']['runs'] != 2) {
43 43 exit(1); exit(1);
44 44 } }
45 45
46 rg_log("OK!");
47 ?>
46
47 rg_log('OK!');
File tests/repo.php changed (mode: 100644) (index e7760dc..f07ded3)
... ... rg_log_exit();
217 217 rg_log(''); rg_log('');
218 218 rg_log_enter('Creating git folder.'); rg_log_enter('Creating git folder.');
219 219 $e = array(); $e = array();
220 $e['ui'] = array();
221 $e['ui']['uid'] = $rg_ui['uid'];
220 $e['ui_login'] = array();
221 $e['ui_login']['uid'] = $rg_ui['uid'];
222 222 $e = rg_array_merge($e, 'ri', $ri); $e = rg_array_merge($e, 'ri', $ri);
223 223 $r = rg_repo_event_storage_create($db, $e); $r = rg_repo_event_storage_create($db, $e);
224 224 if ($r === FALSE) { if ($r === FALSE) {
File tests/rights.php changed (mode: 100644) (index 1d1fa01..73cec7d)
... ... $x['owner'] = 90;
131 131 $x['uid'] = 200; $x['uid'] = 200;
132 132 $x['username'] = 'user_gen'; $x['username'] = 'user_gen';
133 133 $x['needed_rights'] = 'a'; $x['needed_rights'] = 'a';
134 $x['ip'] = '10.2.3.4';
135 134 $x['misc'] = 'misc1/user_gen/a'; $x['misc'] = 'misc1/user_gen/a';
135 rg_ip_set('10.2.3.4');
136 136 $r = rg_rights_allow($db, $x); $r = rg_rights_allow($db, $x);
137 137 if ($r === FALSE) { if ($r === FALSE) {
138 138 rg_log("We should have access because of @USER@"); rg_log("We should have access because of @USER@");
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/ssh.php changed (mode: 100644) (index cca977c..07a68e2)
... ... require_once("common.php");
18 18 $_testns = 'ssh'; $_testns = 'ssh';
19 19
20 20
21 prepare_http();
22
23 21 // This test makes sense only on my devel machine // This test makes sense only on my devel machine
24 22 if (php_uname("n") != "r1.embedromix.ro") { if (php_uname("n") != "r1.embedromix.ro") {
25 23 // TODO: start a sshd daemon? // TODO: start a sshd daemon?
 
... ... rg_log('');
32 30 rg_log_enter("Creating a user..."); rg_log_enter("Creating a user...");
33 31 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
34 32 rg_test_create_repo($db, $rg_ui, $repo); rg_test_create_repo($db, $rg_ui, $repo);
33 $info = array('id' => $rg_ui['username']);
34 prepare_http($info);
35
36
35 37 $r = test_login($test_url, $rg_ui); $r = test_login($test_url, $rg_ui);
36 38 if ($r === FALSE) { if ($r === FALSE) {
37 39 rg_log("Cannot login!"); rg_log("Cannot login!");
File tests/totp.inc.php changed (mode: 100644) (index 3fac13e..f845e7d)
5 5 * Do the http 2fa enrollment * Do the http 2fa enrollment
6 6 * Will return the key. * Will return the key.
7 7 */ */
8 function totp_enroll($db)
8 function totp_enroll($db, $info)
9 9 { {
10 10 global $test_url; global $test_url;
11 11
 
... ... function totp_enroll($db)
15 15 while (1) { while (1) {
16 16 rg_log('Loading enroll form...'); rg_log('Loading enroll form...');
17 17 $data = array(); $headers = array(); $data = array(); $headers = array();
18 $r = do_req($test_url . '/op/settings/totp/enroll', $data, $headers);
18 $r = do_req($info, $test_url . '/op/settings/totp/enroll', $data, $headers);
19 19 if ($r === FALSE) { if ($r === FALSE) {
20 20 rg_log('Cannot load enroll page!'); rg_log('Cannot load enroll page!');
21 21 break; break;
 
... ... function totp_enroll($db)
38 38 'totp::ver' => rg_totp_compute($key, time() / 30, 6) 'totp::ver' => rg_totp_compute($key, time() / 30, 6)
39 39 ); );
40 40 $headers = array(); $headers = array();
41 $r = do_req($test_url . '/op/settings/totp/enroll', $data, $headers);
41 $r = do_req($info, $test_url . '/op/settings/totp/enroll', $data, $headers);
42 42 if (!strstr($r['body'], 'You enrolled your new device with success')) { if (!strstr($r['body'], 'You enrolled your new device with success')) {
43 43 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
44 44 rg_log('Cannot enroll!'); rg_log('Cannot enroll!');
 
... ... function totp_enroll($db)
64 64 /* /*
65 65 * Deletes scratch codes * Deletes scratch codes
66 66 */ */
67 function totp_scratch_delete($list)
67 function totp_scratch_delete($info, $list)
68 68 { {
69 69 global $test_url; global $test_url;
70 70
 
... ... function totp_scratch_delete($list)
73 73 $ret = array('ok' => 0); $ret = array('ok' => 0);
74 74 while (1) { while (1) {
75 75 $headers = array(); $headers = array();
76 $r = do_req($test_url . '/op/settings/totp/sc', $data, $headers);
76 $r = do_req($info, $test_url . '/op/settings/totp/sc', $data, $headers);
77 77 if ($r === FALSE) { if ($r === FALSE) {
78 78 rg_log('Cannot load sc page!'); rg_log('Cannot load sc page!');
79 79 break; break;
 
... ... function totp_scratch_delete($list)
87 87 foreach ($list as $id) foreach ($list as $id)
88 88 $data['delete_list[' . $id . ']'] = 'on'; $data['delete_list[' . $id . ']'] = 'on';
89 89 $headers = array(); $headers = array();
90 $r = do_req($test_url . '/op/settings/totp/sc', $data, $headers);
90 $r = do_req($info, $test_url . '/op/settings/totp/sc', $data, $headers);
91 91 if (!strstr($r['body'], 'success')) { if (!strstr($r['body'], 'success')) {
92 92 rg_log('Cannot delete scratch codes!'); rg_log('Cannot delete scratch codes!');
93 93 break; break;
File tests/user.php changed (mode: 100644) (index b39996f..6c1983b)
... ... if ($uid === FALSE) {
66 66 } }
67 67
68 68 // Simulate event: link_by_name // Simulate event: link_by_name
69 $ev = array('ui' => array('uid' => $uid, 'username' => $_u['username']));
69 $ev = array('ui_login' => array('uid' => $uid, 'username' => $_u['username']));
70 70 $r = rg_user_link_by_name($db, $ev); $r = rg_user_link_by_name($db, $ev);
71 71 if ($r === FALSE) { if ($r === FALSE) {
72 72 rg_log("Cannot link by name (" . rg_user_error() . ")!"); rg_log("Cannot link by name (" . rg_user_error() . ")!");
File tests/util.php changed (mode: 100644) (index acd4f1c..36e9972)
... ... if (strcmp($r, $e) != 0) {
65 65 } }
66 66
67 67
68 rg_log('Testing html escape - attr value');
69 $s = '<a href="@@a@@">'; // TODO: we may do a @@ATTR_ESCAPE:a@@ to escape only ' and "
70 $data = array('a' => '\'È™/È›"<>');
71 $e = '<a href="&apos;È™/È›&quot;&lt;&gt;">';
72 $r = rg_template_string($s, 0, $data, TRUE /*xss*/);
73 if (strcmp($r, $e) != 0) {
74 rg_log(' fail: [' . $r . '] != [' . $e . ']!');
75 exit(1);
76 }
77
78 rg_log('Testing html escape - body');
79 $s = '<b>@@a@@</b>';
80 $data = array('a' => '\'È™/È›"<>&');
81 $e = '<b>&apos;È™/È›&quot;&lt;&gt;&amp;</b>';
82 $r = rg_template_string($s, 0, $data, TRUE /*xss*/);
83 if (strcmp($r, $e) != 0) {
84 rg_log(' fail: [' . $r . '] != [' . $e . ']!');
85 exit(1);
86 }
87
88 rg_log('Testing html escape - para');
89 $s = '<a href="/a?para1=@@URL_ESCAPE:a@@">';
90 $data = array('a' => 'È™/È›&');
91 $e = '<a href="/a?para1=%C8%99%2F%C8%9B%26">';
92 $r = rg_template_string($s, 0, $data, TRUE /*xss*/);
93 if (strcmp($r, $e) != 0) {
94 rg_log(' fail: [' . $r . '] != [' . $e . ']!');
95 exit(1);
96 }
97
68 98 rg_log("Testing ::+nesting"); rg_log("Testing ::+nesting");
69 99 $s = '@@a::b@@'; $s = '@@a::b@@';
70 100 $e = '&lt;'; $e = '&lt;';
 
... ... if (strcmp($r, $e) != 0) {
248 278
249 279
250 280 // Test template functions // Test template functions
251 function inc($v) { rg_log("DEBUG: inc called with v=$v"); return $v + 1; }
252 function dec($v) { rg_log("DEBUG: dec called with v=$v"); return $v - 1; }
281 function inc($v) { global $_rg; rg_log("DEBUG: inc called with v=$v"); return array('value' => $_rg[$v] + 1, 'html' => 0); }
282 function dec($v) { global $_rg; rg_log("DEBUG: dec called with v=$v"); return array('value' => $_rg[$v] - 1, 'html' => 0); }
253 283 rg_template_func("inc", "inc"); rg_template_func("inc", "inc");
254 284 rg_template_func("dec", "dec"); rg_template_func("dec", "dec");
255 285 $_rg = array("uid" => 5); $_rg = array("uid" => 5);
 
... ... if ($r['ok'] == 1) {
303 333 rg_log("running non existing command does not return 0!"); rg_log("running non existing command does not return 0!");
304 334 exit(1); exit(1);
305 335 } }
306 if (strcmp($r['stderr'], "sh: /xxxx: No such file or directory\n") != 0) {
336 $e = 'No such file or directory' . "\n";
337 if (!strstr($r['stderr'], $e) != 0) {
307 338 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
308 rg_log('stderr is not correct!');
339 rg_log('stderr is not correct; not [' . trim($e) . '\n]!');
309 340 exit(1); exit(1);
310 341 } }
311 342 if ($r['code'] != 127) { if ($r['code'] != 127) {
File tests/wh_cloud.php changed (mode: 100644) (index 2b6ed67..67bc13f)
... ... require_once("common.php");
19 19 $_testns = 'wh_cloud'; $_testns = 'wh_cloud';
20 20
21 21
22 prepare_http();
23
24 22 $home = getenv('HOME'); $home = getenv('HOME');
25 23 if (!file_exists($home . '/.aws/conf.php')) { if (!file_exists($home . '/.aws/conf.php')) {
26 24 rg_log('no ~/.aws.conf.php file!'); rg_log('no ~/.aws.conf.php file!');
 
... ... if (!file_exists($home . '/.aws/conf.php')) {
31 29 include($home . '/.aws/conf.php'); include($home . '/.aws/conf.php');
32 30
33 31
34 rg_log('');
35 rg_log("Creating a user...");
32 $rg_ui = array('confirmed' => 20);
36 33 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
34 $info = array('id' => $rg_ui['username']);
35 prepare_http($info);
36
37 37
38 38
39 39 rg_log(''); rg_log('');
 
... ... rg_log_exit();
49 49 rg_log(''); rg_log('');
50 50 rg_log_enter('Registering webhook...'); rg_log_enter('Registering webhook...');
51 51 $extra = array( $extra = array(
52 'wh::htype' => 'cloud',
53 'wh::hsubtype' => 'generic',
54 52 'wh::description' => 'description1 <xss> codedeploy', 'wh::description' => 'description1 <xss> codedeploy',
55 53 'wh::repo' => '', 'wh::repo' => '',
56 54 'wh::refname' => '', 'wh::refname' => '',
 
... ... rg_log_exit();
72 70
73 71 rg_log(''); rg_log('');
74 72 rg_log_enter('Finding out the hook id...'); rg_log_enter('Finding out the hook id...');
75 $r = test_wait_cache('wh' . '::' . $rg_ui['uid']);
73 $r = test_wait_cache('wh' . '::' . $rg_ui['uid'], 50);
76 74 rg_log_ml('r=' . print_r($r, TRUE)); rg_log_ml('r=' . print_r($r, TRUE));
77 75 $t = array_keys($r['list']); $t = array_keys($r['list']);
78 76 if (count($t) != 1) { if (count($t) != 1) {
 
... ... rg_log_exit();
106 104 rg_log(''); rg_log('');
107 105 rg_log_enter('Testing if hook executed with success'); rg_log_enter('Testing if hook executed with success');
108 106 $key = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $wh_id; $key = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $wh_id;
109 $r = test_wait_cache($key);
107 $r = test_wait_cache($key, 50);
110 108 $a = @json_decode($r, TRUE); $a = @json_decode($r, TRUE);
111 109 if ($a === NULL) { if ($a === NULL) {
112 110 rg_log('Cannot decode JSON: ' . $r); rg_log('Cannot decode JSON: ' . $r);
 
... ... rg_log('');
125 123 rg_log_enter('Testing the edit of webhook...'); rg_log_enter('Testing the edit of webhook...');
126 124 $extra = array( $extra = array(
127 125 'wh::id' => $wh_id, 'wh::id' => $wh_id,
128 'wh::htype' => 'cloud',
129 'wh::hsubtype' => 'generic',
130 126 'wh::repo' => '.*', 'wh::repo' => '.*',
131 127 'wh::refname' => '..*', 'wh::refname' => '..*',
132 128 'wh::description' => 'desc2 <xss>', 'wh::description' => 'desc2 <xss>',
 
... ... foreach ($list as $k => $v) {
188 184 rg_log_exit(); rg_log_exit();
189 185
190 186
191 rg_log("OK!");
192 ?>
187 rg_log('OK!');
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!");
File tests/wh_lambda.php changed (mode: 100644) (index 05a04ab..06061b2)
... ... require_once("common.php");
18 18 $_testns = 'wh_lambda'; $_testns = 'wh_lambda';
19 19 $rg_cache_debug = TRUE; $rg_cache_debug = TRUE;
20 20
21 prepare_http();
22
23 21 $home = getenv('HOME'); $home = getenv('HOME');
24 22 if (!file_exists($home . '/.aws/conf.php')) { if (!file_exists($home . '/.aws/conf.php')) {
25 23 rg_log('no ~/.aws.conf.php file!'); rg_log('no ~/.aws.conf.php file!');
 
... ... include($home . '/.aws/conf.php');
32 30
33 31 rg_log(''); rg_log('');
34 32 rg_log("Creating a user..."); rg_log("Creating a user...");
33 $rg_ui = array('confirmed' => 20);
35 34 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
35 $info = array('id' => $rg_ui['username']);
36 prepare_http($info);
36 37
37 38
38 39 rg_log(''); rg_log('');
 
... ... rg_test_create_repo($db, $rg_ui, $repo);
52 53 rg_log(''); rg_log('');
53 54 rg_log_enter('Registering webhook...'); rg_log_enter('Registering webhook...');
54 55 $extra = array( $extra = array(
55 'wh::htype' => 'lambda',
56 'wh::hsubtype' => 'generic',
57 56 'wh::description' => 'description2 <xss> lambda', 'wh::description' => 'description2 <xss> lambda',
58 57 'wh::repo' => '', 'wh::repo' => '',
59 58 'wh::refname' => '', 'wh::refname' => '',
 
... ... rg_log_exit();
71 70
72 71 rg_log(''); rg_log('');
73 72 rg_log_enter('Finding out the hook id...'); rg_log_enter('Finding out the hook id...');
74 $r = test_wait_cache('wh' . '::' . $rg_ui['uid']);
73 $r = test_wait_cache('wh' . '::' . $rg_ui['uid'], 50);
75 74 rg_log_ml('r=' . print_r($r, TRUE)); rg_log_ml('r=' . print_r($r, TRUE));
76 75 $t = array_keys($r['list']); $t = array_keys($r['list']);
77 76 if (count($t) != 1) { if (count($t) != 1) {
 
... ... rg_log_exit();
104 103 rg_log(''); rg_log('');
105 104 rg_log_enter('Testing if hook executed with success'); rg_log_enter('Testing if hook executed with success');
106 105 $key = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $wh_id; $key = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $wh_id;
107 $r = test_wait_cache($key);
106 $r = test_wait_cache($key, 50);
108 107 $a = @json_decode($r, TRUE); $a = @json_decode($r, TRUE);
109 108 if ($a === NULL) { if ($a === NULL) {
110 109 rg_log('Cannot decode JSON: '. $r); rg_log('Cannot decode JSON: '. $r);
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/rocketgit

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main