github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/integration/shared/isolated/disable_service_access_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 5 "code.cloudfoundry.org/cli/integration/helpers" 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(Say("NAME:")) 18 Eventually(session).Should(Say("\\s+disable-service-access - Disable access to a service or service plan for one or all orgs")) 19 Eventually(session).Should(Say("USAGE:")) 20 Eventually(session).Should(Say("\\s+cf disable-service-access SERVICE \\[-p PLAN\\] \\[-o ORG\\]")) 21 Eventually(session).Should(Say("OPTIONS:")) 22 Eventually(session).Should(Say("\\s+\\-o\\s+Disable access for a specified organization")) 23 Eventually(session).Should(Say("\\s+\\-p\\s+Disable access to a specified service plan")) 24 Eventually(session).Should(Say("SEE ALSO:")) 25 Eventually(session).Should(Say("\\s+marketplace, service-access, service-brokers")) 26 Eventually(session).Should(Exit(0)) 27 }) 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.Err).Should(Say("Incorrect Usage: the required argument `SERVICE` was not provided")) 35 Eventually(session).Should(Say("NAME:")) 36 Eventually(session).Should(Say("\\s+disable-service-access - Disable access to a service or service plan for one or all orgs")) 37 Eventually(session).Should(Say("USAGE:")) 38 Eventually(session).Should(Say("\\s+cf disable-service-access SERVICE \\[-p PLAN\\] \\[-o ORG\\]")) 39 Eventually(session).Should(Say("OPTIONS:")) 40 Eventually(session).Should(Say("\\s+\\-o\\s+Disable access for a specified organization")) 41 Eventually(session).Should(Say("\\s+\\-p\\s+Disable access to a specified service plan")) 42 Eventually(session).Should(Say("SEE ALSO:")) 43 Eventually(session).Should(Say("\\s+marketplace, service-access, service-brokers")) 44 Eventually(session).Should(Exit(1)) 45 }) 46 }) 47 48 When("an extra argument is provided", func() { 49 It("displays an error, and exits 1", func() { 50 session := helpers.CF("disable-service-access", "a-service", "extra-arg") 51 Eventually(session).Should(Say("FAILED")) 52 Eventually(session.Err).Should(Say(`Incorrect Usage: unexpected argument "extra-arg"`)) 53 Eventually(session).Should(Say("NAME:")) 54 Eventually(session).Should(Say("\\s+disable-service-access - Disable access to a service or service plan for one or all orgs")) 55 Eventually(session).Should(Say("USAGE:")) 56 Eventually(session).Should(Say("\\s+cf disable-service-access SERVICE \\[-p PLAN\\] \\[-o ORG\\]")) 57 Eventually(session).Should(Say("OPTIONS:")) 58 Eventually(session).Should(Say("\\s+\\-o\\s+Disable access for a specified organization")) 59 Eventually(session).Should(Say("\\s+\\-p\\s+Disable access to a specified service plan")) 60 Eventually(session).Should(Say("SEE ALSO:")) 61 Eventually(session).Should(Say("\\s+marketplace, service-access, service-brokers")) 62 Eventually(session).Should(Exit(1)) 63 }) 64 }) 65 66 Context("not logged in", func() { 67 BeforeEach(func() { 68 helpers.LogoutCF() 69 }) 70 71 It("displays FAILED, an informative error message, and exits 1", func() { 72 session := helpers.CF("disable-service-access", "does-not-matter") 73 Eventually(session).Should(Say("FAILED")) 74 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 75 Eventually(session).Should(Exit(1)) 76 }) 77 }) 78 79 Context("logged in", func() { 80 BeforeEach(func() { 81 helpers.LoginCF() 82 }) 83 84 Context("the service does not exist", func() { 85 When("only the service is specified", func() { 86 It("displays FAILED, an informative error message, and exits 1", func() { 87 session := helpers.CF("disable-service-access", "some-service") 88 Eventually(session).Should(Say("Disabling access to all plans of service some-service for all orgs as admin\\.\\.\\.")) 89 Eventually(session.Err).Should(Say("Service offering 'some-service' not found")) 90 Eventually(session).Should(Say("FAILED")) 91 Eventually(session).Should(Exit(1)) 92 }) 93 }) 94 }) 95 96 Context("a service broker is registered", func() { 97 var ( 98 orgName string 99 spaceName string 100 domain string 101 service string 102 servicePlan string 103 broker helpers.ServiceBroker 104 ) 105 106 BeforeEach(func() { 107 orgName = helpers.NewOrgName() 108 spaceName = helpers.NewSpaceName() 109 helpers.SetupCF(orgName, spaceName) 110 111 domain = helpers.DefaultSharedDomain() 112 service = helpers.PrefixedRandomName("SERVICE") 113 servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN") 114 115 broker = helpers.CreateBroker(domain, service, servicePlan) 116 }) 117 118 AfterEach(func() { 119 helpers.TargetOrgAndSpace(orgName, spaceName) 120 broker.Destroy() 121 helpers.QuickDeleteOrg(orgName) 122 }) 123 124 When("a service has access enabled for all orgs and plans", func() { 125 BeforeEach(func() { 126 session := helpers.CF("enable-service-access", service) 127 Eventually(session).Should(Exit(0)) 128 }) 129 130 When("a service name is provided", func() { 131 It("displays an informative message, exits 0, and disables the service for all orgs", func() { 132 session := helpers.CF("disable-service-access", service) 133 Eventually(session).Should(Say("Disabling access to all plans of service %s for all orgs as admin...", service)) 134 Eventually(session).Should(Say("OK")) 135 Eventually(session).Should(Exit(0)) 136 137 session = helpers.CF("service-access", "-e", service) 138 Eventually(session).Should(Exit(0)) 139 Eventually(session).Should(Say("broker:\\s+%s", broker.Name)) 140 Eventually(session).Should(Say("%s\\s+%s\\s+none", 141 service, 142 servicePlan, 143 )) 144 }) 145 }) 146 147 When("a service name and plan name are provided", func() { 148 It("displays an informative message, exits 0, and disables the plan for all orgs", func() { 149 session := helpers.CF("disable-service-access", service, "-p", servicePlan) 150 Eventually(session).Should(Say("Disabling access of plan %s for service %s as admin...", servicePlan, service)) 151 Eventually(session).Should(Say("OK")) 152 Eventually(session).Should(Exit(0)) 153 154 session = helpers.CF("service-access", "-e", service) 155 Eventually(session).Should(Exit(0)) 156 Eventually(session).Should(Say("broker:\\s+%s", broker.Name)) 157 Eventually(session).Should(Say("%s\\s+.+\\s+all", 158 service, 159 )) 160 Eventually(session).Should(Say("%s\\s+%s\\s+none", 161 service, 162 servicePlan, 163 )) 164 }) 165 }) 166 }) 167 168 When("a service has access enabled for multiple orgs and a specific plan", func() { 169 var orgName2 string 170 171 BeforeEach(func() { 172 orgName2 = helpers.NewOrgName() 173 spaceName2 := helpers.NewSpaceName() 174 helpers.CreateOrgAndSpace(orgName2, spaceName2) 175 Eventually(helpers.CF("enable-service-access", service, "-o", orgName, "-p", servicePlan)).Should(Exit(0)) 176 Eventually(helpers.CF("enable-service-access", service, "-o", orgName2, "-p", servicePlan)).Should(Exit(0)) 177 }) 178 179 AfterEach(func() { 180 helpers.QuickDeleteOrg(orgName2) 181 }) 182 183 When("a service name and org is provided", func() { 184 It("displays an informative message, and exits 0, and disables the service for the given org", func() { 185 session := helpers.CF("disable-service-access", service, "-o", orgName) 186 Eventually(session).Should(Say("Disabling access to all plans of service %s for the org %s as admin...", service, orgName)) 187 Eventually(session).Should(Say("OK")) 188 Eventually(session).Should(Exit(0)) 189 190 session = helpers.CF("service-access", "-e", service) 191 Eventually(session).Should(Exit(0)) 192 Eventually(session).Should(Say("broker:\\s+%s", broker.Name)) 193 Eventually(session).Should(Say("%s\\s+%s\\s+limited\\s+%s", 194 service, 195 servicePlan, 196 orgName2, 197 )) 198 }) 199 }) 200 201 When("a service name, plan name and org is provided", func() { 202 It("displays an informative message, and exits 0, disables the service for the given org and plan", func() { 203 session := helpers.CF("disable-service-access", service, "-p", servicePlan, "-o", orgName) 204 Eventually(session).Should(Say("Disabling access to plan %s of service %s for org %s as admin...", servicePlan, service, orgName)) 205 Eventually(session).Should(Say("OK")) 206 Eventually(session).Should(Exit(0)) 207 208 session = helpers.CF("service-access", "-e", service) 209 Eventually(session).Should(Exit(0)) 210 Eventually(session).Should(Say("broker:\\s+%s", broker.Name)) 211 Eventually(session).Should(Say("%s\\s+%s\\s+limited\\s+%s", 212 service, 213 servicePlan, 214 orgName2, 215 )) 216 }) 217 }) 218 }) 219 220 When("the org does not exist", func() { 221 It("displays FAILED, an informative error message, and exits 1", func() { 222 session := helpers.CF("disable-service-access", service, "-o", "not-a-real-org") 223 Eventually(session).Should(Say("Disabling access to all plans of service %s for the org not-a-real-org as admin...", service)) 224 Eventually(session).Should(Say("FAILED")) 225 Eventually(session.Err).Should(Say("Organization 'not-a-real-org' not found")) 226 Eventually(session).Should(Exit(1)) 227 }) 228 }) 229 230 When("the plan does not exist", func() { 231 It("displays FAILED, an informative error message, and exits 1", func() { 232 session := helpers.CF("disable-service-access", service, "-p", "plan-does-not-exist") 233 Eventually(session).Should(Say("Disabling access of plan plan-does-not-exist for service %s as admin...", service)) 234 Eventually(session).Should(Say("FAILED")) 235 Eventually(session.Err).Should(Say("The plan plan-does-not-exist could not be found for service %s", service)) 236 Eventually(session).Should(Exit(1)) 237 }) 238 }) 239 240 When("two services with the same name are enabled", func() { 241 var secondBroker helpers.ServiceBroker 242 243 BeforeEach(func() { 244 helpers.SkipIfVersionLessThan(ccversion.MinVersionMultiServiceRegistrationV2) 245 secondBroker = helpers.CreateBroker(domain, service, servicePlan) 246 Eventually(helpers.CF("enable-service-access", service, "-b", broker.Name)).Should(Exit(0)) 247 Eventually(helpers.CF("enable-service-access", service, "-b", secondBroker.Name)).Should(Exit(0)) 248 }) 249 250 AfterEach(func() { 251 secondBroker.Destroy() 252 }) 253 254 When("a service name and broker name are provided", func() { 255 It("displays an informative message, exits 0, and disables access to the service", func() { 256 session := helpers.CF("disable-service-access", service, "-b", secondBroker.Name) 257 Eventually(session).Should(Say("Disabling access to all plans of service %s from broker %s for all orgs as admin...", service, secondBroker.Name)) 258 Eventually(session).Should(Say("OK")) 259 Eventually(session).Should(Exit(0)) 260 261 session = helpers.CF("service-access", "-b", secondBroker.Name) 262 Eventually(session).Should(Exit(0)) 263 Eventually(session).Should(Say("broker:\\s+%s", secondBroker.Name)) 264 Eventually(session).Should(Say("%s\\s+%s\\s+none", 265 service, 266 servicePlan, 267 )) 268 }) 269 }) 270 }) 271 }) 272 273 Context("multiple service brokers are registered", func() { 274 var ( 275 orgName string 276 spaceName string 277 domain string 278 service string 279 servicePlan string 280 broker1 helpers.ServiceBroker 281 broker2 helpers.ServiceBroker 282 ) 283 284 BeforeEach(func() { 285 helpers.SkipIfVersionLessThan(ccversion.MinVersionMultiServiceRegistrationV2) 286 orgName = helpers.NewOrgName() 287 spaceName = helpers.NewSpaceName() 288 helpers.SetupCF(orgName, spaceName) 289 290 domain = helpers.DefaultSharedDomain() 291 service = helpers.PrefixedRandomName("SERVICE") 292 servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN") 293 294 broker1 = helpers.CreateBroker(domain, service, servicePlan) 295 broker2 = helpers.CreateBroker(domain, service, servicePlan) 296 }) 297 298 AfterEach(func() { 299 helpers.TargetOrgAndSpace(orgName, spaceName) 300 broker1.Destroy() 301 broker2.Destroy() 302 helpers.QuickDeleteOrg(orgName) 303 }) 304 305 When("two services have access enabled in the same org", func() { 306 BeforeEach(func() { 307 session := helpers.CF("enable-service-access", service, "-b", broker1.Name, "-o", orgName) 308 Eventually(session).Should(Exit(0)) 309 session = helpers.CF("enable-service-access", service, "-b", broker2.Name, "-o", orgName) 310 Eventually(session).Should(Exit(0)) 311 }) 312 313 It("fails to disable access when no broker is specified", func() { 314 session := helpers.CF("disable-service-access", service, "-o", orgName) 315 Eventually(session.Err).Should(Say("Service '%s' is provided by multiple service brokers.", service)) 316 Eventually(session).Should(Exit(1)) 317 }) 318 319 It("successfully disables access when the broker is specified", func() { 320 session := helpers.CF("disable-service-access", service, "-o", orgName, "-b", broker1.Name) 321 Eventually(session).Should(Exit(0)) 322 323 session = helpers.CF("marketplace") 324 Consistently(session.Out).ShouldNot(Say("%s/s+%s/.+%s", service, servicePlan, broker1.Name)) 325 Eventually(session).Should(Exit(0)) 326 }) 327 }) 328 329 When("two services have access enabled in different orgs", func() { 330 var otherOrgName string 331 332 BeforeEach(func() { 333 otherOrgName = helpers.NewOrgName() 334 helpers.SetupCF(otherOrgName, spaceName) 335 336 session := helpers.CF("enable-service-access", service, "-b", broker1.Name, "-o", otherOrgName) 337 Eventually(session).Should(Exit(0)) 338 session = helpers.CF("enable-service-access", service, "-b", broker2.Name, "-o", orgName) 339 Eventually(session).Should(Exit(0)) 340 }) 341 342 It("fails to disable access when no broker is specified", func() { 343 session := helpers.CF("disable-service-access", service, "-o", orgName) 344 Eventually(session.Err).Should(Say("Service '%s' is provided by multiple service brokers.", service)) 345 Eventually(session).Should(Exit(1)) 346 347 session = helpers.CF("disable-service-access", service, "-o", otherOrgName) 348 Eventually(session.Err).Should(Say("Service '%s' is provided by multiple service brokers.", service)) 349 Eventually(session).Should(Exit(1)) 350 }) 351 352 It("successfully disables access when the broker is specified", func() { 353 session := helpers.CF("disable-service-access", service, "-o", orgName, "-b", broker1.Name) 354 Eventually(session).Should(Exit(0)) 355 356 session = helpers.CF("marketplace") 357 Consistently(session.Out).ShouldNot(Say("%s/s+%s/.+%s", service, servicePlan, broker1.Name)) 358 Eventually(session).Should(Exit(0)) 359 }) 360 }) 361 362 When("two services have plan enabeled in different orgs", func() { 363 var otherOrgName string 364 365 BeforeEach(func() { 366 otherOrgName = helpers.NewOrgName() 367 helpers.SetupCF(otherOrgName, spaceName) 368 369 session := helpers.CF("enable-service-access", service, "-b", broker1.Name, "-p", servicePlan, "-o", otherOrgName) 370 Eventually(session).Should(Exit(0)) 371 session = helpers.CF("enable-service-access", service, "-b", broker2.Name, "-p", servicePlan, "-o", orgName) 372 Eventually(session).Should(Exit(0)) 373 }) 374 375 It("fails to disable access when no broker is specified", func() { 376 session := helpers.CF("disable-service-access", service, "-p", servicePlan, "-o", orgName) 377 Eventually(session.Err).Should(Say("Service '%s' is provided by multiple service brokers.", service)) 378 Eventually(session).Should(Exit(1)) 379 380 session = helpers.CF("disable-service-access", service, "-p", servicePlan, "-o", otherOrgName) 381 Eventually(session.Err).Should(Say("Service '%s' is provided by multiple service brokers.", service)) 382 Eventually(session).Should(Exit(1)) 383 }) 384 385 It("successfully disables access when the broker is specified", func() { 386 session := helpers.CF("disable-service-access", service, "-p", servicePlan, "-o", orgName, "-b", broker1.Name) 387 Eventually(session).Should(Exit(0)) 388 389 session = helpers.CF("marketplace") 390 Consistently(session.Out).ShouldNot(Say("%s/s+%s/.+%s", service, servicePlan, broker1.Name)) 391 Eventually(session).Should(Exit(0)) 392 }) 393 }) 394 }) 395 }) 396 })