Config.SetSSLDisabled(false) }) ItSucceeds() ItShowsTheTarget() It("stores the API endpoint and the skip-ssl flag", func() { Expect(endpointRepo.UpdateEndpointReceived).To(Equal("https://api.the-server.com")) Expect(Config.IsSSLDisabled()).To(BeTrue()) }) }) Describe("setting api endpoint failed", func() { BeforeEach(func() { Config.SetSSLDisabled(true) endpointRepo.UpdateEndpointError = 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()) }) }) })
BeforeEach(func() { requirementsFactory.ApiEndpointSuccess = true }) Context("calling endpoint repository to update 'app_ssh_oauth_client'", func() { It("passes the repo the targeted API endpoint", func() { configRepo.SetApiEndpoint("test.endpoint.com") runCommand() Ω(endpointRepo.CallCount).To(Equal(1)) Ω(endpointRepo.UpdateEndpointReceived).To(Equal(configRepo.ApiEndpoint())) }) It("reports any error to user", func() { configRepo.SetApiEndpoint("test.endpoint.com") endpointRepo.UpdateEndpointError = errors.New("endpoint error") runCommand() Ω(endpointRepo.CallCount).To(Equal(1)) Ω(ui.Outputs).To(ContainSubstrings( []string{"Error getting info", "endpoint error"}, )) }) }) Context("refresh oauth-token to make sure it is not stale", func() { It("refreshes the oauth token to make sure it is not stale", func() { runCommand() Ω(authRepo.RefreshTokenCalled).To(BeTrue()) })
callApi := func(args []string, config core_config.Repository, endpointRepo *testapi.FakeEndpointRepo) { testcmd.RunCliCommand("api", args, requirementsFactory, updateCommandDependency, false) } BeforeEach(func() { ui = new(testterm.FakeUI) requirementsFactory = &testreq.FakeReqFactory{} config = testconfig.NewRepository() endpointRepo = &testapi.FakeEndpointRepo{} deps = command_registry.NewDependency() }) Context("when the api endpoint's ssl certificate is invalid", func() { It("warns the user and prints out a tip", func() { endpointRepo.UpdateEndpointError = errors.NewInvalidSSLCert("https://buttontomatoes.org", "why? no. go away") callApi([]string{"https://buttontomatoes.org"}, config, endpointRepo) Expect(ui.Outputs).To(ContainSubstrings( []string{"FAILED"}, []string{"SSL Cert", "https://buttontomatoes.org"}, []string{"TIP", "--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")