Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(632)

Side by Side Diff: ssh/client_func_test.go

Issue 6601043: code review 6601043: go.crypto/ssh: new package: sshtest (Closed)
Patch Set: diff -r aab880ed1ec2 https://code.google.com/p/go.crypto Created 11 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ssh/test/doc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package ssh
6
7 // ClientConn functional tests.
8 // These tests require a running ssh server listening on port 22
9 // on the local host. Functional tests will be skipped unless
10 // -ssh.user and -ssh.pass must be passed to gotest.
11
12 import (
13 "bytes"
14 "flag"
15 "io"
16 "testing"
17 )
18
19 var (
20 sshuser = flag.String("ssh.user", "", "ssh username")
21 sshpass = flag.String("ssh.pass", "", "ssh password")
22 sshprivkey = flag.String("ssh.privkey", "", "ssh privkey file")
23 )
24
25 func TestFuncPasswordAuth(t *testing.T) {
26 if *sshuser == "" {
27 t.Log("ssh.user not defined, skipping test")
28 return
29 }
30 config := &ClientConfig{
31 User: *sshuser,
32 Auth: []ClientAuth{
33 ClientAuthPassword(password(*sshpass)),
34 },
35 }
36 conn, err := Dial("tcp", "localhost:22", config)
37 if err != nil {
38 t.Fatalf("Unable to connect: %s", err)
39 }
40 defer conn.Close()
41 }
42
43 func TestFuncPublickeyAuth(t *testing.T) {
44 if *sshuser == "" {
45 t.Log("ssh.user not defined, skipping test")
46 return
47 }
48 kc := new(keychain)
49 if err := kc.loadPEM(*sshprivkey); err != nil {
50 t.Fatalf("unable to load private key: %s", err)
51 }
52 config := &ClientConfig{
53 User: *sshuser,
54 Auth: []ClientAuth{
55 ClientAuthKeyring(kc),
56 },
57 }
58 conn, err := Dial("tcp", "localhost:22", config)
59 if err != nil {
60 t.Fatalf("unable to connect: %s", err)
61 }
62 defer conn.Close()
63 }
64
65 func TestFuncLargeRead(t *testing.T) {
66 if *sshuser == "" {
67 t.Log("ssh.user not defined, skipping test")
68 return
69 }
70 kc := new(keychain)
71 if err := kc.loadPEM(*sshprivkey); err != nil {
72 t.Fatalf("unable to load private key: %s", err)
73 }
74 config := &ClientConfig{
75 User: *sshuser,
76 Auth: []ClientAuth{
77 ClientAuthKeyring(kc),
78 },
79 }
80 conn, err := Dial("tcp", "localhost:22", config)
81 if err != nil {
82 t.Fatalf("unable to connect: %s", err)
83 }
84 defer conn.Close()
85
86 session, err := conn.NewSession()
87 if err != nil {
88 t.Fatalf("unable to create new session: %s", err)
89 }
90
91 stdout, err := session.StdoutPipe()
92 if err != nil {
93 t.Fatalf("unable to acquire stdout pipe: %s", err)
94 }
95
96 err = session.Start("dd if=/dev/urandom bs=2048 count=1")
97 if err != nil {
98 t.Fatalf("unable to execute remote command: %s", err)
99 }
100
101 buf := new(bytes.Buffer)
102 n, err := io.Copy(buf, stdout)
103 if err != nil {
104 t.Fatalf("error reading from remote stdout: %s", err)
105 }
106
107 if n != 2048 {
108 t.Fatalf("Expected %d bytes but read only %d from remote command ", 2048, n)
109 }
110 }
OLDNEW
« no previous file with comments | « no previous file | ssh/test/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b