github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/integration/isolated/login_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  
     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("login command", func() {
    13  	var buffer *Buffer
    14  
    15  	BeforeEach(func() {
    16  		buffer = NewBuffer()
    17  		buffer.Write([]byte("\n"))
    18  	})
    19  
    20  	Context("when the API endpoint is not set", func() {
    21  		BeforeEach(func() {
    22  			helpers.UnsetAPI()
    23  			buffer = NewBuffer()
    24  			buffer.Write([]byte("\n"))
    25  		})
    26  
    27  		It("prompts the user for an endpoint", func() {
    28  			session := helpers.CFWithStdin(buffer, "login")
    29  			Eventually(session).Should(Say("API endpoint>"))
    30  			session.Interrupt()
    31  			Eventually(session).Should(Exit())
    32  		})
    33  	})
    34  
    35  	Context("when --sso-passcode flag is given", func() {
    36  		Context("when a passcode isn't provided", func() {
    37  			It("prompts the user to try again", func() {
    38  				session := helpers.CFWithStdin(buffer, "login", "--sso-passcode")
    39  				Eventually(session.Err).Should(Say("Incorrect Usage: expected argument for flag `--sso-passcode'"))
    40  				Eventually(session).Should(Exit(1))
    41  			})
    42  		})
    43  
    44  		Context("when the provided passcode is invalid", func() {
    45  			It("prompts the user to try again", func() {
    46  				session := helpers.CFWithStdin(buffer, "login", "--sso-passcode", "bad-passcode")
    47  				Eventually(session).Should(Say("Authenticating..."))
    48  				Eventually(session).Should(Say("Credentials were rejected, please try again."))
    49  				session.Interrupt()
    50  				Eventually(session).Should(Exit())
    51  			})
    52  		})
    53  	})
    54  
    55  	Context("when both --sso and --sso-passcode flags are provided", func() {
    56  		It("errors with invalid use", func() {
    57  			session := helpers.CFWithStdin(buffer, "login", "--sso", "--sso-passcode", "some-passcode")
    58  			Eventually(session).Should(Say("Incorrect usage: --sso-passcode flag cannot be used with --sso"))
    59  			Eventually(session).Should(Exit(1))
    60  		})
    61  	})
    62  
    63  	Context("when a user authenticates with valid client credentials", func() {
    64  		BeforeEach(func() {
    65  			clientID, clientSecret := helpers.SkipIfClientCredentialsNotSet()
    66  			session := helpers.CF("auth", clientID, clientSecret, "--client-credentials")
    67  			Eventually(session).Should(Exit(0))
    68  		})
    69  
    70  		Context("when a different user logs in with valid password credentials", func() {
    71  			It("should fail log in and display an error informing the user they need to log out", func() {
    72  				username, password := helpers.GetCredentials()
    73  				session := helpers.CF("login", "-u", username, "p", password)
    74  
    75  				Eventually(session).Should(Say("FAILED"))
    76  				Eventually(session).Should(Say("Service account currently logged in\\. Use 'cf logout' to log out service account and try again\\."))
    77  				Eventually(session).Should(Exit(1))
    78  			})
    79  		})
    80  	})
    81  })