github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+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.Out).Should(Say("API endpoint>"))
    30  		})
    31  	})
    32  
    33  	Context("when --sso-passcode flag is given", func() {
    34  		Context("when a passcode isn't provided", func() {
    35  			It("prompts the user to try again", func() {
    36  				session := helpers.CFWithStdin(buffer, "login", "--sso-passcode")
    37  				Eventually(session.Err).Should(Say("Incorrect Usage: expected argument for flag `--sso-passcode'"))
    38  			})
    39  		})
    40  
    41  		Context("when the provided passcode is invalid", func() {
    42  			It("prompts the user to try again", func() {
    43  				session := helpers.CFWithStdin(buffer, "login", "--sso-passcode", "bad-passcode")
    44  				Eventually(session.Out).Should(Say("Authenticating..."))
    45  				Eventually(session.Out).Should(Say("Credentials were rejected, please try again."))
    46  			})
    47  		})
    48  	})
    49  
    50  	Context("when both --sso and --sso-passcode flags are provided", func() {
    51  		It("errors with invalid use", func() {
    52  			session := helpers.CFWithStdin(buffer, "login", "--sso", "--sso-passcode", "some-passcode")
    53  			Eventually(session.Out).Should(Say("Incorrect usage: --sso-passcode flag cannot be used with --sso"))
    54  			Eventually(session).Should(Exit(1))
    55  
    56  		})
    57  	})
    58  })