-
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.
Browse files
Browse the repository at this point in the history
* tests for detection engine get/put utils * increases unit test code statement coverage to 100% for search_after / bulk index reindexer * removes mockLogger declaration from individual test cases - clears mock counts before each test case runs so as to not accumulate method calls after each test case * resets default paging size to 1000 - typo from when I was working through my tests * updates tests after rebase with master * fixes type check after fixing test from rebase with master * removes undefined from maxSignals in type definition, updates tests with pure jest function implementations of logger and services - modifying only the return values or creating a mock implementation when necessary, removed some overlapping test cases * fixes type issue * replaces mock implementation with mock return value for unit test * removes mock logger expected counts, just check if error logs are called, don't care about debug / warn etc. * fixes more type checks after rebase with master
- Loading branch information
1 parent
2ff8e9f
commit 5aa6eec
Showing
7 changed files
with
656 additions
and
21 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
150 changes: 150 additions & 0 deletions
150
x-pack/legacy/plugins/siem/server/lib/detection_engine/alerts/__mocks__/es_results.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,150 @@ | ||
/* | ||
* 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 { SignalSourceHit, SignalSearchResponse, SignalAlertParams } from '../types'; | ||
|
||
export const sampleSignalAlertParams = (maxSignals: number | undefined): SignalAlertParams => ({ | ||
id: 'rule-1', | ||
description: 'Detecting root and admin users', | ||
falsePositives: [], | ||
immutable: false, | ||
index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'], | ||
interval: '5m', | ||
name: 'Detect Root/Admin Users', | ||
type: 'query', | ||
from: 'now-6m', | ||
tags: ['some fake tag'], | ||
to: 'now', | ||
severity: 'high', | ||
query: 'user.name: root or user.name: admin', | ||
language: 'kuery', | ||
references: ['http://google.com'], | ||
maxSignals: maxSignals ? maxSignals : 10000, | ||
enabled: true, | ||
filter: undefined, | ||
filters: undefined, | ||
savedId: undefined, | ||
size: 1000, | ||
}); | ||
|
||
export const sampleDocNoSortId: SignalSourceHit = { | ||
_index: 'myFakeSignalIndex', | ||
_type: 'doc', | ||
_score: 100, | ||
_version: 1, | ||
_id: 'someFakeId', | ||
_source: { | ||
someKey: 'someValue', | ||
'@timestamp': 'someTimeStamp', | ||
}, | ||
}; | ||
|
||
export const sampleDocWithSortId: SignalSourceHit = { | ||
_index: 'myFakeSignalIndex', | ||
_type: 'doc', | ||
_score: 100, | ||
_version: 1, | ||
_id: 'someFakeId', | ||
_source: { | ||
someKey: 'someValue', | ||
'@timestamp': 'someTimeStamp', | ||
}, | ||
sort: ['1234567891111'], | ||
}; | ||
|
||
export const sampleEmptyDocSearchResults: SignalSearchResponse = { | ||
took: 10, | ||
timed_out: false, | ||
_shards: { | ||
total: 10, | ||
successful: 10, | ||
failed: 0, | ||
skipped: 0, | ||
}, | ||
hits: { | ||
total: 0, | ||
max_score: 100, | ||
hits: [], | ||
}, | ||
}; | ||
|
||
export const sampleDocSearchResultsNoSortId: SignalSearchResponse = { | ||
took: 10, | ||
timed_out: false, | ||
_shards: { | ||
total: 10, | ||
successful: 10, | ||
failed: 0, | ||
skipped: 0, | ||
}, | ||
hits: { | ||
total: 100, | ||
max_score: 100, | ||
hits: [ | ||
{ | ||
...sampleDocNoSortId, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export const sampleDocSearchResultsNoSortIdNoHits: SignalSearchResponse = { | ||
took: 10, | ||
timed_out: false, | ||
_shards: { | ||
total: 10, | ||
successful: 10, | ||
failed: 0, | ||
skipped: 0, | ||
}, | ||
hits: { | ||
total: 0, | ||
max_score: 100, | ||
hits: [ | ||
{ | ||
...sampleDocNoSortId, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export const repeatedSearchResultsWithSortId = (repeat: number) => ({ | ||
took: 10, | ||
timed_out: false, | ||
_shards: { | ||
total: 10, | ||
successful: 10, | ||
failed: 0, | ||
skipped: 0, | ||
}, | ||
hits: { | ||
total: repeat, | ||
max_score: 100, | ||
hits: Array.from({ length: repeat }).map(x => ({ | ||
...sampleDocWithSortId, | ||
})), | ||
}, | ||
}); | ||
|
||
export const sampleDocSearchResultsWithSortId: SignalSearchResponse = { | ||
took: 10, | ||
timed_out: false, | ||
_shards: { | ||
total: 10, | ||
successful: 10, | ||
failed: 0, | ||
skipped: 0, | ||
}, | ||
hits: { | ||
total: 1, | ||
max_score: 100, | ||
hits: [ | ||
{ | ||
...sampleDocWithSortId, | ||
}, | ||
], | ||
}, | ||
}; |
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
Oops, something went wrong.