-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Security solution][Detection Engine] Fixes "Cannot read property 'kibana_siem_app_url' of null error from actions #75844
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
Merged
FrankHassanabad
merged 2 commits into
elastic:master
from
FrankHassanabad:fix-action-api-breakage
Aug 26, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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
42 changes: 42 additions & 0 deletions
42
...ion/server/lib/detection_engine/scripts/rules/test_cases/queries/action_without_meta.json
This file contains hidden or 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,42 @@ | ||
| { | ||
| "type": "query", | ||
| "index": [ | ||
| "apm-*-transaction*", | ||
| "auditbeat-*", | ||
| "endgame-*", | ||
| "filebeat-*", | ||
| "logs-*", | ||
| "packetbeat-*", | ||
| "winlogbeat-*" | ||
| ], | ||
| "filters": [], | ||
| "language": "kuery", | ||
| "query": "host.name: *", | ||
| "author": [], | ||
| "false_positives": [], | ||
| "references": [], | ||
| "risk_score": 50, | ||
| "risk_score_mapping": [], | ||
| "severity": "low", | ||
| "severity_mapping": [], | ||
| "threat": [], | ||
| "name": "Host Name Test", | ||
| "description": "Host Name Test", | ||
| "tags": [], | ||
| "license": "", | ||
| "interval": "5m", | ||
| "from": "now-30s", | ||
| "to": "now", | ||
| "actions": [ | ||
| { | ||
| "group": "default", | ||
| "id": "4c42ecf2-5e9b-4ce6-8a7a-ab620fd8b169", | ||
| "params": { | ||
| "body": "{}" | ||
| }, | ||
| "action_type_id": ".webhook" | ||
| } | ||
| ], | ||
| "enabled": true, | ||
| "throttle": "rule" | ||
| } |
This file contains hidden or 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 hidden or 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
134 changes: 134 additions & 0 deletions
134
x-pack/test/detection_engine_api_integration/security_and_spaces/tests/add_actions.ts
This file contains hidden or 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,134 @@ | ||
| /* | ||
| * 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 { DETECTION_ENGINE_RULES_URL } from '../../../../plugins/security_solution/common/constants'; | ||
| import { FtrProviderContext } from '../../common/ftr_provider_context'; | ||
| import { | ||
| createSignalsIndex, | ||
| deleteAllAlerts, | ||
| deleteSignalsIndex, | ||
| removeServerGeneratedProperties, | ||
| waitFor, | ||
| getWebHookAction, | ||
| getRuleWithWebHookAction, | ||
| getSimpleRuleOutputWithWebHookAction, | ||
| } from '../../utils'; | ||
| import { CreateRulesSchema } from '../../../../plugins/security_solution/common/detection_engine/schemas/request/create_rules_schema'; | ||
|
|
||
| // eslint-disable-next-line import/no-default-export | ||
| export default ({ getService }: FtrProviderContext) => { | ||
| const supertest = getService('supertest'); | ||
| const es = getService('es'); | ||
|
|
||
| describe('add_actions', () => { | ||
| describe('adding actions', () => { | ||
| beforeEach(async () => { | ||
| await createSignalsIndex(supertest); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await deleteSignalsIndex(supertest); | ||
| await deleteAllAlerts(es); | ||
| }); | ||
|
|
||
| it('should be able to create a new webhook action and attach it to a rule', async () => { | ||
| // create a new action | ||
| const { body: hookAction } = await supertest | ||
| .post('/api/actions/action') | ||
| .set('kbn-xsrf', 'true') | ||
| .send(getWebHookAction()) | ||
| .expect(200); | ||
|
|
||
| // create a rule with the action attached | ||
| const { body } = await supertest | ||
| .post(DETECTION_ENGINE_RULES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(getRuleWithWebHookAction(hookAction.id)) | ||
| .expect(200); | ||
|
|
||
| const bodyToCompare = removeServerGeneratedProperties(body); | ||
| expect(bodyToCompare).to.eql( | ||
| getSimpleRuleOutputWithWebHookAction(`${bodyToCompare?.actions?.[0].id}`) | ||
| ); | ||
| }); | ||
|
|
||
| it('should be able to create a new webhook action and attach it to a rule without a meta field and run it correctly', async () => { | ||
| // create a new action | ||
| const { body: hookAction } = await supertest | ||
| .post('/api/actions/action') | ||
| .set('kbn-xsrf', 'true') | ||
| .send(getWebHookAction()) | ||
| .expect(200); | ||
|
|
||
| // create a rule with the action attached | ||
| const { body: rule } = await supertest | ||
| .post(DETECTION_ENGINE_RULES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(getRuleWithWebHookAction(hookAction.id)) | ||
| .expect(200); | ||
|
|
||
| // wait for Task Manager to execute the rule and its update status | ||
| await waitFor(async () => { | ||
| const { body } = await supertest | ||
| .post(`${DETECTION_ENGINE_RULES_URL}/_find_statuses`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send({ ids: [rule.id] }) | ||
| .expect(200); | ||
| return body[rule.id].current_status?.status === 'succeeded'; | ||
| }); | ||
|
|
||
| // expected result for status should be 'succeeded' | ||
| const { body } = await supertest | ||
| .post(`${DETECTION_ENGINE_RULES_URL}/_find_statuses`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send({ ids: [rule.id] }) | ||
| .expect(200); | ||
| expect(body[rule.id].current_status.status).to.eql('succeeded'); | ||
| }); | ||
|
|
||
| it('should be able to create a new webhook action and attach it to a rule with a meta field and run it correctly', async () => { | ||
| // create a new action | ||
| const { body: hookAction } = await supertest | ||
| .post('/api/actions/action') | ||
| .set('kbn-xsrf', 'true') | ||
| .send(getWebHookAction()) | ||
| .expect(200); | ||
|
|
||
| // create a rule with the action attached and a meta field | ||
| const ruleWithAction: CreateRulesSchema = { | ||
| ...getRuleWithWebHookAction(hookAction.id), | ||
| meta: {}, | ||
| }; | ||
|
|
||
| const { body: rule } = await supertest | ||
| .post(DETECTION_ENGINE_RULES_URL) | ||
| .set('kbn-xsrf', 'true') | ||
| .send(ruleWithAction) | ||
| .expect(200); | ||
|
|
||
| // wait for Task Manager to execute the rule and update status | ||
| await waitFor(async () => { | ||
| const { body } = await supertest | ||
| .post(`${DETECTION_ENGINE_RULES_URL}/_find_statuses`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send({ ids: [rule.id] }) | ||
| .expect(200); | ||
| return body[rule.id].current_status?.status === 'succeeded'; | ||
| }); | ||
|
|
||
| // expected result for status should be 'succeeded' | ||
| const { body } = await supertest | ||
| .post(`${DETECTION_ENGINE_RULES_URL}/_find_statuses`) | ||
| .set('kbn-xsrf', 'true') | ||
| .send({ ids: [rule.id] }) | ||
| .expect(200); | ||
| expect(body[rule.id].current_status.status).to.eql('succeeded'); | ||
| }); | ||
| }); | ||
| }); | ||
| }; |
Oops, something went wrong.
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.
I always go back and forth with the wording - I find myself getting confused sometimes (might just be me). In tests when we say
x is undefinedshould we be explicitly be checking that for example,meta: undefinedor are we testing that the property itself is not there.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.
I guess it's one in the same. 🤯
Uh oh!
There was an error while loading. Please reload this page.
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.
It's technically not the same but we treat it a lot of the times as the same.
For example:
Technically you can see that the key is no longer there compared to if I just set it to undefined.
You can do this too:
And really the key is still there. But for testing and stuff we might not be as strict when we could be. I sometimes try to use delete to be more exact or do a type of omit.
I am lazy and sometimes just use the wording of
undefinedto mean the same thing as for the most part it's treated the same unless/until someone is doing Object.keys() or enumerating against it. We do the same thing a lot of times within TypeScript using something as anundefinedto indicate a value does not exist regardless of if the value was deleted or turned into undefined. So, some small subtle differences.