go.crypto/ssh: add workaround for broken port forwarding in

OpenSSH 5.

Tested with OpenSSH_5.9

R=agl, dave
CC=golang-dev
https://golang.org/cl/11921043
This commit is contained in:
Han-Wen Nienhuys
2013-07-26 14:37:37 -04:00
committed by Adam Langley
parent eb19e229bd
commit 2d394e3025
4 changed files with 74 additions and 32 deletions
+2 -28
View File
@@ -8,47 +8,21 @@ package test
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net"
"testing"
"time"
"code.google.com/p/go.crypto/ssh"
)
func listenSSHAuto(conn *ssh.ClientConn) (net.Listener, error) {
var sshListener net.Listener
var err error
tries := 10
for i := 0; i < tries; i++ {
port := 1024 + rand.Intn(50000)
// We can't reliably test dynamic port allocation, as it does
// not work correctly with OpenSSH before 6.0. See also
// https://bugzilla.mindrot.org/show_bug.cgi?id=2017
sshListener, err = conn.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port))
if err == nil {
break
}
}
if err != nil {
return nil, fmt.Errorf("conn.Listen failed: %v (after %d tries)", err, tries)
}
return sshListener, nil
}
func TestPortForward(t *testing.T) {
server := newServer(t)
defer server.Shutdown()
conn := server.Dial(clientConfig())
defer conn.Close()
sshListener, err := listenSSHAuto(conn)
sshListener, err := conn.Listen("tcp", "localhost:0")
if err != nil {
t.Fatal(err)
}
@@ -124,7 +98,7 @@ func TestAcceptClose(t *testing.T) {
defer server.Shutdown()
conn := server.Dial(clientConfig())
sshListener, err := listenSSHAuto(conn)
sshListener, err := conn.Listen("tcp", "localhost:0")
if err != nil {
t.Fatal(err)
}