Skip to content

Commit

Permalink
[Security Solution][Exceptions]- Increase exceptions test coverage (#…
Browse files Browse the repository at this point in the history
…152757)

## Summary

- Addresses https://github.com/elastic/security-team/issues/5947
- Adding tests to cover the yellow rows in [test
sheet](https://docs.google.com/spreadsheets/d/1Eb_317s7nkQ4axVA270Ja99PRS-NWrYZAEc-1aVuyXg/edit#gid=0)
- Organise the tests to correspond to the following
[structure](https://docs.google.com/spreadsheets/d/14DdtghpxgfEmWoc7kot4XgEva_4GDEC_uTej65MUjV8/edit?pli=1#gid=0)
- Removed the
`x-pack/plugins/security_solution/cypress/e2e/exceptions/alerts_table_flow/add_exception.cy.ts`
as it was duplicated from
`x-pack/plugins/security_solution/cypress/e2e/exceptions/exceptions_management_flow/exceptions_table.cy.ts`
- Skipped the `flyout_validation` tests until resolving this
[ticket](#154994)
- Regarding `Exception-List`, `Exception-List-Item` and `Rule with
exceptions` migrations test cases are handled by most of our old `FTR`
tests as most of them deal with `Exception List Schema` which doesn't
include the new props, like the `expire_time` that was introduced in
`8.7`, so adding new tests using the new schema can be treated as
testing the new versions against the existing scenarios whereas the
existing tests for the migrations (downgrade) tests
[4a75a51](4a75a51)
- Tests under `x-pack/plugins/security_solution/cypress/upgrade_e2e` are
just POCs can't be used

# New tests folder structure based on workflow

<img width="432" alt="image"
src="https://user-images.githubusercontent.com/12671903/234849016-f6f227d1-fcaf-43cb-abe3-d3fc7f9cee00.png">

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
WafaaNasr and kibanamachine authored Jun 7, 2023
1 parent 5e907ed commit 0051086
Show file tree
Hide file tree
Showing 41 changed files with 3,360 additions and 584 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const MenuItemsComponent: FC<MenuItemsProps> = ({
{canUserEditList && (
<EuiFlexItem>
<EuiButton
data-test-subj={`${dataTestSubj || ''}ManageRulesButton`}
data-test-subj={`${dataTestSubj || ''}LinkRulesButton`}
fill
onClick={() => {
if (typeof onManageRules === 'function') onManageRules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('MenuItems', () => {
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.getByTestId('LinkedRulesMenuItems')).toHaveTextContent('Linked to 1 rules');
expect(wrapper.getByTestId('ManageRulesButton')).toBeInTheDocument();
expect(wrapper.getByTestId('LinkRulesButton')).toBeInTheDocument();
expect(wrapper.getByTestId('MenuActionsButtonIcon')).toBeInTheDocument();
});
it('should not render linkedRules HeaderMenu component, instead should render a text', () => {
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('MenuItems', () => {
/>
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.queryByTestId('ManageRulesButton')).not.toBeInTheDocument();
expect(wrapper.queryByTestId('LinkRulesButton')).not.toBeInTheDocument();
});
it('should call onManageRules', () => {
const wrapper = render(
Expand All @@ -115,7 +115,7 @@ describe('MenuItems', () => {
onManageRules={onManageRules}
/>
);
fireEvent.click(wrapper.getByTestId('ManageRulesButton'));
fireEvent.click(wrapper.getByTestId('LinkRulesButton'));
expect(onManageRules).toHaveBeenCalled();
});
it('should call onExportModalOpen', () => {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/lists/common/constants.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,6 @@ export const _VERSION = 'WzI5NywxXQ==';
export const VERSION = 1;
export const IMMUTABLE = false;
export const IMPORT_TIMEOUT = moment.duration(5, 'minutes');

/** Added in 8.7 */
export const EXPIRE_TIME = '2023-04-24T19:00:00.000Z';
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
COMMENTS,
DESCRIPTION,
ENTRIES,
EXPIRE_TIME,
ITEM_ID,
ITEM_TYPE,
LIST_ID,
Expand Down Expand Up @@ -60,3 +61,18 @@ export const getCreateExceptionListItemMinimalSchemaMockWithoutId =
os_types: OS_TYPES,
type: ITEM_TYPE,
});

/**
* Useful for testing newer exception list item versions, as the previous
* versions can be used to test migration cases
*/
export const getCreateExceptionListItemNewerVersionSchemaMock =
(): CreateExceptionListItemSchema => ({
description: DESCRIPTION,
entries: ENTRIES,
expire_time: EXPIRE_TIME,
list_id: LIST_ID,
name: NAME,
os_types: OS_TYPES,
type: ITEM_TYPE,
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ImportExceptionsListSchema,
} from '@kbn/securitysolution-io-ts-list-types';

import { ENTRIES } from '../../constants.mock';
import { ENTRIES, EXPIRE_TIME } from '../../constants.mock';

export const getImportExceptionsListSchemaMock = (
listId = 'detection_list_id'
Expand All @@ -23,6 +23,11 @@ export const getImportExceptionsListSchemaMock = (
type: 'detection',
});

/**
This mock retains the previous properties of the Exception List item, enabling us to
conduct migration test cases. As it lacks the new "expire_time" property, and considering
the absence of API versioning, we can utilize this mock to simulate the migration scenarios.
*/
export const getImportExceptionsListItemSchemaMock = (
itemId = 'item_id_1',
listId = 'detection_list_id'
Expand All @@ -35,6 +40,23 @@ export const getImportExceptionsListItemSchemaMock = (
type: 'simple',
});

/**
Please ensure that this mock is updated with the new properties of the Exception List item,
for example the inclusion of the "expire_time" property. This will allow us to test and evaluate
the new scenarios effectively.
*/
export const getImportExceptionsListItemNewerVersionSchemaMock = (
itemId = 'item_id_1',
listId = 'detection_list_id'
): ImportExceptionListItemSchema => ({
description: 'some description',
entries: ENTRIES,
expire_time: EXPIRE_TIME,
item_id: itemId,
list_id: listId,
name: 'Query with a rule id',
type: 'simple',
});
export const getImportExceptionsListSchemaDecodedMock = (
listId = 'detection_list_id'
): ImportExceptionListSchemaDecoded => ({
Expand Down
Loading

0 comments on commit 0051086

Please sign in to comment.