-
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.
[SIEM][Exceptions] - Updates exception structure and corresponding UI…
… types (#69120) ### Summary This PR is meant to update the `ExceptionListItemSchema.entries` structure to align with the most recent conversations regarding the need for a more explicit depiction of `nested` fields. To summarize: - Adds schema validation for requests and responses within `lists/public/exceptions/api.ts`. It was super helpful in catching existing bugs. Anyone that uses the api will run through this validation. If the client tries to send up a malformed request, the request will not be made and an error returned. If the request is successful, but somehow the response is malformed, an error is returned. There may be some UX things to figure out about how to best communicate these errors to the user, or if surfacing the raw error is fine. - Updates `entries` structure in lists plugin api - Updates hooks and tests within `lists/public` that make reference to new structure - Updates and adds unit tests for updated schemas - Removes unused temporary types in `security_solution/public/common/components/exceptions/` to now reference updated schema - Updates UI tests - Updates `lists/server/scripts`
- Loading branch information
Showing
67 changed files
with
3,047 additions
and
816 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
x-pack/plugins/lists/common/schemas/common/schemas.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,63 @@ | ||
/* | ||
* 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 { pipe } from 'fp-ts/lib/pipeable'; | ||
import { left } from 'fp-ts/lib/Either'; | ||
|
||
import { foldLeftRight, getPaths } from '../../siem_common_deps'; | ||
|
||
import { operator_type as operatorType } from './schemas'; | ||
|
||
describe('Common schemas', () => { | ||
describe('operatorType', () => { | ||
test('it should validate for "match"', () => { | ||
const payload = 'match'; | ||
const decoded = operatorType.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should validate for "match_any"', () => { | ||
const payload = 'match_any'; | ||
const decoded = operatorType.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should validate for "list"', () => { | ||
const payload = 'list'; | ||
const decoded = operatorType.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should validate for "exists"', () => { | ||
const payload = 'exists'; | ||
const decoded = operatorType.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should contain 4 keys', () => { | ||
// Might seem like a weird test, but its meant to | ||
// ensure that if operatorType is updated, you | ||
// also update the OperatorTypeEnum, a workaround | ||
// for io-ts not yet supporting enums | ||
// https://github.com/gcanti/io-ts/issues/67 | ||
const keys = Object.keys(operatorType.keys); | ||
|
||
expect(keys.length).toEqual(4); | ||
}); | ||
}); | ||
}); |
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
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/lists/common/schemas/request/delete_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,14 @@ | ||
/* | ||
* 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 { ID, NAMESPACE_TYPE } from '../../constants.mock'; | ||
|
||
import { DeleteExceptionListItemSchema } from './delete_exception_list_item_schema'; | ||
|
||
export const getDeleteExceptionListItemSchemaMock = (): DeleteExceptionListItemSchema => ({ | ||
id: ID, | ||
namespace_type: NAMESPACE_TYPE, | ||
}); |
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/lists/common/schemas/request/delete_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,61 @@ | ||
/* | ||
* 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 { | ||
DeleteExceptionListItemSchema, | ||
deleteExceptionListItemSchema, | ||
} from './delete_exception_list_item_schema'; | ||
import { getDeleteExceptionListItemSchemaMock } from './delete_exception_list_item_schema.mock'; | ||
|
||
describe('delete_exception_list_item_schema', () => { | ||
test('it should validate a typical exception list item request', () => { | ||
const payload = getDeleteExceptionListItemSchemaMock(); | ||
const decoded = deleteExceptionListItemSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
// TODO It does allow an id of undefined, is this wanted behavior? | ||
test.skip('it should NOT accept an undefined for an "id"', () => { | ||
const payload = getDeleteExceptionListItemSchemaMock(); | ||
delete payload.id; | ||
const decoded = deleteExceptionListItemSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual(['Invalid value "undefined" supplied to "id"']); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should accept an undefined for "namespace_type" but default to "single"', () => { | ||
const payload = getDeleteExceptionListItemSchemaMock(); | ||
delete payload.namespace_type; | ||
const decoded = deleteExceptionListItemSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(getDeleteExceptionListItemSchemaMock()); | ||
}); | ||
|
||
test('it should not allow an extra key to be sent in', () => { | ||
const payload: DeleteExceptionListItemSchema & { | ||
extraKey?: string; | ||
} = getDeleteExceptionListItemSchemaMock(); | ||
payload.extraKey = 'some new value'; | ||
const decoded = deleteExceptionListItemSchema.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({}); | ||
}); | ||
}); |
Oops, something went wrong.