github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/ccv2fakes" 9 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/ghttp" 13 ) 14 15 var _ = Describe("Target", func() { 16 var ( 17 serverAPIURL string 18 19 client *Client 20 ) 21 22 BeforeEach(func() { 23 serverAPIURL = server.URL()[8:] 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 client has wrappers", func() { 56 var fakeWrapper1 *ccv2fakes.FakeConnectionWrapper 57 var fakeWrapper2 *ccv2fakes.FakeConnectionWrapper 58 59 BeforeEach(func() { 60 fakeWrapper1 = new(ccv2fakes.FakeConnectionWrapper) 61 fakeWrapper1.WrapReturns(fakeWrapper1) 62 fakeWrapper2 = new(ccv2fakes.FakeConnectionWrapper) 63 fakeWrapper2.WrapReturns(fakeWrapper2) 64 65 client = NewClient(Config{ 66 AppName: "CF CLI API Target Test", 67 AppVersion: "Unknown", 68 Wrappers: []ConnectionWrapper{fakeWrapper1, fakeWrapper2}, 69 }) 70 }) 71 72 It("calls wrap on all the wrappers", func() { 73 _, err := client.TargetCF(TargetSettings{ 74 SkipSSLValidation: true, 75 URL: server.URL(), 76 }) 77 Expect(err).NotTo(HaveOccurred()) 78 79 Expect(fakeWrapper1.WrapCallCount()).To(Equal(1)) 80 Expect(fakeWrapper2.WrapCallCount()).To(Equal(1)) 81 Expect(fakeWrapper2.WrapArgsForCall(0)).To(Equal(fakeWrapper1)) 82 }) 83 }) 84 85 Context("when passed a valid API URL", func() { 86 BeforeEach(func() { 87 client = NewClient(Config{AppName: "CF CLI API Target Test", AppVersion: "Unknown"}) 88 }) 89 90 Context("when the api has unverified SSL", func() { 91 Context("when setting the skip ssl flat", func() { 92 It("sets all the endpoints on the client", func() { 93 _, err := client.TargetCF(TargetSettings{ 94 SkipSSLValidation: true, 95 URL: server.URL(), 96 }) 97 Expect(err).NotTo(HaveOccurred()) 98 99 Expect(client.API()).To(MatchRegexp("https://%s", serverAPIURL)) 100 Expect(client.APIVersion()).To(Equal("2.59.0")) 101 Expect(client.AuthorizationEndpoint()).To(MatchRegexp("https://login.%s", serverAPIURL)) 102 Expect(client.DopplerEndpoint()).To(MatchRegexp("wss://doppler.%s", serverAPIURL)) 103 Expect(client.RoutingEndpoint()).To(MatchRegexp("https://%s/routing", serverAPIURL)) 104 Expect(client.TokenEndpoint()).To(MatchRegexp("https://uaa.%s", serverAPIURL)) 105 }) 106 }) 107 108 It("sets the http endpoint and warns user", func() { 109 warnings, err := client.TargetCF(TargetSettings{ 110 SkipSSLValidation: true, 111 URL: server.URL(), 112 }) 113 Expect(err).NotTo(HaveOccurred()) 114 Expect(warnings).To(ContainElement("this is a warning")) 115 }) 116 }) 117 }) 118 }) 119 })