-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[SecuritySolution][Case] Disable cases on detections in read-only mode #93010
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
x-pack/plugins/security_solution/cypress/integration/detection_alerts/attach_to_case.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { newRule } from '../../objects/rule'; | ||
| import { ROLES } from '../../../common/test'; | ||
|
|
||
| import { waitForAlertsIndexToBeCreated, waitForAlertsPanelToBeLoaded } from '../../tasks/alerts'; | ||
| import { createCustomRuleActivated } from '../../tasks/api_calls/rules'; | ||
| import { cleanKibana } from '../../tasks/common'; | ||
| import { waitForAlertsToPopulate } from '../../tasks/create_new_rule'; | ||
| import { login, loginAndWaitForPage, waitForPageWithoutDateRange } from '../../tasks/login'; | ||
| import { refreshPage } from '../../tasks/security_header'; | ||
|
|
||
| import { DETECTIONS_URL } from '../../urls/navigation'; | ||
| import { ATTACH_ALERT_TO_CASE_BUTTON } from '../../screens/alerts_detection_rules'; | ||
|
|
||
| const loadDetectionsPage = (role: ROLES) => { | ||
| waitForPageWithoutDateRange(DETECTIONS_URL, role); | ||
| waitForAlertsToPopulate(); | ||
| }; | ||
|
|
||
| describe('Alerts timeline', () => { | ||
| before(() => { | ||
| // First we login as a privileged user to create alerts. | ||
| cleanKibana(); | ||
| loginAndWaitForPage(DETECTIONS_URL, ROLES.platform_engineer); | ||
| waitForAlertsPanelToBeLoaded(); | ||
| waitForAlertsIndexToBeCreated(); | ||
| createCustomRuleActivated(newRule); | ||
| refreshPage(); | ||
| waitForAlertsToPopulate(); | ||
|
|
||
| // Then we login as read-only user to test. | ||
| login(ROLES.reader); | ||
| }); | ||
|
|
||
| context('Privileges: read only', () => { | ||
| beforeEach(() => { | ||
| loadDetectionsPage(ROLES.reader); | ||
| }); | ||
|
|
||
| it('should not allow user with read only privileges to attach alerts to cases', () => { | ||
| cy.get(ATTACH_ALERT_TO_CASE_BUTTON).first().should('be.disabled'); | ||
| }); | ||
| }); | ||
|
|
||
| context('Privileges: can crud', () => { | ||
| beforeEach(() => { | ||
| loadDetectionsPage(ROLES.platform_engineer); | ||
| }); | ||
|
|
||
| it('should allow a user with crud privileges to attach alerts to cases', () => { | ||
| cy.get(ATTACH_ALERT_TO_CASE_BUTTON).first().should('not.be.disabled'); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import React, { ReactNode } from 'react'; | |
| import { mount } from 'enzyme'; | ||
| import { EuiGlobalToastList } from '@elastic/eui'; | ||
|
|
||
| import { useKibana } from '../../../common/lib/kibana'; | ||
| import { useKibana, useGetUserSavedObjectPermissions } from '../../../common/lib/kibana'; | ||
| import { useStateToaster } from '../../../common/components/toasters'; | ||
| import { TestProviders } from '../../../common/mock'; | ||
| import { usePostComment } from '../../containers/use_post_comment'; | ||
|
|
@@ -113,8 +113,8 @@ describe('AddToCaseAction', () => { | |
| ecsRowData: { | ||
| _id: 'test-id', | ||
| _index: 'test-index', | ||
| signal: { rule: { id: ['rule-id'], name: ['rule-name'], false_positives: [] } }, | ||
| }, | ||
| disabled: false, | ||
| }; | ||
|
|
||
| const mockDispatchToaster = jest.fn(); | ||
|
|
@@ -127,6 +127,10 @@ describe('AddToCaseAction', () => { | |
| (useKibana as jest.Mock).mockReturnValue({ | ||
| services: { application: { navigateToApp: mockNavigateToApp } }, | ||
| }); | ||
| (useGetUserSavedObjectPermissions as jest.Mock).mockReturnValue({ | ||
| crud: true, | ||
| read: true, | ||
| }); | ||
| }); | ||
|
|
||
| it('it renders', async () => { | ||
|
|
@@ -181,8 +185,8 @@ describe('AddToCaseAction', () => { | |
| alertId: 'test-id', | ||
| index: 'test-index', | ||
| rule: { | ||
| id: null, | ||
| name: null, | ||
| id: 'rule-id', | ||
| name: 'rule-name', | ||
| }, | ||
| type: 'alert', | ||
| }); | ||
|
|
@@ -218,7 +222,38 @@ describe('AddToCaseAction', () => { | |
| alertId: 'test-id', | ||
| index: 'test-index', | ||
| rule: { | ||
| id: null, | ||
| id: 'rule-id', | ||
| name: 'rule-name', | ||
| }, | ||
| type: 'alert', | ||
| }); | ||
| }); | ||
|
|
||
| it('it set rule information as null when missing', async () => { | ||
| const wrapper = mount( | ||
| <TestProviders> | ||
| <AddToCaseAction | ||
| {...props} | ||
| ecsRowData={{ | ||
| _id: 'test-id', | ||
| _index: 'test-index', | ||
| signal: { rule: { id: ['rule-id'], false_positives: [] } }, | ||
| }} | ||
| /> | ||
| </TestProviders> | ||
| ); | ||
|
|
||
| wrapper.find(`[data-test-subj="attach-alert-to-case-button"]`).first().simulate('click'); | ||
| wrapper.find(`[data-test-subj="add-new-case-item"]`).first().simulate('click'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: You don't need to interpolate here, you can just use |
||
|
|
||
| wrapper.find(`[data-test-subj="form-context-on-success"]`).first().simulate('click'); | ||
|
|
||
| expect(postComment.mock.calls[0][0].caseId).toBe('new-case'); | ||
| expect(postComment.mock.calls[0][0].data).toEqual({ | ||
| alertId: 'test-id', | ||
| index: 'test-index', | ||
| rule: { | ||
| id: 'rule-id', | ||
| name: null, | ||
| }, | ||
| type: 'alert', | ||
|
|
@@ -291,4 +326,39 @@ describe('AddToCaseAction', () => { | |
| path: '/selected-case', | ||
| }); | ||
| }); | ||
|
|
||
| it('disabled when event type is not supported', async () => { | ||
| const wrapper = mount( | ||
| <TestProviders> | ||
| <AddToCaseAction | ||
| {...props} | ||
| ecsRowData={{ | ||
| _id: 'test-id', | ||
| _index: 'test-index', | ||
| }} | ||
| /> | ||
| </TestProviders> | ||
| ); | ||
|
|
||
| expect( | ||
| wrapper.find(`[data-test-subj="attach-alert-to-case-button"]`).first().prop('disabled') | ||
| ).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('disabled when user does not have crud permissions', async () => { | ||
| (useGetUserSavedObjectPermissions as jest.Mock).mockReturnValue({ | ||
| crud: false, | ||
| read: true, | ||
| }); | ||
|
|
||
| const wrapper = mount( | ||
| <TestProviders> | ||
| <AddToCaseAction {...props} /> | ||
| </TestProviders> | ||
| ); | ||
|
|
||
| expect( | ||
| wrapper.find(`[data-test-subj="attach-alert-to-case-button"]`).first().prop('disabled') | ||
| ).toBeTruthy(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine so far. The suggestion with permissions for e2e tests we have been making to each other is that we have 1 test which shows it being disabled for one role and then a second test which shows it being enabled for 1 more role.
This way if someone breaks the code so that it is disabled for all roles we can catch it.