[Fleet] Fix invalid permission entry if the elastic agent package is not installed (#125447) (#125529)

(cherry picked from commit d383bda82e)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
This commit is contained in:
Kibana Machine 2022-02-14 12:43:35 -05:00 committed by GitHub
parent c975b6d7fd
commit 34348522ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View file

@ -43,6 +43,15 @@ describe('getMonitoringPermissions', () => {
);
expect(permissions).toMatchSnapshot();
});
it('should an empty valid permission entry if neither metrics and logs are enabled', async () => {
const permissions = await getMonitoringPermissions(
savedObjectsClientMock.create(),
{ logs: false, metrics: false },
'testnamespace123'
);
expect(permissions).toEqual({ _elastic_agent_monitoring: { indices: [] } });
});
});
describe('With elastic agent package installed', () => {

View file

@ -30,6 +30,14 @@ function buildDefault(enabled: { logs: boolean; metrics: boolean }, namespace: s
);
}
if (names.length === 0) {
return {
_elastic_agent_monitoring: {
indices: [],
},
};
}
return {
_elastic_agent_monitoring: {
indices: [