. "github.com/cloudfoundry/cli/cf/api" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Service Keys Repo", func() { var ( ccServer *ghttp.Server configRepo core_config.ReadWriter repo ServiceKeyRepository ) BeforeEach(func() { configRepo = testconfig.NewRepositoryWithDefaults() configRepo.SetAccessToken("BEARER my_access_token") ccServer = ghttp.NewServer() configRepo.SetApiEndpoint(ccServer.URL()) gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{}) repo = NewCloudControllerServiceKeyRepository(configRepo, gateway) }) AfterEach(func() { ccServer.Close() }) Describe("CreateServiceKey", func() { It("tries to create the service key", func() { ccServer.AppendHandlers(
) var _ = Describe("logs with noaa repository", func() { var ( fakeNoaaConsumer *testapi.FakeNoaaConsumer config core_config.ReadWriter fakeTokenRefresher *testapi.FakeAuthenticationRepository repo api.LogsNoaaRepository ) BeforeEach(func() { fakeNoaaConsumer = &testapi.FakeNoaaConsumer{} config = testconfig.NewRepositoryWithDefaults() config.SetLoggregatorEndpoint("loggregator.test.com") config.SetDopplerEndpoint("doppler.test.com") config.SetAccessToken("the-access-token") fakeTokenRefresher = &testapi.FakeAuthenticationRepository{} repo = api.NewLogsNoaaRepository(config, fakeNoaaConsumer, fakeTokenRefresher) }) Describe("RecentLogsFor", func() { It("refreshes token and get metric once more if token has expired.", func() { fakeNoaaConsumer.RecentLogsReturns([]*events.LogMessage{}, noaa_errors.NewUnauthorizedError("Unauthorized token")) repo.RecentLogsFor("app-guid") Ω(fakeTokenRefresher.RefreshTokenCalled).To(BeTrue()) Ω(fakeNoaaConsumer.RecentLogsCallCount()).To(Equal(2)) })
Expect(config.AccessToken()).To(Equal("")) Expect(config.AuthenticationEndpoint()).To(Equal("https://login.example.com")) Expect(config.LoggregatorEndpoint()).To(Equal("wss://loggregator.foo.example.org:4443")) Expect(config.DopplerEndpoint()).To(Equal("wss://doppler.foo.example.org:4443")) Expect(config.ApiEndpoint()).To(Equal(testServer.URL)) Expect(config.ApiVersion()).To(Equal("42.0.0")) Expect(config.HasOrganization()).To(BeFalse()) Expect(config.HasSpace()).To(BeFalse()) Expect(config.MinCliVersion()).To(Equal("6.5.0")) Expect(config.MinRecommendedCliVersion()).To(Equal("6.7.0")) }) Context("when the api endpoint does not change", func() { BeforeEach(func() { config.SetApiEndpoint(testServer.URL) config.SetAccessToken("some access token") config.SetRefreshToken("some refresh token") }) It("does not clear the session if the api endpoint does not change", func() { repo.UpdateEndpoint(testServer.URL) Expect(config.OrganizationFields()).To(Equal(org)) Expect(config.SpaceFields()).To(Equal(space)) Expect(config.AccessToken()).To(Equal("some access token")) Expect(config.RefreshToken()).To(Equal("some refresh token")) }) }) }) Context("when the API request fails", func() {
var ( requirementsFactory *testreq.FakeReqFactory ui *testterm.FakeUI userRepo *testapi.FakeUserRepository configRepo core_config.ReadWriter ) BeforeEach(func() { requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true} ui = new(testterm.FakeUI) userRepo = &testapi.FakeUserRepository{} configRepo = testconfig.NewRepositoryWithDefaults() accessToken, _ := testconfig.EncodeAccessToken(core_config.TokenInfo{ Username: "******", }) configRepo.SetAccessToken(accessToken) }) runCommand := func(args ...string) bool { cmd := NewCreateUser(ui, configRepo, userRepo) return testcmd.RunCommand(cmd, args, requirementsFactory) } It("creates a user", func() { runCommand("my-user", "my-password") Expect(ui.Outputs).To(ContainSubstrings( []string{"Creating user", "my-user"}, []string{"OK"}, []string{"TIP"}, ))
Expect(ui.FailedWithUsage).To(BeTrue()) }) Describe("when there is no api endpoint set", func() { BeforeEach(func() { requirementsFactory.ApiEndpointSuccess = false }) It("fails requirements", func() { Expect(callTarget([]string{})).To(BeFalse()) }) }) Describe("when the user is not logged in", func() { BeforeEach(func() { config.SetAccessToken("") }) It("prints the target info when no org or space is specified", func() { Expect(callTarget([]string{})).To(BeTrue()) Expect(ui.ShowConfigurationCalled).To(BeTrue()) }) It("panics silently so that it returns an exit code of 1", func() { callTarget([]string{}) Expect(ui.PanickedQuietly).To(BeTrue()) }) It("fails requirements when targeting a space or org", func() { Expect(callTarget([]string{"-o", "some-crazy-org-im-not-in"})).To(BeFalse())
"username": "******", "password": "******", }, })) Expect(ui.Outputs).To(ContainSubstrings([]string{"FAILED"})) }) }) }) Describe("updates to the config", func() { var l Login BeforeEach(func() { Config.SetApiEndpoint("api.the-old-endpoint.com") Config.SetAccessToken("the-old-access-token") Config.SetRefreshToken("the-old-refresh-token") l = NewLogin(ui, Config, authRepo, endpointRepo, orgRepo, spaceRepo) }) JustBeforeEach(func() { testcmd.RunCommand(l, Flags, nil) }) var ItShowsTheTarget = func() { It("shows the target", func() { Expect(ui.ShowConfigurationCalled).To(BeTrue()) }) } var ItDoesntShowTheTarget = func() {