github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/shared/isolated/service_access_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gbytes" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 var _ = Describe("service-access command", func() { 12 var ( 13 userName string 14 ) 15 16 BeforeEach(func() { 17 userName, _ = helpers.GetCredentials() 18 }) 19 20 Describe("help", func() { 21 When("--help flag is set", func() { 22 It("displays command usage to output", func() { 23 session := helpers.CF("service-access", "--help") 24 Eventually(session).Should(Say(`NAME:`)) 25 Eventually(session).Should(Say(`\s+service-access - List service access settings`)) 26 Eventually(session).Should(Say(`USAGE:`)) 27 Eventually(session).Should(Say(`\s+cf service-access \[-b BROKER\] \[-e SERVICE\] \[-o ORG\]`)) 28 Eventually(session).Should(Say(`OPTIONS:`)) 29 Eventually(session).Should(Say(`\s+-b\s+Access for plans of a particular broker`)) 30 Eventually(session).Should(Say(`\s+-e\s+Access for service name of a particular service offering`)) 31 Eventually(session).Should(Say(`\s+-o\s+Plans accessible by a particular organization`)) 32 Eventually(session).Should(Say(`SEE ALSO:`)) 33 Eventually(session).Should(Say(`\s+disable-service-access, enable-service-access, marketplace, service-brokers`)) 34 Eventually(session).Should(Exit(0)) 35 }) 36 }) 37 }) 38 39 When("the environment is not setup correctly", func() { 40 It("fails with the appropriate errors", func() { 41 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "service-access") 42 }) 43 }) 44 45 When("the environment is setup correctly", func() { 46 BeforeEach(func() { 47 helpers.LoginCF() 48 helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) 49 }) 50 51 When("-b is provided with a broker name that does not exist", func() { 52 It("shows an error message", func() { 53 session := helpers.CF("service-access", "-b", "non-existent-broker") 54 Eventually(session).Should(Say(`Getting service access for broker non-existent-broker as %s\.\.\.`, userName)) 55 Eventually(session.Err).Should(Say(`Service broker 'non-existent-broker' not found\.`)) 56 Eventually(session.Err).Should(Say(`TIP: Use 'cf service-brokers' to see a list of available brokers\.`)) 57 Eventually(session).Should(Exit(1)) 58 }) 59 }) 60 61 When("-e is provided with a service name that does not exist", func() { 62 It("shows an error message", func() { 63 session := helpers.CF("service-access", "-e", "non-existent-service") 64 Eventually(session).Should(Say(`Getting service access for service non-existent-service as %s\.\.\.`, userName)) 65 Eventually(session.Err).Should(Say(`Service offering 'non-existent-service' not found\.`)) 66 Eventually(session).Should(Exit(1)) 67 }) 68 }) 69 70 When("-o is provided with a org name that does not exist", func() { 71 It("shows an error message", func() { 72 session := helpers.CF("service-access", "-o", "non-existent-org") 73 Eventually(session).Should(Say(`Getting service access for organization non-existent-org as %s\.\.\.`, userName)) 74 Eventually(session.Err).Should(Say(`Organization 'non-existent-org' not found`)) 75 Eventually(session).Should(Exit(1)) 76 }) 77 }) 78 79 When("there are service offerings", func() { 80 var ( 81 orgName string 82 spaceName string 83 domain string 84 85 service string 86 servicePlan string 87 broker helpers.ServiceBroker 88 ) 89 90 BeforeEach(func() { 91 orgName = helpers.NewOrgName() 92 spaceName = helpers.NewSpaceName() 93 helpers.SetupCF(orgName, spaceName) 94 95 domain = helpers.DefaultSharedDomain() 96 service = helpers.PrefixedRandomName("SERVICE") 97 servicePlan = helpers.NewPlanName() 98 broker = helpers.NewServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, service, servicePlan) 99 broker.SyncPlans[1].Name = helpers.GenerateHigherName(helpers.NewPlanName, servicePlan) 100 101 broker.Push() 102 broker.Configure(true) 103 broker.Create() 104 }) 105 106 AfterEach(func() { 107 broker.Destroy() 108 helpers.QuickDeleteOrg(orgName) 109 }) 110 111 It("displays all service access information", func() { 112 By("showing 'none' when service access is disabled") 113 session := helpers.CF("service-access") 114 Eventually(session).Should(Say("Getting service access as %s...", userName)) 115 Eventually(session).Should(Say(`service\s+plan\s+access\s+org`)) 116 Eventually(session).Should(Say(`%s\s+%s\s+%s`, service, servicePlan, "none")) 117 Eventually(session).Should(Exit(0)) 118 119 By("showing 'all' when service access is enabled globally") 120 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 121 session = helpers.CF("service-access") 122 Eventually(session).Should(Say("Getting service access as %s...", userName)) 123 Eventually(session).Should(Say(`service\s+plan\s+access\s+org`)) 124 Eventually(session).Should(Say(`%s\s+%s\s+%s`, service, servicePlan, "all")) 125 Eventually(session).Should(Exit(0)) 126 }) 127 128 When("some services are only accessible to certain organizations", func() { 129 BeforeEach(func() { 130 Eventually(helpers.CF("enable-service-access", service, "-o", orgName)).Should(Exit(0)) 131 }) 132 133 It("shows 'limited' access to the service", func() { 134 session := helpers.CF("service-access") 135 Eventually(session).Should(Say("Getting service access as %s...", userName)) 136 Eventually(session).Should(Say(`service\s+plan\s+access\s+org`)) 137 Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s`, service, servicePlan, "limited", orgName)) 138 Eventually(session).Should(Exit(0)) 139 }) 140 }) 141 142 When("multiple brokers are registered and with varying service accessibility", func() { 143 var ( 144 otherBroker helpers.ServiceBroker 145 otherService string 146 otherServicePlan string 147 148 otherOrgName string 149 ) 150 151 BeforeEach(func() { 152 helpers.SetupCF(orgName, spaceName) 153 154 otherService = helpers.PrefixedRandomName("SERVICE") 155 otherServicePlan = helpers.NewPlanName() 156 otherBroker = helpers.NewServiceBroker( 157 helpers.GenerateLowerName(helpers.NewServiceBrokerName, broker.Name), 158 helpers.NewAssets().ServiceBroker, 159 domain, 160 otherService, 161 otherServicePlan) 162 otherBroker.SyncPlans[1].Name = helpers.GenerateLowerName(helpers.NewPlanName, otherServicePlan) 163 164 otherBroker.Push() 165 otherBroker.Configure(true) 166 otherBroker.Create() 167 168 otherOrgName = helpers.GenerateLowerName(helpers.NewOrgName, orgName) 169 helpers.CreateOrg(otherOrgName) 170 171 Eventually( 172 helpers.CF("enable-service-access", 173 broker.Service.Name, 174 "-o", otherOrgName, 175 "-p", servicePlan)).Should(Exit(0)) 176 Eventually(helpers.CF("enable-service-access", otherBroker.Service.Name)).Should(Exit(0)) 177 }) 178 179 AfterEach(func() { 180 helpers.QuickDeleteOrg(otherOrgName) 181 otherBroker.Destroy() 182 }) 183 184 When("the -b flag is passed", func() { 185 It("shows only services from the specified broker", func() { 186 session := helpers.CF("service-access", "-b", otherBroker.Name) 187 Eventually(session).Should(Say("Getting service access for broker %s as %s...", otherBroker.Name, userName)) 188 Eventually(session).Should(Say(`broker:\s+%s`, otherBroker.Name)) 189 Eventually(session).Should(Say(`service\s+plan\s+access\s+org`)) 190 Eventually(session).Should(Say(`%s\s+%s\s+%s`, otherService, otherServicePlan, "all")) 191 Eventually(string(session.Out.Contents())).ShouldNot(ContainSubstring(service)) 192 Eventually(session).Should(Exit(0)) 193 }) 194 }) 195 196 When("the -e flag is passed", func() { 197 It("shows only services from the specified service", func() { 198 session := helpers.CF("service-access", "-e", otherService) 199 Eventually(session).Should(Say("Getting service access for service %s as %s...", otherService, userName)) 200 Eventually(session).Should(Say(`broker:\s+%s`, otherBroker.Name)) 201 Eventually(session).Should(Say(`service\s+plan\s+access\s+org`)) 202 Eventually(session).Should(Say(`%s\s+%s\s+%s`, otherService, otherServicePlan, "all")) 203 Eventually(string(session.Out.Contents())).ShouldNot(ContainSubstring(service)) 204 Eventually(session).Should(Exit(0)) 205 }) 206 }) 207 208 When("the -o flag is passed", func() { 209 It("displays only plans accessible by the specified organization", func() { 210 By("not displaying brokers that were only enabled in a different org than the provided one") 211 session := helpers.CF("service-access", "-o", orgName) 212 Eventually(session).Should(Say(`broker:\s+%s`, otherBroker.Name)) 213 Eventually(session).Should(Say(`%s\s+%s\s+all`, 214 otherBroker.Service.Name, 215 otherBroker.SyncPlans[1].Name, 216 )) 217 Eventually(session).Should(Say(`%s\s+%s\s+all`, 218 otherBroker.Service.Name, 219 otherBroker.SyncPlans[0].Name, 220 )) 221 Consistently(session).ShouldNot(Say(`broker:\s+%s`, broker.Name)) 222 Eventually(session).Should(Exit(0)) 223 224 By("displaying brokers that were enabled in the provided org") 225 session = helpers.CF("service-access", "-o", otherOrgName) 226 Eventually(session).Should(Say(`broker:\s+%s`, otherBroker.Name)) 227 Eventually(session).Should(Say(`%s\s+%s\s+all`, 228 otherBroker.Service.Name, 229 otherBroker.SyncPlans[1].Name, 230 )) 231 Eventually(session).Should(Say(`%s\s+%s\s+all`, 232 otherBroker.Service.Name, 233 otherBroker.SyncPlans[0].Name, 234 )) 235 Eventually(session).Should(Say(`broker:\s+%s`, broker.Name)) 236 Eventually(session).Should(Say(`%s\s+%s\s+limited\s+%s`, 237 broker.Service.Name, 238 servicePlan, 239 otherOrgName, 240 )) 241 242 Eventually(session).Should(Exit(0)) 243 }) 244 }) 245 }) 246 }) 247 }) 248 })