github.com/sleungcy/cli@v7.1.0+incompatible/integration/v7/isolated/disallow_space_ssh_command_test.go (about) 1 package isolated 2 3 import ( 4 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("disallow-space-ssh command", func() { 14 var ( 15 orgName string 16 spaceName string 17 ) 18 19 BeforeEach(func() { 20 orgName = helpers.NewOrgName() 21 spaceName = helpers.NewSpaceName() 22 }) 23 24 Describe("help", func() { 25 When("--help flag is set", func() { 26 It("appears in cf help -a", func() { 27 session := helpers.CF("help", "-a") 28 Eventually(session).Should(Exit(0)) 29 Expect(session).To(HaveCommandInCategoryWithDescription("disallow-space-ssh", "SPACES", "Disallow SSH access for the space")) 30 }) 31 32 It("displays command usage to output", func() { 33 session := helpers.CF("disallow-space-ssh", "--help") 34 35 Eventually(session).Should(Say("NAME:")) 36 Eventually(session).Should(Say("disallow-space-ssh - Disallow SSH access for the space")) 37 Eventually(session).Should(Say("USAGE:")) 38 Eventually(session).Should(Say("cf disallow-space-ssh SPACE")) 39 Eventually(session).Should(Say("SEE ALSO:")) 40 Eventually(session).Should(Say("disable-ssh, space-ssh-allowed, ssh, ssh-enabled")) 41 Eventually(session).Should(Exit(0)) 42 }) 43 }) 44 }) 45 46 When("the space name is not provided", func() { 47 It("tells the user that the space name is required, prints help text, and exits 1", func() { 48 session := helpers.CF("disallow-space-ssh") 49 50 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SPACE` was not provided")) 51 Eventually(session).Should(Say("NAME:")) 52 Eventually(session).Should(Exit(1)) 53 }) 54 }) 55 56 When("the environment is not setup correctly", func() { 57 It("fails with the appropriate errors", func() { 58 helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "disallow-space-ssh", spaceName) 59 }) 60 }) 61 62 When("the environment is set up correctly", func() { 63 var userName string 64 65 BeforeEach(func() { 66 helpers.SetupCF(orgName, spaceName) 67 userName, _ = helpers.GetCredentials() 68 }) 69 70 AfterEach(func() { 71 helpers.QuickDeleteOrg(orgName) 72 }) 73 74 When("the space does not exist", func() { 75 It("displays 'space not found' and exits 1", func() { 76 invalidSpaceName := "invalid-space-name" 77 session := helpers.CF("disallow-space-ssh", invalidSpaceName) 78 79 Eventually(session).Should(Say(`Disabling ssh support for space %s as %s\.\.\.`, invalidSpaceName, userName)) 80 Eventually(session.Err).Should(Say("Space '%s' not found", invalidSpaceName)) 81 Eventually(session).Should(Say("FAILED")) 82 Eventually(session).Should(Exit(1)) 83 }) 84 }) 85 86 When("the space exists", func() { 87 When("when ssh has been allowed", func() { 88 It("disallows ssh for the space", func() { 89 session := helpers.CF("disallow-space-ssh", spaceName) 90 91 Eventually(session).Should(Say(`Disabling ssh support for space %s as %s\.\.\.`, spaceName, userName)) 92 Eventually(session).Should(Say("OK")) 93 Eventually(session).Should(Exit(0)) 94 95 session = helpers.CF("space-ssh-allowed", spaceName) 96 Eventually(session).Should(Say(`disabled`)) 97 Eventually(session).Should(Exit(0)) 98 }) 99 }) 100 101 When("ssh was previously disabled for the space", func() { 102 BeforeEach(func() { 103 Eventually(helpers.CF("disallow-space-ssh", spaceName)).Should(Exit(0)) 104 }) 105 106 It("informs the user and exits 0", func() { 107 session := helpers.CF("disallow-space-ssh", spaceName) 108 109 Eventually(session).Should(Say(`Disabling ssh support for space %s as %s\.\.\.`, spaceName, userName)) 110 Eventually(session).Should(Say("ssh support for space '%s' is already disabled.", spaceName)) 111 Eventually(session).Should(Say("OK")) 112 Eventually(session).Should(Exit(0)) 113 114 session = helpers.CF("space-ssh-allowed", spaceName) 115 Eventually(session).Should(Say(`disabled`)) 116 Eventually(session).Should(Exit(0)) 117 }) 118 }) 119 }) 120 }) 121 })