[Security Solution] [Exceptions] fixes error where validation of isAlertsLoading was missing reference to memoized data view id (#147641)

## Summary

ref: https://github.com/elastic/kibana/issues/147591

Thanks @nkhristinin for pairing up on this today!

### Checklist

Delete any items that are not applicable to this PR.


- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

Co-authored-by: Gloria Hornero <gloria.hornero@elastic.co>
This commit is contained in:
Devin W. Hurley 2022-12-19 12:52:19 -05:00 committed by GitHub
parent a67f30b46d
commit 42006836a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 18 deletions

View file

@ -5,15 +5,24 @@
* 2.0.
*/
import { LOADING_INDICATOR } from '../../../screens/security_header';
import { getNewRule } from '../../../objects/rule';
import { ALERTS_COUNT, EMPTY_ALERT_TABLE, NUMBER_OF_ALERTS } from '../../../screens/alerts';
import { createCustomRuleEnabled } from '../../../tasks/api_calls/rules';
import { goToRuleDetails } from '../../../tasks/alerts_detection_rules';
import { goToClosedAlerts, goToOpenedAlerts } from '../../../tasks/alerts';
import {
addExceptionFromFirstAlert,
goToClosedAlerts,
goToOpenedAlerts,
} from '../../../tasks/alerts';
import {
addExceptionConditions,
addExceptionFlyoutItemName,
editException,
editExceptionFlyoutItemName,
selectBulkCloseAlerts,
submitEditedExceptionItem,
submitNewExceptionItem,
} from '../../../tasks/exceptions';
import {
esArchiverLoad,
@ -75,14 +84,57 @@ describe('Add exception using data views from rule details', () => {
);
visitWithoutDateRange(DETECTIONS_RULE_MANAGEMENT_URL);
goToRuleDetails();
goToExceptionsTab();
waitForAlertsToPopulate();
});
afterEach(() => {
esArchiverUnload('exceptions_2');
});
it('Creates an exception item from alert actions overflow menu', () => {
cy.get(LOADING_INDICATOR).should('not.exist');
addExceptionFromFirstAlert();
addExceptionFlyoutItemName(ITEM_NAME);
addExceptionConditions({
field: 'agent.name',
operator: 'is',
values: ['foo'],
});
selectBulkCloseAlerts();
submitNewExceptionItem();
// Alerts table should now be empty from having added exception and closed
// matching alert
cy.get(EMPTY_ALERT_TABLE).should('exist');
// Closed alert should appear in table
goToClosedAlerts();
cy.get(ALERTS_COUNT).should('exist');
cy.get(NUMBER_OF_ALERTS).should('have.text', `${NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS}`);
// Remove the exception and load an event that would have matched that exception
// to show that said exception now starts to show up again
goToExceptionsTab();
// when removing exception and again, no more exist, empty screen shows again
removeException();
cy.get(NO_EXCEPTIONS_EXIST_PROMPT).should('exist');
// load more docs
esArchiverLoad('exceptions_2');
// now that there are no more exceptions, the docs should match and populate alerts
goToAlertsTab();
goToOpenedAlerts();
waitForTheRuleToBeExecuted();
waitForAlertsToPopulate();
cy.get(ALERTS_COUNT).should('exist');
cy.get(NUMBER_OF_ALERTS).should('have.text', '2 alerts');
});
it('Creates an exception item', () => {
goToExceptionsTab();
// when no exceptions exist, empty component shows with action to add exception
cy.get(NO_EXCEPTIONS_EXIST_PROMPT).should('exist');
@ -136,6 +188,7 @@ describe('Add exception using data views from rule details', () => {
const ITEM_FIELD = 'unique_value.test';
const FIELD_DIFFERENT_FROM_EXISTING_ITEM_FIELD = 'agent.name';
goToExceptionsTab();
// add item to edit
addFirstExceptionFromRuleDetails(
{

View file

@ -8,3 +8,5 @@
export const PAGE_TITLE = '[data-test-subj="header-page-title"]';
export const NOT_FOUND = '[data-test-subj="notFoundPage"]';
export const LOADING_SPINNER = '.euiLoadingSpinner';

View file

@ -46,15 +46,14 @@ import {
USER_DETAILS_LINK,
} from '../screens/alerts_details';
import { FIELD_INPUT } from '../screens/exceptions';
import { LOADING_SPINNER } from '../screens/common/page';
export const addExceptionFromFirstAlert = () => {
cy.get(TIMELINE_CONTEXT_MENU_BTN).first().click({ force: true });
cy.root()
.pipe(($el) => {
$el.find(ADD_EXCEPTION_BTN).trigger('click');
return $el.find(FIELD_INPUT);
})
.should('be.visible');
expandFirstAlertActions();
cy.get(ADD_EXCEPTION_BTN, { timeout: 10000 }).should('be.visible');
cy.get(ADD_EXCEPTION_BTN, { timeout: 10000 }).first().click();
cy.get(LOADING_SPINNER).should('exist');
cy.get(LOADING_SPINNER).should('not.exist');
};
export const openAddEndpointExceptionFromFirstAlert = () => {
@ -108,8 +107,8 @@ export const closeAlerts = () => {
};
export const expandFirstAlertActions = () => {
cy.get(TIMELINE_CONTEXT_MENU_BTN).should('be.visible');
cy.get(TIMELINE_CONTEXT_MENU_BTN).first().click({ force: true });
cy.get(TIMELINE_CONTEXT_MENU_BTN, { timeout: 10000 }).should('be.visible');
cy.get(TIMELINE_CONTEXT_MENU_BTN, { timeout: 10000 }).first().click({ force: true });
};
export const expandFirstAlert = () => {

View file

@ -69,12 +69,10 @@ export const editException = (updatedField: string, itemIndex = 0, fieldIndex =
};
export const addExceptionFlyoutItemName = (name: string) => {
cy.root()
.pipe(($el) => {
return $el.find(EXCEPTION_ITEM_NAME_INPUT);
})
.type(`${name}{enter}`)
.should('have.value', name);
cy.get(EXCEPTION_ITEM_NAME_INPUT).should('exist');
cy.get(EXCEPTION_ITEM_NAME_INPUT).should('be.visible');
cy.get(EXCEPTION_ITEM_NAME_INPUT).first().focus();
cy.get(EXCEPTION_ITEM_NAME_INPUT).type(`${name}{enter}`).should('have.value', name);
};
export const editExceptionFlyoutItemName = (name: string) => {
@ -88,6 +86,7 @@ export const editExceptionFlyoutItemName = (name: string) => {
};
export const selectBulkCloseAlerts = () => {
cy.get(CLOSE_ALERTS_CHECKBOX).should('exist');
cy.get(CLOSE_ALERTS_CHECKBOX).click({ force: true });
};

View file

@ -425,7 +425,7 @@ export const AddExceptionFlyoutWrapper: React.FC<AddExceptionFlyoutWrapperProps>
const isLoading =
(isLoadingAlertData && isSignalIndexLoading) ||
enrichedAlert == null ||
memoRuleIndices == null;
(memoRuleIndices == null && memoDataViewId == null);
return (
<AddExceptionFlyout