Skip to content

Commit

Permalink
[CTI] Filters alerts table by presence of threat (elastic/security-te…
Browse files Browse the repository at this point in the history
…am#907) (elastic#96096)

[CTI] Filters alerts table by presence of threat (elastic/security-team#907)
  • Loading branch information
ecezalp committed Apr 12, 2021
1 parent bb6904b commit befe374
Show file tree
Hide file tree
Showing 9 changed files with 406 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ describe('AlertsUtilityBar', () => {
test('renders correctly', () => {
const wrapper = shallow(
<AlertsUtilityBar
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
onShowBuildingBlockAlertsChanged={jest.fn()}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
);
Expand All @@ -41,17 +43,19 @@ describe('AlertsUtilityBar', () => {
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={false} // Does not show showBuildingBlockAlerts checked if this is false
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
Expand All @@ -72,22 +76,61 @@ describe('AlertsUtilityBar', () => {
).toEqual(false);
});

test('does not show the showOnlyThreatIndicatorAlerts checked if the showThreatMatchOnly is false', () => {
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
areEventsLoading={false}
clearSelection={jest.fn()}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
selectedEventIds={{}}
showBuildingBlockAlerts={false} // Does not show showBuildingBlockAlerts checked if this is false
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
);
// click the filters button to popup the checkbox to make it visible
wrapper
.find('[data-test-subj="additionalFilters"] button')
.first()
.simulate('click')
.update();

// The check box should be false
expect(
wrapper
.find('[data-test-subj="showOnlyThreatIndicatorAlertsCheckbox"] input')
.first()
.prop('checked')
).toEqual(false);
});

test('does show the showBuildingBlockAlerts checked if the showBuildingBlockAlerts is true', () => {
const onShowBuildingBlockAlertsChanged = jest.fn();
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={true} // Does show showBuildingBlockAlerts checked if this is true
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
Expand All @@ -108,22 +151,61 @@ describe('AlertsUtilityBar', () => {
).toEqual(true);
});

test('does show the showOnlyThreatIndicatorAlerts checked if the showOnlyThreatIndicatorAlerts is true', () => {
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
areEventsLoading={false}
clearSelection={jest.fn()}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
selectedEventIds={{}}
showBuildingBlockAlerts={true} // Does show showBuildingBlockAlerts checked if this is true
showClearSelection={true}
showOnlyThreatIndicatorAlerts={true}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
);
// click the filters button to popup the checkbox to make it visible
wrapper
.find('[data-test-subj="additionalFilters"] button')
.first()
.simulate('click')
.update();

// The check box should be true
expect(
wrapper
.find('[data-test-subj="showOnlyThreatIndicatorAlertsCheckbox"] input')
.first()
.prop('checked')
).toEqual(true);
});

test('calls the onShowBuildingBlockAlertsChanged when the check box is clicked', () => {
const onShowBuildingBlockAlertsChanged = jest.fn();
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChanged}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
Expand All @@ -145,39 +227,82 @@ describe('AlertsUtilityBar', () => {
expect(onShowBuildingBlockAlertsChanged).toHaveBeenCalled();
});

test('calls the onShowOnlyThreatIndicatorAlertsChanged when the check box is clicked', () => {
const onShowOnlyThreatIndicatorAlertsChanged = jest.fn();
const wrapper = mount(
<TestProviders>
<AlertsUtilityBar
areEventsLoading={false}
clearSelection={jest.fn()}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={onShowOnlyThreatIndicatorAlertsChanged}
selectAll={jest.fn()}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
);
// click the filters button to popup the checkbox to make it visible
wrapper
.find('[data-test-subj="additionalFilters"] button')
.first()
.simulate('click')
.update();

// check the box
wrapper
.find('[data-test-subj="showOnlyThreatIndicatorAlertsCheckbox"] input')
.first()
.simulate('change', { target: { checked: true } });

// Make sure our callback is called
expect(onShowOnlyThreatIndicatorAlertsChanged).toHaveBeenCalled();
});

test('can update showBuildingBlockAlerts from false to true', () => {
const Proxy = (props: AlertsUtilityBarProps) => (
<TestProviders>
<AlertsUtilityBar
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={props.showBuildingBlockAlerts}
onShowBuildingBlockAlertsChanged={jest.fn()}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
);

const wrapper = mount(
<Proxy
hasIndexWrite={true}
hasIndexMaintenance={true}
areEventsLoading={false}
clearSelection={jest.fn()}
totalCount={100}
selectedEventIds={{}}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
showClearSelection={true}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
onShowBuildingBlockAlertsChanged={jest.fn()}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
);
Expand Down Expand Up @@ -214,5 +339,79 @@ describe('AlertsUtilityBar', () => {
.prop('checked')
).toEqual(true);
});

test('can update showOnlyThreatIndicatorAlerts from false to true', () => {
const Proxy = (props: AlertsUtilityBarProps) => (
<TestProviders>
<AlertsUtilityBar
areEventsLoading={false}
clearSelection={jest.fn()}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={props.showOnlyThreatIndicatorAlerts}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
</TestProviders>
);

const wrapper = mount(
<Proxy
areEventsLoading={false}
clearSelection={jest.fn()}
currentFilter="closed"
hasIndexMaintenance={true}
hasIndexWrite={true}
onShowBuildingBlockAlertsChanged={jest.fn()}
onShowOnlyThreatIndicatorAlertsChanged={jest.fn()}
selectAll={jest.fn()}
selectedEventIds={{}}
showBuildingBlockAlerts={false}
showClearSelection={true}
showOnlyThreatIndicatorAlerts={false}
totalCount={100}
updateAlertsStatus={jest.fn()}
/>
);
// click the filters button to popup the checkbox to make it visible
wrapper
.find('[data-test-subj="additionalFilters"] button')
.first()
.simulate('click')
.update();

// The check box should false now since we initially set the showBuildingBlockAlerts to false
expect(
wrapper
.find('[data-test-subj="showOnlyThreatIndicatorAlertsCheckbox"] input')
.first()
.prop('checked')
).toEqual(false);

wrapper.setProps({ showOnlyThreatIndicatorAlerts: true });
wrapper.update();

// click the filters button to popup the checkbox to make it visible
wrapper
.find('[data-test-subj="additionalFilters"] button')
.first()
.simulate('click')
.update();

// The check box should be true now since we changed the showBuildingBlockAlerts from false to true
expect(
wrapper
.find('[data-test-subj="showOnlyThreatIndicatorAlertsCheckbox"] input')
.first()
.prop('checked')
).toEqual(true);
});
});
});
Loading

0 comments on commit befe374

Please sign in to comment.