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

[Security Solution][Exceptions] - Initial updates to exceptions viewer UX #138770

Merged
merged 57 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
363e011
initial changes done, need to add tests, fix types, cleanup
yctercero Aug 12, 2022
091cbab
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 12, 2022
2489fda
continued cleanup, updated jest tests, added some tests
yctercero Aug 14, 2022
d12ddd2
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Aug 14, 2022
8c519ad
Merge branch 'update_viewer' of github.com:yctercero/kibana into upda…
yctercero Aug 14, 2022
c06e497
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 14, 2022
d501eb0
passing down wrong rule value
yctercero Aug 15, 2022
7b093d5
Merge branch 'update_viewer' of github.com:yctercero/kibana into upda…
yctercero Aug 15, 2022
90c191c
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Aug 15, 2022
bfe7776
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Aug 16, 2022
4444e5f
addressing some lint/checks issues and starting cleanup
yctercero Aug 18, 2022
07cbd36
moving components under new folder structure
yctercero Aug 25, 2022
3bb8970
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Aug 25, 2022
5626524
cleanup
yctercero Aug 25, 2022
6a31a42
cleanup unused translations
yctercero Aug 25, 2022
6bdacea
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Aug 25, 2022
7cf9875
fixing loading state when item is deleted
yctercero Aug 25, 2022
dfa9639
fix types
yctercero Aug 25, 2022
64643b3
remove unused translation
yctercero Aug 25, 2022
9181c33
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Aug 25, 2022
68afe7a
updating rule details page to allow tabs to be a part of url
yctercero Aug 26, 2022
e8447a4
fixed alerts tab navigation from execution results tab
yctercero Aug 26, 2022
a70436a
remove unused translation
yctercero Aug 26, 2022
871d5af
updates tests
yctercero Aug 27, 2022
0b8680a
Merge branch 'main' of github.com:elastic/kibana into rule_details_tabs
yctercero Aug 27, 2022
987f4a3
fixing cypress tests
yctercero Aug 29, 2022
c23a83f
Merge branch 'main' of github.com:elastic/kibana into rule_details_tabs
yctercero Aug 29, 2022
f524351
cleanup
yctercero Aug 29, 2022
9262baa
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Aug 29, 2022
d2fb0ea
Merge branch 'main' of github.com:elastic/kibana into rule_details_tabs
yctercero Aug 29, 2022
8354587
updated per PR feedback
yctercero Aug 30, 2022
f9a1e0b
Merge branch 'main' of github.com:elastic/kibana into rule_details_tabs
yctercero Aug 30, 2022
17fc004
cleanup
yctercero Aug 30, 2022
1ecd133
fix type errors
yctercero Aug 30, 2022
348cfa2
Merge branch 'main' of github.com:elastic/kibana into rule_details_tabs
yctercero Aug 30, 2022
bda7329
Merge branch 'main' into rule_details_tabs
kibanamachine Aug 30, 2022
4f050a0
updating per PR feedback
yctercero Aug 30, 2022
9c5a26f
Merge branch 'rule_details_tabs' into update_viewer
yctercero Aug 30, 2022
aa8dba2
updating to account for some new changes around tab routing in rule d…
yctercero Aug 30, 2022
2c3e238
Merge branch 'main' into update_viewer
kibanamachine Aug 30, 2022
fd0d6da
fixing some cypress issues
yctercero Aug 31, 2022
e224504
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Aug 31, 2022
4e7e30a
Merge branch 'update_viewer' of github.com:yctercero/kibana into upda…
yctercero Aug 31, 2022
6a5c4b2
cleanup of code
yctercero Aug 31, 2022
0124115
remove unused logger
yctercero Aug 31, 2022
aac415e
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Aug 31, 2022
01cea4f
adds cypress tests and updates their folder structure to make a bit m…
yctercero Sep 2, 2022
a665aad
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Sep 2, 2022
af121eb
making references route internal
yctercero Sep 2, 2022
f6dc695
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Sep 2, 2022
932cbbc
fix check type error
yctercero Sep 3, 2022
0b59305
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Sep 3, 2022
7d253fe
Merge branch 'main' into update_viewer
kibanamachine Sep 5, 2022
18b0d18
Merge branch 'main' into update_viewer
kibanamachine Sep 7, 2022
4cdd90c
Merge branch 'main' of github.com:elastic/kibana into update_viewer
yctercero Sep 8, 2022
20f8280
fix bug found during PR testing - thanks Mike!
yctercero Sep 8, 2022
23c73ba
Merge branch 'main' into update_viewer
kibanamachine Sep 8, 2022
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
@@ -0,0 +1,90 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { exactCheck, formatErrors, foldLeftRight } from '@kbn/securitysolution-io-ts-utils';
import { findExceptionReferencesOnRuleSchema } from './find_exception_list_references_schema';
import type { FindExceptionReferencesOnRuleSchema } from './find_exception_list_references_schema';

