Skip to content

Commit

Permalink
ssh/test: skip TestValidTerminalMode on non-Bourne shells
Browse files Browse the repository at this point in the history
Fixes golang/go#38037.

Change-Id: Ide77dddc9f57b3f0318a419a1474e11215623b64
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/485175
Run-TryBot: Bryan Mills <bcmills@google.com>
Commit-Queue: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Apr 17, 2023
1 parent 1faeef9 commit 7d6d3f5
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions ssh/test/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"errors"
"fmt"
"io"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -255,15 +257,31 @@ func TestValidTerminalMode(t *testing.T) {
t.Fatalf("session failed: %s", err)
}

stdin.Write([]byte("stty -a && exit\n"))
if _, err := io.WriteString(stdin, "echo SHELL $SHELL && stty -a && exit\n"); err != nil {
t.Fatal(err)
}

var buf bytes.Buffer
if _, err := io.Copy(&buf, stdout); err != nil {
buf := new(strings.Builder)
if _, err := io.Copy(buf, stdout); err != nil {
t.Fatalf("reading failed: %s", err)
}

if testing.Verbose() {
t.Logf("echo SHELL $SHELL && stty -a && exit:\n%s", buf)
}

shellLine := regexp.MustCompile("(?m)^SHELL (.*)$").FindStringSubmatch(buf.String())
if len(shellLine) != 2 {
t.Fatalf("missing output from echo SHELL $SHELL")
}
switch shell := filepath.Base(strings.TrimSpace(shellLine[1])); shell {
case "sh", "bash":
default:
t.Skipf("skipping test on non-Bourne shell %q", shell)
}

if sttyOutput := buf.String(); !strings.Contains(sttyOutput, "-echo ") {
t.Fatalf("terminal mode failure: expected -echo in stty output, got %s", sttyOutput)
t.Fatal("terminal mode failure: expected -echo in stty output")
}
}

Expand Down

0 comments on commit 7d6d3f5

Please sign in to comment.