github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/isolated/auth_command_test.go (about) 1 package isolated 2 3 import ( 4 "github.com/liamawhite/cli-with-i18n/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("auth command", func() { 13 Context("Help", func() { 14 It("displays the help information", func() { 15 session := helpers.CF("auth", "--help") 16 Eventually(session.Out).Should(Say("NAME:")) 17 Eventually(session.Out).Should(Say("auth - Authenticate user non-interactively\n\n")) 18 19 Eventually(session.Out).Should(Say("USAGE:")) 20 Eventually(session.Out).Should(Say("cf auth USERNAME PASSWORD\n\n")) 21 22 Eventually(session.Out).Should(Say("WARNING:")) 23 Eventually(session.Out).Should(Say("Providing your password as a command line option is highly discouraged")) 24 Eventually(session.Out).Should(Say("Your password may be visible to others and may be recorded in your shell history\n\n")) 25 26 Eventually(session.Out).Should(Say("EXAMPLES:")) 27 Eventually(session.Out).Should(Say("cf auth name@example\\.com \"my password\" \\(use quotes for passwords with a space\\)")) 28 Eventually(session.Out).Should(Say("cf auth name@example\\.com \\\"\\\\\"password\\\\\"\\\" \\(escape quotes if used in password\\)\n\n")) 29 30 Eventually(session.Out).Should(Say("SEE ALSO:")) 31 Eventually(session.Out).Should(Say("api, login, target")) 32 33 Eventually(session).Should(Exit(0)) 34 }) 35 }) 36 37 Context("when no arguments are provided", func() { 38 It("errors-out with the help information", func() { 39 session := helpers.CF("auth") 40 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `USERNAME` and `PASSWORD` were not provided\n\n")) 41 Eventually(session.Out).Should(Say("NAME:")) 42 43 Eventually(session).Should(Exit(1)) 44 }) 45 }) 46 47 Context("when only a username is provided", func() { 48 It("errors-out with a password required error and the help information", func() { 49 session := helpers.CF("auth", "some-user") 50 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `PASSWORD` was not provided\n\n")) 51 Eventually(session.Out).Should(Say("NAME:")) 52 53 Eventually(session).Should(Exit(1)) 54 }) 55 }) 56 57 Context("when too many arguments are provided", func() { 58 It("displays an 'unknown flag' error message", func() { 59 session := helpers.CF("auth", "some-username", "some-password", "-a", "api.bosh-lite.com") 60 61 Eventually(session.Err).Should(Say("Incorrect Usage: unknown flag `a'")) 62 Eventually(session.Out).Should(Say("NAME:")) 63 64 Eventually(session).Should(Exit(1)) 65 }) 66 }) 67 68 Context("when the API endpoint is not set", func() { 69 BeforeEach(func() { 70 helpers.UnsetAPI() 71 }) 72 73 It("displays an error message", func() { 74 session := helpers.CF("auth", "some-username", "some-password") 75 76 Eventually(session.Out).Should(Say("FAILED")) 77 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 78 79 Eventually(session).Should(Exit(1)) 80 }) 81 }) 82 83 Context("when the user provides an invalid username/password combo", func() { 84 BeforeEach(func() { 85 helpers.LoginCF() 86 helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) 87 }) 88 89 It("clears the cached tokens and target info, then displays an error message", func() { 90 session := helpers.CF("auth", "some-username", "some-password") 91 92 Eventually(session.Out).Should(Say("API endpoint: %s", helpers.GetAPI())) 93 Eventually(session.Out).Should(Say("Authenticating\\.\\.\\.")) 94 Eventually(session.Out).Should(Say("FAILED")) 95 Eventually(session.Err).Should(Say("Credentials were rejected, please try again\\.")) 96 Eventually(session).Should(Exit(1)) 97 98 // Verify that the user is not logged-in 99 targetSession1 := helpers.CF("target") 100 Eventually(targetSession1.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 101 Eventually(targetSession1.Out).Should(Say("FAILED")) 102 Eventually(targetSession1).Should(Exit(1)) 103 104 // Verify that neither org nor space is targeted 105 helpers.LoginCF() 106 targetSession2 := helpers.CF("target") 107 Eventually(targetSession2.Out).Should(Say("No org or space targeted, use 'cf target -o ORG -s SPACE'")) 108 Eventually(targetSession2).Should(Exit(0)) 109 }) 110 }) 111 112 Context("when the username and password are valid", func() { 113 It("authenticates the user", func() { 114 username, password := helpers.GetCredentials() 115 session := helpers.CF("auth", username, password) 116 117 Eventually(session.Out).Should(Say("API endpoint: %s", helpers.GetAPI())) 118 Eventually(session.Out).Should(Say("Authenticating\\.\\.\\.")) 119 Eventually(session.Out).Should(Say("OK")) 120 Eventually(session.Out).Should(Say("Use 'cf target' to view or set your target org and space")) 121 122 Eventually(session).Should(Exit(0)) 123 }) 124 }) 125 })