aboutsummaryrefslogtreecommitdiff
path: root/session.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-10-12 01:34:59 +0700
committerShulhan <ms@kilabit.info>2023-10-12 22:14:51 +0700
commita0c9e5e87e951df4d1bc86c6ccc2ed73dbe7f942 (patch)
treed0650c477fff66fe87afb51233ce9c88e8c9fd79 /session.go
parent207e7f016bf96ab037f510837940c037111cd42f (diff)
downloadawwan-a0c9e5e87e951df4d1bc86c6ccc2ed73dbe7f942.tar.xz
all: add integration tests for magic command "#get!"
Diffstat (limited to 'session.go')
-rw-r--r--session.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/session.go b/session.go
index 86d4fae..760b362 100644
--- a/session.go
+++ b/session.go
@@ -214,9 +214,16 @@ func (ses *Session) SudoCopy(req *Request, stmt *Statement) (err error) {
sudoCp = &Statement{
kind: statementKindDefault,
- cmd: "sudo",
- args: []string{"cp", src, dst},
- raw: []byte(`sudo cp "` + src + `" "` + dst + `"`),
+ }
+
+ // Detect which stdin we use.
+ // If its non-nil, use "sudo -S" to read password from stdin instead
+ // of from terminal.
+ // This will allow us to test sudo behaviour.
+ if req.stdin == nil {
+ sudoCp.raw = []byte(`sudo cp "` + src + `" "` + dst + `"`)
+ } else {
+ sudoCp.raw = []byte(`sudo -S cp "` + src + `" "` + dst + `"`)
}
err = ses.ExecLocal(req, sudoCp)
@@ -280,9 +287,16 @@ func (ses *Session) ExecLocal(req *Request, stmt *Statement) (err error) {
args = string(stmt.raw)
cmd = exec.Command(`/bin/sh`, `-c`, args)
)
+
+ cmd.Stdin = req.stdin
cmd.Stdout = req.stdout
cmd.Stderr = req.stderr
- return cmd.Run()
+
+ err = cmd.Run()
+ if err != nil {
+ return fmt.Errorf(`ExecLocal: %w`, err)
+ }
+ return nil
}
// executeRequires run the "#require:" statements from line 0 until