File: remote_test.sh

package info (click to toggle)
kworkflow 1%3A0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,212 kB
  • sloc: sh: 31,869; perl: 2,172; sql: 268; ansic: 114; xml: 84; python: 76; makefile: 27
file content (556 lines) | stat: -rwxr-xr-x 18,936 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
#!/usr/bin/env bash

include './src/lib/remote.sh'
include './src/lib/kwlib.sh'
include './src/lib/kw_config_loader.sh'
include './tests/unit/utils.sh'

function which_distro_mock()
{
  printf '%s\n' 'debian'
}

function setupMockFunctions()
{
  shopt -s expand_aliases
  alias which_distro='which_distro_mock'
}

function tearDownMockFunctions()
{
  unalias which_distro
}

function oneTimeSetUp()
{
  local -r current_path="$PWD"
  local -r kernel_install_path='kernel_install'

  FAKE_KW="$SHUNIT_TMPDIR/fake_kw"
  TEST_PATH="$SHUNIT_TMPDIR/test_path"
  RSYNC_PREFIX='rsync --info=progress2 -e'
  RSYNC_FLAGS="-LrlptD --rsync-path='sudo rsync'"

  mkdir -p "$FAKE_KW"
  mkdir -p "$TEST_PATH/.kw"

  cp -f 'tests/unit/samples/kworkflow.config' "$TEST_PATH/.kw/"
  cp -f 'tests/unit/samples/dmesg' "$TEST_PATH"
  cp -f "${KW_REMOTE_SAMPLES_DIR}/remote.config" "${TEST_PATH}/.kw/"
  cp -f "${KW_REMOTE_SAMPLES_DIR}/remote_4.config" "${TEST_PATH}/.kw/"

  export KW_CACHE_DIR="$FAKE_KW"
  export KW_PLUGINS_DIR="$FAKE_KW"
  export DEPLOY_SCRIPT="$FAKE_KW/$kernel_install_path/deploy.sh"
  export KW_ETC_DIR="$TEST_PATH"
  export modules_path="$FAKE_KW/$kernel_install_path/lib/modules"
  export INVALID_ARG='Invalid arguments'
  export NO_SUCH_FILE='No such file'
  export SSH_OK='ssh -p 3333 127.0.0.1'
  export HOME='/home/SOMETHING'
  rm -rf "$FAKE_KW"

  mk_fake_remote "$FAKE_KW" "$modules_path"
}

function oneTimeTearDown()
{
  unset KW_CACHE_DIR
  rm -rf "$SHUNIT_TMPDIR"
}

function setUp()
{
  local -r current_path="$PWD"

  cd "$TEST_PATH" || {
    fail "($LINENO) It was not possible to move to temporary directory"
    return
  }

  remote_parameters['REMOTE_IP']=''
  remote_parameters['REMOTE_PORT']=''
  remote_parameters['REMOTE_USER']=''
  remote_parameters['REMOTE_FILE']=''
  remote_parameters['REMOTE_FILE_HOST']=''

  cd "$current_path" || {
    fail "($LINENO) It was not possible return to original directory"
    return
  }
}

function tearDown()
{
  remote_parameters=()
  configurations=()
}

