accepted, response, err := client.SendRequest("test-global-request", true, []byte("request-payload")) Expect(err).NotTo(HaveOccurred()) Expect(accepted).To(BeTrue()) Expect(response).To(Equal([]byte("response-payload"))) Expect(globalRequestHandler.HandleRequestCallCount()).To(Equal(1)) _, request := globalRequestHandler.HandleRequestArgsForCall(0) Expect(request.Type).To(Equal("test-global-request")) Expect(request.WantReply).To(BeTrue()) Expect(request.Payload).To(Equal([]byte("request-payload"))) }) }) Context("when the client requests a new channel", func() { var newChannelHandler *fake_handlers.FakeNewChannelHandler BeforeEach(func() { newChannelHandler = &fake_handlers.FakeNewChannelHandler{} newChannelHandler.HandleNewChannelStub = func(logger lager.Logger, newChannel ssh.NewChannel) { newChannel.Reject(ssh.Prohibited, "not now") } daemonNewChannelHandlers["test"] = newChannelHandler }) It("gets forwarded to the daemon", func() { _, _, err := client.OpenChannel("test", nil) Expect(err).To(Equal(&ssh.OpenChannelError{Reason: ssh.Prohibited, Message: "not now"})) }) }) })
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/pivotal-golang/lager" "github.com/pivotal-golang/lager/lagertest" "golang.org/x/crypto/ssh" ) var _ = Describe("DirectTcpipChannelHandler", func() { var ( sshd *daemon.Daemon client *ssh.Client logger *lagertest.TestLogger serverSSHConfig *ssh.ServerConfig handler *fake_handlers.FakeNewChannelHandler testHandler *handlers.DirectTcpipChannelHandler testDialer *fakes.FakeDialer echoHandler *fake_server.FakeConnectionHandler echoServer *server.Server echoAddress string ) BeforeEach(func() { logger = lagertest.NewTestLogger("test") echoHandler = &fake_server.FakeConnectionHandler{} echoHandler.HandleConnectionStub = func(conn net.Conn) { io.Copy(conn, conn) conn.Close()
name = "unknown-handler" wantReply = true }) It("rejects the request", func() { Expect(requestErr).NotTo(HaveOccurred()) Expect(accepted).To(BeFalse()) }) }) }) }) }) Describe("handleNewChannels", func() { var newChannelHandlers map[string]handlers.NewChannelHandler var fakeHandler *fake_handlers.FakeNewChannelHandler var client *ssh.Client BeforeEach(func() { fakeHandler = &fake_handlers.FakeNewChannelHandler{} newChannelHandlers = map[string]handlers.NewChannelHandler{ "known-channel-type": fakeHandler, } serverNetConn, clientNetConn := test_helpers.Pipe() sshd = daemon.New(logger, serverSSHConfig, nil, newChannelHandlers) go sshd.HandleConnection(serverNetConn) client = test_helpers.NewClient(clientNetConn, nil) })