LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package ssh | 5 // +build !windows |
| 6 |
| 7 package test |
6 | 8 |
7 // direct-tcpip functional tests | 9 // direct-tcpip functional tests |
8 | 10 |
9 import ( | 11 import ( |
10 "net" | 12 "net" |
11 "net/http" | 13 "net/http" |
12 "testing" | 14 "testing" |
13 ) | 15 ) |
14 | 16 |
15 func TestTCPIPHTTP(t *testing.T) { | 17 func TestTCPIPHTTP(t *testing.T) { |
16 if *sshuser == "" { | |
17 t.Log("ssh.user not defined, skipping test") | |
18 return | |
19 } | |
20 // google.com will generate at least one redirect, possibly three | 18 // google.com will generate at least one redirect, possibly three |
21 // depending on your location. | 19 // depending on your location. |
22 doTest(t, "http://google.com") | 20 doTest(t, "http://google.com") |
23 } | 21 } |
24 | 22 |
25 func TestTCPIPHTTPS(t *testing.T) { | 23 func TestTCPIPHTTPS(t *testing.T) { |
26 if *sshuser == "" { | |
27 t.Log("ssh.user not defined, skipping test") | |
28 return | |
29 } | |
30 doTest(t, "https://encrypted.google.com/") | 24 doTest(t, "https://encrypted.google.com/") |
31 } | 25 } |
32 | 26 |
33 func doTest(t *testing.T, url string) { | 27 func doTest(t *testing.T, url string) { |
34 » config := &ClientConfig{ | 28 » server := newServer(t) |
35 » » User: *sshuser, | 29 » defer server.Shutdown() |
36 » » Auth: []ClientAuth{ | 30 » conn := server.Dial() |
37 » » » ClientAuthPassword(password(*sshpass)), | |
38 » » }, | |
39 » } | |
40 » conn, err := Dial("tcp", "localhost:22", config) | |
41 » if err != nil { | |
42 » » t.Fatalf("Unable to connect: %s", err) | |
43 » } | |
44 defer conn.Close() | 31 defer conn.Close() |
| 32 |
45 tr := &http.Transport{ | 33 tr := &http.Transport{ |
46 Dial: func(n, addr string) (net.Conn, error) { | 34 Dial: func(n, addr string) (net.Conn, error) { |
47 return conn.Dial(n, addr) | 35 return conn.Dial(n, addr) |
48 }, | 36 }, |
49 } | 37 } |
50 client := &http.Client{ | 38 client := &http.Client{ |
51 Transport: tr, | 39 Transport: tr, |
52 } | 40 } |
53 resp, err := client.Get(url) | 41 resp, err := client.Get(url) |
54 if err != nil { | 42 if err != nil { |
55 t.Fatalf("unable to proxy: %s", err) | 43 t.Fatalf("unable to proxy: %s", err) |
56 } | 44 } |
57 // got a body without error | 45 // got a body without error |
58 t.Log(resp) | 46 t.Log(resp) |
59 } | 47 } |
LEFT | RIGHT |