Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: graphql: Minor delete mutation msg fix (#5316) #5564

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 13 additions & 33 deletions ee/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func checkUserCount(t *testing.T, resp []byte, expected int) {
require.Equal(t, expected, len(r.Data.AddUser.User))
}

func deleteUser(t *testing.T, accessToken, username string) {
func deleteUser(t *testing.T, accessToken, username string, confirmDeletion bool) {
// TODO - Verify that only one uid got deleted once numUids are returned as part of the payload.
delUser := `mutation deleteUser($name: String!) {
deleteUser(filter: {name: {eq: $name}}) {
Expand All @@ -110,7 +110,9 @@ func deleteUser(t *testing.T, accessToken, username string) {
},
}
b := makeRequest(t, accessToken, params)
require.JSONEq(t, `{"data":{"deleteUser":{"msg":"Deleted"}}}`, string(b))
if confirmDeletion {
require.JSONEq(t, `{"data":{"deleteUser":{"msg":"Deleted"}}}`, string(b))
}
}

func deleteGroup(t *testing.T, accessToken, name string) {
Expand Down Expand Up @@ -159,19 +161,13 @@ func TestPasswordReturn(t *testing.T) {
}

func TestGetCurrentUser(t *testing.T) {
accessJwt, _, err := testutil.HttpLogin(&testutil.LoginParams{
Endpoint: adminEndpoint,
UserID: "groot",
Passwd: "password",
})
require.NoError(t, err, "login failed")

accessJwt, _ := testutil.GrootHttpLogin(adminEndpoint)
require.Equal(t, string(getCurrentUser(t, accessJwt)),
`{"data":{"getCurrentUser":{"name":"groot"}}}`)

// clean up the user to allow repeated running of this test
userid := "hamilton"
deleteUser(t, accessJwt, userid)
deleteUser(t, accessJwt, userid, false)
glog.Infof("cleaned up db user state")

resp := createUser(t, accessJwt, userid, userpassword)
Expand All @@ -189,42 +185,26 @@ func TestGetCurrentUser(t *testing.T) {
}

func TestCreateAndDeleteUsers(t *testing.T) {
accessJwt, _, err := testutil.HttpLogin(&testutil.LoginParams{
Endpoint: adminEndpoint,
UserID: "groot",
Passwd: "password",
})
require.NoError(t, err, "login failed")

// clean up the user to allow repeated running of this test
deleteUser(t, accessJwt, userid)
glog.Infof("cleaned up db user state")

resp := createUser(t, accessJwt, userid, userpassword)
checkUserCount(t, resp, 1)
resetUser(t)

// adding the user again should fail
resp = createUser(t, accessJwt, userid, userpassword)
accessJwt, _ := testutil.GrootHttpLogin(adminEndpoint)
resp := createUser(t, accessJwt, userid, userpassword)
checkUserCount(t, resp, 0)

// delete the user
deleteUser(t, accessJwt, userid)
deleteUser(t, accessJwt, userid, true)

resp = createUser(t, accessJwt, userid, userpassword)
// now we should be able to create the user again
checkUserCount(t, resp, 1)
}

func resetUser(t *testing.T) {
accessJwt, _, err := testutil.HttpLogin(&testutil.LoginParams{
Endpoint: adminEndpoint,
UserID: "groot",
Passwd: "password",
})
require.NoError(t, err, "login failed")
accessJwt, _ := testutil.GrootHttpLogin(adminEndpoint)

// clean up the user to allow repeated running of this test
deleteUser(t, accessJwt, userid)
deleteUser(t, accessJwt, userid, false)
glog.Infof("deleted user")

resp := createUser(t, accessJwt, userid, userpassword)
Expand Down Expand Up @@ -1564,7 +1544,7 @@ func TestDeleteUserShouldDeleteUserFromGroup(t *testing.T) {
})
require.NoError(t, err, "login failed")

deleteUser(t, accessJwt, userid)
deleteUser(t, accessJwt, userid, true)

gqlQuery := `
query {
Expand Down
Loading