-
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.
[Cases][SecOps] Fix bug where observables are not created (#133752)
* Push observables: * Filter docs without _source (cherry picked from commit 47ffdd8)
- Loading branch information
Showing
4 changed files
with
221 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* 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, loggingSystemMock } from '@kbn/core/server/mocks'; | ||
import { AlertService } from '../../services'; | ||
import { CasesClientArgs } from '../types'; | ||
import { getAlerts } from './get'; | ||
|
||
describe('getAlerts', () => { | ||
const esClient = elasticsearchServiceMock.createElasticsearchClient(); | ||
const logger = loggingSystemMock.create().get('case'); | ||
let alertsService: AlertService; | ||
|
||
beforeEach(async () => { | ||
alertsService = new AlertService(esClient, logger); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const docs = [ | ||
{ | ||
_index: '.internal.alerts-security.alerts-default-000001', | ||
_id: 'c3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f', | ||
_version: 2, | ||
_seq_no: 255, | ||
_primary_term: 1, | ||
found: true, | ||
_source: { | ||
destination: { mac: 'ff:ff:ff:ff:ff:ff' }, | ||
source: { bytes: 444, mac: '11:1f:1e:13:15:14', packets: 6 }, | ||
ecs: { version: '8.0.0' }, | ||
}, | ||
}, | ||
]; | ||
|
||
esClient.mget.mockResolvedValue({ docs }); | ||
|
||
it('returns an empty array if the alert info are empty', async () => { | ||
const clientArgs = { alertsService } as unknown as CasesClientArgs; | ||
const res = await getAlerts([], clientArgs); | ||
|
||
expect(res).toEqual([]); | ||
}); | ||
|
||
it('returns the alerts correctly', async () => { | ||
const clientArgs = { alertsService } as unknown as CasesClientArgs; | ||
const res = await getAlerts( | ||
[ | ||
{ | ||
index: '.internal.alerts-security.alerts-default-000001', | ||
id: 'c3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f', | ||
}, | ||
], | ||
clientArgs | ||
); | ||
|
||
expect(res).toEqual([ | ||
{ | ||
index: '.internal.alerts-security.alerts-default-000001', | ||
id: 'c3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f', | ||
destination: { mac: 'ff:ff:ff:ff:ff:ff' }, | ||
source: { bytes: 444, mac: '11:1f:1e:13:15:14', packets: 6 }, | ||
ecs: { version: '8.0.0' }, | ||
}, | ||
]); | ||
}); | ||
|
||
it('filters mget errors correctly', async () => { | ||
esClient.mget.mockResolvedValue({ | ||
docs: [ | ||
...docs, | ||
{ | ||
error: { type: 'not-found', reason: 'an error' }, | ||
_index: '.internal.alerts-security.alerts-default-000002', | ||
_id: 'd3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f', | ||
}, | ||
], | ||
}); | ||
const clientArgs = { alertsService } as unknown as CasesClientArgs; | ||
|
||
const res = await getAlerts( | ||
[ | ||
{ | ||
index: '.internal.alerts-security.alerts-default-000001', | ||
id: 'c3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f', | ||
}, | ||
], | ||
clientArgs | ||
); | ||
|
||
expect(res).toEqual([ | ||
{ | ||
index: '.internal.alerts-security.alerts-default-000001', | ||
id: 'c3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f', | ||
destination: { mac: 'ff:ff:ff:ff:ff:ff' }, | ||
source: { bytes: 444, mac: '11:1f:1e:13:15:14', packets: 6 }, | ||
ecs: { version: '8.0.0' }, | ||
}, | ||
]); | ||
}); | ||
|
||
it('filters docs without _source correctly', async () => { | ||
esClient.mget.mockResolvedValue({ | ||
docs: [ | ||
...docs, | ||
{ | ||
_index: '.internal.alerts-security.alerts-default-000002', | ||
_id: 'd3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f', | ||
found: true, | ||
}, | ||
], | ||
}); | ||
const clientArgs = { alertsService } as unknown as CasesClientArgs; | ||
|
||
const res = await getAlerts( | ||
[ | ||
{ | ||
index: '.internal.alerts-security.alerts-default-000001', | ||
id: 'c3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f', | ||
}, | ||
], | ||
clientArgs | ||
); | ||
|
||
expect(res).toEqual([ | ||
{ | ||
index: '.internal.alerts-security.alerts-default-000001', | ||
id: 'c3869d546717e8c581add9cbf7d24578f34cd3e72cbc8d8b8e9a9330a899f70f', | ||
destination: { mac: 'ff:ff:ff:ff:ff:ff' }, | ||
source: { bytes: 444, mac: '11:1f:1e:13:15:14', packets: 6 }, | ||
ecs: { version: '8.0.0' }, | ||
}, | ||
]); | ||
}); | ||
}); |
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