BeforeEach(func() { daemonAuthenticator.AuthenticateReturns(nil, errors.New("go away")) }) It("closes the connection", func() { Eventually(client.Wait).Should(Equal(io.EOF)) }) It("logs the failure", func() { Eventually(logger).Should(gbytes.Say(`new-client-conn.handshake-failed`)) }) }) }) Context("when HandleConnection returns", func() { var fakeServerConnection *fake_net.FakeConn BeforeEach(func() { proxySSHConfig.NoClientAuth = true daemonSSHConfig.NoClientAuth = true }) JustBeforeEach(func() { clientNetConn, serverNetConn := test_helpers.Pipe() fakeServerConnection = &fake_net.FakeConn{} fakeServerConnection.ReadStub = serverNetConn.Read fakeServerConnection.WriteStub = serverNetConn.Write fakeServerConnection.CloseStub = serverNetConn.Close go sshProxy.HandleConnection(fakeServerConnection)
fakeLocalListener.AcceptReturns(nil, errors.New("not accepting and connections")) }) It("closes the listener when the client is closed", func() { Eventually(fakeListenerFactory.ListenCallCount).Should(Equal(1)) Eventually(fakeLocalListener.AcceptCallCount).Should(Equal(1)) originalCloseCount := fakeLocalListener.CloseCallCount() err := secureShell.Close() Expect(err).NotTo(HaveOccurred()) Expect(fakeLocalListener.CloseCallCount()).Should(Equal(originalCloseCount + 1)) }) }) Context("when accept fails", func() { var fakeConn *fake_net.FakeConn BeforeEach(func() { fakeConn = &fake_net.FakeConn{} fakeConn.ReadReturns(0, io.EOF) fakeListenerFactory.ListenReturns(fakeLocalListener, nil) }) Context("with a permanent error", func() { BeforeEach(func() { fakeLocalListener.AcceptReturns(nil, errors.New("boom")) }) It("stops trying to accept connections", func() { Eventually(fakeLocalListener.AcceptCallCount).Should(Equal(1)) Consistently(fakeLocalListener.AcceptCallCount).Should(Equal(1))
logger lager.Logger sshd *daemon.Daemon serverSSHConfig *ssh.ServerConfig ) BeforeEach(func() { logger = lagertest.NewTestLogger("test") serverSSHConfig = &ssh.ServerConfig{ NoClientAuth: true, } serverSSHConfig.AddHostKey(TestHostKey) }) Describe("HandleConnection", func() { var fakeConn *fake_net.FakeConn Context("when the function returns", func() { BeforeEach(func() { fakeConn = &fake_net.FakeConn{} fakeConn.ReadReturns(0, errors.New("oops")) sshd = daemon.New(logger, serverSSHConfig, nil, nil) }) It("closes the connection", func() { sshd.HandleConnection(fakeConn) Expect(fakeConn.CloseCallCount()).To(BeNumerically(">=", 1)) }) })