Skip to content

Commit 96fd83b

Browse files
authored
[SECURITY SOLUTION] exclude cloud alias index from our query (#81551)
* exclude cloud alias index * only exclude cloud alias when logs-* is there
1 parent ca8341b commit 96fd83b

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { cloneDeep } from 'lodash/fp';
8+
import { mockGlobalState } from '../../mock';
9+
import { SourcererScopeName } from './model';
10+
import { getSourcererScopeSelector } from './selectors';
11+
12+
describe('Sourcerer selectors', () => {
13+
describe('getSourcererScopeSelector', () => {
14+
it('Should exclude elastic cloud alias when selected patterns include "logs-*" as an alias', () => {
15+
const mapStateToProps = getSourcererScopeSelector();
16+
expect(
17+
mapStateToProps(mockGlobalState, SourcererScopeName.default).selectedPatterns
18+
).toEqual([
19+
'apm-*-transaction*',
20+
'auditbeat-*',
21+
'endgame-*',
22+
'filebeat-*',
23+
'logs-*',
24+
'packetbeat-*',
25+
'winlogbeat-*',
26+
'-*elastic-cloud-logs-*',
27+
]);
28+
});
29+
30+
it('Should NOT exclude elastic cloud alias when selected patterns does NOT include "logs-*" as an alias', () => {
31+
const mapStateToProps = getSourcererScopeSelector();
32+
const myMockGlobalState = cloneDeep(mockGlobalState);
33+
myMockGlobalState.sourcerer.sourcererScopes.default.selectedPatterns = myMockGlobalState.sourcerer.sourcererScopes.default.selectedPatterns.filter(
34+
(index) => !index.includes('logs-*')
35+
);
36+
expect(
37+
mapStateToProps(myMockGlobalState, SourcererScopeName.default).selectedPatterns
38+
).toEqual([
39+
'apm-*-transaction*',
40+
'auditbeat-*',
41+
'endgame-*',
42+
'filebeat-*',
43+
'packetbeat-*',
44+
'winlogbeat-*',
45+
]);
46+
});
47+
48+
it('Should NOT exclude elastic cloud alias when selected patterns include "logs-endpoint.event-*" as an alias', () => {
49+
const mapStateToProps = getSourcererScopeSelector();
50+
const myMockGlobalState = cloneDeep(mockGlobalState);
51+
myMockGlobalState.sourcerer.sourcererScopes.default.selectedPatterns = [
52+
...myMockGlobalState.sourcerer.sourcererScopes.default.selectedPatterns.filter(
53+
(index) => !index.includes('logs-*')
54+
),
55+
'logs-endpoint.event-*',
56+
];
57+
expect(
58+
mapStateToProps(myMockGlobalState, SourcererScopeName.default).selectedPatterns
59+
).toEqual([
60+
'apm-*-transaction*',
61+
'auditbeat-*',
62+
'endgame-*',
63+
'filebeat-*',
64+
'packetbeat-*',
65+
'winlogbeat-*',
66+
'logs-endpoint.event-*',
67+
]);
68+
});
69+
});
70+
});

x-pack/plugins/security_solution/public/common/store/sourcerer/selectors.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,18 @@ export const defaultIndexNamesSelector = () => {
8181
return mapStateToProps;
8282
};
8383

84+
const EXLCUDE_ELASTIC_CLOUD_INDEX = '-*elastic-cloud-logs-*';
8485
export const getSourcererScopeSelector = () => {
8586
const getScopesSelector = scopesSelector();
8687

87-
const mapStateToProps = (state: State, scopeId: SourcererScopeName): ManageScope =>
88-
getScopesSelector(state)[scopeId];
88+
const mapStateToProps = (state: State, scopeId: SourcererScopeName): ManageScope => ({
89+
...getScopesSelector(state)[scopeId],
90+
selectedPatterns: getScopesSelector(state)[scopeId].selectedPatterns.some(
91+
(index) => index === 'logs-*'
92+
)
93+
? [...getScopesSelector(state)[scopeId].selectedPatterns, EXLCUDE_ELASTIC_CLOUD_INDEX]
94+
: getScopesSelector(state)[scopeId].selectedPatterns,
95+
});
8996

9097
return mapStateToProps;
9198
};

0 commit comments

Comments
 (0)