github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+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  })