forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Platform] - Update rule exported counts to includ…
…e total object count (elastic#116338) ### Summary Addresses elastic#116330.
- Loading branch information
1 parent
1064adb
commit e1093d7
Showing
22 changed files
with
379 additions
and
38 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...s/kbn-securitysolution-io-ts-list-types/src/common/exception_export_details/index.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,29 @@ | ||
/* | ||
* 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 { ExportExceptionDetails } from '.'; | ||
|
||
export interface ExportExceptionDetailsMock { | ||
listCount?: number; | ||
missingListsCount?: number; | ||
missingLists?: Array<Record<'list_id', string>>; | ||
itemCount?: number; | ||
missingItemCount?: number; | ||
missingItems?: Array<Record<'item_id', string>>; | ||
} | ||
|
||
export const getExceptionExportDetailsMock = ( | ||
details?: ExportExceptionDetailsMock | ||
): ExportExceptionDetails => ({ | ||
exported_exception_list_count: details?.listCount ?? 0, | ||
exported_exception_list_item_count: details?.itemCount ?? 0, | ||
missing_exception_list_item_count: details?.missingItemCount ?? 0, | ||
missing_exception_list_items: details?.missingItems ?? [], | ||
missing_exception_lists: details?.missingLists ?? [], | ||
missing_exception_lists_count: details?.missingListsCount ?? 0, | ||
}); |
36 changes: 36 additions & 0 deletions
36
...s/kbn-securitysolution-io-ts-list-types/src/common/exception_export_details/index.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,36 @@ | ||
/* | ||
* 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 { pipe } from 'fp-ts/lib/pipeable'; | ||
import { left } from 'fp-ts/lib/Either'; | ||
import { getExceptionExportDetailsMock } from './index.mock'; | ||
import { exportExceptionDetailsSchema, ExportExceptionDetails } from '.'; | ||
import { foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; | ||
|
||
describe('exportExceptionDetails', () => { | ||
test('it should validate export meta', () => { | ||
const payload = getExceptionExportDetailsMock(); | ||
const decoded = exportExceptionDetailsSchema.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should strip out extra keys', () => { | ||
const payload: ExportExceptionDetails & { | ||
extraKey?: string; | ||
} = getExceptionExportDetailsMock(); | ||
payload.extraKey = 'some extra key'; | ||
const decoded = exportExceptionDetailsSchema.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(getExceptionExportDetailsMock()); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
packages/kbn-securitysolution-io-ts-list-types/src/common/exception_export_details/index.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,35 @@ | ||
/* | ||
* 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 * as t from 'io-ts'; | ||
import { NonEmptyString } from '@kbn/securitysolution-io-ts-types'; | ||
|
||
export const exportExceptionDetails = { | ||
exported_exception_list_count: t.number, | ||
exported_exception_list_item_count: t.number, | ||
missing_exception_list_item_count: t.number, | ||
missing_exception_list_items: t.array( | ||
t.exact( | ||
t.type({ | ||
item_id: NonEmptyString, | ||
}) | ||
) | ||
), | ||
missing_exception_lists: t.array( | ||
t.exact( | ||
t.type({ | ||
list_id: NonEmptyString, | ||
}) | ||
) | ||
), | ||
missing_exception_lists_count: t.number, | ||
}; | ||
|
||
export const exportExceptionDetailsSchema = t.exact(t.type(exportExceptionDetails)); | ||
|
||
export type ExportExceptionDetails = t.TypeOf<typeof exportExceptionDetailsSchema>; |
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
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/lists/common/schemas/response/exception_export_details_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,28 @@ | ||
/* | ||
* 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 { ExportExceptionDetails } from '@kbn/securitysolution-io-ts-list-types'; | ||
|
||
export interface ExportExceptionDetailsMock { | ||
listCount?: number; | ||
missingListsCount?: number; | ||
missingLists?: Array<Record<'list_id', string>>; | ||
itemCount?: number; | ||
missingItemCount?: number; | ||
missingItems?: Array<Record<'item_id', string>>; | ||
} | ||
|
||
export const getExceptionExportDetailsMock = ( | ||
details?: ExportExceptionDetailsMock | ||
): ExportExceptionDetails => ({ | ||
exported_exception_list_count: details?.listCount ?? 0, | ||
exported_exception_list_item_count: details?.itemCount ?? 0, | ||
missing_exception_list_item_count: details?.missingItemCount ?? 0, | ||
missing_exception_list_items: details?.missingItems ?? [], | ||
missing_exception_lists: details?.missingLists ?? [], | ||
missing_exception_lists_count: details?.missingListsCount ?? 0, | ||
}); |
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
38 changes: 38 additions & 0 deletions
38
...ity_solution/common/detection_engine/schemas/response/export_rules_details_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,38 @@ | ||
/* | ||
* 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 { ExportRulesDetails } from './export_rules_details_schema'; | ||
import { | ||
ExportExceptionDetailsMock, | ||
getExceptionExportDetailsMock, | ||
} from '../../../../../lists/common/schemas/response/exception_export_details_schema.mock'; | ||
|
||
interface RuleDetailsMock { | ||
totalCount?: number; | ||
rulesCount?: number; | ||
missingCount?: number; | ||
missingRules?: Array<Record<'rule_id', string>>; | ||
} | ||
|
||
export const getOutputDetailsSample = (ruleDetails?: RuleDetailsMock): ExportRulesDetails => ({ | ||
exported_count: ruleDetails?.totalCount ?? 0, | ||
exported_rules_count: ruleDetails?.rulesCount ?? 0, | ||
missing_rules: ruleDetails?.missingRules ?? [], | ||
missing_rules_count: ruleDetails?.missingCount ?? 0, | ||
}); | ||
|
||
export const getOutputDetailsSampleWithExceptions = ( | ||
ruleDetails?: RuleDetailsMock, | ||
exceptionDetails?: ExportExceptionDetailsMock | ||
): ExportRulesDetails => ({ | ||
...getOutputDetailsSample(ruleDetails), | ||
...getExceptionExportDetailsMock(exceptionDetails), | ||
}); | ||
|
||
export const getSampleDetailsAsNdjson = (sample: ExportRulesDetails): string => { | ||
return `${JSON.stringify(sample)}\n`; | ||
}; |
60 changes: 60 additions & 0 deletions
60
...ity_solution/common/detection_engine/schemas/response/export_rules_details_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,60 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* 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 { pipe } from 'fp-ts/lib/pipeable'; | ||
import { left } from 'fp-ts/lib/Either'; | ||
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; | ||
|
||
import { | ||
getOutputDetailsSample, | ||
getOutputDetailsSampleWithExceptions, | ||
} from './export_rules_details_schema.mock'; | ||
import { | ||
ExportRulesDetails, | ||
exportRulesDetailsWithExceptionsSchema, | ||
} from './export_rules_details_schema'; | ||
|
||
describe('exportRulesDetailsWithExceptionsSchema', () => { | ||
test('it should validate export details response', () => { | ||
const payload = getOutputDetailsSample(); | ||
const decoded = exportRulesDetailsWithExceptionsSchema.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 validate export details with exceptions details response', () => { | ||
const payload = getOutputDetailsSampleWithExceptions(); | ||
const decoded = exportRulesDetailsWithExceptionsSchema.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 strip out extra keys', () => { | ||
const payload: ExportRulesDetails & { | ||
extraKey?: string; | ||
} = getOutputDetailsSample(); | ||
payload.extraKey = 'some extra key'; | ||
const decoded = exportRulesDetailsWithExceptionsSchema.decode(payload); | ||
const message = pipe(decoded, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(getOutputDetailsSample()); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
...security_solution/common/detection_engine/schemas/response/export_rules_details_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,41 @@ | ||
/* | ||
* 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 { exportExceptionDetails } from '@kbn/securitysolution-io-ts-list-types'; | ||
import { NonEmptyString } from '@kbn/securitysolution-io-ts-types'; | ||
|
||
const createSchema = <Required extends t.Props, Optional extends t.Props>( | ||
requiredFields: Required, | ||
optionalFields: Optional | ||
) => { | ||
return t.intersection([t.exact(t.type(requiredFields)), t.exact(t.partial(optionalFields))]); | ||
}; | ||
|
||
export const exportRulesDetails = { | ||
exported_count: t.number, | ||
exported_rules_count: t.number, | ||
missing_rules: t.array( | ||
t.exact( | ||
t.type({ | ||
rule_id: NonEmptyString, | ||
}) | ||
) | ||
), | ||
missing_rules_count: t.number, | ||
}; | ||
|
||
const exportRulesDetailsSchema = t.exact(t.type(exportRulesDetails)); | ||
export type ExportRulesDetailsSchema = t.TypeOf<typeof exportRulesDetailsSchema>; | ||
|
||
// With exceptions | ||
export const exportRulesDetailsWithExceptionsSchema = createSchema( | ||
exportRulesDetails, | ||
exportExceptionDetails | ||
); | ||
|
||
export type ExportRulesDetails = t.TypeOf<typeof exportRulesDetailsWithExceptionsSchema>; |
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.