-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution] Adding tests for endpoint package pipelines #73703
Changes from 1 commit
7acb331
f615531
b05e540
0390de9
0ba6021
ede1cab
05aa3f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
package_paths: | ||
- /packages/production | ||
- /packages/staging | ||
- /packages/snapshot |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import expect from '@kbn/expect'; | ||
import { SearchResponse } from 'elasticsearch'; | ||
import { eventsIndexPattern } from '../../../plugins/security_solution/common/endpoint/constants'; | ||
import { | ||
EndpointDocGenerator, | ||
Event, | ||
} from '../../../plugins/security_solution/common/endpoint/generate_data'; | ||
import { FtrProviderContext } from '../ftr_provider_context'; | ||
import { InsertedEvents, processEventsIndex } from '../services/resolver'; | ||
|
||
interface EventIngested { | ||
event: { | ||
ingested: number; | ||
}; | ||
} | ||
|
||
interface NetworkEvent { | ||
source: { | ||
geo?: { | ||
country_name: string; | ||
}; | ||
}; | ||
destination: { | ||
geo?: { | ||
country_name: string; | ||
}; | ||
}; | ||
} | ||
|
||
const networkIndex = 'logs-endpoint.events.network-default'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const resolver = getService('resolverGenerator'); | ||
const es = getService('es'); | ||
const generator = new EndpointDocGenerator('data'); | ||
|
||
const searchForID = async <T>(id: string) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❔ Are you marking this async just so you know it returns a Promise? I don't see it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I think it's discouraged to do
|
||
return es.search<SearchResponse<T>>({ | ||
index: eventsIndexPattern, | ||
body: { | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ | ||
ids: { | ||
values: id, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
describe('Endpoint package', () => { | ||
describe('ingested processor', () => { | ||
let event: Event; | ||
let genData: InsertedEvents; | ||
|
||
before(async () => { | ||
event = generator.generateEvent(); | ||
genData = await resolver.insertEvents([event]); | ||
}); | ||
|
||
after(async () => { | ||
await resolver.deleteData(genData); | ||
}); | ||
|
||
it('sets the event.ingested field', async () => { | ||
const resp = await searchForID<EventIngested>(genData.eventsInfo[0]._id); | ||
expect(resp.body.hits.hits[0]._source.event.ingested).to.not.be(undefined); | ||
}); | ||
}); | ||
|
||
describe('geoip processor', () => { | ||
let processIndexData: InsertedEvents; | ||
let networkIndexData: InsertedEvents; | ||
|
||
before(async () => { | ||
// 46.239.193.5 should be in Iceland | ||
// 8.8.8.8 should be in the US | ||
const eventWithBothIPs = generator.generateEvent({ | ||
extensions: { source: { ip: '8.8.8.8' }, destination: { ip: '46.239.193.5' } }, | ||
}); | ||
|
||
const eventWithSourceOnly = generator.generateEvent({ | ||
extensions: { source: { ip: '8.8.8.8' } }, | ||
}); | ||
networkIndexData = await resolver.insertEvents( | ||
[eventWithBothIPs, eventWithSourceOnly], | ||
networkIndex | ||
); | ||
|
||
processIndexData = await resolver.insertEvents([eventWithBothIPs], processEventsIndex); | ||
}); | ||
|
||
after(async () => { | ||
await resolver.deleteData(networkIndexData); | ||
await resolver.deleteData(processIndexData); | ||
}); | ||
|
||
it('sets the geoip fields', async () => { | ||
const eventWithBothIPs = await searchForID<NetworkEvent>( | ||
networkIndexData.eventsInfo[0]._id | ||
); | ||
expect(eventWithBothIPs.body.hits.hits[0]._source.source.geo?.country_name).to.be( | ||
'United States' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❔ These always going to be in English, regardless of what locale it's running under? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah good point. I don't think they'd change much but for some reason the |
||
); | ||
expect(eventWithBothIPs.body.hits.hits[0]._source.destination.geo?.country_name).to.be( | ||
'Iceland' | ||
); | ||
|
||
const eventWithSourceOnly = await searchForID<NetworkEvent>( | ||
networkIndexData.eventsInfo[1]._id | ||
); | ||
expect(eventWithBothIPs.body.hits.hits[0]._source.source.geo?.country_name).to.be( | ||
'United States' | ||
); | ||
expect(eventWithSourceOnly.body.hits.hits[0]._source.destination?.geo).to.be(undefined); | ||
}); | ||
|
||
it('does not set geoip fields for events in indices other than the network index', async () => { | ||
const eventWithBothIPs = await searchForID<NetworkEvent>( | ||
processIndexData.eventsInfo[0]._id | ||
); | ||
expect(eventWithBothIPs.body.hits.hits[0]._source.source.geo).to.be(undefined); | ||
expect(eventWithBothIPs.body.hits.hits[0]._source.destination.geo).to.be(undefined); | ||
}); | ||
}); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import expect from '@kbn/expect'; | ||
import { SearchResponse } from 'elasticsearch'; | ||
import { eventsIndexPattern } from '../../../../plugins/security_solution/common/endpoint/constants'; | ||
import { | ||
ResolverTree, | ||
|
@@ -20,7 +19,6 @@ import { InsertedEvents } from '../../services/resolver'; | |
export default function resolverAPIIntegrationTests({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
const resolver = getService('resolverGenerator'); | ||
const es = getService('es'); | ||
const generator = new EndpointDocGenerator('resolver'); | ||
|
||
describe('Resolver handling of entity ids', () => { | ||
|
@@ -38,26 +36,10 @@ export default function resolverAPIIntegrationTests({ getService }: FtrProviderC | |
}); | ||
|
||
it('excludes events that have an empty entity_id field', async () => { | ||
// first lets get the _id of the document using the parent.process.entity_id | ||
// then we'll use the API to search for that specific document | ||
const res = await es.search<SearchResponse<Event>>({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clean up based on Rob's previous comments. The |
||
index: genData.indices[0], | ||
body: { | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ | ||
term: { 'process.parent.entity_id': origin.process.parent!.entity_id }, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}); | ||
const { body }: { body: ResolverEntityIndex } = await supertest.get( | ||
// using the same indices value here twice to force the query parameter to be an array | ||
// for some reason using supertest's query() function doesn't construct a parsable array | ||
`/api/endpoint/resolver/entity?_id=${res.body.hits.hits[0]._id}&indices=${eventsIndexPattern}&indices=${eventsIndexPattern}` | ||
`/api/endpoint/resolver/entity?_id=${genData.eventsInfo[0]._id}&indices=${eventsIndexPattern}&indices=${eventsIndexPattern}` | ||
); | ||
expect(body).to.be.empty(); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package is currently in the staging environment which is why we need this. I added the snapshot just in case we ever need to grab one from there.