-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution][Exceptions] - Fixes exceptions builder UI where invalid values can cause overwrites of other values #90634
Merged
Merged
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7a35075
added ids to incoming exception item entries, no ui component changes…
yctercero ec75e51
added code to strip ids from outgoing exception items, no ui componen…
yctercero 76e2f62
made updates to UI portion to now make use of the entry ids
yctercero 2320f62
finicky types, attempting to get types right
yctercero 520a662
Merge branch 'master' of github.com:elastic/kibana into react_keys_ex…
yctercero 6c9d3ec
Merge branch 'master' of github.com:elastic/kibana into react_keys_ex…
yctercero a76e1b2
updating to work with nested
yctercero fe06f3a
Merge branch 'master' of github.com:elastic/kibana into react_keys_ex…
yctercero 5c6b7a8
updated types to remove so many castings
yctercero 65ee43e
finalizing tests
yctercero d640f50
Merge branch 'master' of github.com:elastic/kibana into react_keys_ex…
yctercero d63064b
Merge branch 'master' of github.com:elastic/kibana into react_keys_ex…
yctercero 602cfb6
Merge branch 'master' of github.com:elastic/kibana into react_keys_ex…
yctercero 259fc9d
fixed up tests
yctercero 39933a3
Merge branch 'master' of github.com:elastic/kibana into react_keys_ex…
yctercero a12f211
merged with master and fixed tests
yctercero e679318
cleanup of types
yctercero a4fd2f3
updated to use i18n in one throw
yctercero 7825c7b
updated types to remove casting
yctercero ffb1bd2
Merge branch 'master' of github.com:elastic/kibana into react_keys_ex…
yctercero 3e6e8b6
adding feedback
yctercero 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import { act, renderHook } from '@testing-library/react-hooks'; | ||
|
||
import { ENTRIES_WITH_IDS } from '../../../common/constants.mock'; | ||
import { coreMock } from '../../../../../../src/core/public/mocks'; | ||
import * as api from '../api'; | ||
import { getCreateExceptionListItemSchemaMock } from '../../../common/schemas/request/create_exception_list_item_schema.mock'; | ||
|
@@ -78,12 +79,45 @@ describe('usePersistExceptionItem', () => { | |
>(() => usePersistExceptionItem({ http: mockKibanaHttpService, onError })); | ||
|
||
await waitForNextUpdate(); | ||
result.current[1](getUpdateExceptionListItemSchemaMock()); | ||
// NOTE: Take note here passing in an exception item where it's | ||
// entries have been enriched with ids to ensure that they get stripped | ||
// before the call goes through | ||
result.current[1]({ ...getUpdateExceptionListItemSchemaMock(), entries: ENTRIES_WITH_IDS }); | ||
await waitForNextUpdate(); | ||
|
||
expect(result.current).toEqual([{ isLoading: false, isSaved: true }, result.current[1]]); | ||
expect(addExceptionItem).not.toHaveBeenCalled(); | ||
expect(updateExceptionItem).toHaveBeenCalled(); | ||
expect(updateExceptionItem).toHaveBeenCalledWith({ | ||
http: mockKibanaHttpService, | ||
listItem: getUpdateExceptionListItemSchemaMock(), | ||
signal: new AbortController().signal, | ||
}); | ||
}); | ||
}); | ||
|
||
test('it invokes "addExceptionListItem" when payload has "id"', async () => { | ||
const updateExceptionItem = jest.spyOn(api, 'updateExceptionListItem'); | ||
const createExceptionItem = jest.spyOn(api, 'addExceptionListItem'); | ||
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. The naming here is a little confusing because it's called |
||
await act(async () => { | ||
const { result, waitForNextUpdate } = renderHook< | ||
PersistHookProps, | ||
ReturnPersistExceptionItem | ||
>(() => usePersistExceptionItem({ http: mockKibanaHttpService, onError })); | ||
|
||
await waitForNextUpdate(); | ||
// NOTE: Take note here passing in an exception item where it's | ||
// entries have been enriched with ids to ensure that they get stripped | ||
// before the call goes through | ||
result.current[1]({ ...getCreateExceptionListItemSchemaMock(), entries: ENTRIES_WITH_IDS }); | ||
await waitForNextUpdate(); | ||
|
||
expect(result.current).toEqual([{ isLoading: false, isSaved: true }, result.current[1]]); | ||
expect(updateExceptionItem).not.toHaveBeenCalled(); | ||
expect(createExceptionItem).toHaveBeenCalledWith({ | ||
http: mockKibanaHttpService, | ||
listItem: getCreateExceptionListItemSchemaMock(), | ||
signal: new AbortController().signal, | ||
}); | ||
}); | ||
}); | ||
|
||
|
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
Oops, something went wrong.
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.
Nit, but you could create an
EntryId
to reuse the{ id: string }
pattern that occurs frequently. May not be worth it.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.
fwiw, when I fixed mine id's up, I got the same feedback where the suggestion was I just do a cast and very carefully do the cast in a few areas from @rylnd as the lesser of the evils and only add the extra id in only a few typings and only where I needed it. That felt more right to get past this issue.
I did this type of thing very carefully only where I needed the id:
Everywhere else I left the typings alone. I think @madirey 's suggestions are good as well, it's a bit of a balancing act and your choice in these areas.
Later if we push the id down to the data layer or in the REST routes we can make the id's part of the schema and be ok as well. This all looks good to me here as is though too.
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.
Thanks, yea I could definitely see that it could maybe be cleaned up. I tried to add comments where there were casts to give an explanation of it.
There's a number of refactors that I'd like to do to follow up. If it's ok, I think it could be addressed then?