Exemplo n.º 1
0
	BeforeEach(func() {
		logger = lagertest.NewTestLogger("test")
	})

	Describe("HandleConnection", func() {
		var (
			proxyAuthenticator *fake_authenticators.FakePasswordAuthenticator
			proxySSHConfig     *ssh.ServerConfig
			sshProxy           *proxy.Proxy

			daemonTargetConfig          proxy.TargetConfig
			daemonAuthenticator         *fake_authenticators.FakePasswordAuthenticator
			daemonSSHConfig             *ssh.ServerConfig
			daemonGlobalRequestHandlers map[string]handlers.GlobalRequestHandler
			daemonNewChannelHandlers    map[string]handlers.NewChannelHandler
			sshDaemon                   *daemon.Daemon

			proxyListener net.Listener
			sshdListener  net.Listener

			proxyAddress  string
			daemonAddress string

			proxyServer *server.Server
			sshdServer  *server.Server
		)

		BeforeEach(func() {
			fakeLogSender = fake_logs.NewFakeLogSender()
			logs.Initialize(fakeLogSender)
		})

		JustBeforeEach(func() {
			authenticator = authenticators.NewCompositeAuthenticator(authenticatorMap)
		})

		Context("when no authenticators are specified", func() {
			It("fails to authenticate", func() {
				_, err := authenticator.Authenticate(metadata, password)
				Expect(err).To(Equal(authenticators.InvalidCredentialsErr))
			})
		})

		Context("when one or more authenticators are specified", func() {
			var (
				authenticatorOne *fake_authenticators.FakePasswordAuthenticator
				authenticatorTwo *fake_authenticators.FakePasswordAuthenticator
			)

			BeforeEach(func() {
				authenticatorOne = &fake_authenticators.FakePasswordAuthenticator{}
				authenticatorTwo = &fake_authenticators.FakePasswordAuthenticator{}
				authenticatorMap["one"] = authenticatorOne
				authenticatorMap["two"] = authenticatorOne
			})

			Context("and the users realm matches the first authenticator", func() {
				BeforeEach(func() {
					metadata.UserReturns("one:garbage")
				})

				Context("and the authenticator successfully authenticates", func() {
		})

		JustBeforeEach(func() {
			authenticator = authenticators.NewCompositeAuthenticator(authens...)
		})

		Context("when no authenticators are specified", func() {
			It("fails to authenticate", func() {
				_, err := authenticator.Authenticate(metadata, password)
				Expect(err).To(Equal(authenticators.InvalidCredentialsErr))
			})
		})

		Context("when one or more authenticators are specified", func() {
			var (
				authenticatorOne *fake_authenticators.FakePasswordAuthenticator
				authenticatorTwo *fake_authenticators.FakePasswordAuthenticator
			)

			BeforeEach(func() {
				authenticatorOne = &fake_authenticators.FakePasswordAuthenticator{}
				authenticatorOne.UserRegexpReturns(regexp.MustCompile("one:.*"))

				authenticatorTwo = &fake_authenticators.FakePasswordAuthenticator{}
				authenticatorTwo.UserRegexpReturns(regexp.MustCompile("two:.*"))

				authens = []authenticators.PasswordAuthenticator{
					authenticatorOne,
					authenticatorTwo,
				}
			})