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] Adds Exception TTL Cypress tests #152626

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -85,7 +85,7 @@ export const ExceptionItemCardMetaInfo = memo<ExceptionItemCardMetaInfoProps>(
</EuiFlexItem>
{item.expire_time != null && (
<>
<EuiFlexItem css={itemCss} grow={false}>
<EuiFlexItem css={itemCss} grow={false} data-test-subj="metaInfoExpireTime">
<MetaInfoDetails
label={
isExpired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
addExceptionEntryOperatorValue,
addExceptionFlyoutItemName,
closeExceptionBuilderFlyout,
editExceptionFlyoutExpireTime,
searchExceptionEntryFieldWithPrefix,
selectCurrentEntryField,
showFieldConflictsWarningTooltipWithMessage,
Expand Down Expand Up @@ -338,6 +339,26 @@ describe('Exceptions flyout', { testIsolation: false }, () => {
showMappingConflictsWarningMessage(warningMessage);
});

it('Validates expire time field correctly', () => {
// open add exception modal
openExceptionFlyoutFromEmptyViewerPrompt();

// add exception item name
addExceptionFlyoutItemName('My item name');

// add an entry with a value and submit button should enable
addExceptionEntryFieldValue('agent.name', 0);
addExceptionEntryFieldValueValue('test', 0);

// set an expiration date in the past
editExceptionFlyoutExpireTime(new Date(Date.now() - 1000000).toISOString());
cy.get(CONFIRM_BTN).should('be.disabled');

// set an expiration date in the future
editExceptionFlyoutExpireTime(new Date(Date.now() + 1000000).toISOString());
cy.get(CONFIRM_BTN).should('be.enabled');
});

// TODO - Add back in error states into modal
describe.skip('flyout errors', () => {
beforeEach(() => {
Expand All @@ -358,6 +379,7 @@ describe('Exceptions flyout', { testIsolation: false }, () => {
value: ['some host', 'another host'],
},
],
expire_time: undefined,
});

reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import {
addExceptionConditions,
addExceptionFlyoutItemName,
clearExceptionFlyoutExpireTime,
editException,
editExceptionFlyoutItemName,
selectAddToRuleRadio,
Expand All @@ -56,6 +57,7 @@ import {
EXCEPTION_CARD_ITEM_NAME,
EXCEPTION_CARD_ITEM_CONDITIONS,
FIELD_INPUT_PARENT,
EXCEPTION_CARD_ITEM_META_INFO,
} from '../../../screens/exceptions';
import {
createExceptionList,
Expand Down Expand Up @@ -116,6 +118,7 @@ describe('Add/edit exception from rule details', () => {
value: ['foo'],
},
],
expire_time: new Date(Date.now() + 1000000).toISOString(),
});
});

Expand All @@ -133,6 +136,7 @@ describe('Add/edit exception from rule details', () => {
cy.get(NO_EXCEPTIONS_EXIST_PROMPT).should('not.exist');
cy.get(EXCEPTION_CARD_ITEM_NAME).should('have.text', ITEM_NAME);
cy.get(EXCEPTION_CARD_ITEM_CONDITIONS).should('have.text', ' unique_value.testis one of foo');
cy.get(EXCEPTION_CARD_ITEM_META_INFO).should('exist');

// open edit exception modal
openEditException();
Expand All @@ -150,6 +154,7 @@ describe('Add/edit exception from rule details', () => {

// edit conditions
editException(FIELD_DIFFERENT_FROM_EXISTING_ITEM_FIELD, 0, 0);
clearExceptionFlyoutExpireTime();

// submit
submitEditedExceptionItem();
Expand All @@ -160,6 +165,7 @@ describe('Add/edit exception from rule details', () => {
// check that updates stuck
cy.get(EXCEPTION_CARD_ITEM_NAME).should('have.text', NEW_ITEM_NAME);
cy.get(EXCEPTION_CARD_ITEM_CONDITIONS).should('have.text', ' agent.nameIS foo');
cy.get(EXCEPTION_CARD_ITEM_META_INFO).should('not.exist');
});

describe('rule with existing shared exceptions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('Exceptions viewer read only', () => {
value: ['bar'],
},
],
expire_time: undefined,
});

goToAlertsTab();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ExceptionListItem {
tags: string[];
type: 'simple';
entries: Array<{ field: string; operator: string; type: string; value: string[] }>;
expire_time: string | undefined;
}

export const getExceptionList = (): ExceptionList => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export const EXCEPTION_CARD_ITEM_NAME = '[data-test-subj="exceptionItemCardHeade
export const EXCEPTION_CARD_ITEM_CONDITIONS =
'[data-test-subj="exceptionItemCardConditions-condition"]';

export const EXCEPTION_CARD_ITEM_META_INFO =
'[data-test-subj="exceptionItemCardMetaInfo-expireTime-value1"]';

// Exception flyout components
export const EXCEPTION_ITEM_NAME_INPUT = 'input[data-test-subj="exceptionFlyoutNameInput"]';

Expand All @@ -128,6 +131,9 @@ export const OS_SELECTION_SECTION = '[data-test-subj="osSelectionDropdown"]';

export const OS_INPUT = '[data-test-subj="osSelectionDropdown"] [data-test-subj="comboBoxInput"]';

export const EXCEPTION_ITEM_EXPIRE_TIME_INPUT =
'[data-test-subj="exceptionExpireTimeInputRow"] input.euiDatePicker';

// Shared Exception List Management Page
export const MANAGE_EXCEPTION_CREATE_BUTTON_MENU =
'[data-test-subj="manageExceptionListCreateButton"]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const createExceptionListItem = (
value: ['some host', 'another host'],
},
],
expire_time: exceptionListItem?.expire_time,
},
headers: { 'kbn-xsrf': 'cypress-creds' },
failOnStatusCode: false,
Expand Down
20 changes: 20 additions & 0 deletions x-pack/plugins/security_solution/cypress/tasks/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import moment from 'moment';
import type { Exception } from '../objects/exception';
import {
FIELD_INPUT,
Expand All @@ -24,6 +25,7 @@ import {
SHARED_LIST_SWITCH,
OS_SELECTION_SECTION,
OS_INPUT,
EXCEPTION_ITEM_EXPIRE_TIME_INPUT,
EXCEPTION_FIELD_MAPPING_CONFLICTS_ICON,
EXCEPTION_FIELD_MAPPING_CONFLICTS_TOOLTIP,
EXCEPTION_FIELD_MAPPING_CONFLICTS_ACCORDION_ICON,
Expand Down Expand Up @@ -117,6 +119,24 @@ export const editExceptionFlyoutItemName = (name: string) => {
.should('have.value', name);
};

export const editExceptionFlyoutExpireTime = (date: string) => {
const formattedDate = moment(new Date(date).toISOString()).format('MM DD YYYY hh:mm a');
cy.root()
.pipe(($el) => {
return $el.find(EXCEPTION_ITEM_EXPIRE_TIME_INPUT);
})
.clear()
.type(`${formattedDate}{enter}`);
};

export const clearExceptionFlyoutExpireTime = () => {
cy.root()
.pipe(($el) => {
return $el.find(EXCEPTION_ITEM_EXPIRE_TIME_INPUT);
})
.clear();
};

export const selectBulkCloseAlerts = () => {
cy.get(CLOSE_ALERTS_CHECKBOX).should('exist');
cy.get(CLOSE_ALERTS_CHECKBOX).click({ force: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ const ExceptionItemExpireTime: React.FC<ExceptionItmeExpireTimeProps> = ({
<h3>{i18n.EXCEPTION_EXPIRE_TIME_HEADER}</h3>
</SectionHeader>
<EuiSpacer size="s" />
<EuiFormRow error={errors} isInvalid={isInvalid} label={i18n.EXPIRE_TIME_LABEL}>
<EuiFormRow
data-test-subj="exceptionExpireTimeInputRow"
error={errors}
isInvalid={isInvalid}
label={i18n.EXPIRE_TIME_LABEL}
>
<EuiDatePicker
placeholder="Select an expiration date"
showTimeSelect
selected={dateTime}
isInvalid={isInvalid}
Expand Down