github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/oauth_token_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 "code.cloudfoundry.org/cli/util/configv3" 6 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("oauth-token command", func() { 14 Context("help", func() { 15 It("displays the help information", func() { 16 session := helpers.CF("oauth-token", "--help") 17 18 Eventually(session.Out).Should(Say("NAME:")) 19 Eventually(session.Out).Should(Say("oauth-token - Retrieve and display the OAuth token for the current session")) 20 Eventually(session.Out).Should(Say("USAGE:")) 21 Eventually(session.Out).Should(Say("cf oauth-token")) 22 Eventually(session.Out).Should(Say("SEE ALSO:")) 23 Eventually(session.Out).Should(Say("curl")) 24 Eventually(session).Should(Exit(0)) 25 }) 26 }) 27 28 Context("when the environment is not setup correctly", func() { 29 Context("when no API endpoint is set", func() { 30 BeforeEach(func() { 31 helpers.UnsetAPI() 32 }) 33 34 It("fails with no API endpoint set message", func() { 35 session := helpers.CF("oauth-token") 36 37 Eventually(session.Out).Should(Say("FAILED")) 38 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 39 Eventually(session).Should(Exit(1)) 40 }) 41 }) 42 43 Context("when not logged in", func() { 44 BeforeEach(func() { 45 helpers.LogoutCF() 46 }) 47 48 It("fails with not logged in message", func() { 49 session := helpers.CF("oauth-token") 50 51 Eventually(session.Out).Should(Say("FAILED")) 52 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 53 Eventually(session).Should(Exit(1)) 54 }) 55 }) 56 }) 57 58 Context("when the environment is setup correctly", func() { 59 BeforeEach(func() { 60 helpers.LoginCF() 61 }) 62 63 Context("when the refresh token is invalid", func() { 64 BeforeEach(func() { 65 helpers.SetConfig(func(conf *configv3.Config) { 66 conf.ConfigFile.RefreshToken = "invalid-refresh-token" 67 }) 68 }) 69 70 It("displays an error and exits 1", func() { 71 session := helpers.CF("oauth-token") 72 73 Eventually(session.Out).Should(Say("FAILED")) 74 Eventually(session.Err).Should(Say("The token expired, was revoked, or the token ID is incorrect\\. Please log back in to re-authenticate\\.")) 75 Eventually(session).Should(Exit(1)) 76 }) 77 }) 78 79 Context("when the oauth client ID and secret combination is invalid", func() { 80 BeforeEach(func() { 81 helpers.SetConfig(func(conf *configv3.Config) { 82 conf.ConfigFile.UAAOAuthClient = "foo" 83 conf.ConfigFile.UAAOAuthClientSecret = "bar" 84 }) 85 }) 86 87 It("displays an error and exits 1", func() { 88 session := helpers.CF("oauth-token") 89 90 Eventually(session.Out).Should(Say("FAILED")) 91 Eventually(session.Err).Should(Say("Credentials were rejected, please try again\\.")) 92 Eventually(session).Should(Exit(1)) 93 }) 94 }) 95 96 Context("when the refresh token and oauth creds are valid", func() { 97 It("refreshes the access token and displays it", func() { 98 session := helpers.CF("oauth-token") 99 100 Eventually(session.Out).Should(Say("bearer .+")) 101 Eventually(session).Should(Exit(0)) 102 }) 103 }) 104 }) 105 })