github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/isolated/delete_user_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     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("delete-user command", func() {
    15  	Context("when the logged in user is authorized to delete-users", func() {
    16  		BeforeEach(func() {
    17  			helpers.LoginCF()
    18  		})
    19  
    20  		Context("when deleting a user that exists in multiple origins", func() {
    21  			var newUser string
    22  
    23  			BeforeEach(func() {
    24  				newUser = helpers.RandomUsername()
    25  				session := helpers.CF("create-user", newUser, "--origin", "ldap")
    26  				Eventually(session).Should(Exit(0))
    27  				session = helpers.CF("create-user", newUser, helpers.RandomPassword())
    28  				Eventually(session).Should(Exit(0))
    29  			})
    30  
    31  			AfterEach(func() {
    32  				// Doing the cleanup here because it can't easily be done in
    33  				// bin/cleanup-integration.
    34  				session := helpers.CF("curl", "/v2/users")
    35  				Eventually(session).Should(Exit(0))
    36  
    37  				var usersResponse struct {
    38  					Resources []struct {
    39  						Metadata struct {
    40  							GUID string `json:"guid"`
    41  						} `json:"metadata"`
    42  						Entity struct {
    43  							UserName string `json:"username"`
    44  						} `json:"entity"`
    45  					} `json:"resources"`
    46  				}
    47  
    48  				err := json.Unmarshal(session.Out.Contents(), &usersResponse)
    49  				Expect(err).NotTo(HaveOccurred())
    50  
    51  				for _, user := range usersResponse.Resources {
    52  					if user.Entity.UserName == newUser {
    53  						session = helpers.CF("curl", "-X", "DELETE", fmt.Sprintf("/v2/users/%s", user.Metadata.GUID))
    54  						Eventually(session).Should(Exit(0))
    55  					}
    56  				}
    57  			})
    58  
    59  			It("errors with DuplicateUsernameError", func() {
    60  				session := helpers.CF("delete-user", "-f", newUser)
    61  				Eventually(session.Out).Should(Say("FAILED"))
    62  				Eventually(session.Out).Should(Say("Error deleting user %s.", newUser))
    63  				Eventually(session.Out).Should(Say("Multiple users with that username returned. Please use 'cf curl' with specific origin instead."))
    64  				Eventually(session).Should(Exit(1))
    65  			})
    66  		})
    67  	})
    68  })