describe('find_exception_list_references_schema', () => {
test('validates all fields', () => {
const payload: FindExceptionReferencesOnRuleSchema = {
ids: 'abc,def',
list_ids: '123,456',
namespace_types: 'single,agnostic',
};

const decoded = findExceptionReferencesOnRuleSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const output = foldLeftRight(checked);
expect(formatErrors(output.errors)).toEqual([]);
expect(output.schema).toEqual({
ids: ['abc', 'def'],
list_ids: ['123', '456'],
namespace_types: ['single', 'agnostic'],
});
});

test('"ids" cannot be undefined', () => {
const payload: Omit<FindExceptionReferencesOnRuleSchema, 'ids'> = {
list_ids: '123,456',
namespace_types: 'single,agnostic',
};

const decoded = findExceptionReferencesOnRuleSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const output = foldLeftRight(checked);
expect(formatErrors(output.errors)).toEqual(['Invalid value "undefined" supplied to "ids"']);
expect(output.schema).toEqual({});
});

test('"list_ids" cannot be undefined', () => {
const payload: Omit<FindExceptionReferencesOnRuleSchema, 'list_ids'> = {
ids: 'abc',
namespace_types: 'single',
};

const decoded = findExceptionReferencesOnRuleSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const output = foldLeftRight(checked);
expect(formatErrors(output.errors)).toEqual([
'Invalid value "undefined" supplied to "list_ids"',
]);
expect(output.schema).toEqual({});
});

test('defaults "namespacetypes" to ["single"] if none set', () => {
const payload: Omit<FindExceptionReferencesOnRuleSchema, 'namespace_types'> = {
ids: 'abc',
list_ids: '123',
};

const decoded = findExceptionReferencesOnRuleSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const output = foldLeftRight(checked);
expect(formatErrors(output.errors)).toEqual([]);
expect(output.schema).toEqual({
ids: ['abc'],
list_ids: ['123'],
namespace_types: ['single'],
});
});

test('cannot add extra values', () => {
const payload: FindExceptionReferencesOnRuleSchema & { extra_value?: string } = {
ids: 'abc,def',
list_ids: '123,456',
namespace_types: 'single,agnostic',
extra_value: 'aaa',
};

const decoded = findExceptionReferencesOnRuleSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const output = foldLeftRight(checked);
expect(formatErrors(output.errors)).toEqual(['invalid keys "extra_value"']);
expect(output.schema).toEqual({});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';
import { NonEmptyStringArray } from '@kbn/securitysolution-io-ts-types';
import { DefaultNamespaceArray } from '@kbn/securitysolution-io-ts-list-types';

export const findExceptionReferencesOnRuleSchema = t.exact(
t.type({
ids: NonEmptyStringArray,
list_ids: NonEmptyStringArray,
namespace_types: DefaultNamespaceArray,
})
);

export type FindExceptionReferencesOnRuleSchema = t.OutputOf<
typeof findExceptionReferencesOnRuleSchema
>;

export type FindExceptionReferencesOnRuleSchemaDecoded = t.TypeOf<
typeof findExceptionReferencesOnRuleSchema
>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { exactCheck, formatErrors, foldLeftRight } from '@kbn/securitysolution-io-ts-utils';
import {
ruleReferenceSchema,
rulesReferencedByExceptionListsSchema,
} from './find_exception_list_references_schema';
import type {
RuleReferenceSchema,
RulesReferencedByExceptionListsSchema,
} from './find_exception_list_references_schema';

describe('find_exception_list_references_schema', () => {
describe('ruleReferenceSchema', () => {
test('validates all fields', () => {
const payload: RuleReferenceSchema = {
name: 'My rule',
id: '4656dc92-5832-11ea-8e2d-0242ac130003',
rule_id: 'my-rule-id',
exception_lists: [
{
id: 'myListId',
list_id: 'my-list-id',
namespace_type: 'single',
type: 'detection',
},
],
};

const decoded = ruleReferenceSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const output = foldLeftRight(checked);
expect(formatErrors(output.errors)).toEqual([]);
expect(output.schema).toEqual({
exception_lists: [
{ id: 'myListId', list_id: 'my-list-id', namespace_type: 'single', type: 'detection' },
],
id: '4656dc92-5832-11ea-8e2d-0242ac130003',
name: 'My rule',
rule_id: 'my-rule-id',
});
});

test('cannot add extra values', () => {
const payload: RuleReferenceSchema & { extra_value?: string } = {
name: 'My rule',
id: '4656dc92-5832-11ea-8e2d-0242ac130003',
rule_id: 'my-rule-id',
extra_value: 'foo',
exception_lists: [
{
id: 'myListId',
list_id: 'my-list-id',
namespace_type: 'single',
type: 'detection',
},
],
};

const decoded = ruleReferenceSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const output = foldLeftRight(checked);
expect(formatErrors(output.errors)).toEqual(['invalid keys "extra_value"']);
expect(output.schema).toEqual({});
});
});

describe('rulesReferencedByExceptionListsSchema', () => {
test('validates all fields', () => {
const payload: RulesReferencedByExceptionListsSchema = {
references: [
{
'my-list-id': [
{
name: 'My rule',
id: '4656dc92-5832-11ea-8e2d-0242ac130003',
rule_id: 'my-rule-id',
exception_lists: [
{
id: 'myListId',
list_id: 'my-list-id',
namespace_type: 'single',
type: 'detection',
},
],
},
],
},
],
};

const decoded = rulesReferencedByExceptionListsSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const output = foldLeftRight(checked);
expect(formatErrors(output.errors)).toEqual([]);
expect(output.schema).toEqual({
references: [
{
'my-list-id': [
{
exception_lists: [
{
id: 'myListId',
list_id: 'my-list-id',
namespace_type: 'single',
type: 'detection',
},
],
id: '4656dc92-5832-11ea-8e2d-0242ac130003',
name: 'My rule',
rule_id: 'my-rule-id',
},
],
},
],
});
});

test('validates "references" with empty array', () => {
const payload: RulesReferencedByExceptionListsSchema = {
references: [],
};

const decoded = rulesReferencedByExceptionListsSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const output = foldLeftRight(checked);
expect(formatErrors(output.errors)).toEqual([]);
expect(output.schema).toEqual({
references: [],
});
});

test('cannot add extra values', () => {
const payload: RulesReferencedByExceptionListsSchema & { extra_value?: string } = {
extra_value: 'foo',
references: [
{
'my-list-id': [
{
name: 'My rule',
id: '4656dc92-5832-11ea-8e2d-0242ac130003',
rule_id: 'my-rule-id',
exception_lists: [
{
id: 'myListId',
list_id: 'my-list-id',
namespace_type: 'single',
type: 'detection',
},
],
},
],
},
],
};

const decoded = rulesReferencedByExceptionListsSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const output = foldLeftRight(checked);
expect(formatErrors(output.errors)).toEqual(['invalid keys "extra_value"']);
expect(output.schema).toEqual({});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';

import { listArray, list_id } from '@kbn/securitysolution-io-ts-list-types';

import { rule_id, id, name } from '../common/schemas';

export const ruleReferenceSchema = t.exact(
t.type({
name,
id,
rule_id,
exception_lists: listArray,
})
);

export type RuleReferenceSchema = t.OutputOf<typeof ruleReferenceSchema>;

export const rulesReferencedByExceptionListSchema = t.record(list_id, t.array(ruleReferenceSchema));

export type RuleReferencesSchema = t.OutputOf<typeof rulesReferencedByExceptionListSchema>;

export const rulesReferencedByExceptionListsSchema = t.exact(
t.type({
references: t.array(rulesReferencedByExceptionListSchema),
})
);

export type RulesReferencedByExceptionListsSchema = t.OutputOf<
typeof rulesReferencedByExceptionListsSchema
>;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

export * from './error_schema';
export * from './get_installed_integrations_response_schema';
export * from './find_exception_list_references_schema';
export * from './import_rules_schema';
export * from './prepackaged_rules_schema';
export * from './prepackaged_rules_status_schema';
Expand Down
Loading