github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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  	Describe("password grant type", func() {
    17  		BeforeEach(func() {
    18  			helpers.LoginCF()
    19  		})
    20  
    21  		Context("when the token is invalid", func() {
    22  			BeforeEach(func() {
    23  				helpers.SetConfig(func(config *configv3.Config) {
    24  					config.ConfigFile.AccessToken = helpers.InvalidAccessToken()
    25  					config.ConfigFile.TargetedOrganization.GUID = "fake-org"
    26  					config.ConfigFile.TargetedSpace.GUID = "fake-space"
    27  				})
    28  			})
    29  
    30  			Context("when running a v2 command", func() {
    31  				Context("when the cloud controller client encounters an invalid token response", func() {
    32  					It("refreshes the token", func() {
    33  						session := helpers.CF("unbind-service", "app", "service")
    34  						Eventually(session.Err).Should(Say("App app not found"))
    35  						Eventually(session).Should(Exit(1))
    36  					})
    37  				})
    38  
    39  				Context("when the UAA client encounters an invalid token response", func() {
    40  					It("refreshes the token", func() {
    41  						username, _ := helpers.GetCredentials()
    42  						session := helpers.CF("create-user", username, helpers.NewPassword())
    43  						Eventually(session.Err).Should(Say(fmt.Sprintf("user %s already exists", username)))
    44  						Eventually(session).Should(Exit(0))
    45  					})
    46  				})
    47  			})
    48  
    49  			Context("when running a v3 command", func() {
    50  				Context("when the cloud controller client encounters an invalid token response", func() {
    51  					It("refreshes the token", func() {
    52  						session := helpers.CF("-v", "run-task", "app", "'echo banana'")
    53  						Eventually(session.Err).Should(Say("App app not found"))
    54  						Eventually(session).Should(Exit(1))
    55  					})
    56  				})
    57  			})
    58  		})
    59  	})
    60  
    61  	Describe("client grant type", func() {
    62  		BeforeEach(func() {
    63  			helpers.LoginCFWithClientCredentials()
    64  		})
    65  
    66  		Context("when the token is invalid", func() {
    67  			BeforeEach(func() {
    68  				helpers.SetConfig(func(config *configv3.Config) {
    69  					config.ConfigFile.AccessToken = helpers.InvalidAccessToken()
    70  					config.ConfigFile.TargetedOrganization.GUID = "fake-org"
    71  					config.ConfigFile.TargetedSpace.GUID = "fake-space"
    72  				})
    73  			})
    74  
    75  			Context("when running a v2 command", func() {
    76  				Context("when the cloud controller client encounters an invalid token response", func() {
    77  					It("refreshes the token", func() {
    78  						session := helpers.CF("unbind-service", "app", "service")
    79  						Eventually(session.Err).Should(Say("App app not found"))
    80  						Eventually(session).Should(Exit(1))
    81  					})
    82  				})
    83  
    84  				Context("when the UAA client encounters an invalid token response", func() {
    85  					It("refreshes the token", func() {
    86  						username := helpers.NewUsername()
    87  						session := helpers.CF("create-user", username, helpers.NewPassword())
    88  						Eventually(session.Out).Should(Say("OK"))
    89  						Eventually(session).Should(Exit(0))
    90  					})
    91  				})
    92  			})
    93  
    94  			Context("when running a v3 command", func() {
    95  				Context("when the cloud controller client encounters an invalid token response", func() {
    96  					It("refreshes the token", func() {
    97  						session := helpers.CF("-v", "run-task", "app", "'echo banana'")
    98  						Eventually(session.Err).Should(Say("App app not found"))
    99  						Eventually(session).Should(Exit(1))
   100  					})
   101  				})
   102  			})
   103  		})
   104  	})
   105  })