github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/disable_service_access_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" 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("disable service access command", func() { 13 Describe("help", func() { 14 When("--help flag is set", func() { 15 It("displays command usage to output", func() { 16 session := helpers.CF("disable-service-access", "--help") 17 Eventually(session).Should(Exit(0)) 18 Expect(session).To(Say("NAME:")) 19 Expect(session).To(Say("\\s+disable-service-access - Disable access to a service offering or service plan for one or all orgs")) 20 Expect(session).To(Say("USAGE:")) 21 Expect(session).To(Say("\\s+cf disable-service-access SERVICE \\[-b BROKER\\] \\[-p PLAN\\] \\[-o ORG\\]")) 22 Expect(session).To(Say("OPTIONS:")) 23 Expect(session).To(Say("\\s+\\-b\\s+Disable access to a service offering from a particular service broker. Required when service offering name is ambiguous")) 24 Expect(session).To(Say("\\s+\\-o\\s+Disable access for a specified organization")) 25 Expect(session).To(Say("\\s+\\-p\\s+Disable access to a specified service plan")) 26 Expect(session).To(Say("SEE ALSO:")) 27 Expect(session).To(Say("\\s+enable-service-access, marketplace, service-access, service-brokers")) 28 }) 29 }) 30 31 When("no service argument was provided", func() { 32 It("displays a warning, the help text, and exits 1", func() { 33 session := helpers.CF("disable-service-access") 34 Eventually(session).Should(Exit(1)) 35 Expect(session.Err).To(Say("Incorrect Usage: the required argument `SERVICE` was not provided")) 36 Expect(session).To(Say("NAME:")) 37 Expect(session).To(Say("\\s+disable-service-access - Disable access to a service offering or service plan for one or all orgs")) 38 Expect(session).To(Say("USAGE:")) 39 Expect(session).To(Say("\\s+cf disable-service-access SERVICE \\[-b BROKER\\] \\[-p PLAN\\] \\[-o ORG\\]")) 40 Expect(session).To(Say("OPTIONS:")) 41 Expect(session).To(Say("\\s+\\-b\\s+Disable access to a service offering from a particular service broker. Required when service offering name is ambiguous")) 42 Expect(session).To(Say("\\s+\\-o\\s+Disable access for a specified organization")) 43 Expect(session).To(Say("\\s+\\-p\\s+Disable access to a specified service plan")) 44 Expect(session).To(Say("SEE ALSO:")) 45 Expect(session).To(Say("\\s+enable-service-access, marketplace, service-access, service-brokers")) 46 }) 47 }) 48 49 When("an extra argument is provided", func() { 50 It("displays an error, and exits 1", func() { 51 session := helpers.CF("disable-service-access", "a-service", "extra-arg") 52 Eventually(session).Should(Exit(1)) 53 Expect(session).To(Say("FAILED")) 54 Expect(session.Err).To(Say(`Incorrect Usage: unexpected argument "extra-arg"`)) 55 Expect(session).To(Say("NAME:")) 56 Expect(session).To(Say("\\s+disable-service-access - Disable access to a service offering or service plan for one or all orgs")) 57 Expect(session).To(Say("USAGE:")) 58 Expect(session).To(Say("\\s+cf disable-service-access SERVICE \\[-b BROKER\\] \\[-p PLAN\\] \\[-o ORG\\]")) 59 Expect(session).To(Say("OPTIONS:")) 60 Expect(session).To(Say("\\s+\\-b\\s+Disable access to a service offering from a particular service broker. Required when service offering name is ambiguous")) 61 Expect(session).To(Say("\\s+\\-o\\s+Disable access for a specified organization")) 62 Expect(session).To(Say("\\s+\\-p\\s+Disable access to a specified service plan")) 63 Expect(session).To(Say("SEE ALSO:")) 64 Expect(session).To(Say("\\s+enable-service-access, marketplace, service-access, service-brokers")) 65 }) 66 }) 67 }) 68 69 Context("not logged in", func() { 70 BeforeEach(func() { 71 helpers.LogoutCF() 72 }) 73 74 It("displays FAILED, an informative error message, and exits 1", func() { 75 session := helpers.CF("disable-service-access", "does-not-matter") 76 Eventually(session).Should(Exit(1)) 77 Expect(session).To(Say("FAILED")) 78 Expect(session.Err).To(Say("Not logged in. Use 'cf login' or 'cf login --sso' to log in.")) 79 }) 80 }) 81 82 Context("logged in", func() { 83 var username string 84 85 BeforeEach(func() { 86 username, _ = helpers.GetCredentials() 87 helpers.LoginCF() 88 }) 89 90 When("service does not exist", func() { 91 It("displays FAILED, an informative error message, and exits 1", func() { 92 session := helpers.CF("disable-service-access", "some-service") 93 Eventually(session).Should(Exit(1)) 94 Expect(session).To(Say("Disabling access to all plans of service offering some-service for all orgs as %s\\.\\.\\.", username)) 95 Expect(session.Err).To(Say("Service offering 'some-service' not found")) 96 Expect(session).To(Say("FAILED")) 97 }) 98 }) 99 100 Context("a service broker is registered", func() { 101 var ( 102 orgName string 103 spaceName string 104 broker *servicebrokerstub.ServiceBrokerStub 105 ) 106 107 BeforeEach(func() { 108 orgName = helpers.NewOrgName() 109 spaceName = helpers.NewSpaceName() 110 helpers.SetupCF(orgName, spaceName) 111 112 broker = servicebrokerstub.New().WithPlans(2).Create().Register() 113 }) 114 115 AfterEach(func() { 116 helpers.QuickDeleteOrg(orgName) 117 broker.Forget() 118 }) 119 120 When("plans are public", func() { 121 BeforeEach(func() { 122 session := helpers.CF("enable-service-access", broker.FirstServiceOfferingName()) 123 Eventually(session).Should(Exit(0)) 124 }) 125 126 When("a service name is provided", func() { 127 It("displays an informative message, exits 0, and disables the service for all orgs", func() { 128 session := helpers.CF("disable-service-access", broker.FirstServiceOfferingName()) 129 Eventually(session).Should(Exit(0)) 130 Expect(session).To(Say("Disabling access to all plans of service offering %s for all orgs as %s...", broker.FirstServiceOfferingName(), username)) 131 Expect(session).To(Say("OK")) 132 133 session = helpers.CF("service-access", "-e", broker.FirstServiceOfferingName()) 134 Eventually(session).Should(Exit(0)) 135 Expect(session).To(Say("broker:\\s+%s", broker.Name)) 136 Expect(session).To(Say("%s\\s+%s\\s+none", 137 broker.FirstServiceOfferingName(), 138 broker.FirstServicePlanName(), 139 )) 140 }) 141 }) 142 143 When("a service name and plan name are provided", func() { 144 It("displays an informative message, exits 0, and disables the plan for all orgs", func() { 145 session := helpers.CF("disable-service-access", broker.FirstServiceOfferingName(), "-p", broker.FirstServicePlanName()) 146 Eventually(session).Should(Exit(0)) 147 Expect(session).To(Say("Disabling access to plan %s of service offering %s for all orgs as %s...", broker.FirstServicePlanName(), broker.FirstServiceOfferingName(), username)) 148 Expect(session).To(Say("OK")) 149 150 session = helpers.CF("service-access", "-e", broker.FirstServiceOfferingName()) 151 Eventually(session).Should(Exit(0)) 152 153 Expect(string(session.Out.Contents())).To(MatchRegexp( 154 `%s\s+%s\s+none`, 155 broker.FirstServiceOfferingName(), 156 broker.FirstServicePlanName(), 157 )) 158 159 Expect(string(session.Out.Contents())).To(MatchRegexp( 160 `%s\s+%s\s+all`, 161 broker.FirstServiceOfferingName(), 162 broker.Services[0].Plans[1].Name, 163 )) 164 }) 165 }) 166 167 When("an org name is provided", func() { 168 It("fails", func() { 169 session := helpers.CF("disable-service-access", broker.FirstServiceOfferingName(), "-o", orgName) 170 Eventually(session).Should(Exit(1)) 171 Expect(session).To(Say("Disabling access to all plans of service offering %s for org %s as %s...", broker.FirstServiceOfferingName(), orgName, username)) 172 Expect(session).To(Say("FAILED")) 173 Expect(session.Err).To(Say("Cannot remove organization level access for public plans\\.")) 174 }) 175 }) 176 }) 177 178 When("a plan is enabled for multiple orgs", func() { 179 var orgName2 string 180 181 BeforeEach(func() { 182 orgName2 = helpers.NewOrgName() 183 spaceName2 := helpers.NewSpaceName() 184 helpers.CreateOrgAndSpace(orgName2, spaceName2) 185 Eventually(helpers.CF("enable-service-access", broker.FirstServiceOfferingName(), "-o", orgName, "-p", broker.FirstServicePlanName())).Should(Exit(0)) 186 Eventually(helpers.CF("enable-service-access", broker.FirstServiceOfferingName(), "-o", orgName2, "-p", broker.FirstServicePlanName())).Should(Exit(0)) 187 }) 188 189 AfterEach(func() { 190 helpers.QuickDeleteOrg(orgName2) 191 }) 192 193 When("a service name and org is provided", func() { 194 It("displays an informative message, and exits 0, and disables the service for the given org", func() { 195 session := helpers.CF("disable-service-access", broker.FirstServiceOfferingName(), "-o", orgName) 196 Eventually(session).Should(Exit(0)) 197 Expect(session).To(Say("Disabling access to all plans of service offering %s for org %s as %s...", broker.FirstServiceOfferingName(), orgName, username)) 198 Expect(session).To(Say("Did not update plan %s as it already has visibility none\\.", broker.Services[0].Plans[1].Name)) 199 Expect(session).To(Say("OK")) 200 201 session = helpers.CF("service-access", "-e", broker.FirstServiceOfferingName()) 202 Eventually(session).Should(Exit(0)) 203 Expect(session).To(Say("broker:\\s+%s", broker.Name)) 204 Expect(session).To(Say("%s\\s+%s\\s+limited\\s+%s", 205 broker.FirstServiceOfferingName(), 206 broker.FirstServicePlanName(), 207 orgName2, 208 )) 209 }) 210 }) 211 212 When("a service name, plan name and org is provided", func() { 213 It("displays an informative message, and exits 0, disables the service for the given org and plan", func() { 214 session := helpers.CF("disable-service-access", broker.FirstServiceOfferingName(), "-p", broker.FirstServicePlanName(), "-o", orgName) 215 Eventually(session).Should(Exit(0)) 216 Expect(session).To(Say("Disabling access to plan %s of service offering %s for org %s as %s...", broker.FirstServicePlanName(), broker.FirstServiceOfferingName(), orgName, username)) 217 Expect(session).To(Say("OK")) 218 219 session = helpers.CF("service-access", "-e", broker.FirstServiceOfferingName()) 220 Eventually(session).Should(Exit(0)) 221 Expect(session).To(Say("broker:\\s+%s", broker.Name)) 222 Expect(session).To(Say("%s\\s+%s\\s+limited\\s+%s", 223 broker.FirstServiceOfferingName(), 224 broker.FirstServicePlanName(), 225 orgName2, 226 )) 227 }) 228 }) 229 }) 230 231 When("the org does not exist", func() { 232 It("displays FAILED, an informative error message, and exits 1", func() { 233 session := helpers.CF("disable-service-access", broker.FirstServiceOfferingName(), "-o", "not-a-real-org") 234 Eventually(session).Should(Exit(1)) 235 Expect(session).To(Say("Disabling access to all plans of service offering %s for org not-a-real-org as %s...", broker.FirstServiceOfferingName(), username)) 236 Expect(session).To(Say("FAILED")) 237 Expect(session.Err).To(Say("Organization 'not-a-real-org' not found")) 238 }) 239 }) 240 241 When("the plan does not exist", func() { 242 It("displays FAILED, an informative error message, and exits 1", func() { 243 session := helpers.CF("disable-service-access", broker.FirstServiceOfferingName(), "-p", "plan-does-not-exist") 244 Eventually(session).Should(Exit(1)) 245 Expect(session).To(Say("Disabling access to plan plan-does-not-exist of service offering %s for all orgs as %s...", broker.FirstServiceOfferingName(), username)) 246 Expect(session).To(Say("FAILED")) 247 Expect(session.Err).To(Say("The plan plan-does-not-exist could not be found for service %s", broker.FirstServiceOfferingName())) 248 }) 249 }) 250 251 When("two services with the same name are enabled", func() { 252 var secondBroker *servicebrokerstub.ServiceBrokerStub 253 254 BeforeEach(func() { 255 secondBroker = servicebrokerstub.New() 256 secondBroker.Services[0].Name = broker.FirstServiceOfferingName() 257 secondBroker.Create().Register() 258 Eventually(helpers.CF("enable-service-access", broker.FirstServiceOfferingName(), "-b", broker.Name)).Should(Exit(0)) 259 Eventually(helpers.CF("enable-service-access", secondBroker.FirstServiceOfferingName(), "-b", secondBroker.Name)).Should(Exit(0)) 260 }) 261 262 AfterEach(func() { 263 secondBroker.Forget() 264 }) 265 266 When("no broker name is provided", func() { 267 It("fails and asks for disambiguation", func() { 268 session := helpers.CF("disable-service-access", broker.FirstServiceOfferingName()) 269 Eventually(session).Should(Exit(1)) 270 Expect(session).To(Say("Disabling access to all plans of service offering %s for all orgs as %s...", broker.FirstServiceOfferingName(), username)) 271 Expect(session.Err).To(Say( 272 "Service '%s' is provided by multiple service brokers: %s, %s\nSpecify a broker by using the '-b' flag.", 273 broker.FirstServiceOfferingName(), 274 broker.Name, 275 secondBroker.Name, 276 )) 277 }) 278 }) 279 280 When("a broker name is provided", func() { 281 It("displays an informative message, exits 0, and disables access to the service", func() { 282 session := helpers.CF("disable-service-access", broker.FirstServiceOfferingName(), "-b", secondBroker.Name) 283 Eventually(session).Should(Exit(0)) 284 Expect(session).To(Say("Disabling access to all plans of service offering %s from broker %s for all orgs as %s...", broker.FirstServiceOfferingName(), secondBroker.Name, username)) 285 Expect(session).To(Say("OK")) 286 287 session = helpers.CF("service-access", "-b", secondBroker.Name) 288 Eventually(session).Should(Exit(0)) 289 Expect(session).To(Say("broker:\\s+%s", secondBroker.Name)) 290 Expect(session).To(Say("%s\\s+%s\\s+none", 291 secondBroker.FirstServiceOfferingName(), 292 secondBroker.FirstServicePlanName(), 293 )) 294 }) 295 }) 296 }) 297 }) 298 }) 299 })