Some ssh-agent clients expect the server to support remove all messages for protocols 1 & 2 and error if protocol 1 support is missing. This adds a null-op implementation of the remove all message in similar fashion to the existing list all message support. Fixes golang/go#15159 Change-Id: I9389885d89c9147f3e10850893bba6ed7d0a4e82 Reviewed-on: https://go-review.googlesource.com/21468 Reviewed-by: Han-Wen Nienhuys <hanwen@google.com> Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
110 lines
2.4 KiB
Go
110 lines
2.4 KiB
Go
// Copyright 2012 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 agent
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
)
|
|
|
|
func TestServer(t *testing.T) {
|
|
c1, c2, err := netPipe()
|
|
if err != nil {
|
|
t.Fatalf("netPipe: %v", err)
|
|
}
|
|
defer c1.Close()
|
|
defer c2.Close()
|
|
client := NewClient(c1)
|
|
|
|
go ServeAgent(NewKeyring(), c2)
|
|
|
|
testAgentInterface(t, client, testPrivateKeys["rsa"], nil, 0)
|
|
}
|
|
|
|
func TestLockServer(t *testing.T) {
|
|
testLockAgent(NewKeyring(), t)
|
|
}
|
|
|
|
func TestSetupForwardAgent(t *testing.T) {
|
|
a, b, err := netPipe()
|
|
if err != nil {
|
|
t.Fatalf("netPipe: %v", err)
|
|
}
|
|
|
|
defer a.Close()
|
|
defer b.Close()
|
|
|
|
_, socket, cleanup := startAgent(t)
|
|
defer cleanup()
|
|
|
|
serverConf := ssh.ServerConfig{
|
|
NoClientAuth: true,
|
|
}
|
|
serverConf.AddHostKey(testSigners["rsa"])
|
|
incoming := make(chan *ssh.ServerConn, 1)
|
|
go func() {
|
|
conn, _, _, err := ssh.NewServerConn(a, &serverConf)
|
|
if err != nil {
|
|
t.Fatalf("Server: %v", err)
|
|
}
|
|
incoming <- conn
|
|
}()
|
|
|
|
conf := ssh.ClientConfig{}
|
|
conn, chans, reqs, err := ssh.NewClientConn(b, "", &conf)
|
|
if err != nil {
|
|
t.Fatalf("NewClientConn: %v", err)
|
|
}
|
|
client := ssh.NewClient(conn, chans, reqs)
|
|
|
|
if err := ForwardToRemote(client, socket); err != nil {
|
|
t.Fatalf("SetupForwardAgent: %v", err)
|
|
}
|
|
|
|
server := <-incoming
|
|
ch, reqs, err := server.OpenChannel(channelType, nil)
|
|
if err != nil {
|
|
t.Fatalf("OpenChannel(%q): %v", channelType, err)
|
|
}
|
|
go ssh.DiscardRequests(reqs)
|
|
|
|
agentClient := NewClient(ch)
|
|
testAgentInterface(t, agentClient, testPrivateKeys["rsa"], nil, 0)
|
|
conn.Close()
|
|
}
|
|
|
|
func TestV1ProtocolMessages(t *testing.T) {
|
|
c1, c2, err := netPipe()
|
|
if err != nil {
|
|
t.Fatalf("netPipe: %v", err)
|
|
}
|
|
defer c1.Close()
|
|
defer c2.Close()
|
|
c := NewClient(c1)
|
|
|
|
go ServeAgent(NewKeyring(), c2)
|
|
|
|
testV1ProtocolMessages(t, c.(*client))
|
|
}
|
|
|
|
func testV1ProtocolMessages(t *testing.T, c *client) {
|
|
reply, err := c.call([]byte{agentRequestV1Identities})
|
|
if err != nil {
|
|
t.Fatalf("v1 request all failed: %v", err)
|
|
}
|
|
if msg, ok := reply.(*agentV1IdentityMsg); !ok || msg.Numkeys != 0 {
|
|
t.Fatalf("invalid request all response: %#v", reply)
|
|
}
|
|
|
|
reply, err = c.call([]byte{agentRemoveAllV1Identities})
|
|
if err != nil {
|
|
t.Fatalf("v1 remove all failed: %v", err)
|
|
}
|
|
if _, ok := reply.(*successAgentMsg); !ok {
|
|
t.Fatalf("invalid remove all response: %#v", reply)
|
|
}
|
|
}
|