-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Allow to cancel agent actions (#132168)
- Loading branch information
Showing
11 changed files
with
313 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
x-pack/plugins/fleet/server/services/agents/actions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; | ||
|
||
import { cancelAgentAction } from './actions'; | ||
|
||
describe('Agent actions', () => { | ||
describe('cancelAgentAction', () => { | ||
it('throw if the target action is not found', async () => { | ||
const esClient = elasticsearchServiceMock.createInternalClient(); | ||
esClient.search.mockResolvedValue({ | ||
hits: { | ||
hits: [], | ||
}, | ||
} as any); | ||
await expect(() => cancelAgentAction(esClient, 'i-do-not-exists')).rejects.toThrowError( | ||
/Action not found/ | ||
); | ||
}); | ||
|
||
it('should create one CANCEL action for each action found', async () => { | ||
const esClient = elasticsearchServiceMock.createInternalClient(); | ||
esClient.search.mockResolvedValue({ | ||
hits: { | ||
hits: [ | ||
{ | ||
_source: { | ||
action_id: 'action1', | ||
agents: ['agent1', 'agent2'], | ||
expiration: '2022-05-12T18:16:18.019Z', | ||
}, | ||
}, | ||
{ | ||
_source: { | ||
action_id: 'action1', | ||
agents: ['agent3', 'agent4'], | ||
expiration: '2022-05-12T18:16:18.019Z', | ||
}, | ||
}, | ||
], | ||
}, | ||
} as any); | ||
await cancelAgentAction(esClient, 'action1'); | ||
|
||
expect(esClient.create).toBeCalledTimes(2); | ||
expect(esClient.create).toBeCalledWith( | ||
expect.objectContaining({ | ||
body: expect.objectContaining({ | ||
type: 'CANCEL', | ||
data: { target_id: 'action1' }, | ||
agents: ['agent1', 'agent2'], | ||
}), | ||
}) | ||
); | ||
expect(esClient.create).toBeCalledWith( | ||
expect.objectContaining({ | ||
body: expect.objectContaining({ | ||
type: 'CANCEL', | ||
data: { target_id: 'action1' }, | ||
agents: ['agent3', 'agent4'], | ||
}), | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.