[Security Solution][Exceptions] - Fix exception list description bug (#152391)

## Summary

Addresses https://github.com/elastic/kibana/issues/147338
This commit is contained in:
Yara Tercero 2023-03-08 21:29:08 -08:00 committed by GitHub
parent e57883f3be
commit c072f8ebf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 167 additions and 1 deletions

View file

@ -0,0 +1,93 @@
/*
* 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 { getExceptionList } from '../../../objects/exception';
import { getNewRule } from '../../../objects/rule';
import { login, visitWithoutDateRange } from '../../../tasks/login';
import { createRule } from '../../../tasks/api_calls/rules';
import { exceptionsListDetailsUrl } from '../../../urls/navigation';
import {
editExceptionLisDetails,
waitForExceptionListDetailToBeLoaded,
} from '../../../tasks/exceptions_table';
import { createExceptionList } from '../../../tasks/api_calls/exceptions';
import { esArchiverResetKibana } from '../../../tasks/es_archiver';
import {
EXCEPTIONS_LIST_MANAGEMENT_NAME,
EXCEPTIONS_LIST_MANAGEMENT_DESCRIPTION,
} from '../../../screens/exceptions';
const LIST_NAME = 'My exception list';
const UPDATED_LIST_NAME = 'Updated exception list';
const LIST_DESCRIPTION = 'This is the exception list description.';
const UPDATED_LIST_DESCRIPTION = 'This is an updated version of the exception list description.';
const getExceptionList1 = () => ({
...getExceptionList(),
name: LIST_NAME,
description: LIST_DESCRIPTION,
list_id: 'exception_list_test',
});
describe('Exception list management page', () => {
before(() => {
esArchiverResetKibana();
login();
// Create exception list associated with a rule
createExceptionList(getExceptionList1(), getExceptionList1().list_id).then((response) =>
createRule({
...getNewRule(),
exceptions_list: [
{
id: response.body.id,
list_id: getExceptionList1().list_id,
type: getExceptionList1().type,
namespace_type: getExceptionList1().namespace_type,
},
],
})
);
});
beforeEach(() => {
visitWithoutDateRange(exceptionsListDetailsUrl(getExceptionList1().list_id));
waitForExceptionListDetailToBeLoaded();
});
it('Edits list details', () => {
// Check list details are loaded
cy.get(EXCEPTIONS_LIST_MANAGEMENT_NAME).should('have.text', LIST_NAME);
cy.get(EXCEPTIONS_LIST_MANAGEMENT_DESCRIPTION).should('have.text', LIST_DESCRIPTION);
// Update list details in edit modal
editExceptionLisDetails({
name: { original: LIST_NAME, updated: UPDATED_LIST_NAME },
description: { original: LIST_DESCRIPTION, updated: UPDATED_LIST_DESCRIPTION },
});
// Ensure that list details were updated
cy.get(EXCEPTIONS_LIST_MANAGEMENT_NAME).should('have.text', UPDATED_LIST_NAME);
cy.get(EXCEPTIONS_LIST_MANAGEMENT_DESCRIPTION).should('have.text', UPDATED_LIST_DESCRIPTION);
// Ensure that list details changes persisted
visitWithoutDateRange(exceptionsListDetailsUrl(getExceptionList1().list_id));
cy.get(EXCEPTIONS_LIST_MANAGEMENT_NAME).should('have.text', UPDATED_LIST_NAME);
cy.get(EXCEPTIONS_LIST_MANAGEMENT_DESCRIPTION).should('have.text', UPDATED_LIST_DESCRIPTION);
// Remove description
editExceptionLisDetails({
description: { original: UPDATED_LIST_DESCRIPTION, updated: null },
});
cy.get(EXCEPTIONS_LIST_MANAGEMENT_DESCRIPTION).should('have.text', 'Add a description');
// Ensure description removal persisted
visitWithoutDateRange(exceptionsListDetailsUrl(getExceptionList1().list_id));
cy.get(EXCEPTIONS_LIST_MANAGEMENT_DESCRIPTION).should('have.text', 'Add a description');
});
});

View file

@ -135,3 +135,24 @@ export const MANAGE_EXCEPTION_CREATE_BUTTON_EXCEPTION =
'[data-test-subj="manageExceptionListCreateExceptionButton"]';
export const RULE_ACTION_LINK_RULE_SWITCH = '[data-test-subj="ruleActionLinkRuleSwitch"]';
// Exception list management
export const EXCEPTIONS_LIST_MANAGEMENT_NAME =
'[data-test-subj="exceptionListManagementTitleText"]';
export const EXCEPTIONS_LIST_MANAGEMENT_EDIT_NAME_BTN =
'[data-test-subj="exceptionListManagementTitleEditIcon"]';
export const EXCEPTIONS_LIST_MANAGEMENT_EDIT_MODAL_NAME_INPUT =
'[data-test-subj="editModalNameTextField"]';
export const EXCEPTIONS_LIST_MANAGEMENT_DESCRIPTION =
'[data-test-subj="exceptionListManagementDescriptionText"]';
export const EXCEPTIONS_LIST_MANAGEMENT_EDIT_MODAL_DESCRIPTION_INPUT =
'[data-test-subj="editModalDescriptionTextField"]';
export const EXCEPTIONS_LIST_EDIT_DETAILS_SAVE_BTN = '[data-test-subj="editModalSaveBtn"]';
export const EXCEPTIONS_LIST_DETAILS_HEADER =
'[data-test-subj="exceptionListManagementPageHeader"]';

View file

@ -15,6 +15,12 @@ import {
EXCEPTIONS_TABLE_EXPORT_MODAL_BTN,
EXCEPTIONS_OVERFLOW_ACTIONS_BTN,
EXCEPTIONS_TABLE_EXPORT_CONFIRM_BTN,
EXCEPTIONS_LIST_MANAGEMENT_NAME,
EXCEPTIONS_LIST_MANAGEMENT_EDIT_NAME_BTN,
EXCEPTIONS_LIST_MANAGEMENT_EDIT_MODAL_NAME_INPUT,
EXCEPTIONS_LIST_MANAGEMENT_EDIT_MODAL_DESCRIPTION_INPUT,
EXCEPTIONS_LIST_EDIT_DETAILS_SAVE_BTN,
EXCEPTIONS_LIST_DETAILS_HEADER,
} from '../screens/exceptions';
export const clearSearchSelection = () => {
@ -59,3 +65,45 @@ export const waitForExceptionsTableToBeLoaded = () => {
cy.get(EXCEPTIONS_TABLE).should('exist');
cy.get(EXCEPTIONS_TABLE_SEARCH).should('exist');
};
export const waitForExceptionListDetailToBeLoaded = () => {
cy.get(EXCEPTIONS_LIST_DETAILS_HEADER).should('exist');
};
export const editExceptionLisDetails = ({
name,
description,
}: {
name?: { original: string; updated: string };
description?: { original: string; updated: string | null };
}) => {
cy.get(EXCEPTIONS_LIST_MANAGEMENT_NAME).should('exist');
cy.get(EXCEPTIONS_LIST_MANAGEMENT_EDIT_NAME_BTN).first().click();
if (name != null) {
cy.get(EXCEPTIONS_LIST_MANAGEMENT_NAME).should('have.text', name.original);
cy.get(EXCEPTIONS_LIST_MANAGEMENT_EDIT_MODAL_NAME_INPUT)
.should('have.value', name.original)
.clear({ force: true })
.type(`${name.updated}`);
cy.get(EXCEPTIONS_LIST_MANAGEMENT_EDIT_MODAL_NAME_INPUT).should('have.value', name.updated);
}
if (description != null) {
cy.get(EXCEPTIONS_LIST_MANAGEMENT_EDIT_MODAL_DESCRIPTION_INPUT)
.should('have.value', description.original)
.clear({ force: true })
.should('not.have.value');
if (description.updated != null) {
cy.get(EXCEPTIONS_LIST_MANAGEMENT_EDIT_MODAL_DESCRIPTION_INPUT).type(
`${description.updated}`
);
cy.get(EXCEPTIONS_LIST_MANAGEMENT_EDIT_MODAL_DESCRIPTION_INPUT).should(
'have.value',
description.updated
);
}
}
cy.get(EXCEPTIONS_LIST_EDIT_DETAILS_SAVE_BTN).first().click();
};

View file

@ -32,6 +32,7 @@ export const TIMELINES_URL = '/app/security/timelines';
export const TIMELINE_TEMPLATES_URL = '/app/security/timelines/template';
export const CASES_URL = '/app/security/cases';
export const EXCEPTIONS_URL = 'app/security/exceptions';
export const EXCEPTIONS_LIST_URL = 'app/security/exceptions/details';
export const HOSTS_URL = '/app/security/hosts/allHosts';
export const CSP_FINDINGS_URL = 'app/security/cloud_security_posture/findings';
export const DETECTIONS_RULE_MANAGEMENT_URL = 'app/security/rules';
@ -66,3 +67,5 @@ export const hostDetailsUrl = (hostName: string) =>
`/app/security/hosts/${hostName}/authentications`;
export const userDetailsUrl = (userName: string) => `/app/security/users/${userName}/allUsers`;
export const exceptionsListDetailsUrl = (listId: string) => `${EXCEPTIONS_LIST_URL}/${listId}`;

View file

@ -153,7 +153,7 @@ export const useListDetailsView = (exceptionListId: string) => {
list_id: exceptionListId,
type: list.type,
name: listDetails.name,
description: listDetails.description || list.description,
description: listDetails.description ?? '',
namespace_type: list.namespace_type,
},
});

View file

@ -99,6 +99,7 @@ export const ListsDetailViewComponent: FC = () => {
onExportList={handleExportList}
onDeleteList={handleDelete}
onManageRules={onManageRules}
dataTestSubj="exceptionListManagement"
/>
<AutoDownload blob={exportedList} name={`${listId}.ndjson`} onDownload={handleOnDownload} />