github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/api/cloudcontroller/ccv2/target_test.go (about) 1 package ccv2_test 2 3 import ( 4 "net/http" 5 "strings" 6 7 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 8 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/ghttp" 12 ) 13 14 var _ = Describe("Target", func() { 15 var ( 16 serverAPIURL string 17 18 client *Client 19 ) 20 21 BeforeEach(func() { 22 serverAPIURL = server.URL()[8:] 23 client = NewClient(Config{AppName: "CF CLI API Target Test", AppVersion: "Unknown"}) 24 }) 25 26 Describe("TargetCF", func() { 27 BeforeEach(func() { 28 response := `{ 29 "name":"", 30 "build":"", 31 "support":"http://support.cloudfoundry.com", 32 "version":0, 33 "description":"", 34 "authorization_endpoint":"https://login.APISERVER", 35 "token_endpoint":"https://uaa.APISERVER", 36 "min_cli_version":null, 37 "min_recommended_cli_version":null, 38 "api_version":"2.59.0", 39 "app_ssh_endpoint":"ssh.APISERVER", 40 "app_ssh_host_key_fingerprint":"a6:d1:08:0b:b0:cb:9b:5f:c4:ba:44:2a:97:26:19:8a", 41 "routing_endpoint": "https://APISERVER/routing", 42 "app_ssh_oauth_client":"ssh-proxy", 43 "logging_endpoint":"wss://loggregator.APISERVER", 44 "doppler_logging_endpoint":"wss://doppler.APISERVER" 45 }` 46 response = strings.Replace(response, "APISERVER", serverAPIURL, -1) 47 server.AppendHandlers( 48 CombineHandlers( 49 VerifyRequest(http.MethodGet, "/v2/info"), 50 RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 51 ), 52 ) 53 }) 54 55 Context("when passed a valid API URL", func() { 56 Context("when the api has unverified SSL", func() { 57 Context("when setting the skip ssl flat", func() { 58 It("sets all the endpoints on the client", func() { 59 _, err := client.TargetCF(TargetSettings{ 60 SkipSSLValidation: true, 61 URL: server.URL(), 62 }) 63 Expect(err).NotTo(HaveOccurred()) 64 65 Expect(client.API()).To(MatchRegexp("https://%s", serverAPIURL)) 66 Expect(client.APIVersion()).To(Equal("2.59.0")) 67 Expect(client.AuthorizationEndpoint()).To(MatchRegexp("https://login.%s", serverAPIURL)) 68 Expect(client.DopplerEndpoint()).To(MatchRegexp("wss://doppler.%s", serverAPIURL)) 69 Expect(client.RoutingEndpoint()).To(MatchRegexp("https://%s/routing", serverAPIURL)) 70 Expect(client.TokenEndpoint()).To(MatchRegexp("https://uaa.%s", serverAPIURL)) 71 }) 72 }) 73 74 It("sets the http endpoint and warns user", func() { 75 warnings, err := client.TargetCF(TargetSettings{ 76 SkipSSLValidation: true, 77 URL: server.URL(), 78 }) 79 Expect(err).NotTo(HaveOccurred()) 80 Expect(warnings).To(ContainElement("this is a warning")) 81 }) 82 }) 83 }) 84 }) 85 })