go.crypto/ssh: fix test failure on windows
Use a handler that does not attempt to send a status message as the failing test closes the connection abruptly. Also, check the err response on all shell.ReadLine operations. R=agl, minux.ma, kardianos CC=golang-dev https://golang.org/cl/6487043
This commit is contained in:
+22
-13
@@ -380,8 +380,11 @@ func TestServerStdoutRespectsMaxPacketSize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(dfc) currently writes succeed after Close()
|
func TestClientCannotSendAfterEOF(t *testing.T) {
|
||||||
func testClientCannotSendAfterEOF(t *testing.T) {
|
// TODO(dfc) currently writes succeed after Close()
|
||||||
|
t.Logf("test skipped")
|
||||||
|
return
|
||||||
|
|
||||||
conn := dial(shellHandler, t)
|
conn := dial(shellHandler, t)
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
session, err := conn.NewSession()
|
session, err := conn.NewSession()
|
||||||
@@ -405,7 +408,7 @@ func testClientCannotSendAfterEOF(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestClientCannotSendAfterClose(t *testing.T) {
|
func TestClientCannotSendAfterClose(t *testing.T) {
|
||||||
conn := dial(shellHandler, t)
|
conn := dial(exitWithoutSignalOrStatus, t)
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
session, err := conn.NewSession()
|
session, err := conn.NewSession()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -457,21 +460,21 @@ func exitStatusZeroHandler(ch *serverChan, t *testing.T) {
|
|||||||
defer ch.Close()
|
defer ch.Close()
|
||||||
// this string is returned to stdout
|
// this string is returned to stdout
|
||||||
shell := newServerShell(ch, "> ")
|
shell := newServerShell(ch, "> ")
|
||||||
shell.ReadLine()
|
readLine(shell, t)
|
||||||
sendStatus(0, ch, t)
|
sendStatus(0, ch, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func exitStatusNonZeroHandler(ch *serverChan, t *testing.T) {
|
func exitStatusNonZeroHandler(ch *serverChan, t *testing.T) {
|
||||||
defer ch.Close()
|
defer ch.Close()
|
||||||
shell := newServerShell(ch, "> ")
|
shell := newServerShell(ch, "> ")
|
||||||
shell.ReadLine()
|
readLine(shell, t)
|
||||||
sendStatus(15, ch, t)
|
sendStatus(15, ch, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func exitSignalAndStatusHandler(ch *serverChan, t *testing.T) {
|
func exitSignalAndStatusHandler(ch *serverChan, t *testing.T) {
|
||||||
defer ch.Close()
|
defer ch.Close()
|
||||||
shell := newServerShell(ch, "> ")
|
shell := newServerShell(ch, "> ")
|
||||||
shell.ReadLine()
|
readLine(shell, t)
|
||||||
sendStatus(15, ch, t)
|
sendStatus(15, ch, t)
|
||||||
sendSignal("TERM", ch, t)
|
sendSignal("TERM", ch, t)
|
||||||
}
|
}
|
||||||
@@ -479,31 +482,37 @@ func exitSignalAndStatusHandler(ch *serverChan, t *testing.T) {
|
|||||||
func exitSignalHandler(ch *serverChan, t *testing.T) {
|
func exitSignalHandler(ch *serverChan, t *testing.T) {
|
||||||
defer ch.Close()
|
defer ch.Close()
|
||||||
shell := newServerShell(ch, "> ")
|
shell := newServerShell(ch, "> ")
|
||||||
shell.ReadLine()
|
readLine(shell, t)
|
||||||
sendSignal("TERM", ch, t)
|
sendSignal("TERM", ch, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func exitSignalUnknownHandler(ch *serverChan, t *testing.T) {
|
func exitSignalUnknownHandler(ch *serverChan, t *testing.T) {
|
||||||
defer ch.Close()
|
defer ch.Close()
|
||||||
shell := newServerShell(ch, "> ")
|
shell := newServerShell(ch, "> ")
|
||||||
shell.ReadLine()
|
readLine(shell, t)
|
||||||
sendSignal("SYS", ch, t)
|
sendSignal("SYS", ch, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func exitWithoutSignalOrStatus(ch *serverChan, t *testing.T) {
|
func exitWithoutSignalOrStatus(ch *serverChan, t *testing.T) {
|
||||||
defer ch.Close()
|
defer ch.Close()
|
||||||
shell := newServerShell(ch, "> ")
|
shell := newServerShell(ch, "> ")
|
||||||
shell.ReadLine()
|
readLine(shell, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func shellHandler(ch *serverChan, t *testing.T) {
|
func shellHandler(ch *serverChan, t *testing.T) {
|
||||||
defer ch.Close()
|
defer ch.Close()
|
||||||
// this string is returned to stdout
|
// this string is returned to stdout
|
||||||
shell := newServerShell(ch, "golang")
|
shell := newServerShell(ch, "golang")
|
||||||
shell.ReadLine()
|
readLine(shell, t)
|
||||||
sendStatus(0, ch, t)
|
sendStatus(0, ch, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readLine(shell *ServerTerminal, t *testing.T) {
|
||||||
|
if _, err := shell.ReadLine(); err != nil && err != io.EOF {
|
||||||
|
t.Fatalf("unable to read line: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func sendStatus(status uint32, ch *serverChan, t *testing.T) {
|
func sendStatus(status uint32, ch *serverChan, t *testing.T) {
|
||||||
msg := exitStatusMsg{
|
msg := exitStatusMsg{
|
||||||
PeersId: ch.remoteId,
|
PeersId: ch.remoteId,
|
||||||
@@ -549,7 +558,7 @@ func sendZeroWindowAdjust(ch *serverChan, t *testing.T) {
|
|||||||
// send a bogus zero sized window update
|
// send a bogus zero sized window update
|
||||||
ch.sendWindowAdj(0)
|
ch.sendWindowAdj(0)
|
||||||
shell := newServerShell(ch, "> ")
|
shell := newServerShell(ch, "> ")
|
||||||
shell.ReadLine()
|
readLine(shell, t)
|
||||||
sendStatus(0, ch, t)
|
sendStatus(0, ch, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -559,7 +568,7 @@ func discardHandler(ch *serverChan, t *testing.T) {
|
|||||||
// the initial 1 << 14 window.
|
// the initial 1 << 14 window.
|
||||||
ch.sendWindowAdj(1024 * 1024)
|
ch.sendWindowAdj(1024 * 1024)
|
||||||
shell := newServerShell(ch, "> ")
|
shell := newServerShell(ch, "> ")
|
||||||
shell.ReadLine()
|
readLine(shell, t)
|
||||||
io.Copy(ioutil.Discard, ch.serverConn)
|
io.Copy(ioutil.Discard, ch.serverConn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,7 +578,7 @@ func largeSendHandler(ch *serverChan, t *testing.T) {
|
|||||||
// the initial 1 << 14 window.
|
// the initial 1 << 14 window.
|
||||||
ch.sendWindowAdj(1024 * 1024)
|
ch.sendWindowAdj(1024 * 1024)
|
||||||
shell := newServerShell(ch, "> ")
|
shell := newServerShell(ch, "> ")
|
||||||
shell.ReadLine()
|
readLine(shell, t)
|
||||||
// try to send more than the 32k window
|
// try to send more than the 32k window
|
||||||
// will allow
|
// will allow
|
||||||
if err := ch.writePacket(make([]byte, 128*1024)); err == nil {
|
if err := ch.writePacket(make([]byte, 128*1024)); err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user