Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
COMMENTS,
DESCRIPTION,
ENTRIES,
ITEM_ID,
ITEM_TYPE,
LIST_ID,
META,
Expand All @@ -32,3 +33,26 @@ export const getCreateExceptionListItemSchemaMock = (): CreateExceptionListItemS
tags: TAGS,
type: ITEM_TYPE,
});

/**
* Useful for end to end testing
*/
export const getCreateExceptionListItemMinimalSchemaMock = (): CreateExceptionListItemSchema => ({
description: DESCRIPTION,
entries: ENTRIES,
item_id: ITEM_ID,
list_id: LIST_ID,
name: NAME,
type: ITEM_TYPE,
});

/**
* Useful for end to end testing
*/
export const getCreateExceptionListItemMinimalSchemaMockWithoutId = (): CreateExceptionListItemSchema => ({
description: DESCRIPTION,
entries: ENTRIES,
list_id: LIST_ID,
name: NAME,
type: ITEM_TYPE,
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {
DESCRIPTION,
ENDPOINT_TYPE,
LIST_ID,
META,
NAME,
NAMESPACE_TYPE,
Expand All @@ -26,3 +27,22 @@ export const getCreateExceptionListSchemaMock = (): CreateExceptionListSchema =>
type: ENDPOINT_TYPE,
version: VERSION,
});

/**
* Useful for end to end testing
*/
export const getCreateExceptionListMinimalSchemaMock = (): CreateExceptionListSchema => ({
description: DESCRIPTION,
list_id: LIST_ID,
name: NAME,
type: ENDPOINT_TYPE,
});

/**
* Useful for end to end testing
*/
export const getCreateExceptionListMinimalSchemaMockWithoutId = (): CreateExceptionListSchema => ({
description: DESCRIPTION,
name: NAME,
type: ENDPOINT_TYPE,
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DESCRIPTION,
ENTRIES,
ID,
ITEM_ID,
ITEM_TYPE,
LIST_ITEM_ID,
META,
Expand All @@ -34,3 +35,15 @@ export const getUpdateExceptionListItemSchemaMock = (): UpdateExceptionListItemS
tags: TAGS,
type: ITEM_TYPE,
});

/**
* Useful for end to end tests and other mechanisms which want to fill in the values
* after doing a get of the structure.
*/
export const getUpdateMinimalExceptionListItemSchemaMock = (): UpdateExceptionListItemSchema => ({
description: DESCRIPTION,
entries: ENTRIES,
item_id: ITEM_ID,
name: NAME,
type: ITEM_TYPE,
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ export const getUpdateExceptionListSchemaMock = (): UpdateExceptionListSchema =>
tags: ['malware'],
type: 'endpoint',
});

/**
* Useful for end to end tests and other mechanisms which want to fill in the values
* after doing a get of the structure.
*/
export const getUpdateMinimalExceptionListSchemaMock = (): UpdateExceptionListSchema => ({
description: DESCRIPTION,
list_id: LIST_ID,
name: NAME,
type: 'endpoint',
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import {
COMMENTS,
DATE_NOW,
DESCRIPTION,
ELASTIC_USER,
ENTRIES,
ITEM_ID,
ITEM_TYPE,
LIST_ID,
META,
NAME,
NAMESPACE_TYPE,
Expand Down Expand Up @@ -38,3 +41,24 @@ export const getExceptionListItemSchemaMock = (): ExceptionListItemSchema => ({
updated_at: DATE_NOW,
updated_by: USER,
});

/**
* This is useful for end to end tests where we remove the auto generated parts for comparisons
* such as created_at, updated_at, and id.
*/
export const getExceptionListItemResponseMockWithoutAutoGeneratedValues = (): Partial<
ExceptionListItemSchema
> => ({
_tags: [],
comments: [],
created_by: ELASTIC_USER,
description: DESCRIPTION,
entries: ENTRIES,
item_id: ITEM_ID,
list_id: LIST_ID,
name: NAME,
namespace_type: 'single',
tags: [],
type: ITEM_TYPE,
updated_by: ELASTIC_USER,
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import {
DATE_NOW,
DESCRIPTION,
ELASTIC_USER,
ENDPOINT_TYPE,
IMMUTABLE,
LIST_ID,
META,
NAME,
TIE_BREAKER,
USER,
VERSION,
Expand All @@ -18,6 +21,7 @@ import {
import { ENDPOINT_LIST_ID } from '../..';

import { ExceptionListSchema } from './exception_list_schema';

export const getExceptionListSchemaMock = (): ExceptionListSchema => ({
_tags: ['endpoint', 'process', 'malware', 'os:linux'],
_version: _VERSION,
Expand All @@ -37,3 +41,23 @@ export const getExceptionListSchemaMock = (): ExceptionListSchema => ({
updated_by: 'user_name',
version: VERSION,
});

/**
* This is useful for end to end tests where we remove the auto generated parts for comparisons
* such as created_at, updated_at, and id.
*/
export const getExceptionResponseMockWithoutAutoGeneratedValues = (): Partial<
ExceptionListSchema
> => ({
_tags: [],
created_by: ELASTIC_USER,
description: DESCRIPTION,
immutable: IMMUTABLE,
list_id: LIST_ID,
name: NAME,
namespace_type: 'single',
tags: [],
type: ENDPOINT_TYPE,
updated_by: ELASTIC_USER,
version: VERSION,
});
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const createExceptionListItemRoute = (router: IRouter): void => {
});
if (exceptionList == null) {
return siemResponse.error({
body: `list id: "${listId}" does not exist`,
body: `exception list id: "${listId}" does not exist`,
statusCode: 404,
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const findExceptionListItemRoute = (router: IRouter): void => {
});
if (exceptionListItems == null) {
return siemResponse.error({
body: `list id: "${listId}" does not exist`,
body: `exception list id: "${listId}" does not exist`,
statusCode: 404,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,46 @@ export const updateExceptionListItemRoute = (router: IRouter): void => {
namespace_type: namespaceType,
tags,
} = request.body;
const exceptionLists = getExceptionListClient(context);
const exceptionListItem = await exceptionLists.updateExceptionListItem({
_tags,
_version,
comments,
description,
entries,
id,
itemId,
meta,
name,
namespaceType,
tags,
type,
});
if (exceptionListItem == null) {
if (id != null) {
return siemResponse.error({
body: `list item id: "${id}" not found`,
statusCode: 404,
});
} else {
return siemResponse.error({
body: `list item item_id: "${itemId}" not found`,
statusCode: 404,
});
}
if (id == null && itemId == null) {
return siemResponse.error({
body: 'either id or item_id need to be defined',
statusCode: 404,
});
} else {
const [validated, errors] = validate(exceptionListItem, exceptionListItemSchema);
if (errors != null) {
return siemResponse.error({ body: errors, statusCode: 500 });
const exceptionLists = getExceptionListClient(context);
const exceptionListItem = await exceptionLists.updateExceptionListItem({
_tags,
_version,
comments,
description,
entries,
id,
itemId,
meta,
name,
namespaceType,
tags,
type,
});
if (exceptionListItem == null) {
if (id != null) {
return siemResponse.error({
body: `exception list item id: "${id}" does not exist`,
statusCode: 404,
});
} else {
return siemResponse.error({
body: `exception list item item_id: "${itemId}" does not exist`,
statusCode: 404,
});
}
} else {
return response.ok({ body: validated ?? {} });
const [validated, errors] = validate(exceptionListItem, exceptionListItemSchema);
if (errors != null) {
return siemResponse.error({ body: errors, statusCode: 500 });
} else {
return response.ok({ body: validated ?? {} });
}
}
}
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
updateExceptionListSchema,
} from '../../common/schemas';

import { getExceptionListClient } from './utils';
import { getErrorMessageExceptionList, getExceptionListClient } from './utils';

export const updateExceptionListRoute = (router: IRouter): void => {
router.put(
Expand Down Expand Up @@ -50,7 +50,7 @@ export const updateExceptionListRoute = (router: IRouter): void => {
const exceptionLists = getExceptionListClient(context);
if (id == null && listId == null) {
return siemResponse.error({
body: `either id or list_id need to be defined`,
body: 'either id or list_id need to be defined',
statusCode: 404,
});
} else {
Expand All @@ -69,7 +69,7 @@ export const updateExceptionListRoute = (router: IRouter): void => {
});
if (list == null) {
return siemResponse.error({
body: `exception list id: "${id}" not found`,
body: getErrorMessageExceptionList({ id, listId }),
statusCode: 404,
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export const getErrorMessageExceptionList = ({
listId: string | undefined;
}): string => {
if (id != null) {
return `Exception list id: "${id}" does not exist`;
return `exception list id: "${id}" does not exist`;
} else if (listId != null) {
return `Exception list list_id: "${listId}" does not exist`;
return `exception list list_id: "${listId}" does not exist`;
} else {
return 'Exception list does not exist';
return 'exception list does not exist';
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export const getErrorMessageExceptionListItem = ({
itemId: string | undefined;
}): string => {
if (id != null) {
return `Exception list item id: "${id}" does not exist`;
return `exception list item id: "${id}" does not exist`;
} else if (itemId != null) {
return `Exception list item list_id: "${itemId}" does not exist`;
return `exception list item item_id: "${itemId}" does not exist`;
} else {
return 'Exception list item does not exist';
return 'exception list item does not exist';
}
};
Loading