Skip to content

Commit

Permalink
[Security Solution] Fixes manage alerts permissions on Detections ale…
Browse files Browse the repository at this point in the history
…rts page (#126537)

Co-authored-by: Garrett Spong <[email protected]>
  • Loading branch information
dplumlee and spong authored Mar 10, 2022
1 parent 8cd75df commit affbed7
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { ROLES } from '../../../common/test';
import { getNewRule } from '../../objects/rule';
import {
ALERTS_COUNT,
Expand Down Expand Up @@ -63,3 +64,41 @@ describe('Marking alerts as acknowledged', () => {
});
});
});

describe('Marking alerts as acknowledged with read only role', () => {
beforeEach(() => {
cleanKibana();
loginAndWaitForPage(ALERTS_URL, ROLES.t2_analyst);
createCustomRuleEnabled(getNewRule());
refreshPage();
waitForAlertsToPopulate(100);
});

it('Mark one alert as acknowledged when more than one open alerts are selected', () => {
cy.get(ALERTS_COUNT)
.invoke('text')
.then((alertNumberString) => {
const numberOfAlerts = alertNumberString.split(' ')[0];
const numberOfAlertsToBeMarkedAcknowledged = 1;
const numberOfAlertsToBeSelected = 3;

cy.get(TAKE_ACTION_POPOVER_BTN).should('not.exist');
selectNumberOfAlerts(numberOfAlertsToBeSelected);
cy.get(TAKE_ACTION_POPOVER_BTN).should('exist');

markAcknowledgedFirstAlert();
const expectedNumberOfAlerts = +numberOfAlerts - numberOfAlertsToBeMarkedAcknowledged;
cy.get(ALERTS_COUNT).should('have.text', `${expectedNumberOfAlerts} alerts`);
cy.get(ALERT_COUNT_TABLE_FIRST_ROW_COUNT).should('have.text', `${expectedNumberOfAlerts}`);

goToAcknowledgedAlerts();
waitForAlerts();

cy.get(ALERTS_COUNT).should('have.text', `${numberOfAlertsToBeMarkedAcknowledged} alert`);
cy.get(ALERT_COUNT_TABLE_FIRST_ROW_COUNT).should(
'have.text',
`${numberOfAlertsToBeMarkedAcknowledged}`
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { getNewRule } from '../../objects/rule';
import { ROLES } from '../../../common/test';
import {
ALERTS_COUNT,
SELECTED_ALERTS,
Expand Down Expand Up @@ -174,3 +175,44 @@ describe('Closing alerts', () => {
});
});
});

describe('Closing alerts with read only role', () => {
beforeEach(() => {
cleanKibana();
loginAndWaitForPage(ALERTS_URL, ROLES.t2_analyst);
createCustomRuleEnabled(getNewRule(), '1', '100m', 100);
refreshPage();
waitForAlertsToPopulate(100);
deleteCustomRule();
});

it('Closes alerts', () => {
const numberOfAlertsToBeClosed = 3;
cy.get(ALERTS_COUNT)
.invoke('text')
.then((alertNumberString) => {
const numberOfAlerts = alertNumberString.split(' ')[0];
cy.get(ALERTS_COUNT).should('have.text', `${numberOfAlerts} alerts`);
cy.get(ALERT_COUNT_TABLE_FIRST_ROW_COUNT).should('have.text', `${numberOfAlerts}`);

selectNumberOfAlerts(numberOfAlertsToBeClosed);

cy.get(SELECTED_ALERTS).should('have.text', `Selected ${numberOfAlertsToBeClosed} alerts`);

closeAlerts();
waitForAlerts();

const expectedNumberOfAlertsAfterClosing = +numberOfAlerts - numberOfAlertsToBeClosed;
cy.get(ALERTS_COUNT).should('have.text', `${expectedNumberOfAlertsAfterClosing} alerts`);
cy.get(ALERT_COUNT_TABLE_FIRST_ROW_COUNT).should(
'have.text',
`${expectedNumberOfAlertsAfterClosing}`
);

goToClosedAlerts();
waitForAlerts();

cy.get(ALERTS_COUNT).should('have.text', `${numberOfAlertsToBeClosed} alerts`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useAlertsActions = ({
refetch,
}: Props) => {
const dispatch = useDispatch();
const { hasIndexWrite, hasKibanaCRUD } = useAlertsPrivileges();
const { hasIndexWrite } = useAlertsPrivileges();

const onStatusUpdate = useCallback(() => {
closePopover();
Expand Down Expand Up @@ -66,6 +66,6 @@ export const useAlertsActions = ({
});

return {
actionItems: hasIndexWrite && hasKibanaCRUD ? actionItems : [],
actionItems: hasIndexWrite ? actionItems : [],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ const DetectionEnginePageComponent: React.FC<DetectionEngineComponentProps> = ({
signalIndexName,
hasIndexWrite = false,
hasIndexMaintenance = false,
canUserCRUD = false,
canUserREAD,
hasIndexRead,
},
Expand Down Expand Up @@ -376,8 +375,8 @@ const DetectionEnginePageComponent: React.FC<DetectionEngineComponentProps> = ({
<AlertsTable
timelineId={TimelineId.detectionsPage}
loading={loading}
hasIndexWrite={(hasIndexWrite ?? false) && (canUserCRUD ?? false)}
hasIndexMaintenance={(hasIndexMaintenance ?? false) && (canUserCRUD ?? false)}
hasIndexWrite={hasIndexWrite ?? false}
hasIndexMaintenance={hasIndexMaintenance ?? false}
from={from}
defaultFilters={alertsTableDefaultFilters}
showBuildingBlockAlerts={showBuildingBlockAlerts}
Expand Down

0 comments on commit affbed7

Please sign in to comment.