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