function test_populate_remote_info()
{
  local ret
  local output
  local -r current_path="$PWD"

  cd "$TEST_PATH" || {
    fail "($LINENO) It was not possible to move to temporary directory"
    return
  }

  # Force an unspected error
  configurations=()

  populate_remote_info 'localhost'
  assertEquals "($LINENO) Expected localhost" 'localhost' "${remote_parameters['REMOTE_IP']}"
  assertEquals "($LINENO) Expected 22" 22 "${remote_parameters['REMOTE_PORT']}"
  assertEquals "($LINENO) Expected root" 'root' "${remote_parameters['REMOTE_USER']}"

  populate_remote_info 'localhost:6789'
  assertEquals "($LINENO) Expected localhost" 'localhost' "${remote_parameters['REMOTE_IP']}"
  assertEquals "($LINENO) Expected 6789" 6789 "${remote_parameters['REMOTE_PORT']}"
  assertEquals "($LINENO) Expected root" 'root' "${remote_parameters['REMOTE_USER']}"

  populate_remote_info 'localhost'
  assertEquals "($LINENO) Expected localhost" 'localhost' "${remote_parameters['REMOTE_IP']}"
  assertEquals "($LINENO) Expected 22" 22 "${remote_parameters['REMOTE_PORT']}"
  assertEquals "($LINENO) Expected root" 'root' "${remote_parameters['REMOTE_USER']}"

  populate_remote_info 'ada@localhost:3773'
  assertEquals "($LINENO) Expected localhost" 'localhost' "${remote_parameters['REMOTE_IP']}"
  assertEquals "($LINENO) Expected 3773" 3773 "${remote_parameters['REMOTE_PORT']}"
  assertEquals "($LINENO) Expected ada" 'ada' "${remote_parameters['REMOTE_USER']}"

  # Let's check with a config file information
  populate_remote_info ''
  assertEquals "($LINENO) Expected origin" 'origin' "${remote_parameters['REMOTE_FILE_HOST']}"
  assertEquals "($LINENO) Expected remote.config path" "${PWD}/.kw/remote.config" "${remote_parameters['REMOTE_FILE']}"

  cd "$current_path" || {
    fail "($LINENO) It was not possible return to original directory"
    return
  }
}

function test_is_ssh_connection_configured()
{
  local remote='test_remote'
  local user='test_user'
  local port='22'
  local flag='TEST_MODE'
  local current_path="$PWD"

  cd "$TEST_PATH" || {
    fail "($LINENO) It was not possible to move to temporary directory"
    return
  }

  remote_parameters['REMOTE_IP']="$remote"
  remote_parameters['REMOTE_USER']="$user"
  remote_parameters['REMOTE_PORT']="$port"

  is_ssh_connection_configured "$flag" > /dev/null

  assertEquals "($LINENO):" 0 "$?"

  cd "$current_path" || {
    fail "($LINENO) It was not possible to move to the original path"
    return
  }
}

function test_is_ssh_connection_configured_with_remote_config_file()
{
  local flag='TEST_MODE'
  local current_path="$PWD"

  cd "$TEST_PATH" || {
    fail "($LINENO) It was not possible to move to temporary directory"
    return
  }

  remote_parameters['REMOTE_IP']=''
  remote_parameters['REMOTE_USER']=''
  remote_parameters['REMOTE_PORT']=''
  remote_parameters['REMOTE_FILE']="${TEST_PATH}/.kw/remote.config"
  remote_parameters['REMOTE_FILE_HOST']='origin'

  is_ssh_connection_configured "$flag" > /dev/null

  assertEquals "($LINENO):" 0 "$?"

  cd "$current_path" || {
    fail "($LINENO) It was not possible to move to the original path"
    return
  }
}

function test_is_ssh_connection_configured_no_remote_config_file()
{
  local flag='TEST_MODE'
  local current_path="$PWD"

  cd "$TEST_PATH" || {
    fail "($LINENO) It was not possible to move to temporary directory"
    return
  }

  remote_parameters['REMOTE_IP']=''
  remote_parameters['REMOTE_USER']=''
  remote_parameters['REMOTE_PORT']=''
  remote_parameters['REMOTE_FILE']=''
  remote_parameters['REMOTE_FILE_HOST']=''

  is_ssh_connection_configured "$flag"

  assertEquals "($LINENO):" 2 "$?"

  cd "$current_path" || {
    fail "($LINENO) It was not possible to move to the original path"
    return
  }
}

