github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+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  					"min_cli_version":null,
    36  					"min_recommended_cli_version":null,
    37  					"api_version":"2.59.0",
    38  					"app_ssh_endpoint":"ssh.APISERVER",
    39  					"app_ssh_host_key_fingerprint":"a6:d1:08:0b:b0:cb:9b:5f:c4:ba:44:2a:97:26:19:8a",
    40  					"routing_endpoint": "https://APISERVER/routing",
    41  					"app_ssh_oauth_client":"ssh-proxy",
    42  					"logging_endpoint":"wss://loggregator.APISERVER",
    43  					"doppler_logging_endpoint":"wss://doppler.APISERVER"
    44  				}`
    45  			response = strings.Replace(response, "APISERVER", serverAPIURL, -1)
    46  			server.AppendHandlers(
    47  				CombineHandlers(
    48  					VerifyRequest(http.MethodGet, "/v2/info"),
    49  					RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    50  				),
    51  			)
    52  		})
    53  
    54  		When("client has wrappers", func() {
    55  			var fakeWrapper1 *ccv2fakes.FakeConnectionWrapper
    56  			var fakeWrapper2 *ccv2fakes.FakeConnectionWrapper
    57  
    58  			BeforeEach(func() {
    59  				fakeWrapper1 = new(ccv2fakes.FakeConnectionWrapper)
    60  				fakeWrapper1.WrapReturns(fakeWrapper1)
    61  				fakeWrapper2 = new(ccv2fakes.FakeConnectionWrapper)
    62  				fakeWrapper2.WrapReturns(fakeWrapper2)
    63  
    64  				client = NewClient(Config{
    65  					AppName:    "CF CLI API Target Test",
    66  					AppVersion: "Unknown",
    67  					Wrappers:   []ConnectionWrapper{fakeWrapper1, fakeWrapper2},
    68  				})
    69  			})
    70  
    71  			It("calls wrap on all the wrappers", func() {
    72  				_, err := client.TargetCF(TargetSettings{
    73  					SkipSSLValidation: true,
    74  					URL:               server.URL(),
    75  				})
    76  				Expect(err).NotTo(HaveOccurred())
    77  
    78  				Expect(fakeWrapper1.WrapCallCount()).To(Equal(1))
    79  				Expect(fakeWrapper2.WrapCallCount()).To(Equal(1))
    80  				Expect(fakeWrapper2.WrapArgsForCall(0)).To(Equal(fakeWrapper1))
    81  			})
    82  		})
    83  
    84  		When("passed a valid API URL", func() {
    85  			BeforeEach(func() {
    86  				client = NewClient(Config{AppName: "CF CLI API Target Test", AppVersion: "Unknown"})
    87  			})
    88  
    89  			When("the api has unverified SSL", func() {
    90  				When("setting the skip ssl flat", func() {
    91  					It("sets all the endpoints on the client", func() {
    92  						_, err := client.TargetCF(TargetSettings{
    93  							SkipSSLValidation: true,
    94  							URL:               server.URL(),
    95  						})
    96  						Expect(err).NotTo(HaveOccurred())
    97  
    98  						Expect(client.API()).To(MatchRegexp("https://%s", serverAPIURL))
    99  						Expect(client.APIVersion()).To(Equal("2.59.0"))
   100  						Expect(client.AuthorizationEndpoint()).To(MatchRegexp("https://login.%s", serverAPIURL))
   101  						Expect(client.DopplerEndpoint()).To(MatchRegexp("wss://doppler.%s", serverAPIURL))
   102  						Expect(client.RoutingEndpoint()).To(MatchRegexp("https://%s/routing", serverAPIURL))
   103  					})
   104  				})
   105  
   106  				It("sets the http endpoint and warns user", func() {
   107  					warnings, err := client.TargetCF(TargetSettings{
   108  						SkipSSLValidation: true,
   109  						URL:               server.URL(),
   110  					})
   111  					Expect(err).NotTo(HaveOccurred())
   112  					Expect(warnings).To(ContainElement("this is a warning"))
   113  				})
   114  			})
   115  		})
   116  	})
   117  })