mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[SIEM][Lists] More tests and renames and file movements and types (#64968)
* Adds unit tests to the schema for input/output validation * Changes the mocks to use a `file_name.mock.ts` pattern * Introduces io-ts partials _carefully_ where I get both the partials and the required undefined in the types * Introduces an Identity type to remove weird intersection types and make plain types when using io-ts. * I Introduces a RequiredKeepUndefined in order to work with partials and keep the undefined as required for when the type is used directly within the code. This makes it simpler to force new functions/methods to have to push down `undefined` ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios
This commit is contained in:
parent
7a9261adb2
commit
0730bae5c6
84 changed files with 1600 additions and 341 deletions
|
@ -7,8 +7,8 @@
|
|||
import { CreateDocumentResponse } from 'elasticsearch';
|
||||
import { APICaller } from 'kibana/server';
|
||||
|
||||
import { LIST_INDEX } from './lists_services_mock_constants';
|
||||
import { getShardMock } from './get_shard_mock';
|
||||
import { LIST_INDEX } from './constants.mock';
|
||||
import { getShardMock } from './get_shard.mock';
|
||||
|
||||
export const getEmptyCreateDocumentResponseMock = (): CreateDocumentResponse => ({
|
||||
_id: 'elastic-id-123',
|
|
@ -5,8 +5,7 @@
|
|||
*/
|
||||
|
||||
import { IndexEsListItemSchema } from '../../../common/schemas';
|
||||
|
||||
import { DATE_NOW, LIST_ID, META, TIE_BREAKER, USER, VALUE } from './lists_services_mock_constants';
|
||||
import { DATE_NOW, LIST_ID, META, TIE_BREAKER, USER, VALUE } from '../../../common/constants.mock';
|
||||
|
||||
export const getIndexESListItemMock = (ip = VALUE): IndexEsListItemSchema => ({
|
||||
created_at: DATE_NOW,
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
|
||||
import { IndexEsListSchema } from '../../../common/schemas';
|
||||
|
||||
import {
|
||||
DATE_NOW,
|
||||
DESCRIPTION,
|
||||
|
@ -14,7 +13,7 @@ import {
|
|||
TIE_BREAKER,
|
||||
TYPE,
|
||||
USER,
|
||||
} from './lists_services_mock_constants';
|
||||
} from '../../../common/constants.mock';
|
||||
|
||||
export const getIndexESListMock = (): IndexEsListSchema => ({
|
||||
created_at: DATE_NOW,
|
|
@ -7,10 +7,29 @@
|
|||
import { SearchResponse } from 'elasticsearch';
|
||||
|
||||
import { SearchEsListItemSchema } from '../../../common/schemas';
|
||||
import {
|
||||
DATE_NOW,
|
||||
LIST_ID,
|
||||
LIST_INDEX,
|
||||
LIST_ITEM_ID,
|
||||
META,
|
||||
TIE_BREAKER,
|
||||
USER,
|
||||
VALUE,
|
||||
} from '../../../common/constants.mock';
|
||||
import { getShardMock } from '../../get_shard.mock';
|
||||
|
||||
import { getShardMock } from './get_shard_mock';
|
||||
import { LIST_INDEX, LIST_ITEM_ID } from './lists_services_mock_constants';
|
||||
import { getSearchEsListItemMock } from './get_search_es_list_item_mock';
|
||||
export const getSearchEsListItemMock = (): SearchEsListItemSchema => ({
|
||||
created_at: DATE_NOW,
|
||||
created_by: USER,
|
||||
ip: VALUE,
|
||||
keyword: undefined,
|
||||
list_id: LIST_ID,
|
||||
meta: META,
|
||||
tie_breaker_id: TIE_BREAKER,
|
||||
updated_at: DATE_NOW,
|
||||
updated_by: USER,
|
||||
});
|
||||
|
||||
export const getSearchListItemMock = (): SearchResponse<SearchEsListItemSchema> => ({
|
||||
_scroll_id: '123',
|
|
@ -7,10 +7,30 @@
|
|||
import { SearchResponse } from 'elasticsearch';
|
||||
|
||||
import { SearchEsListSchema } from '../../../common/schemas';
|
||||
import {
|
||||
DATE_NOW,
|
||||
DESCRIPTION,
|
||||
LIST_ID,
|
||||
LIST_INDEX,
|
||||
META,
|
||||
NAME,
|
||||
TIE_BREAKER,
|
||||
TYPE,
|
||||
USER,
|
||||
} from '../../../common/constants.mock';
|
||||
import { getShardMock } from '../../get_shard.mock';
|
||||
|
||||
import { getShardMock } from './get_shard_mock';
|
||||
import { LIST_ID, LIST_INDEX } from './lists_services_mock_constants';
|
||||
import { getSearchEsListMock } from './get_search_es_list_mock';
|
||||
export const getSearchEsListMock = (): SearchEsListSchema => ({
|
||||
created_at: DATE_NOW,
|
||||
created_by: USER,
|
||||
description: DESCRIPTION,
|
||||
meta: META,
|
||||
name: NAME,
|
||||
tie_breaker_id: TIE_BREAKER,
|
||||
type: TYPE,
|
||||
updated_at: DATE_NOW,
|
||||
updated_by: USER,
|
||||
});
|
||||
|
||||
export const getSearchListMock = (): SearchResponse<SearchEsListSchema> => ({
|
||||
_scroll_id: '123',
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* 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 { LIST_ID, LIST_ITEM_ID, META, VALUE } from '../../constants.mock';
|
||||
|
||||
import { CreateListItemSchema } from './create_list_item_schema';
|
||||
|
||||
export const getCreateListItemSchemaMock = (): CreateListItemSchema => ({
|
||||
id: LIST_ITEM_ID,
|
||||
list_id: LIST_ID,
|
||||
meta: META,
|
||||
value: VALUE,
|
||||
});
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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 { getCreateListItemSchemaMock } from './create_list_item_schema.mock';
|
||||
import { CreateListItemSchema, createListItemSchema } from './create_list_item_schema';
|
||||
|
||||
describe('create_list_item_schema', () => {
|
||||
test('it should validate a typical list item request', () => {
|
||||
const payload = getCreateListItemSchemaMock();
|
||||
const decoded = createListItemSchema.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 undefined for an id', () => {
|
||||
const payload = getCreateListItemSchemaMock();
|
||||
delete payload.id;
|
||||
const decoded = createListItemSchema.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 undefined for meta', () => {
|
||||
const payload = getCreateListItemSchemaMock();
|
||||
delete payload.meta;
|
||||
const decoded = createListItemSchema.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 an extra key to be sent in', () => {
|
||||
const payload: CreateListItemSchema & { extraKey?: string } = getCreateListItemSchemaMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = createListItemSchema.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({});
|
||||
});
|
||||
});
|
|
@ -9,14 +9,17 @@
|
|||
import * as t from 'io-ts';
|
||||
|
||||
import { idOrUndefined, list_id, metaOrUndefined, value } from '../common/schemas';
|
||||
import { Identity, RequiredKeepUndefined } from '../../types';
|
||||
|
||||
export const createListItemSchema = t.exact(
|
||||
t.type({
|
||||
id: idOrUndefined,
|
||||
list_id,
|
||||
meta: metaOrUndefined,
|
||||
value,
|
||||
})
|
||||
);
|
||||
export const createListItemSchema = t.intersection([
|
||||
t.exact(
|
||||
t.type({
|
||||
list_id,
|
||||
value,
|
||||
})
|
||||
),
|
||||
t.exact(t.partial({ id: idOrUndefined, meta: metaOrUndefined })),
|
||||
]);
|
||||
|
||||
export type CreateListItemSchema = t.TypeOf<typeof createListItemSchema>;
|
||||
export type CreateListItemSchemaPartial = Identity<t.TypeOf<typeof createListItemSchema>>;
|
||||
export type CreateListItemSchema = RequiredKeepUndefined<t.TypeOf<typeof createListItemSchema>>;
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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 { DESCRIPTION, LIST_ID, META, NAME, TYPE } from '../../constants.mock';
|
||||
|
||||
import { CreateListSchema } from './create_list_schema';
|
||||
|
||||
export const getCreateListSchemaMock = (): CreateListSchema => ({
|
||||
description: DESCRIPTION,
|
||||
id: LIST_ID,
|
||||
meta: META,
|
||||
name: NAME,
|
||||
type: TYPE,
|
||||
});
|
|
@ -9,23 +9,47 @@ import { pipe } from 'fp-ts/lib/pipeable';
|
|||
|
||||
import { exactCheck, foldLeftRight, getPaths } from '../../siem_common_deps';
|
||||
|
||||
import { getListRequest } from './mocks/utils';
|
||||
import { createListSchema } from './create_list_schema';
|
||||
import { CreateListSchema, createListSchema } from './create_list_schema';
|
||||
import { getCreateListSchemaMock } from './create_list_schema.mock';
|
||||
|
||||
describe('create_list_schema', () => {
|
||||
// TODO: Finish the tests for this
|
||||
test('it should validate a typical lists request', () => {
|
||||
const payload = getListRequest();
|
||||
const payload = getCreateListSchemaMock();
|
||||
const decoded = createListSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([]);
|
||||
expect(message.schema).toEqual({
|
||||
description: 'Description of a list item',
|
||||
id: 'some-list-id',
|
||||
name: 'Name of a list item',
|
||||
type: 'ip',
|
||||
});
|
||||
expect(message.schema).toEqual(payload);
|
||||
});
|
||||
|
||||
test('it should accept an undefined for an id', () => {
|
||||
const payload = getCreateListSchemaMock();
|
||||
delete payload.id;
|
||||
const decoded = createListSchema.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 undefined for meta', () => {
|
||||
const payload = getCreateListSchemaMock();
|
||||
delete payload.meta;
|
||||
const decoded = createListSchema.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 an extra key to be sent in', () => {
|
||||
const payload: CreateListSchema & { extraKey?: string } = getCreateListSchemaMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = createListSchema.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({});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,20 +4,21 @@
|
|||
* 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 { description, idOrUndefined, metaOrUndefined, name, type } from '../common/schemas';
|
||||
import { Identity, RequiredKeepUndefined } from '../../types';
|
||||
|
||||
export const createListSchema = t.exact(
|
||||
t.type({
|
||||
description,
|
||||
id: idOrUndefined,
|
||||
meta: metaOrUndefined,
|
||||
name,
|
||||
type,
|
||||
})
|
||||
);
|
||||
export const createListSchema = t.intersection([
|
||||
t.exact(
|
||||
t.type({
|
||||
description,
|
||||
name,
|
||||
type,
|
||||
})
|
||||
),
|
||||
t.exact(t.partial({ id: idOrUndefined, meta: metaOrUndefined })),
|
||||
]);
|
||||
|
||||
export type CreateListSchema = t.TypeOf<typeof createListSchema>;
|
||||
export type CreateListSchemaPartial = Identity<t.TypeOf<typeof createListSchema>>;
|
||||
export type CreateListSchema = RequiredKeepUndefined<t.TypeOf<typeof createListSchema>>;
|
||||
|
|
|
@ -9,13 +9,16 @@
|
|||
import * as t from 'io-ts';
|
||||
|
||||
import { idOrUndefined, list_idOrUndefined, valueOrUndefined } from '../common/schemas';
|
||||
import { Identity, RequiredKeepUndefined } from '../../types';
|
||||
|
||||
export const deleteListItemSchema = t.exact(
|
||||
t.type({
|
||||
id: idOrUndefined,
|
||||
list_id: list_idOrUndefined,
|
||||
value: valueOrUndefined,
|
||||
})
|
||||
);
|
||||
export const deleteListItemSchema = t.intersection([
|
||||
t.exact(
|
||||
t.type({
|
||||
value: valueOrUndefined,
|
||||
})
|
||||
),
|
||||
t.exact(t.partial({ id: idOrUndefined, list_id: list_idOrUndefined })),
|
||||
]);
|
||||
|
||||
export type DeleteListItemSchema = t.TypeOf<typeof deleteListItemSchema>;
|
||||
export type DeleteListItemSchemaPartial = Identity<t.TypeOf<typeof deleteListItemSchema>>;
|
||||
export type DeleteListItemSchema = RequiredKeepUndefined<t.TypeOf<typeof deleteListItemSchema>>;
|
||||
|
|
|
@ -4,12 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { CreateListSchema } from '../create_list_schema';
|
||||
import { LIST_ID } from '../../constants.mock';
|
||||
|
||||
export const getListRequest = (): CreateListSchema => ({
|
||||
description: 'Description of a list item',
|
||||
id: 'some-list-id',
|
||||
meta: undefined,
|
||||
name: 'Name of a list item',
|
||||
type: 'ip',
|
||||
import { DeleteListSchema } from './delete_list_schema';
|
||||
|
||||
export const getDeleteListSchemaMock = (): DeleteListSchema => ({
|
||||
id: LIST_ID,
|
||||
});
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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 { DeleteListSchema, deleteListSchema } from './delete_list_schema';
|
||||
import { getDeleteListSchemaMock } from './delete_list_schema.mock';
|
||||
|
||||
describe('delete_list_schema', () => {
|
||||
test('it should validate a typical lists request', () => {
|
||||
const payload = getDeleteListSchemaMock();
|
||||
const decoded = deleteListSchema.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 = getDeleteListSchemaMock();
|
||||
delete payload.id;
|
||||
const decoded = deleteListSchema.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 not allow an extra key to be sent in', () => {
|
||||
const payload: DeleteListSchema & { extraKey?: string } = getDeleteListSchemaMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = deleteListSchema.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({});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* 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 { LIST_ID } from '../../constants.mock';
|
||||
|
||||
import { ExportListItemQuerySchema } from './export_list_item_query_schema';
|
||||
|
||||
export const getExportListItemQuerySchemaMock = (): ExportListItemQuerySchema => ({
|
||||
list_id: LIST_ID,
|
||||
});
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 {
|
||||
ExportListItemQuerySchema,
|
||||
exportListItemQuerySchema,
|
||||
} from './export_list_item_query_schema';
|
||||
import { getExportListItemQuerySchemaMock } from './export_list_item_query_schema.mock';
|
||||
|
||||
describe('export_list_item_schema', () => {
|
||||
test('it should validate a typical lists request', () => {
|
||||
const payload = getExportListItemQuerySchemaMock();
|
||||
const decoded = exportListItemQuerySchema.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 = getExportListItemQuerySchemaMock();
|
||||
delete payload.list_id;
|
||||
const decoded = exportListItemQuerySchema.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: ExportListItemQuerySchema & {
|
||||
extraKey?: string;
|
||||
} = getExportListItemQuerySchemaMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = exportListItemQuerySchema.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({});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* 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 { LIST_ID, TYPE } from '../../constants.mock';
|
||||
|
||||
import { ImportListItemQuerySchema } from './import_list_item_query_schema';
|
||||
|
||||
export const getImportListItemQuerySchemaMock = (): ImportListItemQuerySchema => ({
|
||||
list_id: LIST_ID,
|
||||
type: TYPE,
|
||||
});
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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 {
|
||||
ImportListItemQuerySchema,
|
||||
importListItemQuerySchema,
|
||||
} from './import_list_item_query_schema';
|
||||
import { getImportListItemQuerySchemaMock } from './import_list_item_query_schema.mock';
|
||||
|
||||
describe('import_list_item_schema', () => {
|
||||
test('it should validate a typical lists request', () => {
|
||||
const payload = getImportListItemQuerySchemaMock();
|
||||
const decoded = importListItemQuerySchema.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 undefined for "list_id"', () => {
|
||||
const payload = getImportListItemQuerySchemaMock();
|
||||
delete payload.list_id;
|
||||
const decoded = importListItemQuerySchema.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 undefined for "type"', () => {
|
||||
const payload = getImportListItemQuerySchemaMock();
|
||||
delete payload.type;
|
||||
const decoded = importListItemQuerySchema.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 undefined for "type" and "list_id', () => {
|
||||
const payload = getImportListItemQuerySchemaMock();
|
||||
delete payload.type;
|
||||
delete payload.list_id;
|
||||
const decoded = importListItemQuerySchema.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 an extra key to be sent in', () => {
|
||||
const payload: ImportListItemQuerySchema & {
|
||||
extraKey?: string;
|
||||
} = getImportListItemQuerySchemaMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = importListItemQuerySchema.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({});
|
||||
});
|
||||
});
|
|
@ -9,9 +9,13 @@
|
|||
import * as t from 'io-ts';
|
||||
|
||||
import { list_idOrUndefined, typeOrUndefined } from '../common/schemas';
|
||||
import { Identity, RequiredKeepUndefined } from '../../types';
|
||||
|
||||
export const importListItemQuerySchema = t.exact(
|
||||
t.type({ list_id: list_idOrUndefined, type: typeOrUndefined })
|
||||
t.partial({ list_id: list_idOrUndefined, type: typeOrUndefined })
|
||||
);
|
||||
|
||||
export type ImportListItemQuerySchema = t.TypeOf<typeof importListItemQuerySchema>;
|
||||
export type ImportListItemQuerySchemaPartial = Identity<t.TypeOf<typeof importListItemQuerySchema>>;
|
||||
export type ImportListItemQuerySchema = RequiredKeepUndefined<
|
||||
t.TypeOf<typeof importListItemQuerySchema>
|
||||
>;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* 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 { ImportListItemSchema } from './import_list_item_schema';
|
||||
|
||||
export const getImportListItemSchemaMock = (): ImportListItemSchema => ({
|
||||
file: {},
|
||||
});
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 { ImportListItemSchema, importListItemSchema } from './import_list_item_schema';
|
||||
import { getImportListItemSchemaMock } from './import_list_item_schema.mock';
|
||||
|
||||
describe('import_list_item_schema', () => {
|
||||
test('it should validate a typical lists request', () => {
|
||||
const payload = getImportListItemSchemaMock();
|
||||
const decoded = importListItemSchema.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 a file', () => {
|
||||
const payload = getImportListItemSchemaMock();
|
||||
delete payload.file;
|
||||
const decoded = importListItemSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "file"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should not allow an extra key to be sent in', () => {
|
||||
const payload: ImportListItemSchema & {
|
||||
extraKey?: string;
|
||||
} = getImportListItemSchemaMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = importListItemSchema.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({});
|
||||
});
|
||||
});
|
|
@ -18,6 +18,8 @@ export const importListItemSchema = t.exact(
|
|||
})
|
||||
);
|
||||
|
||||
export type ImportListItemSchema = t.TypeOf<typeof importListItemSchema>;
|
||||
|
||||
export interface HapiReadableStream extends Readable {
|
||||
hapi: {
|
||||
filename: string;
|
||||
|
@ -27,6 +29,6 @@ export interface HapiReadableStream extends Readable {
|
|||
/**
|
||||
* Special interface since we are streaming in a file through a reader
|
||||
*/
|
||||
export interface ImportListItemSchema {
|
||||
export interface ImportListItemHapiFileSchema {
|
||||
file: HapiReadableStream;
|
||||
}
|
||||
|
|
|
@ -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 { LIST_ITEM_ID, META, VALUE } from '../../constants.mock';
|
||||
|
||||
import { PatchListItemSchema } from './patch_list_item_schema';
|
||||
|
||||
export const getPathListItemSchemaMock = (): PatchListItemSchema => ({
|
||||
id: LIST_ITEM_ID,
|
||||
meta: META,
|
||||
value: VALUE,
|
||||
});
|
|
@ -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 '../../siem_common_deps';
|
||||
|
||||
import { getPathListItemSchemaMock } from './patch_list_item_schema.mock';
|
||||
import { PatchListItemSchema, patchListItemSchema } from './patch_list_item_schema';
|
||||
|
||||
describe('patch_list_item_schema', () => {
|
||||
test('it should validate a typical list item request', () => {
|
||||
const payload = getPathListItemSchemaMock();
|
||||
const decoded = patchListItemSchema.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 "id"', () => {
|
||||
const payload = getPathListItemSchemaMock();
|
||||
delete payload.id;
|
||||
const decoded = patchListItemSchema.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 accept an undefined for "meta"', () => {
|
||||
const payload = getPathListItemSchemaMock();
|
||||
delete payload.meta;
|
||||
const decoded = patchListItemSchema.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 undefined for "value"', () => {
|
||||
const payload = getPathListItemSchemaMock();
|
||||
delete payload.value;
|
||||
const decoded = patchListItemSchema.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 undefined for "meta" and "value"', () => {
|
||||
const payload = getPathListItemSchemaMock();
|
||||
delete payload.meta;
|
||||
delete payload.value;
|
||||
const decoded = patchListItemSchema.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 an extra key to be sent in', () => {
|
||||
const payload: PatchListItemSchema & { extraKey?: string } = getPathListItemSchemaMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = patchListItemSchema.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({});
|
||||
});
|
||||
});
|
|
@ -9,13 +9,16 @@
|
|||
import * as t from 'io-ts';
|
||||
|
||||
import { id, metaOrUndefined, valueOrUndefined } from '../common/schemas';
|
||||
import { Identity, RequiredKeepUndefined } from '../../types';
|
||||
|
||||
export const patchListItemSchema = t.exact(
|
||||
t.type({
|
||||
id,
|
||||
meta: metaOrUndefined,
|
||||
value: valueOrUndefined,
|
||||
})
|
||||
);
|
||||
export const patchListItemSchema = t.intersection([
|
||||
t.exact(
|
||||
t.type({
|
||||
id,
|
||||
})
|
||||
),
|
||||
t.exact(t.partial({ meta: metaOrUndefined, value: valueOrUndefined })),
|
||||
]);
|
||||
|
||||
export type PatchListItemSchema = t.TypeOf<typeof patchListItemSchema>;
|
||||
export type PatchListItemSchemaPartial = Identity<t.TypeOf<typeof patchListItemSchema>>;
|
||||
export type PatchListItemSchema = RequiredKeepUndefined<t.TypeOf<typeof patchListItemSchema>>;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* 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 { DESCRIPTION, LIST_ITEM_ID, META, NAME } from '../../constants.mock';
|
||||
|
||||
import { PatchListSchema } from './patch_list_schema';
|
||||
|
||||
export const getPathListSchemaMock = (): PatchListSchema => ({
|
||||
description: DESCRIPTION,
|
||||
id: LIST_ITEM_ID,
|
||||
meta: META,
|
||||
name: NAME,
|
||||
});
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* 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 { getPathListSchemaMock } from './patch_list_schema.mock';
|
||||
import { PatchListSchema, patchListSchema } from './patch_list_schema';
|
||||
|
||||
describe('patch_list_schema', () => {
|
||||
test('it should validate a typical list item request', () => {
|
||||
const payload = getPathListSchemaMock();
|
||||
const decoded = patchListSchema.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 "id"', () => {
|
||||
const payload = getPathListSchemaMock();
|
||||
delete payload.id;
|
||||
const decoded = patchListSchema.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 accept an undefined for "meta"', () => {
|
||||
const payload = getPathListSchemaMock();
|
||||
delete payload.meta;
|
||||
const decoded = patchListSchema.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 undefined for "name"', () => {
|
||||
const payload = getPathListSchemaMock();
|
||||
delete payload.name;
|
||||
const decoded = patchListSchema.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 undefined for "description"', () => {
|
||||
const payload = getPathListSchemaMock();
|
||||
delete payload.description;
|
||||
const decoded = patchListSchema.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 undefined for "description", "meta", "name', () => {
|
||||
const payload = getPathListSchemaMock();
|
||||
delete payload.description;
|
||||
delete payload.name;
|
||||
delete payload.meta;
|
||||
const decoded = patchListSchema.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 undefined for "description", "meta"', () => {
|
||||
const payload = getPathListSchemaMock();
|
||||
delete payload.description;
|
||||
delete payload.meta;
|
||||
const decoded = patchListSchema.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 undefined for "description", "name"', () => {
|
||||
const payload = getPathListSchemaMock();
|
||||
delete payload.description;
|
||||
delete payload.name;
|
||||
const decoded = patchListSchema.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 undefined for "meta", "name"', () => {
|
||||
const payload = getPathListSchemaMock();
|
||||
delete payload.meta;
|
||||
delete payload.name;
|
||||
const decoded = patchListSchema.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 an extra key to be sent in', () => {
|
||||
const payload: PatchListSchema & { extraKey?: string } = getPathListSchemaMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = patchListSchema.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({});
|
||||
});
|
||||
});
|
|
@ -9,14 +9,18 @@
|
|||
import * as t from 'io-ts';
|
||||
|
||||
import { descriptionOrUndefined, id, metaOrUndefined, nameOrUndefined } from '../common/schemas';
|
||||
import { Identity, RequiredKeepUndefined } from '../../types';
|
||||
|
||||
export const patchListSchema = t.exact(
|
||||
t.type({
|
||||
description: descriptionOrUndefined,
|
||||
id,
|
||||
meta: metaOrUndefined,
|
||||
name: nameOrUndefined,
|
||||
})
|
||||
);
|
||||
export const patchListSchema = t.intersection([
|
||||
t.exact(
|
||||
t.type({
|
||||
id,
|
||||
})
|
||||
),
|
||||
t.exact(
|
||||
t.partial({ description: descriptionOrUndefined, meta: metaOrUndefined, name: nameOrUndefined })
|
||||
),
|
||||
]);
|
||||
|
||||
export type PatchListSchema = t.TypeOf<typeof patchListSchema>;
|
||||
export type PatchListSchemaPartial = Identity<t.TypeOf<typeof patchListSchema>>;
|
||||
export type PatchListSchema = RequiredKeepUndefined<Identity<t.TypeOf<typeof patchListSchema>>>;
|
||||
|
|
|
@ -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 { LIST_ID, LIST_ITEM_ID, VALUE } from '../../constants.mock';
|
||||
|
||||
import { ReadListItemSchema } from './read_list_item_schema';
|
||||
|
||||
export const getReadListItemSchemaMock = (): ReadListItemSchema => ({
|
||||
id: LIST_ITEM_ID,
|
||||
list_id: LIST_ID,
|
||||
value: VALUE,
|
||||
});
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* 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 { getReadListItemSchemaMock } from './read_list_item_schema.mock';
|
||||
import { ReadListItemSchema, readListItemSchema } from './read_list_item_schema';
|
||||
|
||||
describe('read_list_item_schema', () => {
|
||||
test('it should validate a typical list item request', () => {
|
||||
const payload = getReadListItemSchemaMock();
|
||||
const decoded = readListItemSchema.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 undefined for "id"', () => {
|
||||
const payload = getReadListItemSchemaMock();
|
||||
delete payload.id;
|
||||
const decoded = readListItemSchema.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 undefined for "list_id"', () => {
|
||||
const payload = getReadListItemSchemaMock();
|
||||
delete payload.list_id;
|
||||
const decoded = readListItemSchema.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 undefined for "value"', () => {
|
||||
const payload = getReadListItemSchemaMock();
|
||||
delete payload.value;
|
||||
const decoded = readListItemSchema.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 undefined for "id", "list_id", "value"', () => {
|
||||
const payload = getReadListItemSchemaMock();
|
||||
delete payload.id;
|
||||
delete payload.value;
|
||||
delete payload.list_id;
|
||||
const decoded = readListItemSchema.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 undefined for "id", "list_id"', () => {
|
||||
const payload = getReadListItemSchemaMock();
|
||||
delete payload.id;
|
||||
delete payload.list_id;
|
||||
const decoded = readListItemSchema.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 undefined for "id", "value"', () => {
|
||||
const payload = getReadListItemSchemaMock();
|
||||
delete payload.id;
|
||||
delete payload.value;
|
||||
const decoded = readListItemSchema.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 undefined for "list_id", "value"', () => {
|
||||
const payload = getReadListItemSchemaMock();
|
||||
delete payload.value;
|
||||
delete payload.list_id;
|
||||
const decoded = readListItemSchema.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 an extra key to be sent in', () => {
|
||||
const payload: ReadListItemSchema & { extraKey?: string } = getReadListItemSchemaMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = readListItemSchema.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({});
|
||||
});
|
||||
});
|
|
@ -9,9 +9,11 @@
|
|||
import * as t from 'io-ts';
|
||||
|
||||
import { idOrUndefined, list_idOrUndefined, valueOrUndefined } from '../common/schemas';
|
||||
import { Identity, RequiredKeepUndefined } from '../../types';
|
||||
|
||||
export const readListItemSchema = t.exact(
|
||||
t.type({ id: idOrUndefined, list_id: list_idOrUndefined, value: valueOrUndefined })
|
||||
t.partial({ id: idOrUndefined, list_id: list_idOrUndefined, value: valueOrUndefined })
|
||||
);
|
||||
|
||||
export type ReadListItemSchema = t.TypeOf<typeof readListItemSchema>;
|
||||
export type ReadListItemSchemaPartial = Identity<t.TypeOf<typeof readListItemSchema>>;
|
||||
export type ReadListItemSchema = RequiredKeepUndefined<t.TypeOf<typeof readListItemSchema>>;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* 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 { LIST_ID } from '../../constants.mock';
|
||||
|
||||
import { ReadListSchema } from './read_list_schema';
|
||||
|
||||
export const getReadListSchemaMock = (): ReadListSchema => ({
|
||||
id: LIST_ID,
|
||||
});
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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 { getReadListSchemaMock } from './read_list_schema.mock';
|
||||
import { ReadListSchema, readListSchema } from './read_list_schema';
|
||||
|
||||
describe('read_list_schema', () => {
|
||||
test('it should validate a typical list item request', () => {
|
||||
const payload = getReadListSchemaMock();
|
||||
const decoded = readListSchema.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 "id"', () => {
|
||||
const payload = getReadListSchemaMock();
|
||||
delete payload.id;
|
||||
const decoded = readListSchema.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 not allow an extra key to be sent in', () => {
|
||||
const payload: ReadListSchema & { extraKey?: string } = getReadListSchemaMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = readListSchema.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({});
|
||||
});
|
||||
});
|
|
@ -9,13 +9,17 @@
|
|||
import * as t from 'io-ts';
|
||||
|
||||
import { id, metaOrUndefined, value } from '../common/schemas';
|
||||
import { Identity, RequiredKeepUndefined } from '../../types';
|
||||
|
||||
export const updateListItemSchema = t.exact(
|
||||
t.type({
|
||||
id,
|
||||
meta: metaOrUndefined,
|
||||
value,
|
||||
})
|
||||
);
|
||||
export const updateListItemSchema = t.intersection([
|
||||
t.exact(
|
||||
t.type({
|
||||
id,
|
||||
value,
|
||||
})
|
||||
),
|
||||
t.exact(t.partial({ meta: metaOrUndefined })),
|
||||
]);
|
||||
|
||||
export type UpdateListItemSchema = t.TypeOf<typeof updateListItemSchema>;
|
||||
export type UpdateListItemSchemaPartial = Identity<t.TypeOf<typeof updateListItemSchema>>;
|
||||
export type UpdateListItemSchema = RequiredKeepUndefined<t.TypeOf<typeof updateListItemSchema>>;
|
||||
|
|
|
@ -9,14 +9,18 @@
|
|||
import * as t from 'io-ts';
|
||||
|
||||
import { description, id, metaOrUndefined, name } from '../common/schemas';
|
||||
import { Identity, RequiredKeepUndefined } from '../../types';
|
||||
|
||||
export const updateListSchema = t.exact(
|
||||
t.type({
|
||||
description,
|
||||
id,
|
||||
meta: metaOrUndefined,
|
||||
name,
|
||||
})
|
||||
);
|
||||
export const updateListSchema = t.intersection([
|
||||
t.exact(
|
||||
t.type({
|
||||
description,
|
||||
id,
|
||||
name,
|
||||
})
|
||||
),
|
||||
t.exact(t.partial({ meta: metaOrUndefined })),
|
||||
]);
|
||||
|
||||
export type UpdateListSchema = t.TypeOf<typeof updateListSchema>;
|
||||
export type UpdateListSchemaPartial = Identity<t.TypeOf<typeof updateListSchema>>;
|
||||
export type UpdateListSchema = RequiredKeepUndefined<t.TypeOf<typeof updateListSchema>>;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* 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 { AcknowledgeSchema } from './acknowledge_schema';
|
||||
|
||||
export const getAcknowledgeSchemaResponseMock = (): AcknowledgeSchema => ({
|
||||
acknowledged: true,
|
||||
});
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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 { getAcknowledgeSchemaResponseMock } from './acknowledge_schema.mock';
|
||||
import { AcknowledgeSchema, acknowledgeSchema } from './acknowledge_schema';
|
||||
|
||||
describe('acknowledge_schema', () => {
|
||||
test('it should validate a typical response', () => {
|
||||
const payload = getAcknowledgeSchemaResponseMock();
|
||||
const decoded = acknowledgeSchema.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 "ok"', () => {
|
||||
const payload = getAcknowledgeSchemaResponseMock();
|
||||
delete payload.acknowledged;
|
||||
const decoded = acknowledgeSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "acknowledged"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should not allow an extra key to be sent in', () => {
|
||||
const payload: AcknowledgeSchema & { extraKey?: string } = getAcknowledgeSchemaResponseMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = acknowledgeSchema.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({});
|
||||
});
|
||||
});
|
|
@ -6,6 +6,6 @@
|
|||
|
||||
import * as t from 'io-ts';
|
||||
|
||||
export const acknowledgeSchema = t.type({ acknowledged: t.boolean });
|
||||
export const acknowledgeSchema = t.exact(t.type({ acknowledged: t.boolean }));
|
||||
|
||||
export type AcknowledgeSchema = t.TypeOf<typeof acknowledgeSchema>;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* 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 { ListItemIndexExistSchema } from './list_item_index_exist_schema';
|
||||
|
||||
export const getListItemIndexExistSchemaResponseMock = (): ListItemIndexExistSchema => ({
|
||||
list_index: true,
|
||||
list_item_index: true,
|
||||
});
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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 { getListItemIndexExistSchemaResponseMock } from './list_item_index_exist_schema.mock';
|
||||
import { ListItemIndexExistSchema, listItemIndexExistSchema } from './list_item_index_exist_schema';
|
||||
|
||||
describe('list_item_index_exist_schema', () => {
|
||||
test('it should validate a typical list item request', () => {
|
||||
const payload = getListItemIndexExistSchemaResponseMock();
|
||||
const decoded = listItemIndexExistSchema.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 "list_index"', () => {
|
||||
const payload = getListItemIndexExistSchemaResponseMock();
|
||||
delete payload.list_index;
|
||||
const decoded = listItemIndexExistSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "list_index"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "list_item_index"', () => {
|
||||
const payload = getListItemIndexExistSchemaResponseMock();
|
||||
delete payload.list_item_index;
|
||||
const decoded = listItemIndexExistSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "list_item_index"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should not allow an extra key to be sent in', () => {
|
||||
const payload: ListItemIndexExistSchema & {
|
||||
extraKey?: string;
|
||||
} = getListItemIndexExistSchemaResponseMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = listItemIndexExistSchema.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({});
|
||||
});
|
||||
});
|
|
@ -6,9 +6,11 @@
|
|||
|
||||
import * as t from 'io-ts';
|
||||
|
||||
export const listItemIndexExistSchema = t.type({
|
||||
list_index: t.boolean,
|
||||
list_item_index: t.boolean,
|
||||
});
|
||||
export const listItemIndexExistSchema = t.exact(
|
||||
t.type({
|
||||
list_index: t.boolean,
|
||||
list_item_index: t.boolean,
|
||||
})
|
||||
);
|
||||
|
||||
export type ListItemIndexExistSchema = t.TypeOf<typeof listItemIndexExistSchema>;
|
||||
|
|
|
@ -5,17 +5,25 @@
|
|||
*/
|
||||
|
||||
import { ListItemSchema } from '../../../common/schemas';
|
||||
|
||||
import { DATE_NOW, LIST_ID, LIST_ITEM_ID, USER, VALUE } from './lists_services_mock_constants';
|
||||
import {
|
||||
DATE_NOW,
|
||||
LIST_ID,
|
||||
LIST_ITEM_ID,
|
||||
META,
|
||||
TIE_BREAKER,
|
||||
TYPE,
|
||||
USER,
|
||||
VALUE,
|
||||
} from '../../../common/constants.mock';
|
||||
|
||||
export const getListItemResponseMock = (): ListItemSchema => ({
|
||||
created_at: DATE_NOW,
|
||||
created_by: USER,
|
||||
id: LIST_ITEM_ID,
|
||||
list_id: LIST_ID,
|
||||
meta: {},
|
||||
tie_breaker_id: '6a76b69d-80df-4ab2-8c3e-85f466b06a0e',
|
||||
type: 'ip',
|
||||
meta: META,
|
||||
tie_breaker_id: TIE_BREAKER,
|
||||
type: TYPE,
|
||||
updated_at: DATE_NOW,
|
||||
updated_by: USER,
|
||||
value: VALUE,
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* 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 { getListItemResponseMock } from './list_item_schema.mock';
|
||||
import { ListItemSchema, listItemSchema } from './list_item_schema';
|
||||
|
||||
describe('list_item_schema', () => {
|
||||
test('it should validate a typical list item response', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
const decoded = listItemSchema.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 "id"', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
delete payload.id;
|
||||
const decoded = listItemSchema.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 NOT accept an undefined for "list_id"', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
delete payload.list_id;
|
||||
const decoded = listItemSchema.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 accept an undefined for "meta"', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
delete payload.meta;
|
||||
const decoded = listItemSchema.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 "created_at"', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
delete payload.created_at;
|
||||
const decoded = listItemSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "created_at"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "created_by"', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
delete payload.created_by;
|
||||
const decoded = listItemSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "created_by"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "tie_breaker_id"', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
delete payload.tie_breaker_id;
|
||||
const decoded = listItemSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "tie_breaker_id"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "type"', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
delete payload.type;
|
||||
const decoded = listItemSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "type"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "updated_at"', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
delete payload.updated_at;
|
||||
const decoded = listItemSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "updated_at"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "updated_by"', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
delete payload.updated_by;
|
||||
const decoded = listItemSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "updated_by"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "value"', () => {
|
||||
const payload = getListItemResponseMock();
|
||||
delete payload.value;
|
||||
const decoded = listItemSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "value"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should not allow an extra key to be sent in', () => {
|
||||
const payload: ListItemSchema & { extraKey?: string } = getListItemResponseMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = listItemSchema.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({});
|
||||
});
|
||||
});
|
|
@ -5,18 +5,26 @@
|
|||
*/
|
||||
|
||||
import { ListSchema } from '../../../common/schemas';
|
||||
|
||||
import { DATE_NOW, DESCRIPTION, LIST_ID, NAME, USER } from './lists_services_mock_constants';
|
||||
import {
|
||||
DATE_NOW,
|
||||
DESCRIPTION,
|
||||
LIST_ID,
|
||||
META,
|
||||
NAME,
|
||||
TIE_BREAKER,
|
||||
TYPE,
|
||||
USER,
|
||||
} from '../../../common/constants.mock';
|
||||
|
||||
export const getListResponseMock = (): ListSchema => ({
|
||||
created_at: DATE_NOW,
|
||||
created_by: USER,
|
||||
description: DESCRIPTION,
|
||||
id: LIST_ID,
|
||||
meta: {},
|
||||
meta: META,
|
||||
name: NAME,
|
||||
tie_breaker_id: '6a76b69d-80df-4ab2-8c3e-85f466b06a0e',
|
||||
type: 'ip',
|
||||
tie_breaker_id: TIE_BREAKER,
|
||||
type: TYPE,
|
||||
updated_at: DATE_NOW,
|
||||
updated_by: USER,
|
||||
});
|
161
x-pack/plugins/lists/common/schemas/response/list_schema.test.ts
Normal file
161
x-pack/plugins/lists/common/schemas/response/list_schema.test.ts
Normal file
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* 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 { getListResponseMock } from './list_schema.mock';
|
||||
import { ListSchema, listSchema } from './list_schema';
|
||||
|
||||
describe('list_schema', () => {
|
||||
test('it should validate a typical list response', () => {
|
||||
const payload = getListResponseMock();
|
||||
const decoded = listSchema.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 "id"', () => {
|
||||
const payload = getListResponseMock();
|
||||
delete payload.id;
|
||||
const decoded = listSchema.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 accept an undefined for "meta"', () => {
|
||||
const payload = getListResponseMock();
|
||||
delete payload.meta;
|
||||
const decoded = listSchema.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 "created_at"', () => {
|
||||
const payload = getListResponseMock();
|
||||
delete payload.created_at;
|
||||
const decoded = listSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "created_at"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "created_by"', () => {
|
||||
const payload = getListResponseMock();
|
||||
delete payload.created_by;
|
||||
const decoded = listSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "created_by"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "tie_breaker_id"', () => {
|
||||
const payload = getListResponseMock();
|
||||
delete payload.tie_breaker_id;
|
||||
const decoded = listSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "tie_breaker_id"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "type"', () => {
|
||||
const payload = getListResponseMock();
|
||||
delete payload.type;
|
||||
const decoded = listSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "type"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "updated_at"', () => {
|
||||
const payload = getListResponseMock();
|
||||
delete payload.updated_at;
|
||||
const decoded = listSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "updated_at"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "updated_by"', () => {
|
||||
const payload = getListResponseMock();
|
||||
delete payload.updated_by;
|
||||
const decoded = listSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "updated_by"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "name"', () => {
|
||||
const payload = getListResponseMock();
|
||||
delete payload.name;
|
||||
const decoded = listSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "name"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should NOT accept an undefined for "description"', () => {
|
||||
const payload = getListResponseMock();
|
||||
delete payload.description;
|
||||
const decoded = listSchema.decode(payload);
|
||||
const checked = exactCheck(payload, decoded);
|
||||
const message = pipe(checked, foldLeftRight);
|
||||
|
||||
expect(getPaths(left(message.errors))).toEqual([
|
||||
'Invalid value "undefined" supplied to "description"',
|
||||
]);
|
||||
expect(message.schema).toEqual({});
|
||||
});
|
||||
|
||||
test('it should not allow an extra key to be sent in', () => {
|
||||
const payload: ListSchema & { extraKey?: string } = getListResponseMock();
|
||||
payload.extraKey = 'some new value';
|
||||
const decoded = listSchema.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({});
|
||||
});
|
||||
});
|
30
x-pack/plugins/lists/common/types.ts
Normal file
30
x-pack/plugins/lists/common/types.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This makes any optional property the same as Required<T> would but also has the
|
||||
* added benefit of keeping your undefined.
|
||||
*
|
||||
* For example:
|
||||
* type A = RequiredKeepUndefined<{ a?: undefined; b: number }>;
|
||||
*
|
||||
* will yield a type of:
|
||||
* type A = { a: undefined; b: number; }
|
||||
*
|
||||
*/
|
||||
export type RequiredKeepUndefined<T> = { [K in keyof T]-?: [T[K]] } extends infer U
|
||||
? U extends Record<keyof U, [unknown]>
|
||||
? { [K in keyof U]: U[K][0] }
|
||||
: never
|
||||
: never;
|
||||
|
||||
/**
|
||||
* This is just a helper to cleanup nasty intersections and unions to make them
|
||||
* readable from io.ts, it's an identity that strips away the uglyness of them.
|
||||
*/
|
||||
export type Identity<T> = {
|
||||
[P in keyof T]: T[P];
|
||||
};
|
|
@ -14,7 +14,7 @@ import {
|
|||
validate,
|
||||
} from '../siem_server_deps';
|
||||
import {
|
||||
ImportListItemSchema,
|
||||
ImportListItemHapiFileSchema,
|
||||
importListItemQuerySchema,
|
||||
importListItemSchema,
|
||||
listSchema,
|
||||
|
@ -33,7 +33,7 @@ export const importListItemRoute = (router: IRouter): void => {
|
|||
},
|
||||
path: `${LIST_ITEM_URL}/_import`,
|
||||
validate: {
|
||||
body: buildRouteValidation<typeof importListItemSchema, ImportListItemSchema>(
|
||||
body: buildRouteValidation<typeof importListItemSchema, ImportListItemHapiFileSchema>(
|
||||
importListItemSchema
|
||||
),
|
||||
query: buildRouteValidation(importListItemQuerySchema),
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { TestReadable } from '../mocks';
|
||||
import { TestReadable } from '../../../common/test_readable.mock';
|
||||
|
||||
import { BufferLines } from './buffer_lines';
|
||||
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { CreateListItemOptions } from '../items';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import {
|
||||
DATE_NOW,
|
||||
LIST_ID,
|
||||
|
@ -16,7 +15,7 @@ import {
|
|||
TIE_BREAKER,
|
||||
TYPE,
|
||||
USER,
|
||||
} from './lists_services_mock_constants';
|
||||
} from '../../../common/constants.mock';
|
||||
|
||||
export const getCreateListItemOptionsMock = (): CreateListItemOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
|
@ -4,15 +4,12 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import {
|
||||
LIST_ITEM_ID,
|
||||
LIST_ITEM_INDEX,
|
||||
getCreateListItemOptionsMock,
|
||||
getIndexESListItemMock,
|
||||
getListItemResponseMock,
|
||||
} from '../mocks';
|
||||
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
|
||||
import { getIndexESListItemMock } from '../../../common/schemas/elastic_query/index_es_list_item_schema.mock';
|
||||
import { LIST_ITEM_ID, LIST_ITEM_INDEX } from '../../../common/constants.mock';
|
||||
|
||||
import { createListItem } from './create_list_item';
|
||||
import { getCreateListItemOptionsMock } from './create_list_item.mock';
|
||||
|
||||
describe('crete_list_item', () => {
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { CreateListItemsBulkOptions } from '../items';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import {
|
||||
DATE_NOW,
|
||||
LIST_ID,
|
||||
|
@ -17,7 +16,7 @@ import {
|
|||
USER,
|
||||
VALUE,
|
||||
VALUE_2,
|
||||
} from './lists_services_mock_constants';
|
||||
} from '../../../common/constants.mock';
|
||||
|
||||
export const getCreateListItemBulkOptionsMock = (): CreateListItemsBulkOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
|
@ -4,16 +4,11 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { IndexEsListItemSchema } from '../../../common/schemas';
|
||||
import {
|
||||
LIST_ITEM_INDEX,
|
||||
TIE_BREAKERS,
|
||||
VALUE_2,
|
||||
getCreateListItemBulkOptionsMock,
|
||||
getIndexESListItemMock,
|
||||
} from '../mocks';
|
||||
import { getIndexESListItemMock } from '../../../common/schemas/elastic_query/index_es_list_item_schema.mock';
|
||||
import { LIST_ITEM_INDEX, TIE_BREAKERS, VALUE_2 } from '../../../common/constants.mock';
|
||||
|
||||
import { createListItemsBulk } from './create_list_items_bulk';
|
||||
import { getCreateListItemBulkOptionsMock } from './create_list_items_bulk.mock';
|
||||
|
||||
describe('crete_list_item_bulk', () => {
|
||||
beforeEach(() => {
|
||||
|
@ -27,8 +22,8 @@ describe('crete_list_item_bulk', () => {
|
|||
test('It calls "callCluster" with body, index, and the bulk items', async () => {
|
||||
const options = getCreateListItemBulkOptionsMock();
|
||||
await createListItemsBulk(options);
|
||||
const firstRecord: IndexEsListItemSchema = getIndexESListItemMock();
|
||||
const secondRecord: IndexEsListItemSchema = getIndexESListItemMock(VALUE_2);
|
||||
const firstRecord = getIndexESListItemMock();
|
||||
const secondRecord = getIndexESListItemMock(VALUE_2);
|
||||
[firstRecord.tie_breaker_id, secondRecord.tie_breaker_id] = TIE_BREAKERS;
|
||||
expect(options.callCluster).toBeCalledWith('bulk', {
|
||||
body: [
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { DeleteListItemOptions } from '../items';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import { LIST_ITEM_ID, LIST_ITEM_INDEX } from './lists_services_mock_constants';
|
||||
import { LIST_ITEM_ID, LIST_ITEM_INDEX } from '../../../common/constants.mock';
|
||||
|
||||
export const getDeleteListItemOptionsMock = (): DeleteListItemOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
|
@ -4,15 +4,12 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import {
|
||||
LIST_ITEM_ID,
|
||||
LIST_ITEM_INDEX,
|
||||
getDeleteListItemOptionsMock,
|
||||
getListItemResponseMock,
|
||||
} from '../mocks';
|
||||
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
|
||||
import { LIST_ITEM_ID, LIST_ITEM_INDEX } from '../../../common/constants.mock';
|
||||
|
||||
import { getListItem } from './get_list_item';
|
||||
import { deleteListItem } from './delete_list_item';
|
||||
import { getDeleteListItemOptionsMock } from './delete_list_item.mock';
|
||||
|
||||
jest.mock('./get_list_item', () => ({
|
||||
getListItem: jest.fn(),
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { DeleteListItemByValueOptions } from '../items';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE } from './lists_services_mock_constants';
|
||||
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE } from '../../../common/constants.mock';
|
||||
|
||||
export const getDeleteListItemByValueOptionsMock = (): DeleteListItemByValueOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
|
@ -4,10 +4,11 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getDeleteListItemByValueOptionsMock, getListItemResponseMock } from '../mocks';
|
||||
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
|
||||
|
||||
import { getListItemByValues } from './get_list_item_by_values';
|
||||
import { deleteListItemByValue } from './delete_list_item_by_value';
|
||||
import { getDeleteListItemByValueOptionsMock } from './delete_list_item_by_value.mock';
|
||||
|
||||
jest.mock('./get_list_item_by_values', () => ({
|
||||
getListItemByValues: jest.fn(),
|
||||
|
|
|
@ -4,13 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import {
|
||||
LIST_ID,
|
||||
LIST_INDEX,
|
||||
getCallClusterMock,
|
||||
getListItemResponseMock,
|
||||
getSearchListItemMock,
|
||||
} from '../mocks';
|
||||
import { getSearchListItemMock } from '../../../common/schemas/elastic_response/search_es_list_item_schema.mock';
|
||||
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { LIST_ID, LIST_INDEX } from '../../../common/constants.mock';
|
||||
|
||||
import { getListItem } from './get_list_item';
|
||||
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { GetListItemByValueOptions } from '../items';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE } from './lists_services_mock_constants';
|
||||
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE } from '../../../common/constants.mock';
|
||||
|
||||
export const getListItemByValueOptionsMocks = (): GetListItemByValueOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
|
@ -4,10 +4,11 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getListItemByValueOptionsMocks, getListItemResponseMock } from '../mocks';
|
||||
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
|
||||
|
||||
import { getListItemByValues } from './get_list_item_by_values';
|
||||
import { getListItemByValue } from './get_list_item_by_value';
|
||||
import { getListItemByValueOptionsMocks } from './get_list_item_by_value.mock';
|
||||
|
||||
jest.mock('./get_list_item_by_values', () => ({
|
||||
getListItemByValues: jest.fn(),
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { GetListItemByValuesOptions } from '../items';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE, VALUE_2 } from './lists_services_mock_constants';
|
||||
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE, VALUE_2 } from '../../../common/constants.mock';
|
||||
|
||||
export const getListItemByValuesOptionsMocks = (): GetListItemByValuesOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
|
@ -4,15 +4,20 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getSearchListItemMock } from '../../../common/schemas/elastic_response/search_es_list_item_schema.mock';
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import {
|
||||
DATE_NOW,
|
||||
LIST_ID,
|
||||
LIST_ITEM_ID,
|
||||
LIST_ITEM_INDEX,
|
||||
META,
|
||||
TIE_BREAKER,
|
||||
TYPE,
|
||||
USER,
|
||||
VALUE,
|
||||
VALUE_2,
|
||||
getCallClusterMock,
|
||||
getSearchListItemMock,
|
||||
} from '../mocks';
|
||||
} from '../../../common/constants.mock';
|
||||
|
||||
import { getListItemByValues } from './get_list_item_by_values';
|
||||
|
||||
|
@ -53,16 +58,16 @@ describe('get_list_item_by_values', () => {
|
|||
|
||||
expect(listItem).toEqual([
|
||||
{
|
||||
created_at: '2020-04-20T15:25:31.830Z',
|
||||
created_by: 'some user',
|
||||
id: 'some-list-item-id',
|
||||
list_id: 'some-list-id',
|
||||
meta: {},
|
||||
tie_breaker_id: '6a76b69d-80df-4ab2-8c3e-85f466b06a0e',
|
||||
type: 'ip',
|
||||
updated_at: '2020-04-20T15:25:31.830Z',
|
||||
updated_by: 'some user',
|
||||
value: '127.0.0.1',
|
||||
created_at: DATE_NOW,
|
||||
created_by: USER,
|
||||
id: LIST_ITEM_ID,
|
||||
list_id: LIST_ID,
|
||||
meta: META,
|
||||
tie_breaker_id: TIE_BREAKER,
|
||||
type: TYPE,
|
||||
updated_at: DATE_NOW,
|
||||
updated_by: USER,
|
||||
value: VALUE,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { UpdateListItemOptions } from '../items';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import {
|
||||
DATE_NOW,
|
||||
LIST_ITEM_ID,
|
||||
|
@ -13,7 +12,7 @@ import {
|
|||
META,
|
||||
USER,
|
||||
VALUE,
|
||||
} from './lists_services_mock_constants';
|
||||
} from '../../../common/constants.mock';
|
||||
|
||||
export const getUpdateListItemOptionsMock = (): UpdateListItemOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
|
@ -4,10 +4,11 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getListItemResponseMock, getUpdateListItemOptionsMock } from '../mocks';
|
||||
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
|
||||
|
||||
import { updateListItem } from './update_list_item';
|
||||
import { getListItem } from './get_list_item';
|
||||
import { getUpdateListItemOptionsMock } from './update_list_item.mock';
|
||||
|
||||
jest.mock('./get_list_item', () => ({
|
||||
getListItem: jest.fn(),
|
||||
|
|
|
@ -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;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { TestReadable } from '../../../common/test_readable.mock';
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { ImportListItemsToStreamOptions, WriteBufferToItemsOptions } from '../items';
|
||||
import { LIST_ID, LIST_ITEM_INDEX, META, TYPE, USER } from '../../../common/constants.mock';
|
||||
|
||||
export const getImportListItemsToStreamOptionsMock = (): ImportListItemsToStreamOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
||||
listId: LIST_ID,
|
||||
listItemIndex: LIST_ITEM_INDEX,
|
||||
meta: META,
|
||||
stream: new TestReadable(),
|
||||
type: TYPE,
|
||||
user: USER,
|
||||
});
|
||||
|
||||
export const getWriteBufferToItemsOptionsMock = (): WriteBufferToItemsOptions => ({
|
||||
buffer: [],
|
||||
callCluster: getCallClusterMock(),
|
||||
listId: LIST_ID,
|
||||
listItemIndex: LIST_ITEM_INDEX,
|
||||
meta: META,
|
||||
type: TYPE,
|
||||
user: USER,
|
||||
});
|
|
@ -4,17 +4,17 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import {
|
||||
getImportListItemsToStreamOptionsMock,
|
||||
getListItemResponseMock,
|
||||
getWriteBufferToItemsOptionsMock,
|
||||
} from '../mocks';
|
||||
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
|
||||
|
||||
import {
|
||||
LinesResult,
|
||||
importListItemsToStream,
|
||||
writeBufferToItems,
|
||||
} from './write_lines_to_bulk_list_items';
|
||||
import {
|
||||
getImportListItemsToStreamOptionsMock,
|
||||
getWriteBufferToItemsOptionsMock,
|
||||
} from './write_lines_to_bulk_list_items.mock';
|
||||
|
||||
import { getListItemByValues } from '.';
|
||||
|
||||
|
|
|
@ -4,16 +4,16 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getSearchListItemMock } from '../../../common/schemas/elastic_response/search_es_list_item_schema.mock';
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { LIST_ID, LIST_ITEM_INDEX } from '../../../common/constants.mock';
|
||||
|
||||
import {
|
||||
LIST_ID,
|
||||
LIST_ITEM_INDEX,
|
||||
getCallClusterMock,
|
||||
getExportListItemsToStreamOptionsMock,
|
||||
getResponseOptionsMock,
|
||||
getSearchListItemMock,
|
||||
getWriteNextResponseOptions,
|
||||
getWriteResponseHitsToStreamOptionsMock,
|
||||
} from '../mocks';
|
||||
} from './write_list_items_to_streams.mock';
|
||||
|
||||
import {
|
||||
exportListItemsToStream,
|
||||
|
|
|
@ -6,16 +6,15 @@
|
|||
|
||||
import { Stream } from 'stream';
|
||||
|
||||
import { getSearchListItemMock } from '../../../common/schemas/elastic_response/search_es_list_item_schema.mock';
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import {
|
||||
ExportListItemsToStreamOptions,
|
||||
GetResponseOptions,
|
||||
WriteNextResponseOptions,
|
||||
WriteResponseHitsToStreamOptions,
|
||||
} from '../items';
|
||||
|
||||
import { LIST_ID, LIST_ITEM_INDEX } from './lists_services_mock_constants';
|
||||
import { getSearchListItemMock } from './get_search_list_item_mock';
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import { LIST_ID, LIST_ITEM_INDEX } from '../../../common/constants.mock';
|
||||
|
||||
export const getExportListItemsToStreamOptionsMock = (): ExportListItemsToStreamOptions => ({
|
||||
callCluster: getCallClusterMock(getSearchListItemMock()),
|
|
@ -4,9 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { CreateListOptions } from '../lists';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import {
|
||||
DATE_NOW,
|
||||
DESCRIPTION,
|
||||
|
@ -17,7 +16,7 @@ import {
|
|||
TIE_BREAKER,
|
||||
TYPE,
|
||||
USER,
|
||||
} from './lists_services_mock_constants';
|
||||
} from '../../../common/constants.mock';
|
||||
|
||||
export const getCreateListOptionsMock = (): CreateListOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
|
@ -4,15 +4,12 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import {
|
||||
LIST_ID,
|
||||
LIST_INDEX,
|
||||
getCreateListOptionsMock,
|
||||
getIndexESListMock,
|
||||
getListResponseMock,
|
||||
} from '../mocks';
|
||||
import { getListResponseMock } from '../../../common/schemas/response/list_schema.mock';
|
||||
import { getIndexESListMock } from '../../../common/schemas/elastic_query/index_es_list_schema.mock';
|
||||
import { LIST_ID, LIST_INDEX } from '../../../common/constants.mock';
|
||||
|
||||
import { createList } from './create_list';
|
||||
import { getCreateListOptionsMock } from './create_list.mock';
|
||||
|
||||
describe('crete_list', () => {
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { DeleteListOptions } from '../lists';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import { LIST_ID, LIST_INDEX, LIST_ITEM_INDEX } from './lists_services_mock_constants';
|
||||
import { LIST_ID, LIST_INDEX, LIST_ITEM_INDEX } from '../../../common/constants.mock';
|
||||
|
||||
export const getDeleteListOptionsMock = (): DeleteListOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
|
@ -4,16 +4,12 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import {
|
||||
LIST_ID,
|
||||
LIST_INDEX,
|
||||
LIST_ITEM_INDEX,
|
||||
getDeleteListOptionsMock,
|
||||
getListResponseMock,
|
||||
} from '../mocks';
|
||||
import { getListResponseMock } from '../../../common/schemas/response/list_schema.mock';
|
||||
import { LIST_ID, LIST_INDEX, LIST_ITEM_INDEX } from '../../../common/constants.mock';
|
||||
|
||||
import { getList } from './get_list';
|
||||
import { deleteList } from './delete_list';
|
||||
import { getDeleteListOptionsMock } from './delete_list.mock';
|
||||
|
||||
jest.mock('./get_list', () => ({
|
||||
getList: jest.fn(),
|
||||
|
|
|
@ -4,13 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import {
|
||||
LIST_ID,
|
||||
LIST_INDEX,
|
||||
getCallClusterMock,
|
||||
getListResponseMock,
|
||||
getSearchListMock,
|
||||
} from '../mocks';
|
||||
import { getSearchListMock } from '../../../common/schemas/elastic_response/search_es_list_schema.mock';
|
||||
import { getListResponseMock } from '../../../common/schemas/response/list_schema.mock';
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { LIST_ID, LIST_INDEX } from '../../../common/constants.mock';
|
||||
|
||||
import { getList } from './get_list';
|
||||
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { getCallClusterMock } from '../../../common/get_call_cluster.mock';
|
||||
import { UpdateListOptions } from '../lists';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import {
|
||||
DATE_NOW,
|
||||
DESCRIPTION,
|
||||
|
@ -14,7 +13,7 @@ import {
|
|||
META,
|
||||
NAME,
|
||||
USER,
|
||||
} from './lists_services_mock_constants';
|
||||
} from '../../../common/constants.mock';
|
||||
|
||||
export const getUpdateListOptionsMock = (): UpdateListOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
|
@ -4,10 +4,11 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getListResponseMock, getUpdateListOptionsMock } from '../mocks';
|
||||
import { getListResponseMock } from '../../../common/schemas/response/list_schema.mock';
|
||||
|
||||
import { updateList } from './update_list';
|
||||
import { getList } from './get_list';
|
||||
import { getUpdateListOptionsMock } from './update_list.mock';
|
||||
|
||||
jest.mock('./get_list', () => ({
|
||||
getList: jest.fn(),
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* 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 { ImportListItemsToStreamOptions } from '../items';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import { LIST_ID, LIST_ITEM_INDEX, META, TYPE, USER } from './lists_services_mock_constants';
|
||||
import { TestReadable } from './test_readable';
|
||||
|
||||
export const getImportListItemsToStreamOptionsMock = (): ImportListItemsToStreamOptions => ({
|
||||
callCluster: getCallClusterMock(),
|
||||
listId: LIST_ID,
|
||||
listItemIndex: LIST_ITEM_INDEX,
|
||||
meta: META,
|
||||
stream: new TestReadable(),
|
||||
type: TYPE,
|
||||
user: USER,
|
||||
});
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* 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 { SearchEsListItemSchema } from '../../../common/schemas';
|
||||
|
||||
import { DATE_NOW, LIST_ID, USER, VALUE } from './lists_services_mock_constants';
|
||||
|
||||
export const getSearchEsListItemMock = (): SearchEsListItemSchema => ({
|
||||
created_at: DATE_NOW,
|
||||
created_by: USER,
|
||||
ip: VALUE,
|
||||
keyword: undefined,
|
||||
list_id: LIST_ID,
|
||||
meta: {},
|
||||
tie_breaker_id: '6a76b69d-80df-4ab2-8c3e-85f466b06a0e',
|
||||
updated_at: DATE_NOW,
|
||||
updated_by: USER,
|
||||
});
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* 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 { SearchEsListSchema } from '../../../common/schemas';
|
||||
|
||||
import { DATE_NOW, DESCRIPTION, NAME, USER } from './lists_services_mock_constants';
|
||||
|
||||
export const getSearchEsListMock = (): SearchEsListSchema => ({
|
||||
created_at: DATE_NOW,
|
||||
created_by: USER,
|
||||
description: DESCRIPTION,
|
||||
meta: {},
|
||||
name: NAME,
|
||||
tie_breaker_id: '6a76b69d-80df-4ab2-8c3e-85f466b06a0e',
|
||||
type: 'ip',
|
||||
updated_at: DATE_NOW,
|
||||
updated_by: USER,
|
||||
});
|
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
* 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 { WriteBufferToItemsOptions } from '../items';
|
||||
|
||||
import { getCallClusterMock } from './get_call_cluster_mock';
|
||||
import { LIST_ID, LIST_ITEM_INDEX, META, TYPE, USER } from './lists_services_mock_constants';
|
||||
|
||||
export const getWriteBufferToItemsOptionsMock = (): WriteBufferToItemsOptions => ({
|
||||
buffer: [],
|
||||
callCluster: getCallClusterMock(),
|
||||
listId: LIST_ID,
|
||||
listItemIndex: LIST_ITEM_INDEX,
|
||||
meta: META,
|
||||
type: TYPE,
|
||||
user: USER,
|
||||
});
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export * from './get_call_cluster_mock';
|
||||
export * from './get_delete_list_options_mock';
|
||||
export * from './get_create_list_options_mock';
|
||||
export * from './get_list_response_mock';
|
||||
export * from './get_search_list_mock';
|
||||
export * from './get_shard_mock';
|
||||
export * from './lists_services_mock_constants';
|
||||
export * from './get_update_list_options_mock';
|
||||
export * from './get_create_list_item_options_mock';
|
||||
export * from './get_list_item_response_mock';
|
||||
export * from './get_index_es_list_mock';
|
||||
export * from './get_index_es_list_item_mock';
|
||||
export * from './get_create_list_item_bulk_options_mock';
|
||||
export * from './get_delete_list_item_by_value_options_mock';
|
||||
export * from './get_delete_list_item_options_mock';
|
||||
export * from './get_list_item_by_values_options_mock';
|
||||
export * from './get_search_es_list_mock';
|
||||
export * from './get_search_es_list_item_mock';
|
||||
export * from './get_list_item_by_value_options_mock';
|
||||
export * from './get_update_list_item_options_mock';
|
||||
export * from './get_write_buffer_to_items_options_mock';
|
||||
export * from './get_import_list_items_to_stream_options_mock';
|
||||
export * from './get_write_list_items_to_stream_options_mock';
|
||||
export * from './get_search_list_item_mock';
|
||||
export * from './test_readable';
|
|
@ -4,7 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getSearchEsListItemMock } from '../mocks';
|
||||
import { getSearchEsListItemMock } from '../../../common/schemas/elastic_response/search_es_list_item_schema.mock';
|
||||
import { Type } from '../../../common/schemas';
|
||||
|
||||
import { deriveTypeFromItem } from './derive_type_from_es_type';
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getSearchListItemMock } from '../../../common/schemas/elastic_response/search_es_list_item_schema.mock';
|
||||
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
|
||||
import { ListItemArraySchema } from '../../../common/schemas';
|
||||
import { getListItemResponseMock, getSearchListItemMock } from '../mocks';
|
||||
|
||||
import { transformElasticToListItem } from './transform_elastic_to_list_item';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue