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.
This commit is contained in:
Dave Cheney 2016-01-01 15:31:52 +01:00
parent e85cb2364d
commit 94fb4ddd0c
5 changed files with 25 additions and 17 deletions

View File

@ -17,3 +17,5 @@ install:
script:
- go test -integration -v ./...
- go test -testserver -v ./...
- go test -integration -testserver -v ./...

View File

@ -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()

View File

@ -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()

View File

@ -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.

View File

@ -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 {