github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/logout_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("logout command", func() {
    13  	Context("help", func() {
    14  		It("displays help", func() {
    15  			session := helpers.CF("logout", "--help")
    16  			Eventually(session).Should(Say("NAME:"))
    17  			Eventually(session).Should(Say("   logout - Log user out"))
    18  			Eventually(session).Should(Say("USAGE:"))
    19  			Eventually(session).Should(Say("   cf logout"))
    20  			Eventually(session).Should(Say("ALIAS:"))
    21  			Eventually(session).Should(Say("   lo"))
    22  			Eventually(session).Should(Exit(0))
    23  		})
    24  	})
    25  
    26  	When("there's user information set in the config", func() {
    27  		BeforeEach(func() {
    28  			helpers.SetupCF(ReadOnlyOrg, ReadOnlySpace)
    29  		})
    30  
    31  		It("clears out user information in the config", func() {
    32  			username, _ := helpers.GetCredentials()
    33  			session := helpers.CF("logout")
    34  
    35  			Eventually(session).Should(Say(`Logging out %s\.\.\.`, username))
    36  			Eventually(session).Should(Say("OK"))
    37  			Eventually(session).Should(Exit(0))
    38  
    39  			config, err := configv3.LoadConfig()
    40  			Expect(err).ToNot(HaveOccurred())
    41  
    42  			Expect(config.ConfigFile.AccessToken).To(BeEmpty())
    43  			Expect(config.ConfigFile.RefreshToken).To(BeEmpty())
    44  			Expect(config.ConfigFile.TargetedOrganization.GUID).To(BeEmpty())
    45  			Expect(config.ConfigFile.TargetedOrganization.Name).To(BeEmpty())
    46  			Expect(config.ConfigFile.TargetedSpace.AllowSSH).To(BeFalse())
    47  			Expect(config.ConfigFile.TargetedSpace.GUID).To(BeEmpty())
    48  			Expect(config.ConfigFile.TargetedSpace.Name).To(BeEmpty())
    49  			Expect(config.ConfigFile.UAAGrantType).To(BeEmpty())
    50  			Expect(config.ConfigFile.UAAOAuthClient).To(Equal("cf"))
    51  			Expect(config.ConfigFile.UAAOAuthClientSecret).To(BeEmpty())
    52  
    53  			session = helpers.CF("orgs")
    54  			Eventually(session).Should(Exit(1))
    55  			Expect(session.Out).To(Say("FAILED"))
    56  			Expect(session.Err).To(Say("Not logged in."))
    57  		})
    58  	})
    59  
    60  	When("the user has not set a target", func() {
    61  		BeforeEach(func() {
    62  			helpers.UnsetAPI()
    63  		})
    64  
    65  		It("does not cause logout to fail", func() {
    66  			config, err := configv3.LoadConfig()
    67  			Expect(err).ToNot(HaveOccurred())
    68  			Expect(config.ConfigFile.Target).To(BeEmpty())
    69  
    70  			session := helpers.CF("logout")
    71  
    72  			Eventually(session).Should(Exit(0))
    73  			Expect(session).To(Say(`Logging out \.\.\.`))
    74  			Expect(session).To(Say("OK"))
    75  		})
    76  	})
    77  
    78  	When("the user has not logged in", func() {
    79  		It("does not cause logout to fail", func() {
    80  			config, err := configv3.LoadConfig()
    81  			Expect(err).ToNot(HaveOccurred())
    82  			Expect(config.ConfigFile.AccessToken).To(BeEmpty())
    83  			Expect(config.ConfigFile.RefreshToken).To(BeEmpty())
    84  
    85  			session := helpers.CF("logout")
    86  
    87  			Eventually(session).Should(Exit(0))
    88  			Expect(session).To(Say(`Logging out \.\.\.`))
    89  			Expect(session).To(Say("OK"))
    90  		})
    91  	})
    92  })