Skip to content

Commit

Permalink
Merge pull request #17906 from influxdata/bb/update-user-index
Browse files Browse the repository at this point in the history
fix(kv): Ensure UpdateUser cleans up the index when updating names
  • Loading branch information
brettbuddin authored Apr 29, 2020
2 parents 446563c + 19e9162 commit 8f9311d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Bug Fixes

1. [17906](https://github.com/influxdata/influxdb/pull/17906): Ensure UpdateUser cleans up the index when updating names

### UI Improvements

1. [17860](https://github.com/influxdata/influxdb/pull/17860): Allow bucket creation from the Data Explorer and Cell Editor
Expand Down
2 changes: 1 addition & 1 deletion kv/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (s *Service) updateUser(ctx context.Context, tx Tx, id influxdb.ID, upd inf
}

if upd.Name != nil {
if err := s.removeUserFromIndex(ctx, tx, id, *upd.Name); err != nil {
if err := s.removeUserFromIndex(ctx, tx, id, u.Name); err != nil {
return nil, err
}

Expand Down
54 changes: 54 additions & 0 deletions testing/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func UserService(
name: "UpdateUser",
fn: UpdateUser,
},
{
name: "UpdateUser_IndexHygiene",
fn: UpdateUser_IndexHygiene,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -977,3 +981,53 @@ func UpdateUser(
})
}
}

func UpdateUser_IndexHygiene(
init func(UserFields, *testing.T) (platform.UserService, string, func()),
t *testing.T,
) {

oldUserName := "user1"
users := UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: oldUserName,
Status: "active",
},
},
}
s, _, done := init(users, t)
defer done()

newUserName := "user1Updated"
upd := platform.UserUpdate{
Name: &newUserName,
}

ctx := context.Background()
_, err := s.UpdateUser(ctx, MustIDBase16(userOneID), upd)
if err != nil {
t.Error(err)
}

// Ensure we can find the user with the new name.
_, nerr := s.FindUser(ctx, platform.UserFilter{
Name: &newUserName,
})
if nerr != nil {
t.Error("unexpected error when finding user by name", nerr)
}

// Ensure we cannot find a user with the old name. The index used when
// searching by name should have been cleared out by the UpdateUser
// operation.
_, oerr := s.FindUser(ctx, platform.UserFilter{
Name: &oldUserName,
})
ErrorsEqual(t, oerr, &platform.Error{
Code: platform.ENotFound,
Op: platform.OpFindUser,
Msg: "user not found",
})
}

0 comments on commit 8f9311d

Please sign in to comment.