[Fleet] Return empty agents list when submitting a kuery with no keys (#93844)
This commit is contained in:
parent
3992ed13db
commit
5d119cfcbb
|
@ -76,29 +76,42 @@ export async function listAgents(
|
|||
if (showInactive === false) {
|
||||
filters.push(ACTIVE_AGENT_CONDITION);
|
||||
}
|
||||
let { saved_objects: agentSOs, total } = await soClient.find<AgentSOAttributes>({
|
||||
type: AGENT_SAVED_OBJECT_TYPE,
|
||||
filter: _joinFilters(filters) || '',
|
||||
sortField,
|
||||
sortOrder,
|
||||
page,
|
||||
perPage,
|
||||
});
|
||||
// filtering for a range on the version string will not work,
|
||||
// nor does filtering on a flattened field (local_metadata), so filter here
|
||||
if (showUpgradeable) {
|
||||
agentSOs = agentSOs.filter((agent) =>
|
||||
isAgentUpgradeable(savedObjectToAgent(agent), appContextService.getKibanaVersion())
|
||||
);
|
||||
total = agentSOs.length;
|
||||
}
|
||||
try {
|
||||
let { saved_objects: agentSOs, total } = await soClient.find<AgentSOAttributes>({
|
||||
type: AGENT_SAVED_OBJECT_TYPE,
|
||||
filter: _joinFilters(filters) || '',
|
||||
sortField,
|
||||
sortOrder,
|
||||
page,
|
||||
perPage,
|
||||
});
|
||||
// filtering for a range on the version string will not work,
|
||||
// nor does filtering on a flattened field (local_metadata), so filter here
|
||||
if (showUpgradeable) {
|
||||
agentSOs = agentSOs.filter((agent) =>
|
||||
isAgentUpgradeable(savedObjectToAgent(agent), appContextService.getKibanaVersion())
|
||||
);
|
||||
total = agentSOs.length;
|
||||
}
|
||||
|
||||
return {
|
||||
agents: agentSOs.map(savedObjectToAgent),
|
||||
total,
|
||||
page,
|
||||
perPage,
|
||||
};
|
||||
return {
|
||||
agents: agentSOs.map(savedObjectToAgent),
|
||||
total,
|
||||
page,
|
||||
perPage,
|
||||
};
|
||||
} catch (e) {
|
||||
if (e.output?.payload?.message?.startsWith('The key is empty')) {
|
||||
return {
|
||||
agents: [],
|
||||
total: 0,
|
||||
page: 0,
|
||||
perPage: 0,
|
||||
};
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function listAllAgents(
|
||||
|
|
|
@ -102,6 +102,14 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
it('should return a 400 when given an invalid "kuery" value', async () => {
|
||||
await supertest.get(`/api/fleet/agents?kuery=.test%3A`).expect(400);
|
||||
});
|
||||
|
||||
it('should return a 200 and an empty list when given a "kuery" value with a missing saved object type', async () => {
|
||||
const { body: apiResponse } = await supertest
|
||||
.get(`/api/fleet/agents?kuery=m`) // missing saved object type
|
||||
.expect(200);
|
||||
expect(apiResponse.total).to.eql(0);
|
||||
});
|
||||
|
||||
it('should accept a valid "kuery" value', async () => {
|
||||
const filter = encodeURIComponent('fleet-agents.access_api_key_id : "api-key-2"');
|
||||
const { body: apiResponse } = await supertest
|
||||
|
|
Loading…
Reference in a new issue