github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/actor/v3action/target_test.go (about) 1 package v3action_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/actor/v3action" 5 "code.cloudfoundry.org/cli/actor/v3action/v3actionfakes" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 7 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("Targeting", func() { 13 var ( 14 actor *Actor 15 skipSSLValidation bool 16 17 fakeCloudControllerClient *v3actionfakes.FakeCloudControllerClient 18 fakeConfig *v3actionfakes.FakeConfig 19 settings TargetSettings 20 ) 21 22 BeforeEach(func() { 23 fakeCloudControllerClient = new(v3actionfakes.FakeCloudControllerClient) 24 fakeConfig = new(v3actionfakes.FakeConfig) 25 actor = NewActor(fakeCloudControllerClient, fakeConfig, nil, nil) 26 27 settings = TargetSettings{ 28 SkipSSLValidation: skipSSLValidation, 29 } 30 }) 31 32 Describe("SetTarget", func() { 33 var expectedAPI, expectedAPIVersion, expectedAuth, expectedDoppler, expectedRouting string 34 35 BeforeEach(func() { 36 expectedAPI = "https://api.foo.com" 37 expectedAPIVersion = "2.59.0" 38 expectedAuth = "https://login.foo.com" 39 expectedDoppler = "wss://doppler.foo.com" 40 expectedRouting = "https://api.foo.com/routing" 41 42 settings.URL = expectedAPI 43 var meta struct { 44 Version string `json:"version"` 45 HostKeyFingerprint string `json:"host_key_fingerprint"` 46 OAuthClient string `json:"oath_client"` 47 } 48 meta.Version = expectedAPIVersion 49 fakeCloudControllerClient.GetInfoReturns(ccv3.Info{ 50 Links: ccv3.InfoLinks{ 51 CCV3: ccv3.APILink{ 52 Meta: meta}, 53 Logging: ccv3.APILink{ 54 HREF: expectedDoppler, 55 }, 56 Routing: ccv3.APILink{ 57 HREF: expectedRouting, 58 }, 59 UAA: ccv3.APILink{ 60 HREF: expectedAuth, 61 }}}, ccv3.ResourceLinks{}, ccv3.Warnings{}, nil) 62 }) 63 64 It("targets the passed API", func() { 65 _, err := actor.SetTarget(settings) 66 Expect(err).ToNot(HaveOccurred()) 67 68 Expect(fakeCloudControllerClient.TargetCFCallCount()).To(Equal(1)) 69 connectionSettings := fakeCloudControllerClient.TargetCFArgsForCall(0) 70 Expect(connectionSettings.URL).To(Equal(expectedAPI)) 71 Expect(connectionSettings.SkipSSLValidation).To(BeFalse()) 72 }) 73 74 It("sets all the target information", func() { 75 _, err := actor.SetTarget(settings) 76 Expect(err).ToNot(HaveOccurred()) 77 78 Expect(fakeConfig.SetTargetInformationCallCount()).To(Equal(1)) 79 api, apiVersion, auth, _, doppler, routing, sslDisabled := fakeConfig.SetTargetInformationArgsForCall(0) 80 81 Expect(api).To(Equal(expectedAPI)) 82 Expect(apiVersion).To(Equal(expectedAPIVersion)) 83 Expect(auth).To(Equal(expectedAuth)) 84 Expect(doppler).To(Equal(expectedDoppler)) 85 Expect(routing).To(Equal(expectedRouting)) 86 Expect(sslDisabled).To(Equal(skipSSLValidation)) 87 }) 88 89 It("clears all the token information", func() { 90 _, err := actor.SetTarget(settings) 91 Expect(err).ToNot(HaveOccurred()) 92 93 Expect(fakeConfig.SetTokenInformationCallCount()).To(Equal(1)) 94 accessToken, refreshToken, sshOAuthClient := fakeConfig.SetTokenInformationArgsForCall(0) 95 96 Expect(accessToken).To(BeEmpty()) 97 Expect(refreshToken).To(BeEmpty()) 98 Expect(sshOAuthClient).To(BeEmpty()) 99 }) 100 101 When("setting the same API and skip SSL configuration", func() { 102 var APIURL string 103 104 BeforeEach(func() { 105 APIURL = "https://some-api.com" 106 settings.URL = APIURL 107 fakeConfig.TargetReturns(APIURL) 108 fakeConfig.SkipSSLValidationReturns(skipSSLValidation) 109 }) 110 111 It("does not make any API calls", func() { 112 warnings, err := actor.SetTarget(settings) 113 Expect(err).NotTo(HaveOccurred()) 114 Expect(warnings).To(BeNil()) 115 116 Expect(fakeCloudControllerClient.TargetCFCallCount()).To(BeZero()) 117 }) 118 }) 119 }) 120 121 Describe("ClearTarget", func() { 122 It("clears all the target information", func() { 123 actor.ClearTarget() 124 Expect(fakeConfig.SetTargetInformationCallCount()).To(Equal(1)) 125 api, apiVersion, auth, minCLIVersion, doppler, routing, sslDisabled := fakeConfig.SetTargetInformationArgsForCall(0) 126 127 Expect(api).To(BeEmpty()) 128 Expect(apiVersion).To(BeEmpty()) 129 Expect(auth).To(BeEmpty()) 130 Expect(minCLIVersion).To(BeEmpty()) 131 Expect(doppler).To(BeEmpty()) 132 Expect(routing).To(BeEmpty()) 133 Expect(sslDisabled).To(BeFalse()) 134 }) 135 136 It("clears all the token information", func() { 137 actor.ClearTarget() 138 139 Expect(fakeConfig.SetTokenInformationCallCount()).To(Equal(1)) 140 accessToken, refreshToken, sshOAuthClient := fakeConfig.SetTokenInformationArgsForCall(0) 141 142 Expect(accessToken).To(BeEmpty()) 143 Expect(refreshToken).To(BeEmpty()) 144 Expect(sshOAuthClient).To(BeEmpty()) 145 }) 146 }) 147 })