-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Security Solution][Exceptions] - Update exception item comments to include id #73129
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
6 commits
Select commit
Hold shift + click to select a range
a7767a9
updated comments to include id
yctercero 259f511
Merge branch 'master' of github.com:yctercero/kibana into comments_again
yctercero 4be6378
cleanup
yctercero 72f5e0a
Merge branch 'master' of github.com:yctercero/kibana into comments_again
yctercero 4095c23
fixed validation issues for comments, made append only
yctercero 3cfa536
Merge branch 'master' of github.com:yctercero/kibana into comments_again
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 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
43 changes: 43 additions & 0 deletions
43
x-pack/plugins/lists/common/schemas/request/update_exception_list_item_validation.test.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,43 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { getUpdateExceptionListItemSchemaMock } from './update_exception_list_item_schema.mock'; | ||
| import { validateComments } from './update_exception_list_item_validation'; | ||
|
|
||
| describe('update_exception_list_item_validation', () => { | ||
| describe('#validateComments', () => { | ||
| test('it returns no errors if comments is undefined', () => { | ||
| const payload = getUpdateExceptionListItemSchemaMock(); | ||
| delete payload.comments; | ||
| const output = validateComments(payload); | ||
|
|
||
| expect(output).toEqual([]); | ||
| }); | ||
|
|
||
| test('it returns no errors if new comments are append only', () => { | ||
| const payload = getUpdateExceptionListItemSchemaMock(); | ||
| payload.comments = [ | ||
| { comment: 'Im an old comment', id: '1' }, | ||
| { comment: 'Im a new comment' }, | ||
| ]; | ||
| const output = validateComments(payload); | ||
|
|
||
| expect(output).toEqual([]); | ||
| }); | ||
|
|
||
| test('it returns error if comments are not append only', () => { | ||
| const payload = getUpdateExceptionListItemSchemaMock(); | ||
| payload.comments = [ | ||
| { comment: 'Im an old comment', id: '1' }, | ||
| { comment: 'Im a new comment modifying the order of existing comments' }, | ||
| { comment: 'Im an old comment', id: '2' }, | ||
| ]; | ||
| const output = validateComments(payload); | ||
|
|
||
| expect(output).toEqual(['item "comments" are append only']); | ||
| }); | ||
| }); | ||
| }); |
40 changes: 40 additions & 0 deletions
40
x-pack/plugins/lists/common/schemas/request/update_exception_list_item_validation.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,40 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { UpdateExceptionListItemSchema } from './update_exception_list_item_schema'; | ||
|
|
||
| export const validateComments = (item: UpdateExceptionListItemSchema): string[] => { | ||
| if (item.comments == null) { | ||
| return []; | ||
| } | ||
|
|
||
| const [appendOnly] = item.comments.reduce( | ||
| (acc, comment) => { | ||
| const [, hasNewComments] = acc; | ||
| if (comment.id == null) { | ||
| return [true, true]; | ||
| } | ||
|
|
||
| if (hasNewComments && comment.id != null) { | ||
| return [false, true]; | ||
| } | ||
|
|
||
| return acc; | ||
| }, | ||
| [true, false] | ||
| ); | ||
| if (!appendOnly) { | ||
| return ['item "comments" are append only']; | ||
| } else { | ||
| return []; | ||
| } | ||
| }; | ||
|
|
||
| export const updateExceptionListItemValidate = ( | ||
| schema: UpdateExceptionListItemSchema | ||
| ): string[] => { | ||
| return [...validateComments(schema)]; | ||
| }; |
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.
@rylnd you'd mentioned the wording
not validatewas a bit misleading, so began updating the wording. Does this seem better?