github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+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).Should(Say("NAME:")) 19 Eventually(session).Should(Say("oauth-token - Retrieve and display the OAuth token for the current session")) 20 Eventually(session).Should(Say("USAGE:")) 21 Eventually(session).Should(Say("cf oauth-token")) 22 Eventually(session).Should(Say("SEE ALSO:")) 23 Eventually(session).Should(Say("curl")) 24 Eventually(session).Should(Exit(0)) 25 }) 26 }) 27 28 Context("when the environment is not setup correctly", func() { 29 It("fails with the appropriate errors", func() { 30 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "oauth-token") 31 }) 32 }) 33 34 Context("when the environment is setup correctly and user is logged in with password grant", func() { 35 BeforeEach(func() { 36 helpers.LoginCF() 37 }) 38 39 Context("when the refresh token is invalid", func() { 40 BeforeEach(func() { 41 helpers.SetConfig(func(conf *configv3.Config) { 42 conf.ConfigFile.RefreshToken = "invalid-refresh-token" 43 }) 44 }) 45 46 It("displays an error and exits 1", func() { 47 session := helpers.CF("oauth-token") 48 49 Eventually(session).Should(Say("FAILED")) 50 Eventually(session.Err).Should(Say("The token expired, was revoked, or the token ID is incorrect\\. Please log back in to re-authenticate\\.")) 51 Eventually(session).Should(Exit(1)) 52 }) 53 }) 54 55 Context("when the oauth client ID and secret combination is invalid", func() { 56 BeforeEach(func() { 57 helpers.SetConfig(func(conf *configv3.Config) { 58 conf.ConfigFile.UAAOAuthClient = "foo" 59 conf.ConfigFile.UAAOAuthClientSecret = "bar" 60 }) 61 }) 62 63 It("displays an error and exits 1", func() { 64 session := helpers.CF("oauth-token") 65 66 Eventually(session).Should(Say("FAILED")) 67 Eventually(session.Err).Should(Say("Credentials were rejected, please try again\\.")) 68 Eventually(session).Should(Exit(1)) 69 }) 70 }) 71 72 Context("when the refresh token and oauth creds are valid", func() { 73 It("refreshes the access token and displays it", func() { 74 session := helpers.CF("oauth-token") 75 76 Eventually(session).Should(Say("bearer .+")) 77 Eventually(session).Should(Exit(0)) 78 }) 79 }) 80 }) 81 82 Context("when the environment is setup correctly and user is logged in with client credentials grant", func() { 83 BeforeEach(func() { 84 helpers.LoginCFWithClientCredentials() 85 }) 86 87 Context("when the oauth client ID and secret combination is invalid", func() { 88 BeforeEach(func() { 89 helpers.SetConfig(func(conf *configv3.Config) { 90 conf.ConfigFile.UAAOAuthClient = "foo" 91 conf.ConfigFile.UAAOAuthClientSecret = "bar" 92 }) 93 }) 94 95 It("displays an error and exits 1", func() { 96 session := helpers.CF("oauth-token") 97 98 Eventually(session).Should(Say("FAILED")) 99 Eventually(session.Err).Should(Say("Credentials were rejected, please try again\\.")) 100 Eventually(session).Should(Exit(1)) 101 }) 102 }) 103 104 Context("when the access token is invalid", func() { 105 BeforeEach(func() { 106 helpers.SetConfig(func(conf *configv3.Config) { 107 conf.ConfigFile.AccessToken = "invalid-access-token" 108 }) 109 }) 110 111 It("refreshes the access token and displays it", func() { 112 session := helpers.CF("oauth-token") 113 114 Eventually(session).Should(Say("bearer .+")) 115 Eventually(session).Should(Exit(0)) 116 }) 117 }) 118 119 Context("when the oauth creds are valid", func() { 120 It("refreshes the access token and displays it", func() { 121 session := helpers.CF("oauth-token") 122 123 Eventually(session).Should(Say("bearer .+")) 124 Eventually(session).Should(Exit(0)) 125 }) 126 }) 127 }) 128 })