-
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.
[7.x] [Lists][Exceptions] - Updates exception list item comments stru…
…cture (#68864) (#68907) * [Lists][Exceptions] - Updates exception list item comments structure (#68864) ### Summary This is part of a series of upcoming changes to the exception list item structure. This PR focuses solely on updating exception_item.comment. The hope is to keep these PRs relatively small. - Updates exception_item.comment structure which was previously a string to exception_item.comments which is an array of { comment: string; created_by: string; created_at: string; } - Adds a few unit tests server side - Fixes some minor misspellings - Updates ExceptionViewer component in the UI to account for new structure * Update API review file per CI instructions
- Loading branch information
Showing
38 changed files
with
866 additions
and
90 deletions.
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
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
189 changes: 189 additions & 0 deletions
189
x-pack/plugins/lists/common/schemas/request/create_exception_list_item_schema.test.ts
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,189 @@ | ||
/* | ||
* 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 { left } from 'fp-ts/lib/Either'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
|
||
import { exactCheck, foldLeftRight, getPaths } from '../../siem_common_deps'; | ||
|
||
import { | ||
CreateExceptionListItemSchema, | ||
createExceptionListItemSchema, | ||
} from './create_exception_list_item_schema'; | ||
import { getCreateExceptionListItemSchemaMock } from './create_exception_list_item_schema.mock'; | ||
|
||
describe('create_exception_list_schema', () => { | ||
test('it should validate a typical exception list item request', () => { | ||
const payload = getCreateExceptionListItemSchemaMock(); | ||
const outputPayload = getCreateExceptionListItemSchemaMock(); | ||
const decoded = createExceptionListItemSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
outputPayload.item_id = (message.schema as CreateExceptionListItemSchema).item_id; | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(outputPayload); | ||
}); | ||
|
||
test('it should not accept an undefined for "description"', () => { | ||
const payload = getCreateExceptionListItemSchemaMock(); | ||
delete payload.description; | ||
const decoded = createExceptionListItemSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "undefined" supplied to "description"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should not accept an undefined for "name"', () => { | ||
const payload = getCreateExceptionListItemSchemaMock(); | ||
delete payload.name; | ||
const decoded = createExceptionListItemSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "undefined" supplied to "name"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should not accept an undefined for "type"', () => { | ||
const payload = getCreateExceptionListItemSchemaMock(); | ||
delete payload.type; | ||
const decoded = createExceptionListItemSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "undefined" supplied to "type"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should not accept an undefined for "list_id"', () => { | ||
const inputPayload = getCreateExceptionListItemSchemaMock(); | ||
delete inputPayload.list_id; | ||
const decoded = createExceptionListItemSchema.decode(inputPayload); | ||
const checked = exactCheck(inputPayload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "undefined" supplied to "list_id"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should accept an undefined for "meta" but strip it out', () => { | ||
const payload = getCreateExceptionListItemSchemaMock(); | ||
const outputPayload = getCreateExceptionListItemSchemaMock(); | ||
delete payload.meta; | ||
const decoded = createExceptionListItemSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
delete outputPayload.meta; | ||
outputPayload.item_id = (message.schema as CreateExceptionListItemSchema).item_id; | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(outputPayload); | ||
}); | ||
|
||
test('it should accept an undefined for "comments" but return an array', () => { | ||
const inputPayload = getCreateExceptionListItemSchemaMock(); | ||
const outputPayload = getCreateExceptionListItemSchemaMock(); | ||
delete inputPayload.comments; | ||
outputPayload.comments = []; | ||
const decoded = createExceptionListItemSchema.decode(inputPayload); | ||
const checked = exactCheck(inputPayload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
outputPayload.item_id = (message.schema as CreateExceptionListItemSchema).item_id; | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(outputPayload); | ||
}); | ||
|
||
test('it should accept an undefined for "entries" but return an array', () => { | ||
const inputPayload = getCreateExceptionListItemSchemaMock(); | ||
const outputPayload = getCreateExceptionListItemSchemaMock(); | ||
delete inputPayload.entries; | ||
outputPayload.entries = []; | ||
const decoded = createExceptionListItemSchema.decode(inputPayload); | ||
const checked = exactCheck(inputPayload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
outputPayload.item_id = (message.schema as CreateExceptionListItemSchema).item_id; | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(outputPayload); | ||
}); | ||
|
||
test('it should accept an undefined for "namespace_type" but return enum "single"', () => { | ||
const inputPayload = getCreateExceptionListItemSchemaMock(); | ||
const outputPayload = getCreateExceptionListItemSchemaMock(); | ||
delete inputPayload.namespace_type; | ||
outputPayload.namespace_type = 'single'; | ||
const decoded = createExceptionListItemSchema.decode(inputPayload); | ||
const checked = exactCheck(inputPayload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
outputPayload.item_id = (message.schema as CreateExceptionListItemSchema).item_id; | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(outputPayload); | ||
}); | ||
|
||
test('it should accept an undefined for "tags" but return an array', () => { | ||
const inputPayload = getCreateExceptionListItemSchemaMock(); | ||
const outputPayload = getCreateExceptionListItemSchemaMock(); | ||
delete inputPayload.tags; | ||
outputPayload.tags = []; | ||
const decoded = createExceptionListItemSchema.decode(inputPayload); | ||
const checked = exactCheck(inputPayload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
outputPayload.item_id = (message.schema as CreateExceptionListItemSchema).item_id; | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(outputPayload); | ||
}); | ||
|
||
test('it should accept an undefined for "_tags" but return an array', () => { | ||
const inputPayload = getCreateExceptionListItemSchemaMock(); | ||
const outputPayload = getCreateExceptionListItemSchemaMock(); | ||
delete inputPayload._tags; | ||
outputPayload._tags = []; | ||
const decoded = createExceptionListItemSchema.decode(inputPayload); | ||
const checked = exactCheck(inputPayload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
outputPayload.item_id = (message.schema as CreateExceptionListItemSchema).item_id; | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(outputPayload); | ||
}); | ||
|
||
test('it should accept an undefined for "item_id" and auto generate a uuid', () => { | ||
const inputPayload = getCreateExceptionListItemSchemaMock(); | ||
delete inputPayload.item_id; | ||
const decoded = createExceptionListItemSchema.decode(inputPayload); | ||
const checked = exactCheck(inputPayload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect((message.schema as CreateExceptionListItemSchema).item_id).toMatch( | ||
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i | ||
); | ||
}); | ||
|
||
test('it should accept an undefined for "item_id" and generate a correct body not counting the uuid', () => { | ||
const inputPayload = getCreateExceptionListItemSchemaMock(); | ||
delete inputPayload.item_id; | ||
const decoded = createExceptionListItemSchema.decode(inputPayload); | ||
const checked = exactCheck(inputPayload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
delete (message.schema as CreateExceptionListItemSchema).item_id; | ||
expect(message.schema).toEqual(inputPayload); | ||
}); | ||
|
||
test('it should not allow an extra key to be sent in', () => { | ||
const payload: CreateExceptionListItemSchema & { | ||
extraKey?: string; | ||
} = getCreateExceptionListItemSchemaMock(); | ||
payload.extraKey = 'some new value'; | ||
const decoded = createExceptionListItemSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual(['invalid keys "extraKey"']); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
}); |
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
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/lists/common/schemas/request/update_exception_list_item_schema.mock.ts
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,35 @@ | ||
/* | ||
* 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 { | ||
COMMENTS, | ||
DESCRIPTION, | ||
ENTRIES, | ||
ID, | ||
ITEM_TYPE, | ||
LIST_ITEM_ID, | ||
META, | ||
NAME, | ||
NAMESPACE_TYPE, | ||
TAGS, | ||
_TAGS, | ||
} from '../../constants.mock'; | ||
|
||
import { UpdateExceptionListItemSchema } from './update_exception_list_item_schema'; | ||
|
||
export const getUpdateExceptionListItemSchemaMock = (): UpdateExceptionListItemSchema => ({ | ||
_tags: _TAGS, | ||
comments: COMMENTS, | ||
description: DESCRIPTION, | ||
entries: ENTRIES, | ||
id: ID, | ||
item_id: LIST_ITEM_ID, | ||
meta: META, | ||
name: NAME, | ||
namespace_type: NAMESPACE_TYPE, | ||
tags: TAGS, | ||
type: ITEM_TYPE, | ||
}); |
Oops, something went wrong.