From 4e560fd332fed28b730138e0242270cf5794f734 Mon Sep 17 00:00:00 2001 From: Marco Dinis Date: Thu, 24 Oct 2024 11:57:08 +0100 Subject: [PATCH] Improve message when sortBy field is missing in ListUnifiedResources (#47788) --- lib/auth/auth_with_roles_test.go | 8 ++++++++ lib/services/unified_resource.go | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/auth/auth_with_roles_test.go b/lib/auth/auth_with_roles_test.go index 06fcd9e849a09..a040e444083da 100644 --- a/lib/auth/auth_with_roles_test.go +++ b/lib/auth/auth_with_roles_test.go @@ -5351,6 +5351,14 @@ func TestListUnifiedResources_KindsFilter(t *testing.T) { r := resource.GetDatabaseServer() require.Equal(t, types.KindDatabaseServer, r.GetKind()) } + + // Check for invalid sort error message + _, err = clt.ListUnifiedResources(ctx, &proto.ListUnifiedResourcesRequest{ + Kinds: []string{types.KindDatabase}, + Limit: 5, + SortBy: types.SortBy{}, + }) + require.ErrorContains(t, err, "sort field is required") } func TestListUnifiedResources_WithPinnedResources(t *testing.T) { diff --git a/lib/services/unified_resource.go b/lib/services/unified_resource.go index 27975e6fd753a..7c06471b9d3a6 100644 --- a/lib/services/unified_resource.go +++ b/lib/services/unified_resource.go @@ -194,8 +194,10 @@ func (c *UnifiedResourceCache) getSortTree(sortField string) (*btree.BTreeG[*ite return c.nameTree, nil case sortByKind: return c.typeTree, nil + case "": + return nil, trace.BadParameter("sort field is required") default: - return nil, trace.NotImplemented("sorting by %v is not supporting in unified resources", sortField) + return nil, trace.NotImplemented("sorting by %v is not supported in unified resources", sortField) } }