Skip to content

Commit

Permalink
Pass remote sudo password in tests (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpm-canonical authored Sep 2, 2024
1 parent 67d27d0 commit 1f18069
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/thread_tests/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ func remote_exec(t *testing.T, command string) string {

t.Logf("[exec-ssh] %s", command)

// Remote commands that require sudo might ask for the password. Always pass it in. See https://stackoverflow.com/a/11955358
if strings.HasPrefix(command, "sudo ") {
command = strings.TrimPrefix(command, "sudo ")
escapedPassword := strings.ReplaceAll(remotePassword, `"`, `\"`)
command = fmt.Sprintf(`echo "%s" | sudo -S %s`, escapedPassword, command)
}

if SSHClient == nil {
t.Fatalf("SSH client not initialized. Please connect to remote device first")
}
Expand Down

0 comments on commit 1f18069

Please sign in to comment.