github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/uaa/resources_test.go (about) 1 package uaa_test 2 3 import ( 4 "net/http" 5 6 . "code.cloudfoundry.org/cli/api/uaa" 7 "code.cloudfoundry.org/cli/api/uaa/uaafakes" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/ghttp" 11 ) 12 13 var _ = Describe("SetupResources", func() { 14 var ( 15 client *Client 16 fakeConfig *uaafakes.FakeConfig 17 18 setupResourcesErr error 19 ) 20 21 BeforeEach(func() { 22 fakeConfig = NewTestConfig() 23 client = NewClient(fakeConfig) 24 }) 25 26 JustBeforeEach(func() { 27 setupResourcesErr = client.SetupResources(server.URL()) 28 }) 29 30 Context("when the authentication server returns an error", func() { 31 BeforeEach(func() { 32 server.AppendHandlers( 33 CombineHandlers( 34 VerifyRequest(http.MethodGet, "/login"), 35 RespondWith(http.StatusNotFound, `{"errors": [{}]}`, nil), 36 ), 37 ) 38 }) 39 40 It("returns the error", func() { 41 Expect(setupResourcesErr).To(HaveOccurred()) 42 Expect(fakeConfig.SetUAAEndpointCallCount()).To(Equal(0)) 43 }) 44 }) 45 46 Context("when the request succeeds", func() { 47 Context("and the UAA field is populated", func() { 48 BeforeEach(func() { 49 response := `{ 50 "links": { 51 "uaa": "https://uaa.bosh-lite.com" 52 } 53 }` 54 55 server.AppendHandlers( 56 CombineHandlers( 57 VerifyRequest(http.MethodGet, "/login"), 58 RespondWith(http.StatusOK, response, nil), 59 ), 60 ) 61 }) 62 63 It("sets the UAA endpoint to the UAA link and does not return an error", func() { 64 Expect(setupResourcesErr).ToNot(HaveOccurred()) 65 Expect(fakeConfig.SetUAAEndpointCallCount()).To(Equal(1)) 66 Expect(fakeConfig.SetUAAEndpointArgsForCall(0)).To(Equal("https://uaa.bosh-lite.com")) 67 }) 68 }) 69 70 Context("when the UAA field is not populated", func() { 71 BeforeEach(func() { 72 response := `{ 73 "links": {} 74 }` 75 76 server.AppendHandlers( 77 CombineHandlers( 78 VerifyRequest(http.MethodGet, "/login"), 79 RespondWith(http.StatusOK, response, nil), 80 ), 81 ) 82 }) 83 84 It("sets the UAA endpoint to the bootstrap endpoint and does not return an error", func() { 85 Expect(setupResourcesErr).ToNot(HaveOccurred()) 86 Expect(fakeConfig.SetUAAEndpointCallCount()).To(Equal(1)) 87 Expect(fakeConfig.SetUAAEndpointArgsForCall(0)).To(Equal(server.URL())) 88 }) 89 }) 90 }) 91 })