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