Hotfix: add empty host slice validation in ListHosts (#13483)

This commit is contained in:
Tim Lee 2023-08-23 13:57:18 -06:00 committed by GitHub
parent 699701a2db
commit 29e48f402a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -748,6 +748,10 @@ func (ds *Datastore) CleanupPolicyMembership(ctx context.Context, now time.Time)
}
func (ds *Datastore) UpdatePolicyFailureCountsForHosts(ctx context.Context, hosts []*fleet.Host) ([]*fleet.Host, error) {
if len(hosts) == 0 {
return hosts, nil
}
// Get policy failure counts for each host
hostIDs := make([]uint, 0, len(hosts))

View file

@ -2271,4 +2271,9 @@ func testUpdatePolicyFailureCountsForHosts(t *testing.T, ds *Datastore) {
// host 3 doesn't have any policy membership
assert.Equal(t, 0, hostsUpdated[3].TotalIssuesCount)
assert.Equal(t, 0, hostsUpdated[3].FailingPoliciesCount)
// return empty list if no hosts are passed
hostsUpdated, err = ds.UpdatePolicyFailureCountsForHosts(ctx, []*fleet.Host{})
require.NoError(t, err)
require.Len(t, hostsUpdated, 0)
}