github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/create_shared_domain_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  
     7  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     8  	"code.cloudfoundry.org/cli/integration/helpers"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gbytes"
    12  	. "github.com/onsi/gomega/gexec"
    13  )
    14  
    15  var _ = Describe("create-shared-domain command", func() {
    16  	Context("Help", func() {
    17  		It("appears in cf help -a", func() {
    18  			session := helpers.CF("help", "-a")
    19  			Eventually(session).Should(Exit(0))
    20  			Expect(session).To(HaveCommandInCategoryWithDescription("create-shared-domain", "DOMAINS", "Create a domain that can be used by all orgs (admin-only)"))
    21  		})
    22  
    23  		It("displays the help information", func() {
    24  			session := helpers.CF("create-shared-domain", "--help")
    25  			Eventually(session).Should(Say("NAME:\n"))
    26  			Eventually(session).Should(Say(regexp.QuoteMeta("create-shared-domain - Create a domain that can be used by all orgs (admin-only)")))
    27  			Eventually(session).Should(Say("USAGE:\n"))
    28  			Eventually(session).Should(Say(regexp.QuoteMeta("cf create-shared-domain DOMAIN [--router-group ROUTER_GROUP_NAME | --internal]")))
    29  			Eventually(session).Should(Say("OPTIONS:\n"))
    30  			Eventually(session).Should(Say(`--router-group\s+Routes for this domain will use routers in the specified router group`))
    31  			Eventually(session).Should(Say(`--internal\s+Applications that use internal routes communicate directly on the container network`))
    32  			Eventually(session).Should(Say("SEE ALSO:\n"))
    33  			Eventually(session).Should(Say("create-private-domain, domains"))
    34  			Eventually(session).Should(Exit(0))
    35  		})
    36  	})
    37  
    38  	var (
    39  		orgName    string
    40  		spaceName  string
    41  		domainName string
    42  	)
    43  
    44  	BeforeEach(func() {
    45  		orgName = helpers.NewOrgName()
    46  		spaceName = helpers.NewSpaceName()
    47  		helpers.SetupCF(orgName, spaceName)
    48  		domainName = helpers.NewDomainName()
    49  	})
    50  
    51  	When("user is logged in", func() {
    52  		var userName string
    53  
    54  		BeforeEach(func() {
    55  			userName, _ = helpers.GetCredentials()
    56  		})
    57  
    58  		When("No optional flags are specified", func() {
    59  			When("domain name is valid", func() {
    60  				It("should create the shared domain", func() {
    61  					session := helpers.CF("create-shared-domain", domainName)
    62  
    63  					Eventually(session).Should(Say("Creating shared domain %s as %s...", domainName, userName))
    64  					Eventually(session).Should(Say("OK"))
    65  					Eventually(session).Should(Say("TIP: Domain '%s' is shared with all orgs. Run 'cf domains' to view available domains.", domainName))
    66  					Eventually(session).Should(Exit(0))
    67  
    68  					session = helpers.CF("domains")
    69  					Eventually(session).Should(Say(`%s\s+shared`, domainName))
    70  					Eventually(session).Should(Exit(0))
    71  				})
    72  			})
    73  
    74  			When("domain name is invalid", func() {
    75  				BeforeEach(func() {
    76  					domainName = "invalid-domain-name%*$$#)*" + helpers.RandomName()
    77  				})
    78  
    79  				It("should fail and return an error", func() {
    80  					session := helpers.CF("create-shared-domain", domainName)
    81  
    82  					Eventually(session).Should(Say("Creating shared domain %s as %s...", regexp.QuoteMeta(domainName), userName))
    83  					Eventually(session.Err).Should(Say("RFC 1035"))
    84  					Eventually(session).Should(Say("FAILED"))
    85  					Eventually(session).Should(Exit(1))
    86  				})
    87  			})
    88  		})
    89  
    90  		When("the --router-group flag is specified", func() {
    91  			var routerGroup string
    92  
    93  			BeforeEach(func() {
    94  				routerGroup = helpers.FindOrCreateTCPRouterGroup(0)
    95  			})
    96  
    97  			It("creates a domain with a router group", func() {
    98  				session := helpers.CF("create-shared-domain", domainName, "--router-group", routerGroup)
    99  
   100  				Eventually(session).Should(Say("Creating shared domain %s as %s...", domainName, userName))
   101  				Eventually(session).Should(Say("OK"))
   102  				Eventually(session).Should(Exit(0))
   103  			})
   104  
   105  			It("fails helpfully when the router group does not exist", func() {
   106  				session := helpers.CF("create-shared-domain", domainName, "--router-group", "bogus")
   107  
   108  				Eventually(session).Should(Say("Creating shared domain %s as %s...", domainName, userName))
   109  				Eventually(session.Err).Should(Say("Router group 'bogus' not found."))
   110  				Eventually(session).Should(Say("FAILED"))
   111  				Eventually(session).Should(Exit(1))
   112  			})
   113  		})
   114  
   115  		When("the --internal flag is specified", func() {
   116  			It("creates a domain with internal flag", func() {
   117  				session := helpers.CF("create-shared-domain", domainName, "--internal")
   118  
   119  				Eventually(session).Should(Say("Creating shared domain %s as %s...", domainName, userName))
   120  				Eventually(session).Should(Say("OK"))
   121  				Eventually(session).Should(Exit(0))
   122  
   123  				session = helpers.CF("domains")
   124  				Eventually(session).Should(Say(`%s\s+shared\s+true`, domainName))
   125  				Eventually(session).Should(Exit(0))
   126  			})
   127  		})
   128  	})
   129  
   130  	When("user is not an admin", func() {
   131  		var (
   132  			username string
   133  			password string
   134  		)
   135  
   136  		BeforeEach(func() {
   137  			helpers.LoginCF()
   138  			username, password = helpers.CreateUser()
   139  			helpers.LogoutCF()
   140  			helpers.LoginAs(username, password)
   141  		})
   142  
   143  		It("should not be able to create shared domain", func() {
   144  			session := helpers.CF("create-shared-domain", domainName)
   145  			Eventually(session).Should(Say(fmt.Sprintf("Creating shared domain %s as %s...", domainName, username)))
   146  			Eventually(session.Err).Should(Say("You are not authorized to perform the requested action"))
   147  			Eventually(session).Should(Say("FAILED"))
   148  			Eventually(session).Should(Exit(1))
   149  		})
   150  	})
   151  })