-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding prebuilt role tests for rule execution
- Loading branch information
Showing
16 changed files
with
1,044 additions
and
0 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
82 changes: 82 additions & 0 deletions
82
...tection_engine/rule_execution_logic/authorization/rule_execution/essentials_tier/admin.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,82 @@ | ||
/* | ||
* 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 TestAgent from 'supertest/lib/agent'; | ||
import { | ||
QueryRuleCreateProps, | ||
RulePreviewRequestBody, | ||
} from '@kbn/security-solution-plugin/common/api/detection_engine'; | ||
import { DETECTION_ENGINE_RULES_PREVIEW } from '@kbn/security-solution-plugin/common/constants'; | ||
import { FtrProviderContext } from '../../../../../../../ftr_provider_context'; | ||
import { EsArchivePathBuilder } from '../../../../../../../es_archive_path_builder'; | ||
import { | ||
deleteAllRules, | ||
deleteAllAlerts, | ||
getRuleForAlertTesting, | ||
} from '../../../../../../../../common/utils/security_solution'; | ||
|
||
/** | ||
* Specific _id to use for some of the tests. If the archiver changes and you see errors | ||
* here, update this to a new value of a chosen auditbeat record and update the tests values. | ||
*/ | ||
const ID = 'BhbXBmkBR346wHgn4PeZ'; | ||
|
||
export default ({ getService }: FtrProviderContext): void => { | ||
const log = getService('log'); | ||
const utils = getService('securitySolutionUtils'); | ||
const config = getService('config'); | ||
const isServerless = config.get('serverless'); | ||
const dataPathBuilder = new EsArchivePathBuilder(isServerless); | ||
const auditbeatPath = dataPathBuilder.getPath('auditbeat/hosts'); | ||
const esArchiver = getService('esArchiver'); | ||
const es = getService('es'); | ||
const esDeleteAllIndices = getService('esDeleteAllIndices'); | ||
|
||
let admin: TestAgent; | ||
|
||
describe('@serverless @serverlessQA admin rule execution API behaviors', () => { | ||
before(async () => { | ||
await esArchiver.load(auditbeatPath); | ||
admin = await utils.createSuperTest('admin'); | ||
admin = await utils.createSuperTest('admin'); | ||
}); | ||
|
||
afterEach(async () => { | ||
await esDeleteAllIndices('.preview.alerts*'); | ||
}); | ||
|
||
after(async () => { | ||
await esArchiver.unload(auditbeatPath); | ||
await deleteAllAlerts(admin, log, es, [ | ||
'.preview.alerts-security.alerts-*', | ||
'.alerts-security.alerts-*', | ||
]); | ||
await deleteAllRules(admin, log); | ||
}); | ||
|
||
describe('rule execution', () => { | ||
it('should return 200 for admin', async () => { | ||
const rule: QueryRuleCreateProps = { | ||
...getRuleForAlertTesting(['auditbeat-*']), | ||
query: `_id:${ID}`, | ||
}; | ||
const previewRequest: RulePreviewRequestBody = { | ||
...rule, | ||
invocationCount: 1, | ||
timeframeEnd: new Date().toISOString(), | ||
}; | ||
await admin | ||
.post(DETECTION_ENGINE_RULES_PREVIEW) | ||
.query({ enable_logged_requests: true }) | ||
.set('kbn-xsrf', 'true') | ||
.set('elastic-api-version', '2023-10-31') | ||
.send(previewRequest) | ||
.expect(200); | ||
}); | ||
}); | ||
}); | ||
}; |
16 changes: 16 additions & 0 deletions
16
...execution_logic/authorization/rule_execution/essentials_tier/configs/serverless.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,16 @@ | ||
/* | ||
* 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 { createTestConfig } from '../../../../../../../../config/serverless/config.base.essentials'; | ||
|
||
export default createTestConfig({ | ||
testFiles: [require.resolve('..')], | ||
junit: { | ||
reportName: | ||
'Detection Engine - Rule execution Authentication Tests - Serverless Env - Essentials Tier', | ||
}, | ||
}); |
83 changes: 83 additions & 0 deletions
83
...ection_engine/rule_execution_logic/authorization/rule_execution/essentials_tier/editor.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,83 @@ | ||
/* | ||
* 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 TestAgent from 'supertest/lib/agent'; | ||
import { | ||
QueryRuleCreateProps, | ||
RulePreviewRequestBody, | ||
} from '@kbn/security-solution-plugin/common/api/detection_engine'; | ||
import { DETECTION_ENGINE_RULES_PREVIEW } from '@kbn/security-solution-plugin/common/constants'; | ||
import { FtrProviderContext } from '../../../../../../../ftr_provider_context'; | ||
import { EsArchivePathBuilder } from '../../../../../../../es_archive_path_builder'; | ||
import { | ||
deleteAllRules, | ||
deleteAllAlerts, | ||
getRuleForAlertTesting, | ||
} from '../../../../../../../../common/utils/security_solution'; | ||
|
||
/** | ||
* Specific _id to use for some of the tests. If the archiver changes and you see errors | ||
* here, update this to a new value of a chosen auditbeat record and update the tests values. | ||
*/ | ||
const ID = 'BhbXBmkBR346wHgn4PeZ'; | ||
|
||
export default ({ getService }: FtrProviderContext): void => { | ||
const log = getService('log'); | ||
const utils = getService('securitySolutionUtils'); | ||
const config = getService('config'); | ||
const isServerless = config.get('serverless'); | ||
const dataPathBuilder = new EsArchivePathBuilder(isServerless); | ||
const auditbeatPath = dataPathBuilder.getPath('auditbeat/hosts'); | ||
const esArchiver = getService('esArchiver'); | ||
const es = getService('es'); | ||
const esDeleteAllIndices = getService('esDeleteAllIndices'); | ||
|
||
let admin: TestAgent; | ||
let editor: TestAgent; | ||
|
||
describe('@serverless @serverlessQA editor rule execution API behaviors', () => { | ||
before(async () => { | ||
await esArchiver.load(auditbeatPath); | ||
admin = await utils.createSuperTest('admin'); | ||
editor = await utils.createSuperTest('editor'); | ||
}); | ||
|
||
afterEach(async () => { | ||
await esDeleteAllIndices('.preview.alerts*'); | ||
}); | ||
|
||
after(async () => { | ||
await esArchiver.unload(auditbeatPath); | ||
await deleteAllAlerts(admin, log, es, [ | ||
'.preview.alerts-security.alerts-*', | ||
'.alerts-security.alerts-*', | ||
]); | ||
await deleteAllRules(admin, log); | ||
}); | ||
|
||
describe('rule execution', () => { | ||
it('should return 200 for editor', async () => { | ||
const rule: QueryRuleCreateProps = { | ||
...getRuleForAlertTesting(['auditbeat-*']), | ||
query: `_id:${ID}`, | ||
}; | ||
const previewRequest: RulePreviewRequestBody = { | ||
...rule, | ||
invocationCount: 1, | ||
timeframeEnd: new Date().toISOString(), | ||
}; | ||
await editor | ||
.post(DETECTION_ENGINE_RULES_PREVIEW) | ||
.query({ enable_logged_requests: true }) | ||
.set('kbn-xsrf', 'true') | ||
.set('elastic-api-version', '2023-10-31') | ||
.send(previewRequest) | ||
.expect(200); | ||
}); | ||
}); | ||
}); | ||
}; |
83 changes: 83 additions & 0 deletions
83
...ecution_logic/authorization/rule_execution/essentials_tier/endpoint_operations_analyst.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,83 @@ | ||
/* | ||
* 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 TestAgent from 'supertest/lib/agent'; | ||
import { | ||
QueryRuleCreateProps, | ||
RulePreviewRequestBody, | ||
} from '@kbn/security-solution-plugin/common/api/detection_engine'; | ||
import { DETECTION_ENGINE_RULES_PREVIEW } from '@kbn/security-solution-plugin/common/constants'; | ||
import { FtrProviderContext } from '../../../../../../../ftr_provider_context'; | ||
import { EsArchivePathBuilder } from '../../../../../../../es_archive_path_builder'; | ||
import { | ||
deleteAllRules, | ||
deleteAllAlerts, | ||
getRuleForAlertTesting, | ||
} from '../../../../../../../../common/utils/security_solution'; | ||
|
||
/** | ||
* Specific _id to use for some of the tests. If the archiver changes and you see errors | ||
* here, update this to a new value of a chosen auditbeat record and update the tests values. | ||
*/ | ||
const ID = 'BhbXBmkBR346wHgn4PeZ'; | ||
|
||
export default ({ getService }: FtrProviderContext): void => { | ||
const log = getService('log'); | ||
const utils = getService('securitySolutionUtils'); | ||
const config = getService('config'); | ||
const isServerless = config.get('serverless'); | ||
const dataPathBuilder = new EsArchivePathBuilder(isServerless); | ||
const auditbeatPath = dataPathBuilder.getPath('auditbeat/hosts'); | ||
const esArchiver = getService('esArchiver'); | ||
const es = getService('es'); | ||
const esDeleteAllIndices = getService('esDeleteAllIndices'); | ||
|
||
let admin: TestAgent; | ||
let endpointOperationsAnalyst: TestAgent; | ||
|
||
describe('@serverless @serverlessQA endpoint_operations_analyst rule execution API behaviors', () => { | ||
before(async () => { | ||
await esArchiver.load(auditbeatPath); | ||
admin = await utils.createSuperTest('admin'); | ||
endpointOperationsAnalyst = await utils.createSuperTest('endpoint_operations_analyst'); | ||
}); | ||
|
||
afterEach(async () => { | ||
await esDeleteAllIndices('.preview.alerts*'); | ||
}); | ||
|
||
after(async () => { | ||
await esArchiver.unload(auditbeatPath); | ||
await deleteAllAlerts(admin, log, es, [ | ||
'.preview.alerts-security.alerts-*', | ||
'.alerts-security.alerts-*', | ||
]); | ||
await deleteAllRules(admin, log); | ||
}); | ||
|
||
describe('rule execution', () => { | ||
it('should return 200 for endpoint_operations_analyst', async () => { | ||
const rule: QueryRuleCreateProps = { | ||
...getRuleForAlertTesting(['auditbeat-*']), | ||
query: `_id:${ID}`, | ||
}; | ||
const previewRequest: RulePreviewRequestBody = { | ||
...rule, | ||
invocationCount: 1, | ||
timeframeEnd: new Date().toISOString(), | ||
}; | ||
await endpointOperationsAnalyst | ||
.post(DETECTION_ENGINE_RULES_PREVIEW) | ||
.query({ enable_logged_requests: true }) | ||
.set('kbn-xsrf', 'true') | ||
.set('elastic-api-version', '2023-10-31') | ||
.send(previewRequest) | ||
.expect(200); | ||
}); | ||
}); | ||
}); | ||
}; |
83 changes: 83 additions & 0 deletions
83
...e_execution_logic/authorization/rule_execution/essentials_tier/endpoint_policy_manager.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,83 @@ | ||
/* | ||
* 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 TestAgent from 'supertest/lib/agent'; | ||
import { | ||
QueryRuleCreateProps, | ||
RulePreviewRequestBody, | ||
} from '@kbn/security-solution-plugin/common/api/detection_engine'; | ||
import { DETECTION_ENGINE_RULES_PREVIEW } from '@kbn/security-solution-plugin/common/constants'; | ||
import { FtrProviderContext } from '../../../../../../../ftr_provider_context'; | ||
import { EsArchivePathBuilder } from '../../../../../../../es_archive_path_builder'; | ||
import { | ||
deleteAllRules, | ||
deleteAllAlerts, | ||
getRuleForAlertTesting, | ||
} from '../../../../../../../../common/utils/security_solution'; | ||
|
||
/** | ||
* Specific _id to use for some of the tests. If the archiver changes and you see errors | ||
* here, update this to a new value of a chosen auditbeat record and update the tests values. | ||
*/ | ||
const ID = 'BhbXBmkBR346wHgn4PeZ'; | ||
|
||
export default ({ getService }: FtrProviderContext): void => { | ||
const log = getService('log'); | ||
const utils = getService('securitySolutionUtils'); | ||
const config = getService('config'); | ||
const isServerless = config.get('serverless'); | ||
const dataPathBuilder = new EsArchivePathBuilder(isServerless); | ||
const auditbeatPath = dataPathBuilder.getPath('auditbeat/hosts'); | ||
const esArchiver = getService('esArchiver'); | ||
const es = getService('es'); | ||
const esDeleteAllIndices = getService('esDeleteAllIndices'); | ||
|
||
let admin: TestAgent; | ||
let endpointPolicyManager: TestAgent; | ||
|
||
describe('@serverless @serverlessQA endpoint_policy_manager rule execution API behaviors', () => { | ||
before(async () => { | ||
await esArchiver.load(auditbeatPath); | ||
admin = await utils.createSuperTest('admin'); | ||
endpointPolicyManager = await utils.createSuperTest('endpoint_policy_manager'); | ||
}); | ||
|
||
afterEach(async () => { | ||
await esDeleteAllIndices('.preview.alerts*'); | ||
}); | ||
|
||
after(async () => { | ||
await esArchiver.unload(auditbeatPath); | ||
await deleteAllAlerts(admin, log, es, [ | ||
'.preview.alerts-security.alerts-*', | ||
'.alerts-security.alerts-*', | ||
]); | ||
await deleteAllRules(admin, log); | ||
}); | ||
|
||
describe('rule execution', () => { | ||
it('should return 200 for endpoint_policy_manager', async () => { | ||
const rule: QueryRuleCreateProps = { | ||
...getRuleForAlertTesting(['auditbeat-*']), | ||
query: `_id:${ID}`, | ||
}; | ||
const previewRequest: RulePreviewRequestBody = { | ||
...rule, | ||
invocationCount: 1, | ||
timeframeEnd: new Date().toISOString(), | ||
}; | ||
await endpointPolicyManager | ||
.post(DETECTION_ENGINE_RULES_PREVIEW) | ||
.query({ enable_logged_requests: true }) | ||
.set('kbn-xsrf', 'true') | ||
.set('elastic-api-version', '2023-10-31') | ||
.send(previewRequest) | ||
.expect(200); | ||
}); | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.