-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Investigations] - Disable adding notes when read …
…only (#133905) (#134964) Co-authored-by: Kibana Machine <[email protected]> (cherry picked from commit b41bc66) Co-authored-by: Michael Olorunnisola <[email protected]>
- Loading branch information
1 parent
9ee96d7
commit 6824d89
Showing
9 changed files
with
196 additions
and
21 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...ty_solution/public/timelines/components/timeline/body/actions/add_note_icon_item.test.tsx
This file contains 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,68 @@ | ||
/* | ||
* 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 { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { AddEventNoteAction } from './add_note_icon_item'; | ||
import { useUserPrivileges } from '../../../../../common/components/user_privileges'; | ||
import { getEndpointPrivilegesInitialStateMock } from '../../../../../common/components/user_privileges/endpoint/mocks'; | ||
import { TestProviders } from '../../../../../common/mock'; | ||
import { TimelineType } from '../../../../../../common/types'; | ||
|
||
jest.mock('../../../../../common/components/user_privileges'); | ||
const useUserPrivilegesMock = useUserPrivileges as jest.Mock; | ||
|
||
describe('AddEventNoteAction', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('isDisabled', () => { | ||
test('it disables the add note button when the user does NOT have crud privileges', () => { | ||
useUserPrivilegesMock.mockReturnValue({ | ||
kibanaSecuritySolutionsPrivileges: { crud: false, read: true }, | ||
endpointPrivileges: getEndpointPrivilegesInitialStateMock(), | ||
}); | ||
|
||
render( | ||
<TestProviders> | ||
<AddEventNoteAction | ||
showNotes={false} | ||
timelineType={TimelineType.default} | ||
toggleShowNotes={jest.fn} | ||
/> | ||
</TestProviders> | ||
); | ||
|
||
expect(screen.getByTestId('timeline-notes-button-small')).toHaveClass( | ||
'euiButtonIcon-isDisabled' | ||
); | ||
}); | ||
|
||
test('it enables the add note button when the user has crud privileges', () => { | ||
useUserPrivilegesMock.mockReturnValue({ | ||
kibanaSecuritySolutionsPrivileges: { crud: true, read: true }, | ||
endpointPrivileges: getEndpointPrivilegesInitialStateMock(), | ||
}); | ||
|
||
render( | ||
<TestProviders> | ||
<AddEventNoteAction | ||
showNotes={false} | ||
timelineType={TimelineType.default} | ||
toggleShowNotes={jest.fn} | ||
/> | ||
</TestProviders> | ||
); | ||
|
||
expect(screen.getByTestId('timeline-notes-button-small')).not.toHaveClass( | ||
'euiButtonIcon-isDisabled' | ||
); | ||
}); | ||
}); | ||
}); |
This file contains 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
68 changes: 68 additions & 0 deletions
68
...rity_solution/public/timelines/components/timeline/body/actions/pin_event_action.test.tsx
This file contains 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,68 @@ | ||
/* | ||
* 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 { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { PinEventAction } from './pin_event_action'; | ||
import { useUserPrivileges } from '../../../../../common/components/user_privileges'; | ||
import { getEndpointPrivilegesInitialStateMock } from '../../../../../common/components/user_privileges/endpoint/mocks'; | ||
import { TestProviders } from '../../../../../common/mock'; | ||
import { TimelineType } from '../../../../../../common/types'; | ||
|
||
jest.mock('../../../../../common/components/user_privileges'); | ||
const useUserPrivilegesMock = useUserPrivileges as jest.Mock; | ||
|
||
describe('PinEventAction', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('isDisabled', () => { | ||
test('it disables the pin event button when the user does NOT have crud privileges', () => { | ||
useUserPrivilegesMock.mockReturnValue({ | ||
kibanaSecuritySolutionsPrivileges: { crud: false, read: true }, | ||
endpointPrivileges: getEndpointPrivilegesInitialStateMock(), | ||
}); | ||
|
||
render( | ||
<TestProviders> | ||
<PinEventAction | ||
isAlert={false} | ||
noteIds={[]} | ||
onPinClicked={jest.fn} | ||
eventIsPinned={false} | ||
timelineType={TimelineType.default} | ||
/> | ||
</TestProviders> | ||
); | ||
|
||
expect(screen.getByTestId('pin')).toHaveClass('euiButtonIcon-isDisabled'); | ||
}); | ||
|
||
test('it enables the pin event button when the user has crud privileges', () => { | ||
useUserPrivilegesMock.mockReturnValue({ | ||
kibanaSecuritySolutionsPrivileges: { crud: true, read: true }, | ||
endpointPrivileges: getEndpointPrivilegesInitialStateMock(), | ||
}); | ||
|
||
render( | ||
<TestProviders> | ||
<PinEventAction | ||
isAlert={false} | ||
noteIds={[]} | ||
onPinClicked={jest.fn} | ||
eventIsPinned={false} | ||
timelineType={TimelineType.default} | ||
/> | ||
</TestProviders> | ||
); | ||
|
||
expect(screen.getByTestId('pin')).not.toHaveClass('euiButtonIcon-isDisabled'); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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 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 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 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