Skip to content

Commit 184e0dc

Browse files
committed
Fix unit tests
1 parent 42367e3 commit 184e0dc

File tree

4 files changed

+16
-104
lines changed

4 files changed

+16
-104
lines changed

x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_schema.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export const requiredRulesSchema = t.type({
9696
immutable,
9797
interval,
9898
rule_id,
99-
max_signals,
10099
output_index,
100+
max_signals,
101101
risk_score,
102102
risk_score_mapping: DefaultRiskScoreMappingArray,
103103
name,
@@ -161,7 +161,6 @@ export const dependentRulesSchema = t.partial({
161161
* Instead use dependentRulesSchema and check_type_dependents for how to do those.
162162
*/
163163
export const partialRulesSchema = t.partial({
164-
// output_index,
165164
actions,
166165
building_block_type,
167166
license,

x-pack/plugins/security_solution/server/lib/detection_engine/schemas/rule_schemas.mock.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export const getThresholdRuleParams = (): ThresholdRuleParams => {
6161
threshold: {
6262
field: ['host.id'],
6363
value: 5,
64+
cardinality: [
65+
{
66+
field: 'source.ip',
67+
value: 11,
68+
},
69+
],
6470
},
6571
};
6672
};

x-pack/plugins/security_solution/server/lib/detection_engine/signals/build_bulk_body.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ describe('buildBulkBody', () => {
142142
threshold: {
143143
field: ['host.id'],
144144
value: 5,
145+
cardinality: [
146+
{
147+
field: 'source.ip',
148+
value: 11,
149+
},
150+
],
145151
},
146152
},
147153
threshold_result: {

x-pack/plugins/security_solution/server/lib/detection_engine/signals/threshold/find_threshold_signals.test.ts

Lines changed: 3 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -31,108 +31,6 @@ describe('findThresholdSignals', () => {
3131
mockService = alertsMock.createAlertServices();
3232
});
3333

34-
it('should generate a threshold signal for pre-7.12 rules', async () => {
35-
await findThresholdSignals({
36-
from: 'now-6m',
37-
to: 'now',
38-
inputIndexPattern: ['*'],
39-
services: mockService,
40-
logger: mockLogger,
41-
filter: queryFilter,
42-
threshold: {
43-
field: 'host.name',
44-
value: 100,
45-
},
46-
buildRuleMessage,
47-
timestampOverride: undefined,
48-
});
49-
expect(mockSingleSearchAfter).toHaveBeenCalledWith(
50-
expect.objectContaining({
51-
aggregations: {
52-
'threshold_0:host.name': {
53-
terms: {
54-
field: 'host.name',
55-
min_doc_count: 100,
56-
size: 10000,
57-
},
58-
aggs: {
59-
top_threshold_hits: {
60-
top_hits: {
61-
sort: [
62-
{
63-
'@timestamp': {
64-
order: 'desc',
65-
},
66-
},
67-
],
68-
fields: [
69-
{
70-
field: '*',
71-
include_unmapped: true,
72-
},
73-
],
74-
size: 1,
75-
},
76-
},
77-
},
78-
},
79-
},
80-
})
81-
);
82-
});
83-
84-
it('should generate a signal for pre-7.12 rules with no threshold field', async () => {
85-
await findThresholdSignals({
86-
from: 'now-6m',
87-
to: 'now',
88-
inputIndexPattern: ['*'],
89-
services: mockService,
90-
logger: mockLogger,
91-
filter: queryFilter,
92-
threshold: {
93-
field: '',
94-
value: 100,
95-
},
96-
buildRuleMessage,
97-
timestampOverride: undefined,
98-
});
99-
expect(mockSingleSearchAfter).toHaveBeenCalledWith(
100-
expect.objectContaining({
101-
aggregations: {
102-
threshold_0: {
103-
terms: {
104-
script: {
105-
source: '""',
106-
lang: 'painless',
107-
},
108-
min_doc_count: 100,
109-
},
110-
aggs: {
111-
top_threshold_hits: {
112-
top_hits: {
113-
sort: [
114-
{
115-
'@timestamp': {
116-
order: 'desc',
117-
},
118-
},
119-
],
120-
fields: [
121-
{
122-
field: '*',
123-
include_unmapped: true,
124-
},
125-
],
126-
size: 1,
127-
},
128-
},
129-
},
130-
},
131-
},
132-
})
133-
);
134-
});
135-
13634
it('should generate a threshold signal query when only a value is provided', async () => {
13735
await findThresholdSignals({
13836
from: 'now-6m',
@@ -144,6 +42,7 @@ describe('findThresholdSignals', () => {
14442
threshold: {
14543
field: [],
14644
value: 100,
45+
cardinality: [],
14746
},
14847
buildRuleMessage,
14948
timestampOverride: undefined,
@@ -196,6 +95,7 @@ describe('findThresholdSignals', () => {
19695
threshold: {
19796
field: ['host.name'],
19897
value: 100,
98+
cardinality: [],
19999
},
200100
buildRuleMessage,
201101
timestampOverride: undefined,
@@ -246,6 +146,7 @@ describe('findThresholdSignals', () => {
246146
threshold: {
247147
field: ['host.name', 'user.name'],
248148
value: 100,
149+
cardinality: [],
249150
},
250151
buildRuleMessage,
251152
timestampOverride: undefined,

0 commit comments

Comments
 (0)