Ejemplo n.º 1
0
			Describe("client requests to target", func() {
				var client *ssh.Client

				JustBeforeEach(func() {
					var err error
					client, err = ssh.Dial("tcp", proxyAddress, clientConfig)
					Expect(err).NotTo(HaveOccurred())
				})

				AfterEach(func() {
					client.Close()
				})

				Context("when the client sends a global request", func() {
					var globalRequestHandler *fake_handlers.FakeGlobalRequestHandler

					BeforeEach(func() {
						globalRequestHandler = &fake_handlers.FakeGlobalRequestHandler{}
						globalRequestHandler.HandleRequestStub = func(logger lager.Logger, request *ssh.Request) {
							request.Reply(true, []byte("response-payload"))
						}
						daemonGlobalRequestHandlers["test-global-request"] = globalRequestHandler
					})

					It("gets forwarded to the daemon and the response comes back", func() {
						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")))
Ejemplo n.º 2
0
			AfterEach(func() {
				if client != nil {
					client.Close()
				}
			})

			It("performs a handshake", func() {
				Expect(clientConnErr).NotTo(HaveOccurred())
			})
		})
	})

	Describe("handleGlobalRequests", func() {
		var (
			globalRequestHandlers map[string]handlers.GlobalRequestHandler

			fakeHandler *fake_handlers.FakeGlobalRequestHandler
			client      *ssh.Client
		)

		BeforeEach(func() {
			fakeHandler = &fake_handlers.FakeGlobalRequestHandler{}
			globalRequestHandlers = map[string]handlers.GlobalRequestHandler{
				"known-handler": fakeHandler,
			}

			serverNetConn, clientNetConn := test_helpers.Pipe()

			sshd = daemon.New(logger, serverSSHConfig, globalRequestHandlers, nil)
			go sshd.HandleConnection(serverNetConn)

			client = test_helpers.NewClient(clientNetConn, nil)