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); |