@@ -53,6 +53,7 @@ func addLineSSHProxyConf(line string) {
53
53
54
54
func removeLineSSHProxyConf (line string ) {
55
55
ctx := context .Background ()
56
+ line = strings .ReplaceAll (line , "/" , "\\ /" )
56
57
for _ , gateway := range gateways {
57
58
_ , _ , _ , err := runCommand (ctx , "ssh" , []string {fmt .Sprintf ("root@%s" , gateway ), "--" , fmt .Sprintf ("sed -i 's/^%s$//' %s" , line , SSHPROXYCONFIG )}, nil , nil )
58
59
if err != nil {
@@ -63,6 +64,7 @@ func removeLineSSHProxyConf(line string) {
63
64
64
65
func updateLineSSHProxyConf (key string , value string ) {
65
66
ctx := context .Background ()
67
+ value = strings .ReplaceAll (value , "/" , "\\ /" )
66
68
for _ , gateway := range gateways {
67
69
_ , _ , _ , err := runCommand (ctx , "ssh" , []string {fmt .Sprintf ("root@%s" , gateway ), "--" , fmt .Sprintf ("sed -i '/%s:/s/: .*$/: %s/' %s" , key , value , SSHPROXYCONFIG )}, nil , nil )
68
70
if err != nil {
@@ -243,6 +245,29 @@ func TestSimpleConnect(t *testing.T) {
243
245
}
244
246
}
245
247
248
+ func TestBlockingCommand (t * testing.T ) {
249
+ addLineSSHProxyConf ("blocking_command: /bin/true" )
250
+ ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
251
+ defer cancel ()
252
+ args , cmd := prepareCommand ("gateway1" , 2023 , "hostname" )
253
+ _ , stdout , stderr , err := runCommand (ctx , "ssh" , args , nil , nil )
254
+ stdoutStr := strings .TrimSpace (string (stdout ))
255
+ if err != nil {
256
+ t .Errorf ("%s unexpected error: %v | stderr = %s" , cmd , err , string (stderr ))
257
+ } else if stdoutStr != "server1" {
258
+ t .Errorf ("%s hostname = %s, want server1" , cmd , stdoutStr )
259
+ }
260
+ updateLineSSHProxyConf ("blocking_command" , "/bin/false" )
261
+ defer removeLineSSHProxyConf ("blocking_command: /bin/false" )
262
+ args , _ = prepareCommand ("gateway1" , 2023 , "hostname" )
263
+ rc , _ , _ , err := runCommand (ctx , "ssh" , args , nil , nil )
264
+ if err == nil {
265
+ t .Errorf ("got no error, expected error due to blocking_command" )
266
+ } else if rc != 1 {
267
+ t .Errorf ("blocking_command rc = %d, want 1" , rc )
268
+ }
269
+ }
270
+
246
271
func TestNodesets (t * testing.T ) {
247
272
disableHost ("server[1000-1002]" )
248
273
checkHostState (t , "server1000:22" , "disabled" , true )
@@ -382,12 +407,12 @@ func TestEtcdConnections(t *testing.T) {
382
407
}
383
408
384
409
func TestWithoutEtcd (t * testing.T ) {
385
- updateLineSSHProxyConf ("endpoints" , "[\" https:\\ / \\ /void:2379\" ]" )
410
+ updateLineSSHProxyConf ("endpoints" , "[\" https:/ /void:2379\" ]" )
386
411
ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
387
412
defer cancel ()
388
413
args , cmdStr := prepareCommand ("gateway1" , 2023 , "hostname" )
389
414
_ , stdout , _ , err := runCommand (ctx , "ssh" , args , nil , nil )
390
- updateLineSSHProxyConf ("endpoints" , "[\" https:\\ / \\ /etcd:2379\" ]" )
415
+ updateLineSSHProxyConf ("endpoints" , "[\" https:/ /etcd:2379\" ]" )
391
416
if err != nil {
392
417
log .Fatal (err )
393
418
}
@@ -396,10 +421,10 @@ func TestWithoutEtcd(t *testing.T) {
396
421
t .Errorf ("%s got %s, expected server1" , cmdStr , dest )
397
422
}
398
423
399
- updateLineSSHProxyConf ("endpoints" , "[\" https:\\ / \\ /void:2379\" ]" )
424
+ updateLineSSHProxyConf ("endpoints" , "[\" https:/ /void:2379\" ]" )
400
425
updateLineSSHProxyConf ("mandatory" , "true" )
401
426
_ , _ , _ , err = runCommand (ctx , "ssh" , args , nil , nil )
402
- updateLineSSHProxyConf ("endpoints" , "[\" https:\\ / \\ /etcd:2379\" ]" )
427
+ updateLineSSHProxyConf ("endpoints" , "[\" https:/ /etcd:2379\" ]" )
403
428
updateLineSSHProxyConf ("mandatory" , "false" )
404
429
if err == nil {
405
430
t .Error ("the connection should have been rejected" )
0 commit comments