-
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.
Merge remote-tracking branch 'upstream/master' into switch-to-core-ap…
…plication-service
- Loading branch information
Showing
41 changed files
with
3,159 additions
and
46 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
14 changes: 14 additions & 0 deletions
14
x-pack/test/detection_engine_api_integration/basic/config.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,14 @@ | ||
/* | ||
* 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 { createTestConfig } from '../common/config'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default createTestConfig('basic', { | ||
disabledPlugins: [], | ||
license: 'basic', | ||
ssl: true, | ||
}); |
92 changes: 92 additions & 0 deletions
92
x-pack/test/detection_engine_api_integration/basic/tests/add_prepackaged_rules.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,92 @@ | ||
/* | ||
* 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_PREPACKAGED_URL } from '../../../../plugins/siem/common/constants'; | ||
import { FtrProviderContext } from '../../common/ftr_provider_context'; | ||
import { createSignalsIndex, deleteAllAlerts, deleteSignalsIndex } from '../../utils'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext): void => { | ||
const supertest = getService('supertest'); | ||
const es = getService('legacyEs'); | ||
|
||
describe('add_prepackaged_rules', () => { | ||
describe('validation errors', () => { | ||
it('should give an error that the index must exist first if it does not exist before adding prepackaged rules', async () => { | ||
const { body } = await supertest | ||
.put(DETECTION_ENGINE_PREPACKAGED_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(400); | ||
|
||
expect(body).to.eql({ | ||
message: | ||
'Pre-packaged rules cannot be installed until the signals index is created: .siem-signals-default', | ||
status_code: 400, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('creating prepackaged rules', () => { | ||
beforeEach(async () => { | ||
await createSignalsIndex(supertest); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteSignalsIndex(supertest); | ||
await deleteAllAlerts(es); | ||
}); | ||
|
||
it('should contain two output keys of rules_installed and rules_updated', async () => { | ||
const { body } = await supertest | ||
.put(DETECTION_ENGINE_PREPACKAGED_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
expect(Object.keys(body)).to.eql(['rules_installed', 'rules_updated']); | ||
}); | ||
|
||
it('should create the prepackaged rules and return a count greater than zero', async () => { | ||
const { body } = await supertest | ||
.put(DETECTION_ENGINE_PREPACKAGED_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
expect(body.rules_installed).to.be.greaterThan(0); | ||
}); | ||
|
||
it('should create the prepackaged rules that the rules_updated is of size zero', async () => { | ||
const { body } = await supertest | ||
.put(DETECTION_ENGINE_PREPACKAGED_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
expect(body.rules_updated).to.eql(0); | ||
}); | ||
|
||
it('should be possible to call the API twice and the second time the number of rules installed should be zero', async () => { | ||
await supertest | ||
.put(DETECTION_ENGINE_PREPACKAGED_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
const { body } = await supertest | ||
.put(DETECTION_ENGINE_PREPACKAGED_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send() | ||
.expect(200); | ||
|
||
expect(body.rules_installed).to.eql(0); | ||
}); | ||
}); | ||
}); | ||
}; |
126 changes: 126 additions & 0 deletions
126
x-pack/test/detection_engine_api_integration/basic/tests/create_rules.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,126 @@ | ||
/* | ||
* 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/siem/common/constants'; | ||
import { FtrProviderContext } from '../../common/ftr_provider_context'; | ||
import { | ||
createSignalsIndex, | ||
deleteAllAlerts, | ||
deleteSignalsIndex, | ||
getSimpleRule, | ||
getSimpleRuleOutput, | ||
getSimpleRuleOutputWithoutRuleId, | ||
getSimpleRuleWithoutRuleId, | ||
removeServerGeneratedProperties, | ||
removeServerGeneratedPropertiesIncludingRuleId, | ||
getSimpleMlRule, | ||
} from '../../utils'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext) => { | ||
const supertest = getService('supertest'); | ||
const es = getService('legacyEs'); | ||
|
||
describe('create_rules', () => { | ||
describe('validation errors', () => { | ||
it('should give an error that the index must exist first if it does not exist before creating a rule', async () => { | ||
const { body } = await supertest | ||
.post(DETECTION_ENGINE_RULES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getSimpleRule()) | ||
.expect(400); | ||
|
||
expect(body).to.eql({ | ||
message: | ||
'To create a rule, the index must exist first. Index .siem-signals-default does not exist', | ||
status_code: 400, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('creating rules', () => { | ||
beforeEach(async () => { | ||
await createSignalsIndex(supertest); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteSignalsIndex(supertest); | ||
await deleteAllAlerts(es); | ||
}); | ||
|
||
it('should create a single rule with a rule_id', async () => { | ||
const { body } = await supertest | ||
.post(DETECTION_ENGINE_RULES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getSimpleRule()) | ||
.expect(200); | ||
|
||
const bodyToCompare = removeServerGeneratedProperties(body); | ||
expect(bodyToCompare).to.eql(getSimpleRuleOutput()); | ||
}); | ||
|
||
it('should create a single rule without an input index', async () => { | ||
const { index, ...payload } = getSimpleRule(); | ||
const { index: _index, ...expected } = getSimpleRuleOutput(); | ||
|
||
const { body } = await supertest | ||
.post(DETECTION_ENGINE_RULES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(payload) | ||
.expect(200); | ||
|
||
const bodyToCompare = removeServerGeneratedProperties(body); | ||
expect(bodyToCompare).to.eql(expected); | ||
}); | ||
|
||
it('should create a single rule without a rule_id', async () => { | ||
const { body } = await supertest | ||
.post(DETECTION_ENGINE_RULES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getSimpleRuleWithoutRuleId()) | ||
.expect(200); | ||
|
||
const bodyToCompare = removeServerGeneratedPropertiesIncludingRuleId(body); | ||
expect(bodyToCompare).to.eql(getSimpleRuleOutputWithoutRuleId()); | ||
}); | ||
|
||
it('should give a 403 when trying to create a single Machine Learning rule since the license is basic', async () => { | ||
const { body } = await supertest | ||
.post(DETECTION_ENGINE_RULES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getSimpleMlRule()) | ||
.expect(403); | ||
|
||
const bodyToCompare = removeServerGeneratedProperties(body); | ||
expect(bodyToCompare).to.eql({ | ||
message: 'Your license does not support machine learning. Please upgrade your license.', | ||
status_code: 403, | ||
}); | ||
}); | ||
|
||
it('should cause a 409 conflict if we attempt to create the same rule_id twice', async () => { | ||
await supertest | ||
.post(DETECTION_ENGINE_RULES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getSimpleRule()) | ||
.expect(200); | ||
|
||
const { body } = await supertest | ||
.post(DETECTION_ENGINE_RULES_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getSimpleRule()) | ||
.expect(409); | ||
|
||
expect(body).to.eql({ | ||
message: 'rule_id: "rule-1" already exists', | ||
status_code: 409, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.