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