Beispiel #1
0
			})

			It("returns the error", func() {
				Expect(fakeAppFactory.GetCallCount()).To(Equal(1))
				Expect(connectErr).To(Equal(errors.New("woops")))
			})

			It("does not attempt to acquire endpoint info", func() {
				Expect(fakeInfoFactory.GetCallCount()).To(Equal(0))
			})
		})

		Context("when the app model is successfully acquired", func() {
			BeforeEach(func() {
				fakeAppFactory.GetReturns(app.App{}, nil)
				fakeInfoFactory.GetReturns(info.Info{}, nil)
			})

			It("gets the ssh endpoint information", func() {
				Expect(fakeInfoFactory.GetCallCount()).To(Equal(1))
			})

			Context("when getting the endpoint info fails", func() {
				BeforeEach(func() {
					fakeInfoFactory.GetReturns(info.Info{}, errors.New("woops"))
				})

				It("returns the error", func() {
					Expect(fakeAppFactory.GetCallCount()).To(Equal(1))
					Expect(connectErr).To(Equal(errors.New("woops")))
				})
Beispiel #2
0
		credFactory = credential.NewCredentialFactory(fakeCliConnection, fakeInfoFactory)
	})

	Describe("AuthorizationCode", func() {
		var v2Info info.Info
		var fakeUAA *ghttp.Server

		BeforeEach(func() {
			fakeCliConnection.AccessTokenReturns("bearer client-bearer-token", nil)

			fakeUAA = ghttp.NewTLSServer()
			v2Info = info.Info{
				SSHOAuthClient: "ssh-oauth-client-id",
				TokenEndpoint:  fakeUAA.URL(),
			}
			fakeInfoFactory.GetReturns(v2Info, nil)

			fakeUAA.RouteToHandler("GET", "/oauth/authorize", ghttp.CombineHandlers(
				ghttp.VerifyRequest("GET", "/oauth/authorize"),
				ghttp.VerifyFormKV("response_type", "code"),
				ghttp.VerifyFormKV("client_id", "ssh-oauth-client-id"),
				ghttp.VerifyFormKV("grant_type", "authorization_code"),
				ghttp.VerifyHeaderKV("authorization", "bearer client-bearer-token"),
				ghttp.RespondWith(http.StatusFound, "", http.Header{
					"Location": []string{"https://uaa.example.com/login?code=abc123"},
				}),
			))
		})

		It("forces the cli to refresh the access token used to acquire the access code", func() {
			_, err := credFactory.AuthorizationCode()