Skip to content

Commit

Permalink
Do not change the status when sync is off
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Mar 10, 2022
1 parent bc82a8c commit 4565d38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 3 additions & 1 deletion x-pack/plugins/cases/server/client/cases/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ export const push = async (
owner: myCase.attributes.owner,
});

await changeAlertsStatusToClose(myCase.id, caseService, alertsService);
if (myCase.attributes.settings.syncAlerts) {
await changeAlertsStatusToClose(myCase.id, caseService, alertsService);
}
}

await userActionService.createUserAction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ export default ({ getService }: FtrProviderContext): void => {

describe('alerts', () => {
const defaultSignalsIndex = '.siem-signals-default-000001';
const signalID = '4679431ee0ba3209b6fcd60a255a696886fe0a7d18f5375de510ff5b68fa6b78';
const signalID2 = '1023bcfea939643c5e51fd8df53797e0ea693cee547db579ab56d96402365c1e';

beforeEach(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/signals/default');
Expand All @@ -313,11 +315,9 @@ export default ({ getService }: FtrProviderContext): void => {
await deleteAllCaseItems(es);
});

it('should change the status of all alerts attached to a case to close when closure_type: close-by-pushing', async () => {
const signalID = '4679431ee0ba3209b6fcd60a255a696886fe0a7d18f5375de510ff5b68fa6b78';
const signalID2 = '1023bcfea939643c5e51fd8df53797e0ea693cee547db579ab56d96402365c1e';

const attachAlertsAndPush = async ({ syncAlerts = true }: { syncAlerts?: boolean } = {}) => {
const { postedCase, connector } = await createCaseWithConnector({
createCaseReq: { ...getPostCaseRequest(), settings: { syncAlerts } },
configureReq: {
closure_type: 'close-by-pushing',
},
Expand Down Expand Up @@ -364,6 +364,11 @@ export default ({ getService }: FtrProviderContext): void => {
ids: [signalID, signalID2],
});

return signals;
};

it('should change the status of all alerts attached to a case to close when closure_type: close-by-pushing and syncAlerts: true', async () => {
const signals = await attachAlertsAndPush();
/**
* The status of the alerts should be changed to closed when pushing a case and the
* closure_type is set to close-by-pushing
Expand All @@ -376,6 +381,21 @@ export default ({ getService }: FtrProviderContext): void => {
CaseStatuses.closed
);
});

it('should NOT change the status of all alerts attached to a case to close when closure_type: close-by-pushing and syncAlerts: false', async () => {
const signals = await attachAlertsAndPush({ syncAlerts: false });
/**
* The status of the alerts should NOT be changed to closed when pushing a case and the
* closure_type is set to close-by-pushing and syncAlert is set to false
*/
expect(signals.get(defaultSignalsIndex)?.get(signalID)?._source?.signal?.status).to.be(
CaseStatuses.open
);

expect(signals.get(defaultSignalsIndex)?.get(signalID2)?._source?.signal?.status).to.be(
CaseStatuses.open
);
});
});

describe('rbac', () => {
Expand Down

0 comments on commit 4565d38

Please sign in to comment.