Skip to content

Commit 6d2ed9b

Browse files
committed
updates tests
1 parent 8251d0e commit 6d2ed9b

12 files changed

Lines changed: 586 additions & 501 deletions

File tree

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_bulk_actions/trial_license_complete_tier/perform_bulk_action.ts

Lines changed: 243 additions & 184 deletions
Large diffs are not rendered by default.

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_creation/basic_license_essentials_tier/create_rules.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import expect from '@kbn/expect';
8+
import expect from 'expect';
99
import { RuleCreateProps } from '@kbn/security-solution-plugin/common/api/detection_engine';
1010

1111
import {
@@ -16,6 +16,7 @@ import {
1616
removeServerGeneratedPropertiesIncludingRuleId,
1717
updateUsername,
1818
getSimpleRuleOutput,
19+
getCustomQueryRuleParams,
1920
} from '../../../utils';
2021
import {
2122
createAlertsIndex,
@@ -65,7 +66,28 @@ export default ({ getService }: FtrProviderContext) => {
6566
const bodyToCompare = removeServerGeneratedProperties(body);
6667
const expectedRule = updateUsername(getSimpleRuleOutput(), ELASTICSEARCH_USERNAME);
6768

68-
expect(bodyToCompare).to.eql(expectedRule);
69+
expect(bodyToCompare).toEqual(expectedRule);
70+
});
71+
72+
it('should create a rule with defaultable fields', async () => {
73+
const expectedRule = getCustomQueryRuleParams({
74+
rule_id: 'rule-1',
75+
setup: '# some setup markdown',
76+
});
77+
78+
const { body: createdRuleResponse } = await securitySolutionApi
79+
.createRule({ body: expectedRule })
80+
.expect(200);
81+
82+
expect(createdRuleResponse).toMatchObject(expectedRule);
83+
84+
const { body: createdRule } = await securitySolutionApi
85+
.readRule({
86+
query: { rule_id: 'rule-1' },
87+
})
88+
.expect(200);
89+
90+
expect(createdRule).toMatchObject(expectedRule);
6991
});
7092

7193
it('should create a single rule without an input index', async () => {
@@ -120,7 +142,7 @@ export default ({ getService }: FtrProviderContext) => {
120142
ELASTICSEARCH_USERNAME
121143
);
122144

123-
expect(bodyToCompare).to.eql(expectedRule);
145+
expect(bodyToCompare).toEqual(expectedRule);
124146
});
125147

126148
it('should create a single rule without a rule_id', async () => {
@@ -134,7 +156,7 @@ export default ({ getService }: FtrProviderContext) => {
134156
ELASTICSEARCH_USERNAME
135157
);
136158

137-
expect(bodyToCompare).to.eql(expectedRule);
159+
expect(bodyToCompare).toEqual(expectedRule);
138160
});
139161

140162
it('should cause a 409 conflict if we attempt to create the same rule_id twice', async () => {
@@ -144,7 +166,7 @@ export default ({ getService }: FtrProviderContext) => {
144166
.createRule({ body: getSimpleRule() })
145167
.expect(409);
146168

147-
expect(body).to.eql({
169+
expect(body).toEqual({
148170
message: 'rule_id: "rule-1" already exists',
149171
status_code: 409,
150172
});

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_creation/basic_license_essentials_tier/create_rules_bulk.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
* 2.0.
66
*/
77

8-
import expect from '@kbn/expect';
8+
import expect from 'expect';
99

1010
import { EsArchivePathBuilder } from '../../../../../es_archive_path_builder';
1111
import { FtrProviderContext } from '../../../../../ftr_provider_context';
1212
import {
13+
getCustomQueryRuleParams,
1314
getSimpleRule,
1415
getSimpleRuleOutput,
1516
getSimpleRuleOutputWithoutRuleId,
@@ -64,7 +65,28 @@ export default ({ getService }: FtrProviderContext): void => {
6465
const bodyToCompare = removeServerGeneratedProperties(body[0]);
6566
const expectedRule = updateUsername(getSimpleRuleOutput(), ELASTICSEARCH_USERNAME);
6667

67-
expect(bodyToCompare).to.eql(expectedRule);
68+
expect(bodyToCompare).toEqual(expectedRule);
69+
});
70+
71+
it('should create a rule with defaultable fields', async () => {
72+
const expectedRule = getCustomQueryRuleParams({
73+
rule_id: 'rule-1',
74+
setup: '# some setup markdown',
75+
});
76+
77+
const { body: createdRulesBulkResponse } = await securitySolutionApi
78+
.bulkCreateRules({ body: [expectedRule] })
79+
.expect(200);
80+
81+
expect(createdRulesBulkResponse[0]).toMatchObject(expectedRule);
82+
83+
const { body: createdRule } = await securitySolutionApi
84+
.readRule({
85+
query: { rule_id: 'rule-1' },
86+
})
87+
.expect(200);
88+
89+
expect(createdRule).toMatchObject(expectedRule);
6890
});
6991

7092
it('should create a single rule without a rule_id', async () => {
@@ -78,15 +100,15 @@ export default ({ getService }: FtrProviderContext): void => {
78100
ELASTICSEARCH_USERNAME
79101
);
80102

81-
expect(bodyToCompare).to.eql(expectedRule);
103+
expect(bodyToCompare).toEqual(expectedRule);
82104
});
83105

84106
it('should return a 200 ok but have a 409 conflict if we attempt to create the same rule_id twice', async () => {
85107
const { body } = await securitySolutionApi
86108
.bulkCreateRules({ body: [getSimpleRule(), getSimpleRule()] })
87109
.expect(200);
88110

89-
expect(body).to.eql([
111+
expect(body).toEqual([
90112
{
91113
error: {
92114
message: 'rule_id: "rule-1" already exists',
@@ -104,7 +126,7 @@ export default ({ getService }: FtrProviderContext): void => {
104126
.bulkCreateRules({ body: [getSimpleRule()] })
105127
.expect(200);
106128

107-
expect(body).to.eql([
129+
expect(body).toEqual([
108130
{
109131
error: {
110132
message: 'rule_id: "rule-1" already exists',

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_creation/trial_license_complete_tier/create_rules.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -691,27 +691,5 @@ export default ({ getService }: FtrProviderContext) => {
691691
});
692692
});
693693
});
694-
695-
describe('setup guide', async () => {
696-
beforeEach(async () => {
697-
await deleteAllAlerts(supertest, log, es);
698-
await deleteAllRules(supertest, log);
699-
});
700-
701-
it('creates a rule with a setup guide when setup parameter is present', async () => {
702-
const { body } = await supertest
703-
.post(DETECTION_ENGINE_RULES_URL)
704-
.set('kbn-xsrf', 'true')
705-
.set('elastic-api-version', '2023-10-31')
706-
.send(
707-
getCustomQueryRuleParams({
708-
setup: 'A setup guide',
709-
})
710-
)
711-
.expect(200);
712-
713-
expect(body.setup).toEqual('A setup guide');
714-
});
715-
});
716694
});
717695
};

x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_import_export/basic_license_essentials_tier/export_rules.ts

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,28 @@
77

88
import expect from 'expect';
99

10-
import { DETECTION_ENGINE_RULES_URL } from '@kbn/security-solution-plugin/common/constants';
1110
import { BaseDefaultableFields } from '@kbn/security-solution-plugin/common/api/detection_engine';
1211
import { FtrProviderContext } from '../../../../../ftr_provider_context';
1312
import { binaryToString, getCustomQueryRuleParams } from '../../../utils';
14-
import {
15-
createRule,
16-
createAlertsIndex,
17-
deleteAllRules,
18-
deleteAllAlerts,
19-
} from '../../../../../../common/utils/security_solution';
13+
import { deleteAllRules } from '../../../../../../common/utils/security_solution';
2014
export default ({ getService }: FtrProviderContext): void => {
2115
const supertest = getService('supertest');
2216
const log = getService('log');
23-
const es = getService('es');
2417
const securitySolutionApi = getService('securitySolutionApi');
2518

2619
describe('@ess @serverless export_rules', () => {
2720
describe('exporting rules', () => {
28-
beforeEach(async () => {
29-
await createAlertsIndex(supertest, log);
30-
});
31-
3221
afterEach(async () => {
33-
await deleteAllAlerts(supertest, log, es);
3422
await deleteAllRules(supertest, log);
3523
});
3624

3725
it('should set the response content types to be expected', async () => {
38-
await createRule(supertest, log, getCustomQueryRuleParams());
26+
const ruleToExport = getCustomQueryRuleParams();
27+
28+
await securitySolutionApi.createRule({ body: ruleToExport });
3929

40-
await supertest
41-
.post(`${DETECTION_ENGINE_RULES_URL}/_export`)
42-
.set('kbn-xsrf', 'true')
43-
.set('elastic-api-version', '2023-10-31')
44-
.send()
30+
await securitySolutionApi
31+
.exportRules({ query: {}, body: null })
4532
.expect(200)
4633
.expect('Content-Type', 'application/ndjson')
4734
.expect('Content-Disposition', 'attachment; filename="export.ndjson"');
@@ -50,13 +37,10 @@ export default ({ getService }: FtrProviderContext): void => {
5037
it('should export a single rule with a rule_id', async () => {
5138
const ruleToExport = getCustomQueryRuleParams();
5239

53-
await createRule(supertest, log, ruleToExport);
40+
await securitySolutionApi.createRule({ body: ruleToExport });
5441

55-
const { body } = await supertest
56-
.post(`${DETECTION_ENGINE_RULES_URL}/_export`)
57-
.set('kbn-xsrf', 'true')
58-
.set('elastic-api-version', '2023-10-31')
59-
.send()
42+
const { body } = await securitySolutionApi
43+
.exportRules({ query: {}, body: null })
6044
.expect(200)
6145
.parse(binaryToString);
6246

@@ -84,13 +68,12 @@ export default ({ getService }: FtrProviderContext): void => {
8468
});
8569

8670
it('should have export summary reflecting a number of rules', async () => {
87-
await createRule(supertest, log, getCustomQueryRuleParams());
71+
const ruleToExport = getCustomQueryRuleParams();
72+
73+
await securitySolutionApi.createRule({ body: ruleToExport });
8874

89-
const { body } = await supertest
90-
.post(`${DETECTION_ENGINE_RULES_URL}/_export`)
91-
.set('kbn-xsrf', 'true')
92-
.set('elastic-api-version', '2023-10-31')
93-
.send()
75+
const { body } = await securitySolutionApi
76+
.exportRules({ query: {}, body: null })
9477
.expect(200)
9578
.parse(binaryToString);
9679

@@ -108,14 +91,11 @@ export default ({ getService }: FtrProviderContext): void => {
10891
const ruleToExport1 = getCustomQueryRuleParams({ rule_id: 'rule-1' });
10992
const ruleToExport2 = getCustomQueryRuleParams({ rule_id: 'rule-2' });
11093

111-
await createRule(supertest, log, ruleToExport1);
112-
await createRule(supertest, log, ruleToExport2);
94+
await securitySolutionApi.createRule({ body: ruleToExport1 });
95+
await securitySolutionApi.createRule({ body: ruleToExport2 });
11396

114-
const { body } = await supertest
115-
.post(`${DETECTION_ENGINE_RULES_URL}/_export`)
116-
.set('kbn-xsrf', 'true')
117-
.set('elastic-api-version', '2023-10-31')
118-
.send()
97+
const { body } = await securitySolutionApi
98+
.exportRules({ query: {}, body: null })
11999
.expect(200)
120100
.parse(binaryToString);
121101

0 commit comments

Comments
 (0)