function test_ssh_connection_failure_message()
{
  local expected_remote='deb-tm'
  local expected_user='root'
  local expected_port='333'
  local returned_remote
  local returned_user
  local returned_port
  local ret
  local no_config_file_failure_message='Could not find remote config file.'$'\n'
  no_config_file_failure_message+='Suggestion: check if there is a remote.config or try using'$'\n'
  no_config_file_failure_message+='  kw ssh (-r | --remote) <user>@<ip>:<port>'

  cd "$TEST_PATH" || {
    fail "($LINENO) It was not possible to move to temporary directory"
    return
  }

  # Case 1: IP, user and port passed as command line arguments (kw ssh -r)
  remote_parameters['REMOTE_IP']='deb-tm'
  remote_parameters['REMOTE_USER']='root'
  remote_parameters['REMOTE_PORT']='333'

  ret=$(ssh_connection_failure_message)
  returned_remote=$(printf '%s' "$ret" | grep 'IP' | sed 's/ IP: //')
  returned_user=$(printf '%s' "$ret" | grep 'User' | sed 's/ User: //')
  returned_port=$(printf '%s' "$ret" | grep 'Port' | sed 's/ Port: //')

  assertEquals "($LINENO):" "$expected_remote" "$returned_remote"
  assertEquals "($LINENO):" "$expected_user" "$returned_user"
  assertEquals "($LINENO):" "$expected_port" "$returned_port"

  # Case 2: Using a remote config file
  remote_parameters['REMOTE_IP']=''
  remote_parameters['REMOTE_USER']=''
  remote_parameters['REMOTE_PORT']=''
  remote_parameters['REMOTE_FILE']="${TEST_PATH}/.kw/remote.config"
  remote_parameters['REMOTE_FILE_HOST']='origin'

  ret=$(ssh_connection_failure_message)
  returned_remote=$(printf '%s' "$ret" | grep 'IP' | sed 's/ IP: //')
  returned_user=$(printf '%s' "$ret" | grep 'User' | sed 's/ User: //')
  returned_port=$(printf '%s' "$ret" | grep 'Port' | sed 's/ Port: //')

  assertEquals "($LINENO):" "$expected_remote" "$returned_remote"
  assertEquals "($LINENO):" "$expected_user" "$returned_user"
  assertEquals "($LINENO):" "$expected_port" "$returned_port"

  # Case 3: No remote config file found
  remote_parameters['REMOTE_FILE']=''
  remote_parameters['REMOTE_FILE_HOST']=''

  ret=$(ssh_connection_failure_message)
  assertEquals "($LINENO):" "$no_config_file_failure_message" "$ret"
}

function test_ssh_connection_failure_message_with_bad_formatted_remote_config()
{
  local displayed_ip
  local displayed_user
  local displayed_port
  local output

  remote_parameters['REMOTE_IP']=''
  remote_parameters['REMOTE_USER']=''
  remote_parameters['REMOTE_PORT']=''
  remote_parameters['REMOTE_FILE']="${TEST_PATH}/.kw/remote_4.config"
  remote_parameters['REMOTE_FILE_HOST']='origin'

  output=$(ssh_connection_failure_message)
  displayed_ip=$(printf '%s' "$output" | grep 'IP' | sed 's/ IP: //')
  displayed_user=$(printf '%s' "$output" | grep 'User' | sed 's/ User: //')
  displayed_port=$(printf '%s' "$output" | grep 'Port' | sed 's/ Port: //')

  assert_equals_helper 'Wrong IP displayed' "$LINENO" 'deb-tm' "$displayed_ip"
  assert_equals_helper 'Wrong User displayed' "$LINENO" 'root' "$displayed_user"
  assert_equals_helper 'Wrong Port displayed' "$LINENO" 123 "$displayed_port"
}

function test_ssh_connection_failure_message_with_invalid_host_in_remote_config()
{
  local displayed_ip
  local displayed_user
  local displayed_port
  local output

  remote_parameters['REMOTE_IP']=''
  remote_parameters['REMOTE_USER']=''
  remote_parameters['REMOTE_PORT']=''
  remote_parameters['REMOTE_FILE']="${TEST_PATH}/.kw/remote_4.config"
  remote_parameters['REMOTE_FILE_HOST']='fedora-test'

  output=$(ssh_connection_failure_message)
  displayed_ip=$(printf '%s' "$output" | grep 'IP' | sed 's/ IP: //')
  displayed_user=$(printf '%s' "$output" | grep 'User' | sed 's/ User: //')
  displayed_port=$(printf '%s' "$output" | grep 'Port' | sed 's/ Port: //')

  assert_equals_helper 'Wrong IP displayed' "$LINENO" 'fedora-tm' "$displayed_ip"
  assert_equals_helper 'Wrong User displayed' "$LINENO" '' "$displayed_user"
  assert_equals_helper 'Wrong Port displayed' "$LINENO" '' "$displayed_port"
}

