Skip to content
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
1 change: 1 addition & 0 deletions api/types/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func (u *UserV2) SetStaticLabels(sl map[string]string) {
// match against the list of search values.
func (u *UserV2) MatchSearch(values []string) bool {
fieldVals := append(utils.MapToStrings(u.Metadata.Labels), u.GetName())
fieldVals = append(fieldVals, u.GetRoles()...)
return MatchSearch(fieldVals, values, nil)
}

Expand Down
19 changes: 19 additions & 0 deletions lib/auth/users/usersv1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,19 @@ func TestListUsers(t *testing.T) {

ctx := context.Background()

// Create a role to assign to users for search testing.
accessSvc := env.backend.(interface {
UpsertRole(context.Context, types.Role) (types.Role, error)
})
role, err := types.NewRole("test-role", types.RoleSpecV6{})
require.NoError(t, err, "creating role")
_, err = accessSvc.UpsertRole(ctx, role)
require.NoError(t, err, "upserting role")

llama, err := types.NewUser("llama")
require.NoError(t, err, "creating new user llama")
require.NoError(t, generateUserSecrets(llama), "generating user secrets")
llama.SetRoles([]string{"test-role"})

// Validate that the user does not exist.
resp, err := env.ListUsers(ctx, &userspb.ListUsersRequest{PageSize: 10})
Expand Down Expand Up @@ -494,6 +504,15 @@ func TestListUsers(t *testing.T) {
assert.Empty(t, cmp.Diff(created.User, resp.Users[0], cmpopts.IgnoreFields(types.Metadata{}, "Revision")))
assert.Empty(t, cmp.Diff(llama.GetLocalAuth(), resp.Users[0].GetLocalAuth()), "user secrets do not match")

// Validate that searching by role returns matching users.
resp, err = env.ListUsers(ctx, &userspb.ListUsersRequest{
PageSize: 10,
Filter: &types.UserFilter{SearchKeywords: []string{"test-role"}},
})
require.NoError(t, err, "listing users with role filter")
require.Len(t, resp.Users, 1, "expected one user with test-role")
assert.Equal(t, "llama", resp.Users[0].GetName(), "expected llama to match role search")

// Create addition users to test pagination
createdUsers := []*types.UserV2{llama.(*types.UserV2)}
for i := 0; i < 22; i++ {
Expand Down
Loading