Skip to content

Commit

Permalink
Merge branch 'master' into fix-abs
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jan 18, 2021
2 parents 3a42a5c + 3b6ac73 commit 1d270e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/cluster/executor/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ var _ Executor = &Local{}
func (l *Local) Execute(cmd string, sudo bool, timeout ...time.Duration) ([]byte, []byte, error) {
// try to acquire root permission
if l.Sudo || sudo {
cmd = fmt.Sprintf("sudo -H -u root bash -c \"cd; %s\"", cmd)
cmd = fmt.Sprintf("sudo -H -u root bash -c 'cd; %s'", cmd)
} else {
cmd = fmt.Sprintf("sudo -H -u %s bash -c \"cd; %s\"", l.Config.User, cmd)
cmd = fmt.Sprintf("sudo -H -u %s bash -c 'cd; %s'", l.Config.User, cmd)
}

// set a basic PATH in case it's empty on login
Expand Down
25 changes: 25 additions & 0 deletions pkg/cluster/executor/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package executor

import (
"fmt"
"io/ioutil"
"os"
"os/user"
Expand Down Expand Up @@ -66,3 +67,27 @@ func TestWrongIP(t *testing.T) {
assert.NotNil(err)
assert.Contains(err.Error(), "not found")
}

func TestLocalExecuteWithQuotes(t *testing.T) {
assert := require.New(t)
user, err := user.Current()
assert.Nil(err)
local, err := New(SSHTypeNone, false, SSHConfig{Host: "127.0.0.1", User: user.Username})
assert.Nil(err)

deployDir, err := ioutil.TempDir("", "tiup-*")
assert.Nil(err)
defer os.RemoveAll(deployDir)

cmds := []string{
fmt.Sprintf(`find %s -type f -exec sed -i "s/\${DS_.*-CLUSTER}/hello/g" {} \;`, deployDir),
fmt.Sprintf(`find %s -type f -exec sed -i "s/DS_.*-CLUSTER/hello/g" {} \;`, deployDir),
`ls '/tmp'`,
}
for _, cmd := range cmds {
for _, sudo := range []bool{true, false} {
_, _, err = local.Execute(cmd, sudo)
assert.Nil(err)
}
}
}

0 comments on commit 1d270e0

Please sign in to comment.