Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Security Solution][Detection Engine] Fixes agnostic type bug (#108610) #108745

Merged
merged 1 commit into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ to any newly saved rule:
{
"name" : "param:exceptionsList_0",
"id" : "endpoint_list",
"type" : "exception-list"
"type" : "exception-list-agnostic"
},
{
"name" : "param:exceptionsList_1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import { extractExceptionsList } from './extract_exceptions_list';
import { loggingSystemMock } from 'src/core/server/mocks';
import { RuleParams } from '../../schemas/rule_schemas';
import { EXCEPTION_LIST_NAMESPACE } from '@kbn/securitysolution-list-constants';
import { EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME } from './utils';
import {
EXCEPTION_LIST_NAMESPACE,
EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
} from '@kbn/securitysolution-list-constants';
import { EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME } from './utils/constants';

describe('extract_exceptions_list', () => {
type FuncReturn = ReturnType<typeof extractExceptionsList>;
Expand Down Expand Up @@ -48,21 +51,21 @@ describe('extract_exceptions_list', () => {
{
id: '123',
name: `${EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME}_0`,
type: EXCEPTION_LIST_NAMESPACE,
type: EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
},
]);
});

test('It returns two exception lists transformed into a saved object references', () => {
test('It returns 2 exception lists transformed into a saved object references', () => {
const twoInputs: RuleParams['exceptionsList'] = [
mockExceptionsList()[0],
{ ...mockExceptionsList()[0], id: '976' },
{ ...mockExceptionsList()[0], id: '976', namespace_type: 'single' },
];
expect(extractExceptionsList({ logger, exceptionsList: twoInputs })).toEqual<FuncReturn>([
{
id: '123',
name: `${EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME}_0`,
type: EXCEPTION_LIST_NAMESPACE,
type: EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
},
{
id: '976',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Logger, SavedObjectReference } from 'src/core/server';
import { EXCEPTION_LIST_NAMESPACE } from '@kbn/securitysolution-list-constants';
import { getSavedObjectType } from '@kbn/securitysolution-list-utils';
import { RuleParams } from '../../schemas/rule_schemas';
import { getSavedObjectNamePatternForExceptionsList } from './utils';

Expand Down Expand Up @@ -35,7 +35,7 @@ export const extractExceptionsList = ({
return exceptionsList.map((exceptionItem, index) => ({
name: getSavedObjectNamePatternForExceptionsList(index),
id: exceptionItem.id,
type: EXCEPTION_LIST_NAMESPACE,
type: getSavedObjectType({ namespaceType: exceptionItem.namespace_type }),
}));
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import { loggingSystemMock } from 'src/core/server/mocks';
import { extractReferences } from './extract_references';
import { RuleParams } from '../../schemas/rule_schemas';
import { EXCEPTION_LIST_NAMESPACE } from '@kbn/securitysolution-list-constants';
import { EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME } from './utils';
import {
EXCEPTION_LIST_NAMESPACE,
EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
} from '@kbn/securitysolution-list-constants';
import { EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME } from './utils/constants';

describe('extract_references', () => {
type FuncReturn = ReturnType<typeof extractReferences>;
Expand Down Expand Up @@ -43,6 +46,36 @@ describe('extract_references', () => {
{
id: '123',
name: `${EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME}_0`,
type: EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
},
],
});
});

test('It returns params untouched and the references extracted as 2 exception list saved object references', () => {
const params: Partial<RuleParams> = {
note: 'some note',
exceptionsList: [
mockExceptionsList()[0],
{ ...mockExceptionsList()[0], id: '456', namespace_type: 'single' },
],
};
expect(
extractReferences({
logger,
params: params as RuleParams,
})
).toEqual<FuncReturn>({
params: params as RuleParams,
references: [
{
id: '123',
name: `${EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME}_0`,
type: EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
},
{
id: '456',
name: `${EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME}_1`,
type: EXCEPTION_LIST_NAMESPACE,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import { loggingSystemMock } from 'src/core/server/mocks';
import { SavedObjectReference } from 'src/core/server';
import { EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME } from './utils';
import { EXCEPTION_LIST_NAMESPACE } from '@kbn/securitysolution-list-constants';
import { injectExceptionsReferences } from './inject_exceptions_list';
import { RuleParams } from '../../schemas/rule_schemas';
import { EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME } from './utils/constants';

describe('inject_exceptions_list', () => {
type FuncReturn = ReturnType<typeof injectExceptionsReferences>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import { loggingSystemMock } from 'src/core/server/mocks';
import { SavedObjectReference } from 'src/core/server';
import { EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME } from './utils';
import { EXCEPTION_LIST_NAMESPACE } from '@kbn/securitysolution-list-constants';
import { injectReferences } from './inject_references';
import { RuleParams } from '../../schemas/rule_schemas';
import { EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME } from './utils/constants';

describe('inject_references', () => {
type FuncReturn = ReturnType<typeof injectReferences>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

/**
* Given a name and index this will return the pattern of "${name_${index}"
* Given a name and index this will return the pattern of "${name}_${index}"
* @param name The name to suffix the string
* @param index The index to suffix the string
* @returns The pattern "${name_${index}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
* 2.0.
*/

import {
EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME,
getSavedObjectNamePatternForExceptionsList,
} from '.';
import { EXCEPTIONS_SAVED_OBJECT_REFERENCE_NAME } from './constants';
import { getSavedObjectNamePatternForExceptionsList } from './get_saved_object_name_pattern_for_exception_list';

describe('get_saved_object_name_pattern_for_exception_list', () => {
test('returns expected pattern given a zero', () => {
Expand Down