github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/api/uaa/ssh_test.go (about) 1 package uaa_test 2 3 import ( 4 "fmt" 5 "net/http" 6 7 . "code.cloudfoundry.org/cli/api/uaa" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/ghttp" 11 ) 12 13 var _ = Describe("SSH", func() { 14 var client *Client 15 16 BeforeEach(func() { 17 client = NewTestUAAClientAndStore() 18 }) 19 20 Describe("GetSSHPasscode", func() { 21 Context("when no errors occur", func() { 22 var expectedCode string 23 24 BeforeEach(func() { 25 expectedCode = "c0d3" 26 locationHeader := http.Header{} 27 locationHeader.Add("Location", fmt.Sprintf("http://localhost/redirect/cf?code=%s&state=", expectedCode)) 28 uaaServer.AppendHandlers( 29 CombineHandlers( 30 verifyRequestHost(TestUAAResource), 31 VerifyRequest(http.MethodGet, "/oauth/authorize", "response_type=code&client_id=ssh-proxy"), 32 RespondWith(http.StatusFound, nil, locationHeader), 33 )) 34 }) 35 36 It("returns a ssh passcode", func() { 37 code, err := client.GetSSHPasscode("4c3sst0k3n", "ssh-proxy") 38 Expect(err).NotTo(HaveOccurred()) 39 Expect(code).To(Equal(expectedCode)) 40 }) 41 }) 42 43 Context("when an error occurs", func() { 44 var response string 45 46 BeforeEach(func() { 47 response = `{ 48 "error": "some-error", 49 "error_description": "some-description" 50 }` 51 uaaServer.AppendHandlers( 52 CombineHandlers( 53 verifyRequestHost(TestUAAResource), 54 VerifyRequest(http.MethodGet, "/oauth/authorize", "response_type=code&client_id=ssh-proxy"), 55 RespondWith(http.StatusBadRequest, response), 56 )) 57 }) 58 59 It("returns an error", func() { 60 _, err := client.GetSSHPasscode("4c3sst0k3n", "ssh-proxy") 61 Expect(err).To(MatchError(RawHTTPStatusError{ 62 StatusCode: http.StatusBadRequest, 63 RawResponse: []byte(response), 64 })) 65 }) 66 }) 67 }) 68 })