-
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.
[Security Solution][Detections] - Fix export on exceptions list view (#…
…86135) (#86862) ## Summary This PR addresses a fix on the exceptions list table export functionality. A dedicated route for exception list export needed to be created. List is exported into an `.ndjson` format. Exception lists consist of two elements - the list itself, and its items. The export file should now contain both these elements, the list followed by its items. Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
19a0119
commit fa0e310
Showing
18 changed files
with
459 additions
and
23 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/lists/common/schemas/request/export_exception_list_query_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,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. | ||
*/ | ||
|
||
import { ID, LIST_ID, NAMESPACE_TYPE } from '../../constants.mock'; | ||
|
||
import { ExportExceptionListQuerySchema } from './export_exception_list_query_schema'; | ||
|
||
export const getExportExceptionListQuerySchemaMock = (): ExportExceptionListQuerySchema => ({ | ||
id: ID, | ||
list_id: LIST_ID, | ||
namespace_type: NAMESPACE_TYPE, | ||
}); |
80 changes: 80 additions & 0 deletions
80
x-pack/plugins/lists/common/schemas/request/export_exception_list_query_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,80 @@ | ||
/* | ||
* 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 '../../shared_imports'; | ||
|
||
import { | ||
ExportExceptionListQuerySchema, | ||
exportExceptionListQuerySchema, | ||
} from './export_exception_list_query_schema'; | ||
import { getExportExceptionListQuerySchemaMock } from './export_exception_list_query_schema.mock'; | ||
|
||
describe('export_exception_list_schema', () => { | ||
test('it should validate a typical lists request', () => { | ||
const payload = getExportExceptionListQuerySchemaMock(); | ||
const decoded = exportExceptionListQuerySchema.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 accept an undefined for an id', () => { | ||
const payload = getExportExceptionListQuerySchemaMock(); | ||
// @ts-expect-error | ||
delete payload.id; | ||
const decoded = exportExceptionListQuerySchema.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 default namespace_type to "single" if an undefined given for namespacetype', () => { | ||
const payload = getExportExceptionListQuerySchemaMock(); | ||
delete payload.namespace_type; | ||
const decoded = exportExceptionListQuerySchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
|
||
expect(message.schema).toEqual({ | ||
id: 'uuid_here', | ||
list_id: 'some-list-id', | ||
namespace_type: 'single', | ||
}); | ||
}); | ||
|
||
test('it should NOT accept an undefined for an list_id', () => { | ||
const payload = getExportExceptionListQuerySchemaMock(); | ||
// @ts-expect-error | ||
delete payload.list_id; | ||
const decoded = exportExceptionListQuerySchema.decode(payload); | ||
const checked = exactCheck(payload, 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 not allow an extra key to be sent in', () => { | ||
const payload: ExportExceptionListQuerySchema & { | ||
extraKey?: string; | ||
} = getExportExceptionListQuerySchemaMock(); | ||
payload.extraKey = 'some new value'; | ||
const decoded = exportExceptionListQuerySchema.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({}); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/lists/common/schemas/request/export_exception_list_query_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,20 @@ | ||
/* | ||
* 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 * as t from 'io-ts'; | ||
|
||
import { id, list_id, namespace_type } from '../common/schemas'; | ||
|
||
export const exportExceptionListQuerySchema = t.exact( | ||
t.type({ | ||
id, | ||
list_id, | ||
namespace_type, | ||
// TODO: Add file_name here with a default value | ||
}) | ||
); | ||
|
||
export type ExportExceptionListQuerySchema = t.OutputOf<typeof exportExceptionListQuerySchema>; |
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.