mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
SIEM] Moves validation up to the common section
## Summary Moves validation up to the common section so it can be used by others in common for API boundary validation.
This commit is contained in:
parent
3de93501c6
commit
d5785a0d6d
43 changed files with 128 additions and 190 deletions
|
@ -147,7 +147,7 @@ describe('update_exception_list_item_schema', () => {
|
|||
|
||||
// TODO: Is it expected behavior for it not to auto-generate a uui or throw
|
||||
// error if item_id is not passed in?
|
||||
xtest('it should accept an undefined for "item_id" and auto generate a uuid', () => {
|
||||
test.skip('it should accept an undefined for "item_id" and auto generate a uuid', () => {
|
||||
const inputPayload = getUpdateExceptionListItemSchemaMock();
|
||||
delete inputPayload.item_id;
|
||||
const decoded = updateExceptionListItemSchema.decode(inputPayload);
|
||||
|
|
|
@ -101,7 +101,7 @@ describe('exception_list_item_schema', () => {
|
|||
|
||||
// TODO: Should this throw an error? "namespace_type" gets auto-populated
|
||||
// with default "single", is that desired behavior?
|
||||
xtest('it should NOT accept an undefined for "namespace_type"', () => {
|
||||
test.skip('it should NOT accept an undefined for "namespace_type"', () => {
|
||||
const payload = getExceptionListItemSchemaMock();
|
||||
delete payload.namespace_type;
|
||||
const decoded = exceptionListItemSchema.decode(payload);
|
||||
|
|
|
@ -9,3 +9,5 @@ export { DefaultUuid } from '../../security_solution/common/detection_engine/sch
|
|||
export { DefaultStringArray } from '../../security_solution/common/detection_engine/schemas/types/default_string_array';
|
||||
export { exactCheck } from '../../security_solution/common/exact_check';
|
||||
export { getPaths, foldLeftRight } from '../../security_solution/common/test_utils';
|
||||
export { validate } from '../../security_solution/common/validate';
|
||||
export { formatErrors } from '../../security_solution/common/format_errors';
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import {
|
||||
CreateExceptionListItemSchemaDecoded,
|
||||
createExceptionListItemSchema,
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import {
|
||||
CreateExceptionListSchemaDecoded,
|
||||
createExceptionListSchema,
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { buildSiemResponse, transformError, validate } from '../siem_server_deps';
|
||||
import { buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { LIST_INDEX } from '../../common/constants';
|
||||
import { acknowledgeSchema } from '../../common/schemas';
|
||||
|
||||
|
|
|
@ -7,13 +7,9 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { createListItemSchema, listItemSchema } from '../../common/schemas';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { createListSchema, listSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import {
|
||||
DeleteExceptionListItemSchemaDecoded,
|
||||
deleteExceptionListItemSchema,
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import {
|
||||
DeleteExceptionListSchemaDecoded,
|
||||
deleteExceptionListSchema,
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_INDEX } from '../../common/constants';
|
||||
import { buildSiemResponse, transformError, validate } from '../siem_server_deps';
|
||||
import { buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { acknowledgeSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { deleteListItemSchema, listItemArraySchema, listItemSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { deleteListSchema, listSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import {
|
||||
FindExceptionListItemSchemaDecoded,
|
||||
findExceptionListItemSchema,
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import {
|
||||
FindExceptionListSchemaDecoded,
|
||||
findExceptionListSchema,
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { findListItemSchema, foundListItemSchema } from '../../common/schemas';
|
||||
import { decodeCursor } from '../services/utils';
|
||||
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { findListSchema, foundListSchema } from '../../common/schemas';
|
||||
import { decodeCursor } from '../services/utils';
|
||||
|
||||
|
|
|
@ -9,12 +9,8 @@ import { Readable } from 'stream';
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { importListItemQuerySchema, importListItemSchema, listSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { listItemSchema, patchListItemSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { listSchema, patchListSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import {
|
||||
ReadExceptionListItemSchemaDecoded,
|
||||
exceptionListItemSchema,
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import {
|
||||
ReadExceptionListSchemaDecoded,
|
||||
exceptionListSchema,
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_INDEX } from '../../common/constants';
|
||||
import { buildSiemResponse, transformError, validate } from '../siem_server_deps';
|
||||
import { buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { listItemIndexExistSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -7,13 +7,9 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { listItemArraySchema, listItemSchema, readListItemSchema } from '../../common/schemas';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { listSchema, readListSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import {
|
||||
UpdateExceptionListItemSchemaDecoded,
|
||||
exceptionListItemSchema,
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import {
|
||||
UpdateExceptionListSchemaDecoded,
|
||||
exceptionListSchema,
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { listItemSchema, updateListItemSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
transformError,
|
||||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { validate } from '../../common/siem_common_deps';
|
||||
import { listSchema, updateListSchema } from '../../common/schemas';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -17,5 +17,4 @@ export {
|
|||
createBootstrapIndex,
|
||||
getIndexExists,
|
||||
buildRouteValidation,
|
||||
validate,
|
||||
} from '../../security_solution/server';
|
||||
|
|
34
x-pack/plugins/security_solution/common/validate.test.ts
Normal file
34
x-pack/plugins/security_solution/common/validate.test.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* 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 { validate } from './validate';
|
||||
|
||||
describe('validate', () => {
|
||||
test('it should do a validation correctly', () => {
|
||||
const schema = t.exact(t.type({ a: t.number }));
|
||||
const payload = { a: 1 };
|
||||
const [validated, errors] = validate(payload, schema);
|
||||
|
||||
expect(validated).toEqual(payload);
|
||||
expect(errors).toEqual(null);
|
||||
});
|
||||
|
||||
test('it should do an in-validation correctly', () => {
|
||||
const schema = t.exact(t.type({ a: t.number }));
|
||||
const payload = { a: 'some other value' };
|
||||
const [validated, errors] = validate(payload, schema);
|
||||
|
||||
expect(validated).toEqual(null);
|
||||
expect(errors).toEqual('Invalid value "some other value" supplied to "a"');
|
||||
});
|
||||
});
|
25
x-pack/plugins/security_solution/common/validate.ts
Normal file
25
x-pack/plugins/security_solution/common/validate.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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 { fold } from 'fp-ts/lib/Either';
|
||||
import { pipe } from 'fp-ts/lib/pipeable';
|
||||
import * as t from 'io-ts';
|
||||
import { exactCheck } from './exact_check';
|
||||
import { formatErrors } from './format_errors';
|
||||
|
||||
export const validate = <T extends t.Mixed>(
|
||||
obj: object,
|
||||
schema: T
|
||||
): [t.TypeOf<T> | null, string | null] => {
|
||||
const decoded = schema.decode(obj);
|
||||
const checked = exactCheck(obj, decoded);
|
||||
const left = (errors: t.Errors): [T | null, string | null] => [
|
||||
null,
|
||||
formatErrors(errors).join(','),
|
||||
];
|
||||
const right = (output: T): [T | null, string | null] => [output, null];
|
||||
return pipe(checked, fold(left, right));
|
||||
};
|
|
@ -27,5 +27,4 @@ export { getPolicyExists } from './lib/detection_engine/index/get_policy_exists'
|
|||
export { createBootstrapIndex } from './lib/detection_engine/index/create_bootstrap_index';
|
||||
export { getIndexExists } from './lib/detection_engine/index/get_index_exists';
|
||||
export { buildRouteValidation } from './utils/build_validation/route_validation';
|
||||
export { validate } from './lib/detection_engine/routes/rules/validate';
|
||||
export { transformError, buildSiemResponse } from './lib/detection_engine/routes/utils';
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { validate } from '../../../../../common/validate';
|
||||
import {
|
||||
PrePackagedRulesSchema,
|
||||
prePackagedRulesSchema,
|
||||
|
@ -18,7 +19,6 @@ import { updatePrepackagedRules } from '../../rules/update_prepacked_rules';
|
|||
import { getRulesToInstall } from '../../rules/get_rules_to_install';
|
||||
import { getRulesToUpdate } from '../../rules/get_rules_to_update';
|
||||
import { getExistingPrepackagedRules } from '../../rules/get_existing_prepackaged_rules';
|
||||
import { validate } from './validate';
|
||||
|
||||
export const addPrepackedRulesRoute = (router: IRouter) => {
|
||||
router.put(
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { validate } from '../../../../../common/validate';
|
||||
import { createRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/create_rules_type_dependents';
|
||||
import { RuleAlertAction } from '../../../../../common/detection_engine/types';
|
||||
import {
|
||||
|
@ -19,7 +20,7 @@ import { throwHttpError } from '../../../machine_learning/validation';
|
|||
import { createRules } from '../../rules/create_rules';
|
||||
import { readRules } from '../../rules/read_rules';
|
||||
import { getDuplicates } from './utils';
|
||||
import { transformValidateBulkError, validate } from './validate';
|
||||
import { transformValidateBulkError } from './validate';
|
||||
import { getIndexExists } from '../../index/get_index_exists';
|
||||
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation';
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { validate } from '../../../../../common/validate';
|
||||
import { queryRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/query_rules_type_dependents';
|
||||
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation';
|
||||
import {
|
||||
|
@ -14,7 +15,7 @@ import { rulesBulkSchema } from '../../../../../common/detection_engine/schemas/
|
|||
import { IRouter, RouteConfig, RequestHandler } from '../../../../../../../../src/core/server';
|
||||
import { DETECTION_ENGINE_RULES_URL } from '../../../../../common/constants';
|
||||
import { getIdBulkError } from './utils';
|
||||
import { transformValidateBulkError, validate } from './validate';
|
||||
import { transformValidateBulkError } from './validate';
|
||||
import { transformBulkError, buildSiemResponse, createBulkErrorObject } from '../utils';
|
||||
import { deleteRules } from '../../rules/delete_rules';
|
||||
import { deleteNotifications } from '../../notifications/delete_notifications';
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { validate } from '../../../../../common/validate';
|
||||
import {
|
||||
PrePackagedRulesStatusSchema,
|
||||
prePackagedRulesStatusSchema,
|
||||
|
@ -16,7 +17,6 @@ import { getRulesToInstall } from '../../rules/get_rules_to_install';
|
|||
import { getRulesToUpdate } from '../../rules/get_rules_to_update';
|
||||
import { findRules } from '../../rules/find_rules';
|
||||
import { getExistingPrepackagedRules } from '../../rules/get_existing_prepackaged_rules';
|
||||
import { validate } from './validate';
|
||||
|
||||
export const getPrepackagedRulesStatusRoute = (router: IRouter) => {
|
||||
router.get(
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import { chunk } from 'lodash/fp';
|
||||
import { extname } from 'path';
|
||||
|
||||
import { validate } from '../../../../../common/validate';
|
||||
import {
|
||||
importRulesQuerySchema,
|
||||
ImportRulesQuerySchemaDecoded,
|
||||
|
@ -39,7 +40,6 @@ import {
|
|||
} from '../utils';
|
||||
import { patchRules } from '../../rules/patch_rules';
|
||||
import { getTupleDuplicateErrorsAndUniqueRules } from './utils';
|
||||
import { validate } from './validate';
|
||||
import { createRulesStreamFromNdJson } from '../../rules/create_rules_stream_from_ndjson';
|
||||
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation';
|
||||
import { HapiReadableStream } from '../../rules/types';
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { validate } from '../../../../../common/validate';
|
||||
import { RuleAlertAction } from '../../../../../common/detection_engine/types';
|
||||
import {
|
||||
patchRulesBulkSchema,
|
||||
|
@ -18,7 +19,7 @@ import { buildMlAuthz } from '../../../machine_learning/authz';
|
|||
import { throwHttpError } from '../../../machine_learning/validation';
|
||||
import { transformBulkError, buildSiemResponse } from '../utils';
|
||||
import { getIdBulkError } from './utils';
|
||||
import { transformValidateBulkError, validate } from './validate';
|
||||
import { transformValidateBulkError } from './validate';
|
||||
import { patchRules } from '../../rules/patch_rules';
|
||||
import { updateRulesNotifications } from '../../rules/update_rules_notifications';
|
||||
import { ruleStatusSavedObjectsClientFactory } from '../../signals/rule_status_saved_objects_client';
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { validate } from '../../../../../common/validate';
|
||||
import { updateRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/update_rules_type_dependents';
|
||||
import { RuleAlertAction } from '../../../../../common/detection_engine/types';
|
||||
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation';
|
||||
|
@ -18,7 +19,7 @@ import { SetupPlugins } from '../../../../plugin';
|
|||
import { buildMlAuthz } from '../../../machine_learning/authz';
|
||||
import { throwHttpError } from '../../../machine_learning/validation';
|
||||
import { getIdBulkError } from './utils';
|
||||
import { transformValidateBulkError, validate } from './validate';
|
||||
import { transformValidateBulkError } from './validate';
|
||||
import { transformBulkError, buildSiemResponse, createBulkErrorObject } from '../utils';
|
||||
import { updateRules } from '../../rules/update_rules';
|
||||
import { updateRulesNotifications } from '../../rules/update_rules_notifications';
|
||||
|
|
|
@ -4,10 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import * as t from 'io-ts';
|
||||
|
||||
import {
|
||||
validate,
|
||||
transformValidate,
|
||||
transformValidateFindAlerts,
|
||||
transformValidateBulkError,
|
||||
|
@ -121,26 +118,6 @@ describe('validate', () => {
|
|||
unSetFeatureFlagsForTestsOnly();
|
||||
});
|
||||
|
||||
describe('validate', () => {
|
||||
test('it should do a validation correctly', () => {
|
||||
const schema = t.exact(t.type({ a: t.number }));
|
||||
const payload = { a: 1 };
|
||||
const [validated, errors] = validate(payload, schema);
|
||||
|
||||
expect(validated).toEqual(payload);
|
||||
expect(errors).toEqual(null);
|
||||
});
|
||||
|
||||
test('it should do an in-validation correctly', () => {
|
||||
const schema = t.exact(t.type({ a: t.number }));
|
||||
const payload = { a: 'some other value' };
|
||||
const [validated, errors] = validate(payload, schema);
|
||||
|
||||
expect(validated).toEqual(null);
|
||||
expect(errors).toEqual('Invalid value "some other value" supplied to "a"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('transformValidate', () => {
|
||||
test('it should do a validation correctly of a partial alert', () => {
|
||||
const ruleAlert = getResult();
|
||||
|
|
|
@ -9,6 +9,7 @@ import { fold } from 'fp-ts/lib/Either';
|
|||
import { pipe } from 'fp-ts/lib/pipeable';
|
||||
import * as t from 'io-ts';
|
||||
|
||||
import { validate } from '../../../../../common/validate';
|
||||
import { findRulesSchema } from '../../../../../common/detection_engine/schemas/response/find_rules_schema';
|
||||
import {
|
||||
RulesSchema,
|
||||
|
@ -113,17 +114,3 @@ export const transformValidateBulkError = (
|
|||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const validate = <T extends t.Mixed>(
|
||||
obj: object,
|
||||
schema: T
|
||||
): [t.TypeOf<T> | null, string | null] => {
|
||||
const decoded = schema.decode(obj);
|
||||
const checked = exactCheck(obj, decoded);
|
||||
const left = (errors: t.Errors): [T | null, string | null] => [
|
||||
null,
|
||||
formatErrors(errors).join(','),
|
||||
];
|
||||
const right = (output: T): [T | null, string | null] => [output, null];
|
||||
return pipe(checked, fold(left, right));
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import { extname } from 'path';
|
||||
import { chunk, omit } from 'lodash/fp';
|
||||
|
||||
import { validate } from '../../../../common/validate';
|
||||
import { importRulesSchema } from '../../../../common/detection_engine/schemas/response/import_rules_schema';
|
||||
import { createPromiseFromStreams } from '../../../../../../../src/legacy/utils';
|
||||
import { IRouter } from '../../../../../../../src/core/server';
|
||||
|
@ -17,7 +18,6 @@ import { SetupPlugins } from '../../../plugin';
|
|||
import { ConfigType } from '../../../config';
|
||||
import { buildRouteValidation } from '../../../utils/build_validation/route_validation';
|
||||
|
||||
import { validate } from '../../detection_engine/routes/rules/validate';
|
||||
import {
|
||||
buildSiemResponse,
|
||||
createBulkErrorObject,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue