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 7fc439c93b2e9df218292d20fbe50606d770955f

tests: deal with the case when ControlMaster is not 'no'
Author: Catalin(ux) M. BOIE
Author date (UTC): 2017-07-09 06:35
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2017-07-09 06:35
Parent(s): af14b07381106cbc015aa6620d587b7e64ce7ed5
Signing key:
Tree: 321d07a3a3b9d690eec1b464c53a5f3425c85cf0
File Lines added Lines deleted
tests/helpers.inc.php 17 0
tests/pr_anon.php 5 4
tests/source.php 2 2
tests/ssh.php 20 23
tests/wh_cloud.git.sh 1 1
File tests/helpers.inc.php changed (mode: 100644) (index 7267b69..8d3502c)
... ... function rg_test_mr_in_db($db, $repo_id)
455 455 return $row; return $row;
456 456 } }
457 457
458 /*
459 *
460 */
461 function test_ssh($uid, $extra)
462 {
463 global $rg_ssh_host, $rg_ssh_port;
464
465 $cmd = 'ssh -v'
466 . ' -i keys/' . $uid
467 . ' -p ' . $rg_ssh_port
468 . ' -o ControlMaster=auto'
469 . ' -o ControlPath=' . __DIR__ . '/jars/ssh-' . $uid
470 . ' rocketgit@' . $rg_ssh_host;
471
472 return rg_exec($cmd . ' ' . $extra, '', FALSE, FALSE);
473 }
474
458 475 ?> ?>
File tests/pr_anon.php changed (mode: 100644) (index 9fb00f8..27a90da)
... ... $rg_event_socket = "/var/lib/rocketgit/sockets/event.sock";
25 25
26 26 prepare_http(); prepare_http();
27 27
28 $ssh = 'ssh -v -o ControlMaster=no -o IdentityFile=../../keys/pr_anon'
29 . ' -o IdentitiesOnly=yes';
30
28 31 rg_log(''); rg_log('');
29 32 rg_log_enter('Creating user...'); rg_log_enter('Creating user...');
30 33 rg_test_create_user($db, $rg_ui); rg_test_create_user($db, $rg_ui);
 
