-
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.
- Loading branch information
Showing
81 changed files
with
2,100 additions
and
1,031 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
68 changes: 68 additions & 0 deletions
68
...urity_solution/common/detection_engine/schemas/request/perform_bulk_action_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,68 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { performBulkActionSchema, PerformBulkActionSchema } from './perform_bulk_action_schema'; | ||
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; | ||
import { left } from 'fp-ts/lib/Either'; | ||
import { BulkAction } from '../common/schemas'; | ||
|
||
describe('perform_bulk_action_schema', () => { | ||
test('query and action is valid', () => { | ||
const payload: PerformBulkActionSchema = { | ||
query: 'name: test', | ||
action: BulkAction.enable, | ||
}; | ||
|
||
const decoded = performBulkActionSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('missing query is valid', () => { | ||
const payload: PerformBulkActionSchema = { | ||
query: undefined, | ||
action: BulkAction.enable, | ||
}; | ||
|
||
const decoded = performBulkActionSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('missing action is invalid', () => { | ||
const payload: Omit<PerformBulkActionSchema, 'action'> = { | ||
query: 'name: test', | ||
}; | ||
|
||
const decoded = performBulkActionSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "undefined" supplied to "action"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('unknown action is invalid', () => { | ||
const payload: Omit<PerformBulkActionSchema, 'action'> & { action: 'unknown' } = { | ||
query: 'name: test', | ||
action: 'unknown', | ||
}; | ||
|
||
const decoded = performBulkActionSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "unknown" supplied to "action"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
...s/security_solution/common/detection_engine/schemas/request/perform_bulk_action_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,18 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import * as t from 'io-ts'; | ||
import { bulkAction, queryOrUndefined } from '../common/schemas'; | ||
|
||
export const performBulkActionSchema = t.exact( | ||
t.type({ | ||
query: queryOrUndefined, | ||
action: bulkAction, | ||
}) | ||
); | ||
|
||
export type PerformBulkActionSchema = t.TypeOf<typeof performBulkActionSchema>; |
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
Oops, something went wrong.