function test_cmd_remote()
{
  local log_path="${SHUNIT_TMPDIR}/cmd_remote_test.log"
  local command='ls -lah'
  local remote='178.31.38.12'
  local port='2222'
  local user='kw'
  local flag='TEST_MODE'
  local output
  local expected_command
  local ret

  remote_parameters['REMOTE_FILE']="${SHUNIT_TMPDIR}/remote.config"
  remote_parameters['REMOTE_FILE_HOST']='origin'

  expected_command="ssh -F ${SHUNIT_TMPDIR}/remote.config origin sudo \"$command\""
  output=$(cmd_remotely "$flag" "$command")
  assertEquals "($LINENO): Command did not match" "$expected_command" "$output"

  configurations=()
  parse_configuration "$SAMPLES_DIR/kworkflow_template.config"

  # Remote
  remote_parameters['REMOTE_IP']='localhost'
  remote_parameters['REMOTE_PORT']='22'
  remote_parameters['REMOTE_USER']='root'

  expected_command="ssh -p $port $user@$remote sudo \"$command\""
  output=$(cmd_remotely "$flag" "$command" "$remote" "$port" "$user")
  assertEquals "($LINENO):" "$expected_command" "$output"

  expected_command="ssh -p $port $user@localhost sudo \"$command\""
  output=$(cmd_remotely "$flag" "$command" '' "$port" "$user")
  assertEquals "($LINENO):" "$expected_command" "$output"

  expected_command="ssh -p 22 $user@localhost sudo \"$command\""
  output=$(cmd_remotely "$flag" "$command" '' '' "$user")
  assertEquals "($LINENO):" "$expected_command" "$output"

  expected_command="ssh -p 22 root@localhost sudo \"$command\""
  output=$(cmd_remotely "$flag" "$command")
  assertEquals "($LINENO):" "$expected_command" "$output"

  expected_command="No command specified"
  output=$(cmd_remotely "$flag" '')
  assertEquals "($LINENO):" "$expected_command" "$output"
}

function test_cp2remote()
{
  local src='/any/path'
  local dst='/any/path/2'
  local remote='172.16.224.1'
  local port='2222'
  local user='kw'
  local flag='TEST_MODE'
  local rsync_params='--include="*/" --exclude="*"'
  local expected_cmd_str="$RSYNC_PREFIX 'ssh -p $port' $src $user@$remote:$dst $RSYNC_FLAGS $rsync_params"

  remote_parameters['REMOTE_IP']='127.0.0.1'
  remote_parameters['REMOTE_PORT']='3333'
  remote_parameters['REMOTE_USER']='juca'

  # Load default configureation, because we want to test default values
  output=$(cp2remote "$flag" "$src" "$dst" "$rsync_params" "$remote" "$port" "$user")
  assert_equals_helper 'Standard Rsync' "$LINENO" "$expected_cmd_str" "$output"

  # Default src
  src="$KW_CACHE_DIR/$LOCAL_TO_DEPLOY_DIR/*"
  expected_cmd_str="$RSYNC_PREFIX 'ssh -p $port' $src $user@$remote:$dst $RSYNC_FLAGS"
  output=$(cp2remote "$flag" '' "$dst" '' "$remote" "$port" "$user")
  assert_equals_helper 'Default src' "$LINENO" "$expected_cmd_str" "$output"

  # Default src and dst
  dst="$REMOTE_KW_DEPLOY"
  expected_cmd_str="$RSYNC_PREFIX 'ssh -p $port' $src $user@$remote:$dst $RSYNC_FLAGS"

  output=$(cp2remote "$flag" '' '' '' "$remote" "$port" "$user")
  assert_equals_helper 'Default src and dst' "$LINENO" "$expected_cmd_str" "$output"

  # Default src, dst, and remote
  remote='127.0.0.1'
  expected_cmd_str="$RSYNC_PREFIX 'ssh -p $port' $src $user@$remote:$dst $RSYNC_FLAGS"

  output=$(cp2remote "$flag" '' '' '' '' "$port" "$user")
  assert_equals_helper 'Default src, dst, and remote' "$LINENO" "$expected_cmd_str" "$output"

  # Default port
  port='3333'
  expected_cmd_str="$RSYNC_PREFIX 'ssh -p $port' $src $user@$remote:$dst $RSYNC_FLAGS"
  output=$(cp2remote "$flag" '' '' '' '' '' "$user")
  assert_equals_helper 'Default src, dst, remote, and port' "$LINENO" "$expected_cmd_str" "$output"

  # Default user
  user='juca'
  expected_cmd_str="$RSYNC_PREFIX 'ssh -p $port' $src $user@$remote:$dst $RSYNC_FLAGS"
  output=$(cp2remote "$flag" '' '' '' '' '' '')
  assert_equals_helper 'Default src, dst, remote, port, and user' "$LINENO" "$expected_cmd_str" "$output"
}

