Beispiel #1
0
					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")))

						Expect(globalRequestHandler.HandleRequestCallCount()).To(Equal(1))

						_, request := globalRequestHandler.HandleRequestArgsForCall(0)
						Expect(request.Type).To(Equal("test-global-request"))
						Expect(request.WantReply).To(BeTrue())
				name      string
				wantReply bool
			)

			JustBeforeEach(func() {
				accepted, _, requestErr = client.SendRequest(name, wantReply, []byte("payload"))
			})

			Context("and there is an associated handler", func() {
				BeforeEach(func() {
					name = "known-handler"
					wantReply = true

					fakeHandler.HandleRequestStub = func(logger lager.Logger, request *ssh.Request) {
						request.Reply(true, []byte("response"))
					}
				})

				It("calls the handler to handle the request", func() {
					Eventually(fakeHandler.HandleRequestCallCount).Should(Equal(1))
				})

				It("does not reject the request as unknown", func() {
					Expect(requestErr).NotTo(HaveOccurred())
					Expect(accepted).To(BeTrue())
				})
			})

			Context("and there is not an associated handler", func() {
				Context("when WantReply is true", func() {