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