github.com/arunkumar7540/cli@v6.45.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/integration/helpers"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("create-shared-domain command", func() {
    15  	Context("Help", func() {
    16  		It("displays the help information", func() {
    17  			session := helpers.CF("create-shared-domain", "--help")
    18  			Eventually(session).Should(Say("NAME:\n"))
    19  			Eventually(session).Should(Say(regexp.QuoteMeta("create-shared-domain - Create a domain that can be used by all orgs (admin-only)")))
    20  			Eventually(session).Should(Say("USAGE:\n"))
    21  			Eventually(session).Should(Say(regexp.QuoteMeta("cf create-shared-domain DOMAIN [--internal]")))
    22  			Eventually(session).Should(Say("OPTIONS:\n"))
    23  			Eventually(session).Should(Say(`--internal\s+Applications that use internal routes communicate directly on the container network`))
    24  			Eventually(session).Should(Say("SEE ALSO:\n"))
    25  			Eventually(session).Should(Say("create-private-domain, domains"))
    26  			Eventually(session).Should(Exit(0))
    27  		})
    28  	})
    29  
    30  	var (
    31  		orgName    string
    32  		spaceName  string
    33  		domainName string
    34  	)
    35  
    36  	BeforeEach(func() {
    37  		orgName = helpers.NewOrgName()
    38  		spaceName = helpers.NewSpaceName()
    39  		helpers.SetupCF(orgName, spaceName)
    40  		domainName = helpers.NewDomainName()
    41  	})
    42  
    43  	When("user is logged in as admin", func() {
    44  		When("No optional flags are specified", func() {
    45  			When("domain name is valid", func() {
    46  				It("should create the shared domain", func() {
    47  					session := helpers.CF("create-shared-domain", domainName)
    48  
    49  					Eventually(session).Should(Say("Creating shared domain %s as admin...", domainName))
    50  					Eventually(session).Should(Say("OK"))
    51  					Eventually(session).Should(Say("TIP: Domain '%s' is shared with all orgs. Run 'cf domains' to view available domains.", domainName))
    52  					Eventually(session).Should(Exit(0))
    53  
    54  					session = helpers.CF("domains")
    55  					Eventually(session).Should(Say(`%s\s+shared`, domainName))
    56  					Eventually(session).Should(Exit(0))
    57  				})
    58  			})
    59  
    60  			When("domain name is invalid", func() {
    61  				BeforeEach(func() {
    62  					domainName = "invalid-domain-name%*$$#)*" + helpers.RandomName()
    63  				})
    64  
    65  				It("should fail and return an error", func() {
    66  					session := helpers.CF("create-shared-domain", domainName)
    67  
    68  					Eventually(session).Should(Say("Creating shared domain %s as admin...", regexp.QuoteMeta(domainName)))
    69  					Eventually(session.Err).Should(Say("RFC 1035"))
    70  					Eventually(session).Should(Say("FAILED"))
    71  					Eventually(session).Should(Exit(1))
    72  				})
    73  			})
    74  		})
    75  
    76  		When("the --internal flag is specified", func() {
    77  			It("creates a domain with internal flag", func() {
    78  				session := helpers.CF("create-shared-domain", domainName, "--internal")
    79  
    80  				Eventually(session).Should(Say("Creating shared domain %s as admin...", domainName))
    81  				Eventually(session).Should(Say("OK"))
    82  				Eventually(session).Should(Exit(0))
    83  
    84  				session = helpers.CF("domains")
    85  				Eventually(session).Should(Say(`%s\s+shared\s+true`, domainName))
    86  				Eventually(session).Should(Exit(0))
    87  			})
    88  		})
    89  	})
    90  
    91  	When("user is not logged in as admin", func() {
    92  		var (
    93  			username string
    94  			password string
    95  		)
    96  
    97  		BeforeEach(func() {
    98  			helpers.LoginCF()
    99  			username, password = helpers.CreateUser()
   100  			helpers.LoginAs(username, password)
   101  		})
   102  
   103  		It("should not be able to create shared domain", func() {
   104  			session := helpers.CF("create-shared-domain", domainName)
   105  			Eventually(session).Should(Say(fmt.Sprintf("Creating shared domain %s as %s...", domainName, username)))
   106  			Eventually(session.Err).Should(Say("You are not authorized to perform the requested action"))
   107  			Eventually(session).Should(Say("FAILED"))
   108  			Eventually(session).Should(Exit(1))
   109  		})
   110  	})
   111  })