Skip to content

Commit

Permalink
updates exception flyout edit error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Mar 4, 2022
1 parent 9c3c323 commit 33cefaa
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ import {
EXCEPTION_ITEM_CONTAINER,
ADD_EXCEPTIONS_BTN,
EXCEPTION_FIELD_LIST,
EDIT_EXCEPTIONS_BTN,
EXCEPTION_EDIT_FLYOUT_SAVE_BTN,
EXCEPTION_FLYOUT_VERSION_CONFLICT,
} from '../../screens/exceptions';

import { DETECTIONS_RULE_MANAGEMENT_URL } from '../../urls/navigation';
import { cleanKibana, reload } from '../../tasks/common';
import {
createExceptionList,
createExceptionListItem,
updateExceptionListItem,
} from '../../tasks/api_calls/exceptions';
import { getExceptionList } from '../../objects/exception';

// NOTE: You might look at these tests and feel they're overkill,
// but the exceptions flyout has a lot of logic making it difficult
Expand All @@ -43,7 +52,20 @@ describe('Exceptions flyout', () => {
before(() => {
cleanKibana();
loginAndWaitForPageWithoutDateRange(DETECTIONS_RULE_MANAGEMENT_URL);
createCustomRule({ ...getNewRule(), index: ['exceptions-*'] });
createExceptionList(getExceptionList(), getExceptionList().list_id).then((response) =>
createCustomRule({
...getNewRule(),
index: ['exceptions-*'],
exceptionLists: [
{
id: response.body.id,
list_id: getExceptionList().list_id,
type: getExceptionList().type,
namespace_type: getExceptionList().namespace_type,
},
],
})
);
reload();
goToRuleDetails();

Expand All @@ -61,7 +83,7 @@ describe('Exceptions flyout', () => {
esArchiverUnload('exceptions');
});

it('Does not overwrite values and-ed together', () => {
it.skip('Does not overwrite values and-ed together', () => {
cy.get(ADD_EXCEPTIONS_BTN).click({ force: true });

// add multiple entries with invalid field values
Expand All @@ -79,7 +101,7 @@ describe('Exceptions flyout', () => {
closeExceptionBuilderFlyout();
});

it('Does not overwrite values or-ed together', () => {
it.skip('Does not overwrite values or-ed together', () => {
cy.get(ADD_EXCEPTIONS_BTN).click({ force: true });

// exception item 1
Expand Down Expand Up @@ -132,7 +154,7 @@ describe('Exceptions flyout', () => {
closeExceptionBuilderFlyout();
});

it('Does not overwrite values of nested entry items', () => {
it.skip('Does not overwrite values of nested entry items', () => {
openExceptionFlyoutFromRuleSettings();
cy.get(LOADING_SPINNER).should('not.exist');

Expand Down Expand Up @@ -196,12 +218,80 @@ describe('Exceptions flyout', () => {
closeExceptionBuilderFlyout();
});

it('Contains custom index fields', () => {
it.skip('Contains custom index fields', () => {
cy.get(ADD_EXCEPTIONS_BTN).click({ force: true });

cy.get(FIELD_INPUT).eq(0).click({ force: true });
cy.get(EXCEPTION_FIELD_LIST).contains('unique_value.test');

closeExceptionBuilderFlyout();
});

context('When updating an item with version conflict', () => {
it('Displays version conflict error', () => {
// create exception item via api
createExceptionListItem(getExceptionList().list_id, {
list_id: getExceptionList().list_id,
item_id: 'simple_list_item',
tags: [],
type: 'simple',
description: 'Test exception item',
name: 'Sample Exception List Item',
namespace_type: 'single',
entries: [
{
field: 'host.name',
operator: 'included',
type: 'match_any',
value: ['some host', 'another host'],
},
],
});

cy.reload();

goToExceptionsTab();

cy.get(EDIT_EXCEPTIONS_BTN).should('be.visible');

cy.get(EDIT_EXCEPTIONS_BTN).click({ force: true });

// update exception item via api
updateExceptionListItem('simple_list_item', {
name: 'Updated item name',
item_id: 'simple_list_item',
tags: [],
type: 'simple',
description: 'Test exception item',
namespace_type: 'single',
entries: [
{
field: 'host.name',
operator: 'included',
type: 'match_any',
value: ['some host', 'another host'],
},
],
});

// try to save and see version conflict error
cy.get(EXCEPTION_EDIT_FLYOUT_SAVE_BTN).click({ force: true });

cy.get(EXCEPTION_FLYOUT_VERSION_CONFLICT).should('be.visible');

closeExceptionBuilderFlyout();
});
});

context.skip('When updating an item for a list that has since been deleted', () => {
it.skip('Displays missing exception list error', () => {
cy.get(EDIT_EXCEPTIONS_BTN).click({ force: true });

// delete exception list via api

// try to save and see error

closeExceptionBuilderFlyout();
});
});
});
11 changes: 11 additions & 0 deletions x-pack/plugins/security_solution/cypress/objects/exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export interface ExceptionList {
type: 'detection' | 'endpoint';
}

export interface ExceptionListItem {
description: string;
list_id: string;
item_id: string;
name: string;
namespace_type: 'single' | 'agnostic';
tags: string[];
type: 'simple';
entries: Array<{ field: string; operator: string; type: string; value: string[] }>;
}

export const getExceptionList = (): ExceptionList => ({
description: 'Test exception list description',
list_id: 'test_exception_list',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

export const EDIT_EXCEPTIONS_BTN = '[data-test-subj="exceptionsViewerEditBtn"]';

export const ADD_EXCEPTIONS_BTN = '[data-test-subj="exceptionsHeaderAddExceptionBtn"]';

export const CLOSE_ALERTS_CHECKBOX =
Expand Down Expand Up @@ -61,3 +63,8 @@ export const EXCEPTION_FIELD_LIST =
'[data-test-subj="comboBoxOptionsList fieldAutocompleteComboBox-optionsList"]';

export const EXCEPTION_FLYOUT_TITLE = '[data-test-subj="exception-flyout-title"]';

export const EXCEPTION_EDIT_FLYOUT_SAVE_BTN = '[data-test-subj="edit-exception-confirm-button"]';

export const EXCEPTION_FLYOUT_VERSION_CONFLICT =
'[data-test-subj="exceptionsFlyoutVersionConflict"]';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { ExceptionList } from '../../objects/exception';
import { ExceptionList, ExceptionListItem } from '../../objects/exception';

export const createExceptionList = (
exceptionList: ExceptionList,
Expand All @@ -23,3 +23,50 @@ export const createExceptionList = (
headers: { 'kbn-xsrf': 'cypress-creds' },
failOnStatusCode: false,
});

export const createExceptionListItem = (
exceptionListId: string,
exceptionListItem?: ExceptionListItem
) =>
cy.request({
method: 'POST',
url: '/api/exception_lists/items',
body: {
list_id: exceptionListItem?.list_id ?? exceptionListId,
item_id: exceptionListItem?.item_id ?? 'simple_list_item',
tags: exceptionListItem?.tags ?? ['user added string for a tag', 'malware'],
type: exceptionListItem?.type ?? 'simple',
description: exceptionListItem?.description ?? 'This is a sample endpoint type exception',
name: exceptionListItem?.name ?? 'Sample Exception List Item',
entries: exceptionListItem?.entries ?? [
{
field: 'actingProcess.file.signer',
operator: 'excluded',
type: 'exists',
},
{
field: 'host.name',
operator: 'included',
type: 'match_any',
value: ['some host', 'another host'],
},
],
},
headers: { 'kbn-xsrf': 'cypress-creds' },
failOnStatusCode: false,
});

export const updateExceptionListItem = (
exceptionListItemId: string,
exceptionListItemUpdate?: Partial<ExceptionListItem>
) =>
cy.request({
method: 'PUT',
url: '/api/exception_lists/items',
body: {
item_id: exceptionListItemId,
...exceptionListItemUpdate,
},
headers: { 'kbn-xsrf': 'cypress-creds' },
failOnStatusCode: false,
});
Original file line number Diff line number Diff line change
Expand Up @@ -410,27 +410,35 @@ export const EditExceptionFlyout = memo(function EditExceptionFlyout({
</FlyoutCheckboxesSection>
</>
)}
{updateError != null && (
<EuiFlyoutFooter>
<ErrorCallout
http={http}
errorInfo={updateError}
rule={maybeRule}
onCancel={onCancel}
onSuccess={handleDissasociationSuccess}
onError={handleDissasociationError}
/>
</EuiFlyoutFooter>
)}
{hasVersionConflict && (
<EuiFlyoutFooter>
<EuiCallOut title={i18n.VERSION_CONFLICT_ERROR_TITLE} color="danger" iconType="alert">
<p>{i18n.VERSION_CONFLICT_ERROR_DESCRIPTION}</p>
</EuiCallOut>
</EuiFlyoutFooter>
)}
{updateError == null && (
<EuiFlyoutFooter>

<EuiFlyoutFooter>
{hasVersionConflict && (
<>
<EuiCallOut
title={i18n.VERSION_CONFLICT_ERROR_TITLE}
color="danger"
iconType="alert"
data-test-subj="exceptionsFlyoutVersionConflict"
>
<p>{i18n.VERSION_CONFLICT_ERROR_DESCRIPTION}</p>
</EuiCallOut>
<EuiSpacer size="m" />
</>
)}
{updateError != null && (
<>
<ErrorCallout
http={http}
errorInfo={updateError}
rule={maybeRule}
onCancel={onCancel}
onSuccess={handleDissasociationSuccess}
onError={handleDissasociationError}
/>
<EuiSpacer size="m" />
</>
)}
{updateError === null && (
<FlyoutFooterGroup justifyContent="spaceBetween">
<EuiButtonEmpty data-test-subj="cancelExceptionAddButton" onClick={onCancel}>
{i18n.CANCEL}
Expand All @@ -446,8 +454,8 @@ export const EditExceptionFlyout = memo(function EditExceptionFlyout({
{i18n.EDIT_EXCEPTION_SAVE_BUTTON}
</EuiButton>
</FlyoutFooterGroup>
</EuiFlyoutFooter>
)}
)}
</EuiFlyoutFooter>
</EuiFlyout>
);
});

0 comments on commit 33cefaa

Please sign in to comment.