From fcd515f9420fd80cdd386454c565dd227a9c6f8b Mon Sep 17 00:00:00 2001 From: Davis Plumlee <56367316+dplumlee@users.noreply.github.com> Date: Fri, 16 Jul 2021 14:51:46 -0600 Subject: [PATCH] [Security Solution][Exceptions] Adds error catch to Exceptions toString method (#105928) --- .../common/components/exceptions/helpers.test.tsx | 15 ++++++++++++++- .../common/components/exceptions/helpers.tsx | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.test.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.test.tsx index 32eb4baad505..bf6a94c53b47 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.test.tsx @@ -26,8 +26,9 @@ import { getProcessCodeSignature, retrieveAlertOsTypes, filterIndexPatterns, + getCodeSignatureValue, } from './helpers'; -import { AlertData } from './types'; +import { AlertData, Flattened } from './types'; import { ListOperatorTypeEnum as OperatorTypeEnum, EntriesArray, @@ -41,6 +42,7 @@ import { getCommentsArrayMock } from '../../../../../lists/common/schemas/types/ import { fields } from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks'; import { ENTRIES, OLD_DATE_RELATIVE_TO_DATE_NOW } from '../../../../../lists/common/constants.mock'; import { IFieldType, IIndexPattern } from 'src/plugins/data/common'; +import { CodeSignature } from '../../../../common/ecs/file'; jest.mock('uuid', () => ({ v4: jest.fn().mockReturnValue('123'), @@ -340,6 +342,17 @@ describe('Exception helpers', () => { }); }); + describe('#getCodeSignatureValue', () => { + test('it should return empty string if code_signature nested value are undefined', () => { + // Using the unsafe casting because with our types this shouldn't be possible but there have been issues with old data having undefined values in these fields + const payload = ([{ trusted: undefined, subject_name: undefined }] as unknown) as Flattened< + CodeSignature[] + >; + const result = getCodeSignatureValue(payload); + expect(result).toEqual([{ trusted: '', subjectName: '' }]); + }); + }); + describe('#entryHasNonEcsType', () => { const mockEcsIndexPattern = { title: 'testIndex', diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.tsx index 3c8652637a99..f8260062f697 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.tsx @@ -325,8 +325,8 @@ export const getCodeSignatureValue = ( if (Array.isArray(codeSignature) && codeSignature.length > 0) { return codeSignature.map((signature) => { return { - subjectName: signature.subject_name ?? '', - trusted: signature.trusted.toString() ?? '', + subjectName: signature?.subject_name ?? '', + trusted: signature?.trusted?.toString() ?? '', }; }); } else {