github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/isolated/token_refresh.go (about)

     1  package isolated
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  	"code.cloudfoundry.org/cli/util/configv3"
     8  
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gbytes"
    12  	. "github.com/onsi/gomega/gexec"
    13  )
    14  
    15  var _ = Describe("Token Refreshing", func() {
    16  	Context("when running a v2 command with an invalid token", func() {
    17  		BeforeEach(func() {
    18  			helpers.LoginCF()
    19  
    20  			helpers.SetConfig(func(config *configv3.Config) {
    21  				config.ConfigFile.AccessToken = config.ConfigFile.AccessToken + "foo"
    22  				config.ConfigFile.TargetedOrganization.GUID = "fake-org"
    23  				config.ConfigFile.TargetedSpace.GUID = "fake-space"
    24  			})
    25  		})
    26  
    27  		Context("when the cloud controller client encounters an invalid token response", func() {
    28  			It("refreshes the token", func() {
    29  				session := helpers.CF("unbind-service", "app", "service")
    30  				Eventually(session.Err).Should(Say("App app not found"))
    31  				Eventually(session).Should(Exit(1))
    32  			})
    33  		})
    34  
    35  		Context("when the UAA client encounters an invalid token response", func() {
    36  			It("refreshes the token", func() {
    37  				username, _ := helpers.GetCredentials()
    38  				session := helpers.CF("create-user", username, helpers.RandomPassword())
    39  				Eventually(session.Err).Should(Say(fmt.Sprintf("user %s already exists", username)))
    40  				Eventually(session).Should(Exit(0))
    41  			})
    42  		})
    43  	})
    44  
    45  	Context("when running a v3 command with an invalid token", func() {
    46  		BeforeEach(func() {
    47  			helpers.LoginCF()
    48  
    49  			helpers.SetConfig(func(config *configv3.Config) {
    50  				config.ConfigFile.AccessToken = config.ConfigFile.AccessToken + "foo"
    51  				config.ConfigFile.TargetedOrganization.GUID = "fake-org"
    52  				config.ConfigFile.TargetedSpace.GUID = "fake-space"
    53  			})
    54  		})
    55  
    56  		Context("when the cloud controller client encounters an invalid token response", func() {
    57  			It("refreshes the token", func() {
    58  				session := helpers.CF("-v", "run-task", "app", "'echo banana'")
    59  				Eventually(session.Err).Should(Say("App app not found"))
    60  				Eventually(session).Should(Exit(1))
    61  			})
    62  		})
    63  	})
    64  })