This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] [Exceptions] Fix edit the exception while adding …
…new comment. (elastic#145575) ## Summary Address elastic#144523 1. Fix type schema check to use `updateExceptionListItemSchema` instead of `exceptionListItemSchema` as the comments array could be empty when the user adds the Exceptions and in Editing with adding a new comment(s) it will contain only (comment and id) in the newly created comment 2. Add `removeCreatedAtCreatedByFromCommentsOnUpdate` to remove the `createdAt`, and `createdBy` from the updated exception Item if a comment was added before to fix the `400 Schema validations` as per the below Schema The `packages/kbn-securitysolution-io-ts-list-types/src/common/update_comment/index.ts` ``` export const updateComment = t.intersection([ t.exact( t.type({ comment: NonEmptyString, }) ), t.exact( t.partial({ id, }) ), ]); ``` 3. Moving tests and mocks to the `hooks` package as well add new tests for the new `removeCreatedAtCreatedByFromCommentsOnUpdate` ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
193b4ec
commit 2bd2226
Showing
7 changed files
with
577 additions
and
6 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
63 changes: 63 additions & 0 deletions
63
...n-securitysolution-list-hooks/src/mocks/request/create_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,63 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { CreateExceptionListItemSchema } from '@kbn/securitysolution-io-ts-list-types'; | ||
|
||
import { | ||
COMMENTS, | ||
DESCRIPTION, | ||
ENTRIES, | ||
ITEM_ID, | ||
ITEM_TYPE, | ||
LIST_ID, | ||
META, | ||
NAME, | ||
NAMESPACE_TYPE, | ||
OS_TYPES, | ||
TAGS, | ||
} from '../constants.mock'; | ||
|
||
export const getCreateExceptionListItemSchemaMock = (): CreateExceptionListItemSchema => ({ | ||
comments: COMMENTS, | ||
description: DESCRIPTION, | ||
entries: ENTRIES, | ||
item_id: undefined, | ||
list_id: LIST_ID, | ||
meta: META, | ||
name: NAME, | ||
namespace_type: NAMESPACE_TYPE, | ||
os_types: OS_TYPES, | ||
tags: TAGS, | ||
type: ITEM_TYPE, | ||
}); | ||
|
||
/** | ||
* Useful for end to end testing | ||
*/ | ||
export const getCreateExceptionListItemMinimalSchemaMock = (): CreateExceptionListItemSchema => ({ | ||
description: DESCRIPTION, | ||
entries: ENTRIES, | ||
item_id: ITEM_ID, | ||
list_id: LIST_ID, | ||
name: NAME, | ||
os_types: OS_TYPES, | ||
type: ITEM_TYPE, | ||
}); | ||
|
||
/** | ||
* Useful for end to end testing | ||
*/ | ||
export const getCreateExceptionListItemMinimalSchemaMockWithoutId = | ||
(): CreateExceptionListItemSchema => ({ | ||
description: DESCRIPTION, | ||
entries: ENTRIES, | ||
list_id: LIST_ID, | ||
name: NAME, | ||
os_types: OS_TYPES, | ||
type: ITEM_TYPE, | ||
}); |
52 changes: 52 additions & 0 deletions
52
...n-securitysolution-list-hooks/src/mocks/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,52 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { UpdateExceptionListItemSchema } from '@kbn/securitysolution-io-ts-list-types'; | ||
|
||
import { | ||
DESCRIPTION, | ||
ENTRIES, | ||
ID, | ||
ITEM_ID, | ||
ITEM_TYPE, | ||
LIST_ITEM_ID, | ||
META, | ||
NAME, | ||
NAMESPACE_TYPE, | ||
OS_TYPES, | ||
TAGS, | ||
UPDATED_COMMENTS, | ||
} from '../constants.mock'; | ||
|
||
export const getUpdateExceptionListItemSchemaMock = (): UpdateExceptionListItemSchema => ({ | ||
_version: undefined, | ||
comments: UPDATED_COMMENTS, | ||
description: DESCRIPTION, | ||
entries: ENTRIES, | ||
id: ID, | ||
item_id: LIST_ITEM_ID, | ||
meta: META, | ||
name: NAME, | ||
namespace_type: NAMESPACE_TYPE, | ||
os_types: ['linux'], | ||
tags: TAGS, | ||
type: ITEM_TYPE, | ||
}); | ||
|
||
/** | ||
* Useful for end to end tests and other mechanisms which want to fill in the values | ||
* after doing a get of the structure. | ||
*/ | ||
export const getUpdateMinimalExceptionListItemSchemaMock = (): UpdateExceptionListItemSchema => ({ | ||
description: DESCRIPTION, | ||
entries: ENTRIES, | ||
item_id: ITEM_ID, | ||
name: NAME, | ||
os_types: OS_TYPES, | ||
type: ITEM_TYPE, | ||
}); |
70 changes: 70 additions & 0 deletions
70
...ges/kbn-securitysolution-list-hooks/src/mocks/response/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,70 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { ExceptionListItemSchema } from '@kbn/securitysolution-io-ts-list-types'; | ||
|
||
import { | ||
COMMENTS, | ||
DATE_NOW, | ||
DESCRIPTION, | ||
ELASTIC_USER, | ||
ENTRIES, | ||
ITEM_ID, | ||
ITEM_TYPE, | ||
LIST_ID, | ||
META, | ||
NAME, | ||
NAMESPACE_TYPE, | ||
OS_TYPES, | ||
TIE_BREAKER, | ||
USER, | ||
} from '../constants.mock'; | ||
|
||
export const getExceptionListItemSchemaMock = ( | ||
overrides?: Partial<ExceptionListItemSchema> | ||
): ExceptionListItemSchema => ({ | ||
_version: undefined, | ||
comments: COMMENTS, | ||
created_at: DATE_NOW, | ||
created_by: USER, | ||
description: DESCRIPTION, | ||
entries: ENTRIES, | ||
id: '1', | ||
item_id: 'endpoint_list_item', | ||
list_id: 'endpoint_list_id', | ||
meta: META, | ||
name: NAME, | ||
namespace_type: NAMESPACE_TYPE, | ||
os_types: [], | ||
tags: ['user added string for a tag', 'malware'], | ||
tie_breaker_id: TIE_BREAKER, | ||
type: ITEM_TYPE, | ||
updated_at: DATE_NOW, | ||
updated_by: USER, | ||
...(overrides || {}), | ||
}); | ||
|
||
/** | ||
* This is useful for end to end tests where we remove the auto generated parts for comparisons | ||
* such as created_at, updated_at, and id. | ||
*/ | ||
export const getExceptionListItemResponseMockWithoutAutoGeneratedValues = | ||
(): Partial<ExceptionListItemSchema> => ({ | ||
comments: [], | ||
created_by: ELASTIC_USER, | ||
description: DESCRIPTION, | ||
entries: ENTRIES, | ||
item_id: ITEM_ID, | ||
list_id: LIST_ID, | ||
name: NAME, | ||
namespace_type: 'single', | ||
os_types: OS_TYPES, | ||
tags: [], | ||
type: ITEM_TYPE, | ||
updated_by: ELASTIC_USER, | ||
}); |
Oops, something went wrong.