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