... ... rg_log_exit();
103 106
104 107 rg_log(''); rg_log('');
105 108 rg_log_enter('Do a non-anonymous push...'); rg_log_enter('Do a non-anonymous push...');
106 $r = rg_exec('export GIT_SSH_COMMAND="ssh -o IdentityFile=../../keys/pr_anon'
107 . ' -o IdentitiesOnly=yes"'
109 $r = rg_exec('export GIT_SSH_COMMAND="' . $ssh . '"'
108 110 . ' && cd temp_repos/pr_anon' . ' && cd temp_repos/pr_anon'
109 111 . ' && echo "change1" > a && git add a && git commit -m "change1 desc"' . ' && echo "change1" > a && git add a && git commit -m "change1 desc"'
110 112 . ' && echo "change2" > a && git commit -a -m "change2 desc"' . ' && echo "change2" > a && git commit -a -m "change2 desc"'
 
... ... if ($r['ok'] != 1) {
212 214 rg_log('Could not pull/commit/push by git proto: ' . $r['errmsg'] . '!'); rg_log('Could not pull/commit/push by git proto: ' . $r['errmsg'] . '!');
213 215 exit(1); exit(1);
214 216 } }
215 $r = rg_exec('export GIT_SSH_COMMAND="ssh -o IdentityFile=../../keys/pr_anon'
216 . ' -o IdentitiesOnly=yes"'
217 $r = rg_exec('export GIT_SSH_COMMAND="' . $ssh . '"'
217 218 . ' && cd temp_repos/pr_anon' . ' && cd temp_repos/pr_anon'
218 219 . ' && git reset --hard HEAD^1' . ' && git reset --hard HEAD^1'
219 220 . ' && echo "change1" > a' . ' && echo "change1" > a'
File tests/source.php changed (mode: 100644) (index 1075894..f6c7c39)
... ... $r = rg_exec('mkdir -p temp_repos && cd temp_repos'
47 47 . ' && rm -rf .source && mkdir .source && cd .source' . ' && rm -rf .source && mkdir .source && cd .source'
48 48 . ' && git init && git commit --allow-empty -m "' . $cmsg . '"' . ' && git init && git commit --allow-empty -m "' . $cmsg . '"'
49 49 . ' && git remote add origin ' . $remote . ' && git remote add origin ' . $remote
50 . ' && export GIT_SSH_COMMAND="ssh -v -o IdentityFile=../../keys/source -o IdentitiesOnly=yes"'
50 . ' && export GIT_SSH_COMMAND="ssh -v -o ControlMaster=no -o IdentityFile=../../keys/source -o IdentitiesOnly=yes"'
51 51 . ' && git push origin master', . ' && git push origin master',
52 52 '', FALSE, FALSE); '', FALSE, FALSE);
53 53 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
54 54 rg_log_ml('out: ' . $r['errmsg']); rg_log_ml('out: ' . $r['errmsg']);
55 rg_log("Seems I cannot push master! err=$err");
55 rg_log('Seems I cannot push master!');
56 56 exit(1); exit(1);
57 57 } }
58 58 $data = array(); $data = array();
File tests/ssh.php changed (mode: 100644) (index 5f90361..5223049)
... ... if ($r === FALSE) {
39 39 exit(1); exit(1);
40 40 } }
41 41
42 $cmd = 'ssh -i keys/' . $rg_ui['uid'] . ' rocketgit@' . $rg_ssh_host
43 . ' -p ' . $rg_ssh_port;
44
45 42 rg_test_upload_ssh_key($db, $rg_ui, $rg_ui['uid']); rg_test_upload_ssh_key($db, $rg_ui, $rg_ui['uid']);
46 43
47 44 rg_log(''); rg_log('');
48 45 $list = array('', 'status', 'repos', 'repo', 'totp'); $list = array('', 'status', 'repos', 'repo', 'totp');
49 46 foreach ($list as $s) { foreach ($list as $s) {
50 47 rg_log('Connecting for [' . $s . ']'); rg_log('Connecting for [' . $s . ']');
51 $r = rg_exec($cmd . ' ' . $s, '', FALSE, FALSE);
48 $r = test_ssh($rg_ui['uid'], $s);
52 49 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
53 50 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
54 51 exit(1); exit(1);
 
... ... foreach ($list as $s) {
63 60 $list = array('remove-device', 'unenroll'); $list = array('remove-device', 'unenroll');
64 61 foreach ($list as $s) { foreach ($list as $s) {
65 62 rg_log('Connecting for [totp ' . $s . ']'); rg_log('Connecting for [totp ' . $s . ']');
66 $r = rg_exec($cmd . ' totp ' . $s, '', FALSE, FALSE);
63 $r = test_ssh($rg_ui['uid'], ' totp ' . $s);
67 64 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
68 65 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
69 66 exit(1); exit(1);
 
... ... foreach ($list as $s) {
73 70
74 71 rg_log(''); rg_log('');
75 72 rg_log_enter('Testing wrong command'); rg_log_enter('Testing wrong command');
76 $r = rg_exec($cmd . ' wrongcmd', '', FALSE, FALSE);
73 $r = test_ssh($rg_ui['uid'], ' wrongcmd');
77 74 if ($r['ok'] != 0) { if ($r['ok'] != 0) {
78 75 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
79 76 rg_log('We should receive error code 0 not ' . $r['ok'] . '!'); rg_log('We should receive error code 0 not ' . $r['ok'] . '!');
 
... ... rg_log_exit();
89 86
90 87 rg_log(''); rg_log('');
91 88 rg_log('Testing enroll procedure'); rg_log('Testing enroll procedure');
92 $r = rg_exec($cmd . ' totp enroll', '', FALSE, FALSE);
89 $r = test_ssh($rg_ui['uid'], ' totp enroll', '', FALSE, FALSE);
93 90 $t = explode('enter the following code: ', $r['data']); $t = explode('enter the following code: ', $r['data']);
94 91 $t = explode('.', $t[1]); $t = explode('.', $t[1]);
95 92 $key = trim($t[0]); $key = trim($t[0]);
 
... ... rg_log("key=$key");
97 94
98 95 $tc = intval(time() / 30) - 1; // we try one in the past $tc = intval(time() / 30) - 1; // we try one in the past
99 96 $token = rg_totp_compute($key, $tc, 6); $token = rg_totp_compute($key, $tc, 6);
100 $r = rg_exec($cmd . ' totp enroll ' . $token, '', FALSE, FALSE);
97 $r = test_ssh($rg_ui['uid'], ' totp enroll ' . $token);
101 98 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
102 99 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
103 100 exit(1); exit(1);
 
... ... rg_log('');
113 110 rg_log('Testing \'val\' command'); rg_log('Testing \'val\' command');
114 111 $tc = intval(time() / 30); $tc = intval(time() / 30);
115 112 $token = rg_totp_compute($key, $tc, 6); $token = rg_totp_compute($key, $tc, 6);
116 $r = rg_exec($cmd . ' totp val ' . $token . ' 2m', '', FALSE, FALSE);
113 $r = test_ssh($rg_ui['uid'], ' totp val ' . $token . ' 2m');
117 114 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
118 115 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
119 116 exit(1); exit(1);
 
... ... rg_log('exp=' . $exp);
130 127
131 128 rg_log(''); rg_log('');
132 129 rg_log('Reuse of the token must be forbidden (device)'); rg_log('Reuse of the token must be forbidden (device)');
133 $r = rg_exec($cmd . ' totp val ' . $token . ' 2m', '', FALSE, FALSE);
130 $r = test_ssh($rg_ui['uid'], ' totp val ' . $token . ' 2m');
134 131 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
135 132 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
136 133 exit(1); exit(1);
 
... ... if (!strstr($r['stderr'], 'cannot reuse')) {
144 141
145 142 rg_log(''); rg_log('');
146 143 rg_log('Testing \'list-val\' command'); rg_log('Testing \'list-val\' command');
147 $r = rg_exec($cmd . ' totp list-val', '', FALSE, FALSE);
144 $r = test_ssh($rg_ui['uid'], ' totp list-val');
148 145 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
149 146 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
150 147 exit(1); exit(1);
 
... ... rg_log('');
160 157 rg_log('Testing \'inval\' command - wrong ip'); rg_log('Testing \'inval\' command - wrong ip');
161 158 $tc = intval(time() / 30) + 1; // we try one in the future $tc = intval(time() / 30) + 1; // we try one in the future
162 159 $token = rg_totp_compute($key, $tc, 6); $token = rg_totp_compute($key, $tc, 6);
163 $r = rg_exec($cmd . ' totp inval 1.1.1.1', '', FALSE, FALSE);
160 $r = test_ssh($rg_ui['uid'], ' totp inval 1.1.1.1');
164 161 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
165 162 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
166 163 exit(1); exit(1);
 
... ... rg_log('');
176 173 rg_log('Testing \'inval\' command - all'); rg_log('Testing \'inval\' command - all');
177 174 $tc = intval(time() / 30) + 1; // we try one in the future $tc = intval(time() / 30) + 1; // we try one in the future
178 175 $token = rg_totp_compute($key, $tc, 6); $token = rg_totp_compute($key, $tc, 6);
179 $r = rg_exec($cmd . ' totp inval all', '', FALSE, FALSE);
176 $r = test_ssh($rg_ui['uid'], ' totp inval all');
180 177 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
181 178 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
182 179 exit(1); exit(1);
 
... ... rg_log('');
192 189 rg_log('Testing \'remove-device\''); rg_log('Testing \'remove-device\'');
193 190 $tc = intval(time() / 30) + 2; $tc = intval(time() / 30) + 2;
194 191 $token = rg_totp_compute($key, $tc, 6); $token = rg_totp_compute($key, $tc, 6);
195 $_cmd = $cmd . ' totp remove-device ' . $token;
196 $r = rg_exec($_cmd, '', FALSE, FALSE);
192 $_cmd = ' totp remove-device ' . $token;
193 $r = test_ssh($rg_ui['uid'], $_cmd);
197 194 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
198 195 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
199 196 exit(1); exit(1);
 
... ... foreach ($sc as &$t)
218 215
219 216
220 217 rg_log(''); rg_log('');
221 rg_log('Testing \'unenroll\'');
218 rg_log('Testing \'unenroll\' (must work)');
222 219 $token = array_pop($sc); $token = array_pop($sc);
223 220 $token = ltrim($token, '0'); $token = ltrim($token, '0');
224 $_cmd = $cmd . ' totp unenroll ' . $token;
225 $r = rg_exec($_cmd, '', FALSE, FALSE);
221 $_cmd = ' totp unenroll ' . $token;
222 $r = test_ssh($rg_ui['uid'], $_cmd);
226 223 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
227 224 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
228 225 exit(1); exit(1);
 
... ... if (!strstr($r['data'], 'You are now unenrolled')) {
236 233 rg_log(''); rg_log('');
237 234 rg_log('After enroll we should not be able to use the scratch codes'); rg_log('After enroll we should not be able to use the scratch codes');
238 235 $token = array_pop($sc); $token = array_pop($sc);
239 $r = rg_exec($cmd . ' totp val ' . $token . ' 2m', '', FALSE, FALSE);
236 $r = test_ssh($rg_ui['uid'], ' totp val ' . $token . ' 2m');
240 237 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
241 238 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
242 239 exit(1); exit(1);
 
... ... $sc = rg_test_sc_generate($db, $rg_ui);
254 251 rg_log(''); rg_log('');
255 252 rg_log('sc: testing \'val\' cmd...'); rg_log('sc: testing \'val\' cmd...');
256 253 $token = array_pop($sc); $token = array_pop($sc);
257 $_cmd = $cmd . ' totp val ' . $token . ' 2m';
258 $r = rg_exec($_cmd, '', FALSE, FALSE);
254 $_cmd = ' totp val ' . $token . ' 2m';
255 $r = test_ssh($rg_ui['uid'], $_cmd);
259 256 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
260 257 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
261 258 exit(1); exit(1);
 
... ... if (!strstr($r['data'], 'Success!')) {
269 266
270 267 rg_log(''); rg_log('');
271 268 rg_log('Reuse of the scratch code must be forbidden (sc)'); rg_log('Reuse of the scratch code must be forbidden (sc)');
272 $_cmd = $cmd . ' totp val ' . $token . ' 2m';
273 $r = rg_exec($_cmd, '', FALSE, FALSE);
269 $_cmd = ' totp val ' . $token . ' 2m';
270 $r = test_ssh($rg_ui['uid'], $_cmd);
274 271 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
275 272 rg_log_ml('error: ' . $r['stderr']); rg_log_ml('error: ' . $r['stderr']);
276 273 exit(1); exit(1);
File tests/wh_cloud.git.sh changed (mode: 100755) (index 5a361f5..bb99f0f)
3 3 set -e set -e
4 4 set -u set -u
5 5
6 export GIT_SSH_COMMAND="ssh -o IdentityFile=${PWD}/keys/wh_cloud -o IdentitiesOnly=yes"
6 export GIT_SSH_COMMAND="ssh -o ControlMaster=no -o IdentityFile=${PWD}/keys/wh_cloud -o IdentitiesOnly=yes"
7 7
8 8 echo "Cloning repo..." echo "Cloning repo..."
9 9 rm -rf wh_cloud.git rm -rf wh_cloud.git
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