-
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] [Security Solution][Exception Modal] Create endpoint exception …
…list if it doesn't already exist (#71807) (#71832) Co-authored-by: Pedro Jaramillo <pedro.jaramillo@elastic.co>
- Loading branch information
1 parent
465f6dd
commit c76ea55
Showing
12 changed files
with
207 additions
and
22 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
x-pack/plugins/lists/common/schemas/response/create_endpoint_list_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,58 @@ | ||
/* | ||
* 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 { getExceptionListSchemaMock } from './exception_list_schema.mock'; | ||
import { CreateEndpointListSchema, createEndpointListSchema } from './create_endpoint_list_schema'; | ||
|
||
describe('create_endpoint_list_schema', () => { | ||
test('it should validate a typical endpoint list response', () => { | ||
const payload = getExceptionListSchemaMock(); | ||
const decoded = createEndpointListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should accept an empty object when an endpoint list already exists', () => { | ||
const payload = {}; | ||
const decoded = createEndpointListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should NOT allow missing fields', () => { | ||
const payload = getExceptionListSchemaMock(); | ||
delete payload.list_id; | ||
const decoded = createEndpointListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors)).length).toEqual(1); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should not allow an extra key to be sent in', () => { | ||
const payload: CreateEndpointListSchema & { | ||
extraKey?: string; | ||
} = getExceptionListSchemaMock(); | ||
payload.extraKey = 'some new value'; | ||
const decoded = createEndpointListSchema.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({}); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/lists/common/schemas/response/create_endpoint_list_schema.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,15 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* eslint-disable @typescript-eslint/camelcase */ | ||
|
||
import * as t from 'io-ts'; | ||
|
||
import { exceptionListSchema } from './exception_list_schema'; | ||
|
||
export const createEndpointListSchema = t.union([exceptionListSchema, t.exact(t.type({}))]); | ||
|
||
export type CreateEndpointListSchema = t.TypeOf<typeof createEndpointListSchema>; |
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
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
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