xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
Commit af00ea421d6eec2877cab0c37f9c492fff3860ec

Fixed push by HTTP; fixing some tests
Author: Catalin(ux) M. BOIE
Author date (UTC): 2017-01-30 18:48
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2017-01-30 18:48
Parent(s): c308a9b435c9e5baa39ac3529c794df227ab9196
Signing key:
Tree: a7a39092af14a5d421f89f3859a3fd677c7a7819
File Lines added Lines deleted
inc/repo.inc.php 18 8
inc/ssh.inc.php 9 3
inc/user.inc.php 2 1
inc/util.inc.php 2 2
samples/config.php 2 1
scripts/remote.php 2 1
tests/.gitignore 2 0
tests/Makefile 7 111
tests/_run_tests.sh 36 0
tests/ask_pass 13 0
tests/by_http.php 136 0
tests/config.php 2 1
tests/helpers.inc.php 9 7
tests/token.php 4 2
tests/wh_cloud.git.sh 3 1
tests/wh_lambda.php 3 2
File inc/repo.inc.php changed (mode: 100644) (index 187a479..bd16481)
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2415 2415 . ' repo=' . $repo . ' cmd=' . $cmd . ' repo=' . $repo . ' cmd=' . $cmd
2416 2416 . ' need_namespace_copy=' . ($need_namespace_copy ? 'yes' : 'no')); . ' need_namespace_copy=' . ($need_namespace_copy ? 'yes' : 'no'));
2417 2417
2418 $ret = array('ok' => 0, 'allow' => 1, 'push_allowed' => 1);
2418 $ret = array('ok' => 0, 'allow' => 0, 'push_allowed' => 0);
2419 2419 while (1) { while (1) {
2420 2420 // Extracts command and computes permissions // Extracts command and computes permissions
2421 2421 if (strncasecmp($cmd, 'git-upload-pack', 15) == 0) { if (strncasecmp($cmd, 'git-upload-pack', 15) == 0) {
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2448 2448 break; break;
2449 2449 } }
2450 2450
2451 // TODO: What if the user is deleted?
2452
2451 2453 // Loading info about the repository // Loading info about the repository
2452 2454 if (rg_repo_ok($repo) !== TRUE) { if (rg_repo_ok($repo) !== TRUE) {
2453 2455 $ret['error'] = 'Repository is invalid (' $ret['error'] = 'Repository is invalid ('
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2488 2490 $repo_path = rg_repo_path_by_id($ret['owner_ui']['uid'], $repo_path = rg_repo_path_by_id($ret['owner_ui']['uid'],
2489 2491 $ret['ri']['repo_id']); $ret['ri']['repo_id']);
2490 2492 $ret['repo_path'] = $repo_path; $ret['repo_path'] = $repo_path;
2491 rg_log('DEBUG: repo_path=' . $repo_path);
2492 2493
2493 2494 // TODO: signal user that the repo moved and provide a hint how to follow // TODO: signal user that the repo moved and provide a hint how to follow
2494 2495
2496 $ret['ok'] = 1;
2497
2495 2498 $x = array(); $x = array();
2496 2499 $x['obj_id'] = $ret['ri']['repo_id']; $x['obj_id'] = $ret['ri']['repo_id'];
2497 2500 $x['type'] = 'repo_refs'; $x['type'] = 'repo_refs';
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2502 2505 $x['ip'] = $ip; $x['ip'] = $ip;
2503 2506 $x['misc'] = ''; $x['misc'] = '';
2504 2507 $r = rg_rights_allow($db, $x); $r = rg_rights_allow($db, $x);
2508 // TODO: what if an error occured? How we signal this?!
2505 2509 if ($r !== TRUE) { if ($r !== TRUE) {
2506 2510 $ret['error'] = 'You have no rights to access this repo'; $ret['error'] = 'You have no rights to access this repo';
2507 $ret['allow'] = 0;
2508 2511 break; break;
2509 2512 } }
2510 2513
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2512 2515 // give the user a chance to authenticate. // give the user a chance to authenticate.
2513 2516 // TODO: change rg_rights_allow to return what rights are // TODO: change rg_rights_allow to return what rights are
2514 2517 // allowed and use it. // allowed and use it.
2515 $x['needed_rights'] = 'P';
2516 $r = rg_rights_allow($db, $x);
2517 if ($r !== TRUE)
2518 $ret['push_allowed'] = 0;
2518 if ($push == 1) {
2519 $x['needed_rights'] = 'P';
2520 $r = rg_rights_allow($db, $x);
2521 if ($r === TRUE)
2522 $ret['push_allowed'] = 1;
2523 }
2519 2524
2520 2525 // If we are enrolled, ask for login token // If we are enrolled, ask for login token
2521 2526 // For push we always ask for it, for fetch only if repo is // For push we always ask for it, for fetch only if repo is
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2526 2531 if (($ret['ri']['public'] == 0) || ($push == 1)) { if (($ret['ri']['public'] == 0) || ($push == 1)) {
2527 2532 $r = rg_totp_verify_ip($db, $login_ui['uid'], $r = rg_totp_verify_ip($db, $login_ui['uid'],
2528 2533 $ip); $ip);
2529 if (($r['ok'] == 0) && (empty($r['list']))) {
2534 if (($r['ok'] !== 1)
2535 || ($r['enrolled'] && empty($r['ip_list']))) {
2530 2536 $ret['error'] = rg_totp_error(); $ret['error'] = rg_totp_error();
2537 $ret['ok'] = 0;
2531 2538 break; break;
2532 2539 } }
2533 2540 } }
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2551 2558 break; break;
2552 2559 } }
2553 2560
2561 // We are allowed at this point
2562 $ret['allow'] = 1;
2563
2554 2564 // Put in environment all we need // Put in environment all we need
2555 2565 putenv('ROCKETGIT_LOGIN_UID=' . $login_ui['uid']); putenv('ROCKETGIT_LOGIN_UID=' . $login_ui['uid']);
2556 2566 putenv('ROCKETGIT_LOGIN_URL=' . rg_re_userpage($login_ui)); putenv('ROCKETGIT_LOGIN_URL=' . rg_re_userpage($login_ui));
File inc/ssh.inc.php changed (mode: 100644) (index f5c2f6d..6c072f4)
... ... function rg_ssh_totp_verify_ip($db, $uid, $ip)
124 124 $ret = FALSE; $ret = FALSE;
125 125 while (1) { while (1) {
126 126 $r = rg_totp_verify_ip($db, $uid, $ip); $r = rg_totp_verify_ip($db, $uid, $ip);
127 if (($r['ok'] == 0) || (empty($r['ip_list']))) {
127 if ($r['ok'] !== 1) {
128 128 echo 'Error: ' . rg_totp_error() . ".\n"; echo 'Error: ' . rg_totp_error() . ".\n";
129 129 break; break;
130 130 } }
131
131 132 if ($r['enrolled'] == 0) { if ($r['enrolled'] == 0) {
132 133 echo 'Info: You are not enrolled.' . "\n"; echo 'Info: You are not enrolled.' . "\n";
133 134 break; break;
134 135 } }
135 136
137 if (empty($r['ip_list'])) {
138 echo 'Error: ' . rg_totp_error() . ".\n";
139 break;
140 }
141
136 142 $ret = $r['ip_list']; $ret = $r['ip_list'];
137 143 break; break;
138 144 } }
 
... ... function rg_ssh_dispatch($db, $ip, $uid, $orig_cmd)
374 380 case 'totp': break; // totp will verify the ip only for some commands case 'totp': break; // totp will verify the ip only for some commands
375 381 default: default:
376 382 $r = rg_totp_verify_ip($db, $uid, $ip); $r = rg_totp_verify_ip($db, $uid, $ip);
377 if (($r['ok'] == 0)
378 || (($r['enrolled'] == 1) && (empty($r['ip_list'])))) {
383 if (($r['ok'] !== 1)
384 || ($r['enrolled'] && empty($r['ip_list']))) {
379 385 echo 'Error: ' . rg_totp_error() . ".\n"; echo 'Error: ' . rg_totp_error() . ".\n";
380 386 return TRUE; // = we must exit' return TRUE; // = we must exit'
381 387 } }
File inc/user.inc.php changed (mode: 100644) (index ed27197..05b52c0)
... ... function rg_user_http_git($db, $rg, $paras)
1952 1952 break; break;
1953 1953 } }
1954 1954
1955 if ($r['ri']['exists'] != 1) {
1955 if (($r['ri']['exists'] != 1)
1956 || ($r['ri']['deleted'] > 0)) {
1956 1957 header($protocol . ' 404 Not found'); header($protocol . ' 404 Not found');
1957 1958 break; break;
1958 1959 } }
File inc/util.inc.php changed (mode: 100644) (index d6c838b..e367f6f)
... ... function rg_ok($msg)
987 987 * Execute $cmd and returns the output as a string, binary safe * Execute $cmd and returns the output as a string, binary safe
988 988 * @input: some data to be sent to the process and received as stdin * @input: some data to be sent to the process and received as stdin
989 989 * @cb_stdout - call back called when there is something to be send to stdout * @cb_stdout - call back called when there is something to be send to stdout
990 * if @cb_stdout is FALSE, stdout output will be returned in $ret
990 * if @cb_stdout is FALSE, stdout output will be returned in $ret['data']
991 991 * cb_stderr - call back called when there is something to be send to stderr * cb_stderr - call back called when there is something to be send to stderr
992 * if @cb_stderr is FALSE, stderr output will be returned in $ret
992 * if @cb_stderr is FALSE, stderr output will be returned in $ret['stderr']
993 993 */ */
994 994 function rg_exec($cmd, $input, $cb_stdout, $cb_stderr) function rg_exec($cmd, $input, $cb_stdout, $cb_stderr)
995 995 { {
File samples/config.php changed (mode: 100644) (index 7c4c806..a8e7c07)
... ... $rg_repo_allow = '-\p{L}\p{N}._+=*&';
25 25 $rg_repo_min_len = 2; $rg_repo_min_len = 2;
26 26 $rg_repo_max_len = 64; $rg_repo_max_len = 64;
27 27
28 // Allowed user names (negated regular expression)
28 // Allowed user names (regular expression)
29 // Do not allow ':' - else HTTP Basic auth will not work!
29 30 $rg_user_allow = '-\p{L}\p{N}._+=*&'; $rg_user_allow = '-\p{L}\p{N}._+=*&';
30 31
31 32 // Allowed user name length // Allowed user name length
File scripts/remote.php changed (mode: 100644) (index 1d64022..3dd203b)
... ... if (strstr($flags, 'W')) {
196 196
197 197 $r = rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user, $r = rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
198 198 $repo, $cmd, TRUE /*need_namespace_copy*/); $repo, $cmd, TRUE /*need_namespace_copy*/);
199 if ($r['ok'] != 1)
199 rg_log_ml('DEBUG: repo_fetch_push_helper: ' . print_r($r, TRUE));
200 if ($r['ok'] !== 1)
200 201 fatal($r['error']); fatal($r['error']);
201 202
202 203 $run = "git-shell -c \"" . $cmd . " " . escapeshellarg($r['repo_path']) . "\""; $run = "git-shell -c \"" . $cmd . " " . escapeshellarg($r['repo_path']) . "\"";
File tests/.gitignore changed (mode: 100644) (index 3cc55b1..a69af15)
... ... _pr_anon.git
27 27 hook_update_dest.git hook_update_dest.git
28 28 hook_update_src.git hook_update_src.git
29 29 export.json export.json
30 .by_http
31 _run_tests.failed
File tests/Makefile changed (mode: 100644) (index d5762e9..6dfa24a)
1 tests := wh_lambda http_keys http_forgot \
2 api wh_cloud pr_anon wh_http ssh http_totp totp git_log1.sh \
3 http_admin http_bug \
4 http_create_account http_login http_settings http_csrf http_top \
5 token util log state cache prof db event rights keys user repo git \
6 bug hook_update git2
7 .PHONY: $(tests)
8
9 all: clean $(tests)
1 all: clean run
10 2 @echo "All OK. Good work!" @echo "All OK. Good work!"
11 3 @-ls -l err-* @-ls -l err-*
4 @-ls -l /var/log/rocketgit/err-*
12 5 @echo "Do not forget to check for errors in /var/log/rocketgit!" @echo "Do not forget to check for errors in /var/log/rocketgit!"
13 6
14 wh_lambda:
15 php wh_lambda.php
16
17 http_keys:
18 php http_keys.php
19
20 http_forgot:
21 php http_forgot.php
22
23 api:
24 ./api.sh
25
26 wh_cloud:
27 php wh_cloud.php
28
29 pr_anon:
30 php pr_anon.php
31
32 wh_http:
33 php wh_http.php
34
35 ssh:
36 php ssh.php
37
38 http_totp:
39 php http_totp.php
40
41 totp:
42 php totp.php
43
44 git_log1.sh:
45 ./git_log1.sh
46
47 token:
48 php token.php
49
50 util:
51 php util.php
52
53 sql:
54 php sql.php
55
56 keys:
57 php keys.php
58
59 repo:
60 php repo.php
61
62 rights:
63 php rights.php
64
65 state:
66 php state.php
67
68 user:
69 php user.php
70
71 git:
72 php git.php
73
74 prof:
75 php prof.php
76
77 bug:
78 php bug.php
79
80 log:
81 php log.php
82
83 event:
84 php event.php
85
86 cache:
87 php cache.php
88
89 hook_update:
90 ./hook_update.sh
91
92 http_create_account:
93 php http_create_account.php
94
95 http_login:
96 php http_login.php
97
98 http_settings:
99 php http_settings.php
100
101 http_csrf:
102 php http_csrf.php
103
104 http_bug:
105 php http_bug.php
106
107 http_admin:
108 php http_admin.php
109
110 http_top:
111 php http_top.php
112
113 git2:
114 php git2.php
7 .PHONY: run
8 run:
9 @./_run_tests.sh
115 10
116 11 .PHONY: clean .PHONY: clean
117 12 clean: clean:
118 13 @rm -rf git_log1 *.log *.strace *.strace.* *.out *.lock err-* *.diff \ @rm -rf git_log1 *.log *.strace *.strace.* *.out *.lock err-* *.diff \
119 14 http.arond *.pub git2key git2 *.in q_merge_requests/mr-* \ http.arond *.pub git2key git2 *.in q_merge_requests/mr-* \
120 15 qstats/* repos/* helper helper.pub keys/* ca *.pid \ qstats/* repos/* helper helper.pub keys/* ca *.pid \
121 _pr_anon.git *.tmp base ubase wh_cloud.git export.json
16 _pr_anon.git *.tmp base ubase wh_cloud.git export.json \
17 .by_http
File tests/_run_tests.sh added (mode: 100755) (index 0000000..bcc30d9)
1 #!/bin/bash
2
3 tests="by_http wh_lambda http_keys http_forgot \
4 api wh_cloud pr_anon wh_http ssh http_totp totp git_log1 \
5 http_admin http_bug \
6 http_create_account http_login http_settings http_csrf http_top \
7 token util log state cache prof event rights keys user repo git \
8 bug hook_update git2"
9
10 failed=""
11 add=""
12 for t in ${tests}; do
13 echo
14 echo "${t}: Running..."
15 if [ -r "${t}.sh" ]; then
16 ./${t}.sh
17 else
18 php ${t}.php
19 fi
20 if [ "${?}" != "0" ]; then
21 failed="${failed}${add}${t}"
22 add=" "
23 echo "${t}: FAILED!"
24 fi
25 done
26
27 echo "${failed}" > _run_tests.failed
28
29 echo
30
31 if [ "${failed}" = "" ]; then
32 exit 0
33 fi
34
35 echo "Some tests failed: ${failed}"
36 exit 1
File tests/ask_pass added (mode: 100755) (index 0000000..c4c995f)
1 #!/bin/bash
2
3 if [ "${1:0:8}" = "Username" ]; then
4 #echo -n "'"
5 echo -n "${git_username}"
6 #echo "'"
7 fi
8
9 if [ "${1:0:8}" = "Password" ]; then
10 #echo -n "'"
11 echo -n "${git_password}"
12 #echo "'"
13 fi
File tests/by_http.php added (mode: 100644) (index 0000000..b8162a6)
1 <?php
2 error_reporting(E_ALL | E_STRICT);
3 ini_set("track_errors", "On");
4
5 $INC = dirname(__FILE__) . "/../inc";
6 require_once(dirname(__FILE__) . "/config.php");
7 require_once($INC . "/init.inc.php");
8 require_once($INC . "/git.inc.php");
9 require_once("helpers.inc.php");
10 require_once("http.inc.php");
11
12 rg_log_set_file("by_http.log");
13
14 $rg_sql = "host=localhost user=rocketgit dbname=rocketgit connect_timeout=10";
15 $rg_no_db = TRUE;
16 require_once("common.php");
17
18 $_testns = 'by_http';
19 $rg_cache_enable = TRUE;
20
21
22 rg_test_create_user($db, $rg_ui);
23 rg_log('Created user ' . $rg_ui['uid']);
24
25 putenv('git_username=' . $rg_ui['username']);
26 putenv('git_password=' . $rg_ui['pass']);
27
28 rg_test_create_repo($db, $rg_ui, $repo);
29 rg_log('Created repo ' . $repo['repo_id']);
30 $repo2 = array('public' => 0);
31 rg_test_create_repo($db, $rg_ui, $repo2);
32 rg_log('Created repo2 ' . $repo2['repo_id']);
33 $r = test_login($test_url, $rg_ui, $good_sid);
34 if ($r === FALSE) {
35 rg_log("Cannot login!");
36 exit(1);
37 }
38
39
40 $commit_body = rg_id(32);
41 $a = rg_exec('rm -rf .by_http'
42 . ' && mkdir .by_http'
43 . ' && cd .by_http'
44 . ' && git init'
45 . ' && git remote add origin ' . escapeshellarg($repo['clone_url_http'])
46 . ' && git remote add origin2 ' . escapeshellarg($repo2['clone_url_http'])
47 . ' && echo "a signature" > a'
48 . ' && git add a'
49 . ' && git commit -a -m "' . $commit_body . '"', '', FALSE, FALSE);
50 if ($a['ok'] != 1) {
51 rg_log("Something wrong generating the git repo: " . $a['stderr']);
52 exit(1);
53 }
54
55
56 rg_log('');
57 rg_log_enter('Trying to push master (without user/pass)...');
58 putenv('GIT_ASKPASS=/bin/true');
59 $r = rg_exec('cd .by_http && git push origin master', '', FALSE, FALSE);
60 if ($r['ok'] != 1) {
61 rg_log_ml('out: ' . print_r($r, TRUE));
62 rg_log('Seems I cannot push master without authentication (anonymous push)!');
63 exit(1);
64 }
65 if (!strstr($r['stderr'], 'transformed into a pull request')) {
66 rg_log_ml('out: ' . print_r($r, TRUE));
67 rg_log('The stderr does not contain something about anonymous push!');
68 exit(1);
69 }
70 rg_log_exit();
71
72
73 rg_log('');
74 rg_log_enter('Trying to push master (with user/pass)...');
75 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');
76 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o x.strace git push --verbose origin master', '', FALSE, FALSE);
77 if ($r['ok'] != 1) {
78 rg_log_ml('out: ' . print_r($r, TRUE));
79 rg_log('Seems I can push master with authentication!');
80 exit(1);
81 }
82 rg_log_exit();
83
84
85 rg_log('');
86 rg_log_enter('Trying to push master (without user/pass; private repo)...');
87 putenv('GIT_ASKPASS=/bin/true');
88 $r = rg_exec('cd .by_http && git push origin2 master', '', FALSE, FALSE);
89 if ($r['ok'] == 1) {
90 rg_log_ml('out: ' . print_r($r, TRUE));
91 rg_log('Seems I can push master without authentication (anonymous push)!');
92 exit(1);
93 }
94 if (!strstr($r['stderr'], 'Authentication failed')) {
95 rg_log_ml('out: ' . print_r($r, TRUE));
96 rg_log('The error is not authentication failure!');
97 exit(1);
98 }
99 rg_log_exit();
100
101
102 rg_log('');
103 rg_log_enter('Trying to push master (with user/pass; private repo)...');
104 putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass');
105 $r = rg_exec('cd .by_http && strace -s2000 -f -tt -o x2.strace git push --verbose origin2 master', '', FALSE, FALSE);
106 if ($r['ok'] != 1) {
107 rg_log_ml('out: ' . print_r($r, TRUE));
108 rg_log('Seems I can push master with authentication!');
109 exit(1);
110 }
111 rg_log_exit();
112
113
114 rg_log('');
115 $commit = trim(file_get_contents('.by_http/.git/refs/heads/master'));
116 rg_log('master from .git: ' . $commit);
117 rg_log_enter('Checking on web that everything is OK...');
118 $data = array();
119 $headers = array("Cookie: sid=" . $good_sid);
120 $r = do_req($test_url . '/user/' . rawurlencode($rg_ui['username'])
121 . '/' . rawurlencode($repo['name']) . '/source/log/commit/'
122 . $commit, $data, $headers);
123 if ($r === FALSE) {
124 rg_log('Cannot load master commit!');
125 exit(1);
126 }
127 if (!strstr($r['body'], $commit_body)) {
128 rg_log_ml('r: ' . print_r($r, TRUE));
129 rg_log('I cannot find [' . $commit_body . '] inside the body!');
130 exit(1);
131 }
132 rg_log_exit();
133
134
135 rg_log('OK!');
136 ?>
File tests/config.php changed (mode: 100644) (index 65fb166..130a75b)
... ... $rg_scripts = dirname(dirname(__FILE__));
10 10 $rg_repo_allow = '-\p{L}\p{N}._+=*&<>'; $rg_repo_allow = '-\p{L}\p{N}._+=*&<>';
11 11 $rg_repo_min_len = 1; $rg_repo_min_len = 1;
12 12 $rg_repo_max_len = 100; $rg_repo_max_len = 100;
13 $rg_user_allow = '-\p{L}\p{N}._+=*&<>';
13 $rg_user_allow = '-\p{L}\p{N}._+=*&<>\':';
14 14 $rg_user_min_len = 1; $rg_user_min_len = 1;
15 15 $rg_user_max_len = 50; $rg_user_max_len = 50;
16 16 $rg_ssh_paras = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty"; $rg_ssh_paras = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty";
 
... ... $rg_git_port = 9418;
34 34
35 35 // For http testing // For http testing
36 36 $test_url = "http://rg:9000"; $test_url = "http://rg:9000";
37 $rg_web_url = 'http://rg:9000';
37 38 $rg_debug = 1; $rg_debug = 1;
38 39
39 40 ?> ?>
File tests/helpers.inc.php changed (mode: 100644) (index 25e9608..9254495)
... ... function rg_test_create_user($db, &$rg_ui)
17 17 if (!is_array($rg_ui)) if (!is_array($rg_ui))
18 18 $rg_ui = array(); $rg_ui = array();
19 19
20 $username = $_testns . '-user-' . $_user_id . '<xss>';
20 $username = $_testns . '-user-' . $_user_id . '<xss>e';
21 21
22 22 $new = array(); $new = array();
23 23 $new['uid'] = 0; $new['uid'] = 0;
 
... ... function rg_test_create_user($db, &$rg_ui)
31 31 $new['confirm_token'] = ''; $new['confirm_token'] = '';
32 32 $new['confirmed'] = 0; $new['confirmed'] = 0;
33 33 $new['plan_id'] = 0; $new['plan_id'] = 0;
34 $new['pass'] = 'pass-' . $_user_id;
35 $new['pass2'] = 'pass-' . $_user_id;
34 $new['pass'] = 'pass-' . $_user_id . ':';
35 $new['pass2'] = 'pass-' . $_user_id . ':';
36 36 $new['disk_used_mb'] = 0; $new['disk_used_mb'] = 0;
37 37 $new['last_ip'] = '?'; $new['last_ip'] = '?';
38 38 $new['ask_for_email_confirmation'] = 0; $new['ask_for_email_confirmation'] = 0;
39 39 $_user_id++; $_user_id++;
40 40
41 41 // Delete old user // Delete old user
42 $sql = 'DELETE FROM users WHERE username = \'' . $new['username'] . '\'';
43 $res = rg_sql_query($db, $sql);
42 $sql = 'DELETE FROM users WHERE username = @@username@@';
43 $res = rg_sql_query_params($db, $sql, $new);
44 44 if ($res === FALSE) { if ($res === FALSE) {
45 45 rg_log("Cannot delete old user: " . rg_sql_error()); rg_log("Cannot delete old user: " . rg_sql_error());
46 46 exit(1); exit(1);
 
... ... function rg_test_create_repo($db, $rg_ui, &$extra)
135 135
136 136 rg_log("Deleting repo " . $repo_id . "/" . $new['name']); rg_log("Deleting repo " . $repo_id . "/" . $new['name']);
137 137 $sql = 'DELETE FROM repos WHERE repo_id = ' . $repo_id $sql = 'DELETE FROM repos WHERE repo_id = ' . $repo_id
138 . ' OR name = \'' . $new['name'] . '\'';
139 $res = rg_sql_query($db, $sql);
138 . ' OR name = @@name@@';
139 $res = rg_sql_query_params($db, $sql, $new);
140 140 if ($res === FALSE) { if ($res === FALSE) {
141 141 rg_log("Cannot delete old repo: " . rg_sql_error()); rg_log("Cannot delete old repo: " . rg_sql_error());
142 142 exit(1); exit(1);
 
... ... function rg_test_create_repo($db, $rg_ui, &$extra)
151 151 rg_log("Cannot insert a repo (" . rg_repo_error() . ")!"); rg_log("Cannot insert a repo (" . rg_repo_error() . ")!");
152 152 exit(1); exit(1);
153 153 } }
154 rg_repo_cosmetic($db, $extra);
154 155
155 156 if ($repo_id > 0) { if ($repo_id > 0) {
156 157 $sql = "UPDATE repos SET repo_id = $repo_id" $sql = "UPDATE repos SET repo_id = $repo_id"
 
... ... function rg_test_create_repo($db, $rg_ui, &$extra)
158 159 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
159 160 rg_sql_free_result($res); rg_sql_free_result($res);
160 161 $new['repo_id'] = $repo_id; $new['repo_id'] = $repo_id;
162 // TODO: this is strange
161 163 rg_cache_unset('repo_by_name::' . $rg_ui['uid'], rg_cache_unset('repo_by_name::' . $rg_ui['uid'],
162 164 RG_SOCKET_NO_WAIT); RG_SOCKET_NO_WAIT);
163 165 } }
File tests/token.php changed (mode: 100644) (index 07bae60..1405f79)
... ... if ($r === FALSE) {
30 30 } }
31 31
32 32
33 rg_log("Now, test pre-login sessions...");
33 rg_log_enter("Now, test pre-login sessions...");
34 34 $rg_token = FALSE; /* we must remove it from memory */ $rg_token = FALSE; /* we must remove it from memory */
35 35 $a = array("ua" => "user-agent1", "sid" => "Xsession2", 'debug' => 1); $a = array("ua" => "user-agent1", "sid" => "Xsession2", 'debug' => 1);
36 36 $token = rg_token_get($db, $a, 'tag2'); $token = rg_token_get($db, $a, 'tag2');
 
... ... if ($r === FALSE) {
54 54 rg_log("Validating a correct token must work (" . rg_token_error() . ")!"); rg_log("Validating a correct token must work (" . rg_token_error() . ")!");
55 55 exit(1); exit(1);
56 56 } }
57 rg_log_exit();
57 58
58 59
59 rg_log("Testing double posting...");
60 rg_log_enter('Testing double posting...');
60 61 $rg_token = FALSE; /* we must remove it from memory */ $rg_token = FALSE; /* we must remove it from memory */
61 62 $a = array("ua" => "user-agent3", $a = array("ua" => "user-agent3",
62 63 "sid" => "session_double", "sid" => "session_double",
 
... ... if ($r !== FALSE) {
78 79 rg_log("Calling 'valid' second time must NOT work!"); rg_log("Calling 'valid' second time must NOT work!");
79 80 exit(1); exit(1);
80 81 } }
82 rg_log_exit();
81 83
82 84 rg_log("OK!"); rg_log("OK!");
83 85 ?> ?>
File tests/wh_cloud.git.sh changed (mode: 100755) (index b24985d..5a361f5)
3 3 set -e set -e
4 4 set -u set -u
5 5
6 export GIT_SSH_COMMAND="ssh -v -o IdentityFile=${PWD}/keys/wh_cloud -o IdentitiesOnly=yes"
6 export GIT_SSH_COMMAND="ssh -o IdentityFile=${PWD}/keys/wh_cloud -o IdentitiesOnly=yes"
7 7
8 echo "Cloning repo..."
8 9 rm -rf wh_cloud.git rm -rf wh_cloud.git
9 10 git clone "${1}" wh_cloud.git git clone "${1}" wh_cloud.git
10 11 cd wh_cloud.git cd wh_cloud.git
 
... ... EOF
30 31 git add appspec.yml git add appspec.yml
31 32 git commit -a -m "a commit" git commit -a -m "a commit"
32 33
34 echo "Pushing..."
33 35 git push origin master git push origin master
File tests/wh_lambda.php changed (mode: 100644) (index 6e515e6..b29a163)
... ... rg_log('');
96 96 rg_log_enter('Creating a repo and pushing it'); rg_log_enter('Creating a repo and pushing it');
97 97 $repo = array('name' => 'wh-cloud'); $repo = array('name' => 'wh-cloud');
98 98 rg_test_create_repo($db, $rg_ui, $repo); rg_test_create_repo($db, $rg_ui, $repo);
99 // TODO: extract url from $repo
99 100 $repo_url = 'ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port $repo_url = 'ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port
100 101 . '/user/' . $rg_ui['username'] . '/' . $repo['name']; . '/user/' . $rg_ui['username'] . '/' . $repo['name'];
101 rg_log('repo_url=' . escapeshellarg($repo_url));
102 rg_log('repo_url=' . $repo_url);
102 103 $r = rg_exec('./wh_cloud.git.sh ' . escapeshellarg($repo_url), '', FALSE, FALSE); $r = rg_exec('./wh_cloud.git.sh ' . escapeshellarg($repo_url), '', FALSE, FALSE);
103 104 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
104 rg_log('Could not create local git repo: ' . $r['errmsg'] . '!');
105 rg_log_ml('Could not create local git repo: ' . $r['errmsg'] . '!');
105 106 exit(1); exit(1);
106 107 } }
107 108 rg_log_exit(); rg_log_exit();
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://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

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