github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/isolated/delete_user_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("delete-user command", func() {
    12  	Describe("help", func() {
    13  		When("--help flag is set", func() {
    14  			It("Displays command usage to output", func() {
    15  				session := helpers.CF("delete-user", "--help")
    16  				Eventually(session).Should(Say("NAME:"))
    17  				Eventually(session).Should(Say("delete-user - Delete a user"))
    18  				Eventually(session).Should(Say("USAGE:"))
    19  				Eventually(session).Should(Say(`cf delete-user USERNAME \[-f\]`))
    20  				Eventually(session).Should(Say(`cf delete-user USERNAME \[--origin ORIGIN\]`))
    21  				Eventually(session).Should(Say("EXAMPLES:"))
    22  				Eventually(session).Should(Say("   cf delete-user jsmith                   # internal user"))
    23  				Eventually(session).Should(Say("   cf delete-user jsmith --origin ldap     # LDAP user"))
    24  				Eventually(session).Should(Say("OPTIONS:"))
    25  				Eventually(session).Should(Say(`-f\s+Prompt interactively for password`))
    26  				Eventually(session).Should(Say(`--origin\s+Origin for mapping a user account to a user in an external identity provider`))
    27  				Eventually(session).Should(Say("SEE ALSO:"))
    28  				Eventually(session).Should(Say("org-users"))
    29  				Eventually(session).Should(Exit(0))
    30  			})
    31  		})
    32  	})
    33  
    34  	When("the environment is not setup correctly", func() {
    35  		It("fails with the appropriate errors", func() {
    36  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "delete-user", "username")
    37  		})
    38  	})
    39  
    40  	When("the environment is setup correctly", func() {
    41  		BeforeEach(func() {
    42  			helpers.LoginCF()
    43  		})
    44  
    45  		When("one users exist", func() {
    46  			var (
    47  				someUser string
    48  			)
    49  
    50  			BeforeEach(func() {
    51  				helpers.LoginCF()
    52  				someUser = helpers.NewUsername()
    53  				somePassword := helpers.NewPassword()
    54  				session := helpers.CF("create-user", someUser, somePassword)
    55  				Eventually(session).Should(Exit(0))
    56  			})
    57  
    58  			AfterEach(func() {
    59  				session := helpers.CF("delete-user", "-f", someUser)
    60  				Eventually(session).Should(Exit(0))
    61  			})
    62  
    63  			It("deletes the user", func() {
    64  				session := helpers.CF("delete-user", someUser, "-f")
    65  				Eventually(session).Should(Say("Deleting user %s...", someUser))
    66  				Eventually(session).Should(Say("OK"))
    67  				Eventually(session).Should(Exit(0))
    68  			})
    69  
    70  			When("multiple users exist with the same username", func() {
    71  				BeforeEach(func() {
    72  					session := helpers.CF("create-user", someUser, "--origin", "ldap")
    73  					Eventually(session).Should(Exit(0))
    74  				})
    75  
    76  				AfterEach(func() {
    77  					session := helpers.CF("delete-user", "-f", someUser, "--origin", "ldap")
    78  					Eventually(session).Should(Exit(0))
    79  				})
    80  
    81  				When("the origin flag is NOT passed in", func() {
    82  					It("errors", func() {
    83  						session := helpers.CF("delete-user", someUser, "-f")
    84  						Eventually(session).Should(Say("Deleting user %s...", someUser))
    85  						Eventually(session).Should(Say("FAILED"))
    86  						Eventually(session.Err).Should(Say("The username '%s' is found in multiple origins: (uaa|ldap), (uaa|ldap).", someUser))
    87  						Eventually(session).Should(Exit(1))
    88  					})
    89  				})
    90  
    91  				When("the origin flag is passed in", func() {
    92  					It("deletes the correct user", func() {
    93  						session := helpers.CF("delete-user", someUser, "-f", "--origin", "ldap")
    94  						Eventually(session).Should(Say("Deleting user %s...", someUser))
    95  						Eventually(session).Should(Say("OK"))
    96  						Eventually(session).Should(Exit(0))
    97  
    98  						Expect(helpers.GetUsersV3()).ToNot(ContainElement(helpers.User{
    99  							Username: someUser,
   100  							Origin:   "ldap",
   101  						}))
   102  					})
   103  				})
   104  			})
   105  		})
   106  
   107  		When("the user does not exist", func() {
   108  			It("does not error but prints a message letting the user know it never existed", func() {
   109  				session := helpers.CF("delete-user", "non-existent-user", "-f")
   110  				Eventually(session).Should(Say("User 'non-existent-user' does not exist."))
   111  				Eventually(session).Should(Say("OK"))
   112  				Eventually(session).Should(Exit(0))
   113  			})
   114  		})
   115  	})
   116  })