BeforeEach(func() { ccInfo = &CCInfo{ LoggregatorEndpoint: "some-endpoint", } endpointRepo = new(coreconfigfakes.FakeEndpointRepository) r = APIConfigRefresher{ EndpointRepo: endpointRepo, Config: new(coreconfigfakes.FakeReadWriter), Endpoint: "api.some.endpoint.com", } }) It("gives a warning", func() { endpointRepo.GetCCInfoReturns(ccInfo, "api.some.endpoint.com", nil) warning, err := r.Refresh() Expect(err).NotTo(HaveOccurred()) Expect(warning.Warn()).To(Equal("Warning: Insecure http API endpoint detected: secure https API endpoints are recommended\n")) }) }) Context("when the cloud controller returns a secure api endpoint", func() { var ( r APIConfigRefresher ccInfo *CCInfo endpointRepo *coreconfigfakes.FakeEndpointRepository ) BeforeEach(func() { ccInfo = &CCInfo{
Expect(firstErr.Error()).To(ContainSubstring("Incorrect Usage. No argument required")) }) }) }) Describe("Execute", func() { var runCLIerr error BeforeEach(func() { cmd.Requirements(factory, flagContext) endpointRepo.GetCCInfoReturns( &coreconfig.CCInfo{ LoggregatorEndpoint: "loggregator/endpoint", }, "some-endpoint", nil, ) }) JustBeforeEach(func() { runCLIerr = cmd.Execute(flagContext) }) It("tries to update the endpoint", func() { Expect(runCLIerr).NotTo(HaveOccurred()) Expect(endpointRepo.GetCCInfoCallCount()).To(Equal(1)) Expect(endpointRepo.GetCCInfoArgsForCall(0)).To(Equal("fake-api-endpoint")) })
}) ItSucceeds() ItShowsTheTarget() It("stores the API endpoint and the skip-ssl flag", func() { Expect(endpointRepo.GetCCInfoCallCount()).To(Equal(1)) Expect(endpointRepo.GetCCInfoArgsForCall(0)).To(Equal("https://api.the-server.com")) Expect(Config.IsSSLDisabled()).To(BeTrue()) }) }) Describe("setting api endpoint failed", func() { BeforeEach(func() { Config.SetSSLDisabled(true) endpointRepo.GetCCInfoReturns(nil, "", errors.New("API endpoint not found")) }) ItFails() ItDoesntShowTheTarget() It("clears the entire config", func() { Expect(Config.APIEndpoint()).To(BeEmpty()) Expect(Config.IsSSLDisabled()).To(BeFalse()) Expect(Config.AccessToken()).To(BeEmpty()) Expect(Config.RefreshToken()).To(BeEmpty()) Expect(Config.OrganizationFields().GUID).To(BeEmpty()) Expect(Config.SpaceFields().GUID).To(BeEmpty()) }) }) })
repoLocator = api.RepositoryLocator{}.SetEndpointRepository(endpointRepo) deps = commandregistry.Dependency{ UI: ui, Config: config, RepoLocator: repoLocator, } cmd = commands.API{}.SetDependency(deps, false).(commands.API) flagContext = flags.NewFlagContext(cmd.MetaData().Flags) }) Context("when the api endpoint's ssl certificate is invalid", func() { It("warns the user and prints out a tip", func() { endpointRepo.GetCCInfoReturns(nil, "", errors.NewInvalidSSLCert("https://buttontomatoes.org", "why? no. go away")) callApi([]string{"https://buttontomatoes.org"}) Expect(runCLIErr).To(HaveOccurred()) Expect(runCLIErr.Error()).To(ContainSubstring("Invalid SSL Cert for https://buttontomatoes.org")) Expect(runCLIErr.Error()).To(ContainSubstring("TIP")) Expect(runCLIErr.Error()).To(ContainSubstring("--skip-ssl-validation")) }) }) Context("when the user does not provide an endpoint", func() { Context("when the endpoint is set in the config", func() { BeforeEach(func() { config.SetAPIEndpoint("https://api.run.pivotal.io") config.SetAPIVersion("2.0") config.SetSSLDisabled(true)