github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/shared/isolated/token_refresh_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("Token Refreshing", func() {
    14  	Describe("password grant type", func() {
    15  		BeforeEach(func() {
    16  			helpers.LoginCF()
    17  		})
    18  
    19  		When("the token is invalid", func() {
    20  			When("password is explicitly stored as the grant type", func() {
    21  				BeforeEach(func() {
    22  					helpers.SetConfig(func(config *configv3.Config) {
    23  						config.ConfigFile.AccessToken = helpers.ExpiredAccessToken()
    24  						config.ConfigFile.TargetedOrganization.GUID = "fake-org"
    25  						config.ConfigFile.TargetedSpace.GUID = "fake-space"
    26  						config.ConfigFile.UAAGrantType = "password"
    27  					})
    28  				})
    29  
    30  				When("running a v7 command", func() {
    31  					When("the cloud controller client encounters an invalid token response", func() {
    32  						It("refreshes the token", func() {
    33  							session := helpers.CF("run-task", "app", "'echo banana'")
    34  							Eventually(session.Err).Should(Say("App 'app' not found"))
    35  							Eventually(session).Should(Exit(1))
    36  						})
    37  					})
    38  				})
    39  			})
    40  
    41  			When("no grant type is explicitly stored", func() {
    42  				BeforeEach(func() {
    43  					helpers.SetConfig(func(config *configv3.Config) {
    44  						config.ConfigFile.AccessToken = helpers.ExpiredAccessToken()
    45  						config.ConfigFile.TargetedOrganization.GUID = "fake-org"
    46  						config.ConfigFile.TargetedSpace.GUID = "fake-space"
    47  						config.ConfigFile.UAAGrantType = ""
    48  					})
    49  				})
    50  
    51  				When("running a v7 command", func() {
    52  					When("the cloud controller client encounters an invalid token response", func() {
    53  						It("refreshes the token", func() {
    54  							session := helpers.CF("run-task", "app", "'echo banana'")
    55  							Eventually(session.Err).Should(Say("App 'app' not found"))
    56  							Eventually(session).Should(Exit(1))
    57  						})
    58  					})
    59  				})
    60  			})
    61  		})
    62  	})
    63  
    64  	Describe("client grant type", func() {
    65  		BeforeEach(func() {
    66  			helpers.LoginCFWithClientCredentials()
    67  		})
    68  
    69  		When("the token is invalid", func() {
    70  			BeforeEach(func() {
    71  				helpers.SetConfig(func(config *configv3.Config) {
    72  					config.ConfigFile.AccessToken = helpers.ExpiredAccessToken()
    73  					config.ConfigFile.TargetedOrganization.GUID = "fake-org"
    74  					config.ConfigFile.TargetedSpace.GUID = "fake-space"
    75  				})
    76  			})
    77  
    78  			When("running a v7 command", func() {
    79  				When("the cloud controller client encounters an invalid token response", func() {
    80  					It("displays an error and exits 1", func() {
    81  						session := helpers.CF("run-task", "app", "'echo banana'")
    82  						Eventually(session.Err).Should(Say(`Credentials were rejected, please try again\.`))
    83  						Eventually(session).Should(Exit(1))
    84  					})
    85  				})
    86  			})
    87  		})
    88  	})
    89  })