mirror of
https://github.com/golang/go
synced 2024-11-20 06:54:42 -07:00
exp/ssh: add simple tcpip.go functional tests
R=rsc, agl, n13m3y3r, bradfitz CC=golang-dev https://golang.org/cl/5385041
This commit is contained in:
parent
d5514120b1
commit
f2c858749a
59
src/pkg/exp/ssh/tcpip_func_test.go
Normal file
59
src/pkg/exp/ssh/tcpip_func_test.go
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ssh
|
||||
|
||||
// direct-tcpip functional tests
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTCPIPHTTP(t *testing.T) {
|
||||
if *sshuser == "" {
|
||||
t.Log("ssh.user not defined, skipping test")
|
||||
return
|
||||
}
|
||||
// google.com will generate at least one redirect, possibly three
|
||||
// depending on your location.
|
||||
doTest(t, "http://google.com")
|
||||
}
|
||||
|
||||
func TestTCPIPHTTPS(t *testing.T) {
|
||||
if *sshuser == "" {
|
||||
t.Log("ssh.user not defined, skipping test")
|
||||
return
|
||||
}
|
||||
doTest(t, "https://encrypted.google.com/")
|
||||
}
|
||||
|
||||
func doTest(t *testing.T, url string) {
|
||||
config := &ClientConfig{
|
||||
User: *sshuser,
|
||||
Auth: []ClientAuth{
|
||||
ClientAuthPassword(password(*sshpass)),
|
||||
},
|
||||
}
|
||||
conn, err := Dial("tcp", "localhost:22", config)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to connect: %s", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
tr := &http.Transport{
|
||||
Dial: func(n, addr string) (net.Conn, error) {
|
||||
return conn.Dial(n, addr)
|
||||
},
|
||||
}
|
||||
client := &http.Client{
|
||||
Transport: tr,
|
||||
}
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to proxy: %s", err)
|
||||
}
|
||||
// got a body without error
|
||||
t.Log(resp)
|
||||
}
|
Loading…
Reference in New Issue
Block a user