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