github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/configuration/coreconfig/api_config_refresher_test.go (about) 1 package coreconfig_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 5 "code.cloudfoundry.org/cli/cf/util/testhelpers/configuration" 6 7 "code.cloudfoundry.org/cli/cf/configuration/coreconfig/coreconfigfakes" 8 "code.cloudfoundry.org/cli/cf/i18n" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("APIConfigRefresher", func() { 14 Describe("Refresh", func() { 15 BeforeEach(func() { 16 config := configuration.NewRepositoryWithDefaults() 17 i18n.T = i18n.Init(config) 18 }) 19 20 Context("when the cloud controller returns an insecure api endpoint", func() { 21 var ( 22 r APIConfigRefresher 23 ccInfo *CCInfo 24 endpointRepo *coreconfigfakes.FakeEndpointRepository 25 ) 26 27 BeforeEach(func() { 28 ccInfo = &CCInfo{} 29 endpointRepo = new(coreconfigfakes.FakeEndpointRepository) 30 31 r = APIConfigRefresher{ 32 EndpointRepo: endpointRepo, 33 Config: new(coreconfigfakes.FakeReadWriter), 34 Endpoint: "api.some.endpoint.com", 35 } 36 }) 37 38 It("gives a warning", func() { 39 endpointRepo.GetCCInfoReturns(ccInfo, "api.some.endpoint.com", nil) 40 warning, err := r.Refresh() 41 Expect(err).NotTo(HaveOccurred()) 42 Expect(warning.Warn()).To(Equal("Warning: Insecure http API endpoint detected: secure https API endpoints are recommended\n")) 43 }) 44 }) 45 46 Context("when the cloud controller returns a secure api endpoint", func() { 47 var ( 48 r APIConfigRefresher 49 ccInfo *CCInfo 50 endpointRepo *coreconfigfakes.FakeEndpointRepository 51 ) 52 53 BeforeEach(func() { 54 ccInfo = &CCInfo{} 55 endpointRepo = new(coreconfigfakes.FakeEndpointRepository) 56 57 r = APIConfigRefresher{ 58 EndpointRepo: endpointRepo, 59 Config: new(coreconfigfakes.FakeReadWriter), 60 Endpoint: "api.some.endpoint.com", 61 } 62 }) 63 64 It("gives a warning", func() { 65 endpointRepo.GetCCInfoReturns(ccInfo, "https://api.some.endpoint.com", nil) 66 warning, err := r.Refresh() 67 Expect(err).NotTo(HaveOccurred()) 68 Expect(warning).To(BeNil()) 69 }) 70 }) 71 }) 72 })