From 94fb4ddd0cc697b8b51db0915164a62672001739 Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Fri, 1 Jan 2016 15:31:52 +0100 Subject: [PATCH] Add -testserver permutation Fixes #69 io.Pipe is unbuffered and provides a poor replacement for a net.Conn, use an os.Pipe instead. Also skip some tests which don't work under the Go server as it runs in process. --- .travis.yml | 2 ++ client_integration_darwin_test.go | 3 +++ client_integration_linux_test.go | 3 +++ client_integration_test.go | 16 +++++++++++++--- server.go | 18 ++++-------------- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index a4fb252..9ef70d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,3 +17,5 @@ install: script: - go test -integration -v ./... + - go test -testserver -v ./... + - go test -integration -testserver -v ./... diff --git a/client_integration_darwin_test.go b/client_integration_darwin_test.go index b3fb168..0f7cd01 100644 --- a/client_integration_darwin_test.go +++ b/client_integration_darwin_test.go @@ -8,6 +8,9 @@ import ( const sftpServer = "/usr/libexec/sftp-server" func TestClientStatVFS(t *testing.T) { + if *testServerImpl { + t.Skipf("go server does not support FXP_EXTENDED") + } sftp, cmd := testClient(t, READWRITE, NO_DELAY) defer cmd.Wait() defer sftp.Close() diff --git a/client_integration_linux_test.go b/client_integration_linux_test.go index 3e74bfa..1663ad4 100644 --- a/client_integration_linux_test.go +++ b/client_integration_linux_test.go @@ -8,6 +8,9 @@ import ( const sftpServer = "/usr/lib/openssh/sftp-server" func TestClientStatVFS(t *testing.T) { + if *testServerImpl { + t.Skipf("go server does not support FXP_EXTENDED") + } sftp, cmd := testClient(t, READWRITE, NO_DELAY) defer cmd.Wait() defer sftp.Close() diff --git a/client_integration_test.go b/client_integration_test.go index b4f995a..a3f4119 100644 --- a/client_integration_test.go +++ b/client_integration_test.go @@ -85,8 +85,14 @@ func (w delayedWriter) Close() error { } func testClientGoSvr(t testing.TB, readonly bool, delay time.Duration) (*Client, *exec.Cmd) { - txPipeRd, txPipeWr := io.Pipe() - rxPipeRd, rxPipeWr := io.Pipe() + txPipeRd, txPipeWr, err := os.Pipe() + if err != nil { + t.Fatal(err) + } + rxPipeRd, rxPipeWr, err := os.Pipe() + if err != nil { + t.Fatal(err) + } server, err := NewServer(txPipeRd, rxPipeWr, os.Stderr, 0, readonly, ".") if err != nil { @@ -1217,7 +1223,12 @@ func TestClientWalk(t *testing.T) { // sftp/issue/42, abrupt server hangup would result in client hangs. func TestServerRoughDisconnect(t *testing.T) { + if *testServerImpl { + t.Skipf("skipping with -testserver") + } sftp, cmd := testClient(t, READONLY, NO_DELAY) + defer cmd.Wait() + defer sftp.Close() f, err := sftp.Open("/dev/zero") if err != nil { @@ -1230,7 +1241,6 @@ func TestServerRoughDisconnect(t *testing.T) { }() io.Copy(ioutil.Discard, f) - sftp.Close() } // sftp/issue/26 writing to a read only file caused client to loop. diff --git a/server.go b/server.go index ae98b3f..a0b0f08 100644 --- a/server.go +++ b/server.go @@ -111,16 +111,13 @@ func (svr *Server) rxPackets() error { pktType, pktBytes, err := recvPacket(svr.in) switch err { case nil: - break + svr.pktChan <- rxPacket{fxp(pktType), pktBytes} case io.EOF: - fmt.Fprintf(svr.debugStream, "rxPackets loop done\n") return nil default: fmt.Fprintf(svr.debugStream, "recvPacket error: %v\n", err) return err } - - svr.pktChan <- rxPacket{fxp(pktType), pktBytes} } } @@ -153,7 +150,6 @@ func (svr *Server) Serve() error { break } } - fmt.Fprintf(svr.debugStream, "sftp server run finished\n") // close any still-open files for handle, file := range svr.openFiles { fmt.Fprintf(svr.debugStream, "sftp server file with handle '%v' left open: %v\n", handle, file.Name()) @@ -163,7 +159,6 @@ func (svr *Server) Serve() error { } func (svr *Server) decodePacket(pktType fxp, pktBytes []byte) (serverRespondablePacket, error) { - //pktId, restBytes := unmarshalUint32(pktBytes[1:]) var pkt serverRespondablePacket = nil switch pktType { case ssh_FXP_INIT: @@ -205,15 +200,10 @@ func (svr *Server) decodePacket(pktType fxp, pktBytes []byte) (serverRespondable case ssh_FXP_SYMLINK: pkt = &sshFxpSymlinkPacket{} default: - return nil, fmt.Errorf("unhandled packet type: %s", pktType.String()) + return nil, fmt.Errorf("unhandled packet type: %s", pktType) } - if pkt == nil { - return nil, fmt.Errorf("unhandled packet type: %s", pktType.String()) - } - if err := pkt.UnmarshalBinary(pktBytes); err != nil { - return nil, err - } - return pkt, nil + err := pkt.UnmarshalBinary(pktBytes) + return pkt, err } func (p sshFxInitPacket) respond(svr *Server) error {