forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix a bug where we were not waiting for updates to complete when usin… #3
Merged
semd
merged 1 commit into
semd:tgrid-bulk-actions-rbac-update
from
dhurley14:bulk_update_sec_sol_integration_test
Aug 13, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
164 changes: 164 additions & 0 deletions
164
x-pack/test/detection_engine_api_integration/basic/tests/update_rac_alerts.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,164 @@ | ||
/* | ||
* 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 expect from '@kbn/expect'; | ||
|
||
import type { estypes } from '@elastic/elasticsearch'; | ||
import { Signal } from '../../../../plugins/security_solution/server/lib/detection_engine/signals/types'; | ||
import { | ||
RAC_ALERTS_BULK_UPDATE_URL, | ||
DETECTION_ENGINE_QUERY_SIGNALS_URL, | ||
} from '../../../../plugins/security_solution/common/constants'; | ||
import { FtrProviderContext } from '../../common/ftr_provider_context'; | ||
import { | ||
createSignalsIndex, | ||
deleteSignalsIndex, | ||
getSignalStatusEmptyResponse, | ||
getQuerySignalIds, | ||
deleteAllAlerts, | ||
createRule, | ||
waitForSignalsToBePresent, | ||
getSignalsByIds, | ||
waitForRuleSuccessOrStatus, | ||
getRuleForSignalTesting, | ||
} from '../../utils'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext) => { | ||
const supertest = getService('supertest'); | ||
const esArchiver = getService('esArchiver'); | ||
|
||
describe('open_close_signals', () => { | ||
describe('validation checks', () => { | ||
it.skip('should not give errors when querying and the signals index does not exist yet', async () => { | ||
const { body } = await supertest | ||
.post(RAC_ALERTS_BULK_UPDATE_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send({ ids: ['123'], status: 'open', index: '.siem-signals-default' }); | ||
// .expect(200); | ||
// console.error('BODY', JSON.stringify(body, null, 2)); | ||
|
||
// remove any server generated items that are indeterministic | ||
delete body.took; | ||
|
||
expect(body).to.eql(getSignalStatusEmptyResponse()); | ||
}); | ||
|
||
it('should not give errors when querying and the signals index does exist and is empty', async () => { | ||
await createSignalsIndex(supertest); | ||
const { body } = await supertest | ||
.post(RAC_ALERTS_BULK_UPDATE_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send({ ids: ['123'], status: 'open', index: '.siem-signals-default' }) | ||
.expect(200); | ||
|
||
// remove any server generated items that are indeterministic | ||
// delete body.took; | ||
|
||
// expect(body).to.eql(getSignalStatusEmptyResponse()); | ||
|
||
// await deleteSignalsIndex(supertest); | ||
}); | ||
}); | ||
|
||
describe('tests with auditbeat data', () => { | ||
before(async () => { | ||
await esArchiver.load('x-pack/test/functional/es_archives/auditbeat/hosts'); | ||
}); | ||
after(async () => { | ||
await esArchiver.unload('x-pack/test/functional/es_archives/auditbeat/hosts'); | ||
}); | ||
beforeEach(async () => { | ||
await deleteAllAlerts(supertest); | ||
await createSignalsIndex(supertest); | ||
}); | ||
afterEach(async () => { | ||
await deleteSignalsIndex(supertest); | ||
await deleteAllAlerts(supertest); | ||
}); | ||
|
||
it('should be able to execute and get 10 signals', async () => { | ||
const rule = getRuleForSignalTesting(['auditbeat-*']); | ||
const { id } = await createRule(supertest, rule); | ||
await waitForRuleSuccessOrStatus(supertest, id); | ||
await waitForSignalsToBePresent(supertest, 10, [id]); | ||
const signalsOpen = await getSignalsByIds(supertest, [id]); | ||
expect(signalsOpen.hits.hits.length).equal(10); | ||
}); | ||
|
||
it('should be have set the signals in an open state initially', async () => { | ||
const rule = getRuleForSignalTesting(['auditbeat-*']); | ||
const { id } = await createRule(supertest, rule); | ||
await waitForRuleSuccessOrStatus(supertest, id); | ||
await waitForSignalsToBePresent(supertest, 10, [id]); | ||
const signalsOpen = await getSignalsByIds(supertest, [id]); | ||
const everySignalOpen = signalsOpen.hits.hits.every( | ||
(hit) => hit._source?.signal?.status === 'open' | ||
); | ||
expect(everySignalOpen).to.eql(true); | ||
}); | ||
|
||
it('should be able to get a count of 10 closed signals when closing 10', async () => { | ||
const rule = getRuleForSignalTesting(['auditbeat-*']); | ||
const { id } = await createRule(supertest, rule); | ||
await waitForRuleSuccessOrStatus(supertest, id); | ||
await waitForSignalsToBePresent(supertest, 10, [id]); | ||
const signalsOpen = await getSignalsByIds(supertest, [id]); | ||
const signalIds = signalsOpen.hits.hits.map((signal) => signal._id); | ||
|
||
// set all of the signals to the state of closed. There is no reason to use a waitUntil here | ||
// as this route intentionally has a waitFor within it and should only return when the query has | ||
// the data. | ||
await supertest | ||
.post(RAC_ALERTS_BULK_UPDATE_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send({ ids: signalIds, status: 'closed', index: '.siem-signals-default' }) | ||
.expect(200); | ||
|
||
const { | ||
body: signalsClosed, | ||
}: { body: estypes.SearchResponse<{ signal: Signal }> } = await supertest | ||
.post(DETECTION_ENGINE_QUERY_SIGNALS_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getQuerySignalIds(signalIds)) | ||
.expect(200); | ||
expect(signalsClosed.hits.hits.length).to.equal(10); | ||
}); | ||
|
||
it('should be able close 10 signals immediately and they all should be closed', async () => { | ||
const rule = getRuleForSignalTesting(['auditbeat-*']); | ||
const { id } = await createRule(supertest, rule); | ||
await waitForRuleSuccessOrStatus(supertest, id); | ||
await waitForSignalsToBePresent(supertest, 10, [id]); | ||
const signalsOpen = await getSignalsByIds(supertest, [id]); | ||
const signalIds = signalsOpen.hits.hits.map((signal) => signal._id); | ||
|
||
// set all of the signals to the state of closed. There is no reason to use a waitUntil here | ||
// as this route intentionally has a waitFor within it and should only return when the query has | ||
// the data. | ||
await supertest | ||
.post(RAC_ALERTS_BULK_UPDATE_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send({ ids: signalIds, status: 'closed', index: '.siem-signals-default' }) | ||
.expect(200); | ||
|
||
const { | ||
body: signalsClosed, | ||
}: { body: estypes.SearchResponse<{ signal: Signal }> } = await supertest | ||
.post(DETECTION_ENGINE_QUERY_SIGNALS_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getQuerySignalIds(signalIds)) | ||
.expect(200); | ||
|
||
const everySignalClosed = signalsClosed.hits.hits.every( | ||
(hit) => hit._source?.signal?.status === 'closed' | ||
); | ||
expect(everySignalClosed).to.eql(true); | ||
}); | ||
}); | ||
}); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you might want to use this in place of this const here:
https://github.com/elastic/kibana/pull/108092/files#diff-72432ac56ed999450944dac918fcfc78995c78218ccdb5a8d5532eff769f63c6R14