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