function test_remote2host()
{
  local flag='TEST_MODE'
  local src='/some/path'
  local dst='/another/path'
  local remote_host='origin'
  local port='2223'
  local user='root'
  local remote='192.168.122.116'
  local output
  local expected_cmd_str

  # Use remote configuration file
  remote_parameters['REMOTE_FILE']="${TEST_PATH}/.kw/remote.config"
  remote_parameters['REMOTE_FILE_HOST']="$remote_host"
  expected_cmd_str="$RSYNC_PREFIX 'ssh -F ${TEST_PATH}/.kw/remote.config' $remote_host:$src $dst $RSYNC_FLAGS"
  output=$(remote2host "$flag" "$src" "$dst" '' '' '' '' '')
  assert_equals_helper 'Remote configuration file' "$LINENO" "$expected_cmd_str" "$output"

  remote_parameters['REMOTE_IP']='192.168.122.197'
  remote_parameters['REMOTE_PORT']='2225'
  remote_parameters['REMOTE_USER']='juca'

  # No use of remote_parameters by remote2host
  expected_cmd_str="$RSYNC_PREFIX 'ssh -p $port' $user@$remote:$src $dst $RSYNC_FLAGS"
  output=$(remote2host "$flag" "$src" "$dst" "$remote" "$port" "$user")
  assert_equals_helper 'Pass ip, port and user to remote2host' "$LINENO" "$expected_cmd_str" "$output"

  # Default remote
  remote='192.168.122.197'
  expected_cmd_str="$RSYNC_PREFIX 'ssh -p $port' $user@$remote:$src $dst $RSYNC_FLAGS"
  output=$(remote2host "$flag" "$src" "$dst" '' "$port" "$user")
  assert_equals_helper 'Default remote' "$LINENO" "$expected_cmd_str" "$output"

  # Default port
  port='2225'
  expected_cmd_str="$RSYNC_PREFIX 'ssh -p $port' $user@$remote:$src $dst $RSYNC_FLAGS"
  output=$(remote2host "$flag" "$src" "$dst" "$remote" '' "$user")
  assert_equals_helper 'Default port' "$LINENO" "$expected_cmd_str" "$output"

  # Default user
  user='juca'
  expected_cmd_str="$RSYNC_PREFIX 'ssh -p $port' $user@$remote:$src $dst $RSYNC_FLAGS"
  output=$(remote2host "$flag" "$src" "$dst" "$remote" "$port")
  assert_equals_helper 'Default user' "$LINENO" "$expected_cmd_str" "$output"
}

