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