function test_extract_remote_info_from_config_file()
{
  remote_parameters['REMOTE_FILE']="${TEST_PATH}/.kw/remote.config"
  remote_parameters['REMOTE_FILE_HOST']='steamos'

  extract_remote_info_from_config_file
  assert_equals_helper 'Remote did not match' "$LINENO" 'steamdeck' "${remote_parameters['REMOTE_IP']}"
  assert_equals_helper 'Port did not match' "$LINENO" 8888 "${remote_parameters['REMOTE_PORT']}"
  assert_equals_helper 'User did not match' "$LINENO" 'jozzi' "${remote_parameters['REMOTE_USER']}"
}

function test_remove_key_from_kwown_hosts_by_user_request()
{
  local expected_cmd="ssh-keygen -q -f '${HOME}/.ssh/known_hosts' -R 'steamdeck'"

  remote_parameters['REMOTE_FILE']="${TEST_PATH}/.kw/remote.config"
  remote_parameters['REMOTE_FILE_HOST']='steamos'

  output=$(remove_key_from_kwown_hosts 'TEST_MODE' 'something' <<< 'Y' | tail -1)
  assert_equals_helper 'Remove identification command is wrong' "$LINENO" "$expected_cmd" "$output"
}

function test_remove_key_from_kwown_hosts_by_user_request_cancel_operation()
{
  local output

  remote_parameters['REMOTE_FILE']="${TEST_PATH}/.kw/remote.config"
  remote_parameters['REMOTE_FILE_HOST']='steamos'

  output=$(remove_key_from_kwown_hosts 'TEST_MODE' 'something' <<< 'N')
  assert_equals_helper 'User canceled the operation' "$LINENO" 125 "$?"
}

function test_ssh_error_handling()
{
  ssh_error_handling 'This is not a valid error'
  assert_equals_helper 'This is not a valid error' "$LINENO" 0 "$?"

  ssh_error_handling 'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED'
  assert_equals_helper 'Remote host change' "$LINENO" 111 "$?"
}

function test_which_distro()
{
  local cmd='cat /etc/os-release'
  local remote='172.16.224.1'
  local user='xpto'
  local port='2222'
  local flag='TEST_MODE'
  local expected_str

  remote_parameters['REMOTE_IP']='127.0.0.1'
  remote_parameters['REMOTE_PORT']='3333'
  remote_parameters['REMOTE_USER']='juca'

  output=$(which_distro "$remote" "$port" "$user" "$flag")
  expected_str="ssh -p $port $user@$remote sudo \"$cmd\""
  assertEquals "($LINENO):" "$expected_str" "$output"

  user='juca'
  output=$(which_distro "$remote" "$port" '' "$flag")
  expected_str="ssh -p $port $user@$remote sudo \"$cmd\""
  assertEquals "($LINENO)" "$expected_str" "$output"

  port=3333
  output=$(which_distro "$remote" '' '' "$flag")
  expected_str="ssh -p $port $user@$remote sudo \"$cmd\""
  assertEquals "($LINENO)" "$expected_str" "$output"

  remote='127.0.0.1'
  output=$(which_distro '' '' '' "$flag")
  expected_str="ssh -p $port $user@$remote sudo \"$cmd\""
  assert_equals_helper 'Command did not match' "$LINENO" "$expected_str" "$output"
}

function test_setup_remote_ssh_with_passwordless()
{
  local output
  declare -a expected_cmd=(
    '-> Trying to set up passwordless access'
    '' # Extra line due to \n in the say message
    'ssh-copy-id root@127.0.0.1'
    'ssh -o StrictHostKeyChecking=accept-new -o BatchMode=yes -o ConnectTimeout=5 -p 3333 root@127.0.0.1 exit'
    'ssh-copy-id juca@127.0.0.1'
    'ssh -o StrictHostKeyChecking=accept-new -o BatchMode=yes -o ConnectTimeout=5 -p 3333 juca@127.0.0.1 exit'
  )

  remote_parameters['REMOTE_USER']='juca'
  remote_parameters['REMOTE_IP']='127.0.0.1'
  remote_parameters['REMOTE_PORT']='3333'
  output=$(setup_remote_ssh_with_passwordless 'TEST_MODE')
  compare_command_sequence '' "$LINENO" 'expected_cmd' "$output"
}

invoke_shunit