From 6fbf5fec10d9949ad3a5a10e80166edca042ce14 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Mon, 1 Mar 2021 23:21:00 +0200 Subject: [PATCH] [Security Solution][Case] Migrate category & subcategory fields of ServiceNow ITSM connector (#93092) --- .../server/saved_object_types/migrations.ts | 22 +++++++++++++--- .../basic/tests/cases/migrations.ts | 24 +++++++++++++++++- .../cases/migrations/7.11.1/data.json.gz | Bin 679 -> 1039 bytes 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/case/server/saved_object_types/migrations.ts b/x-pack/plugins/case/server/saved_object_types/migrations.ts index 117e2eaeea4d8..bf9694d7e6bb0 100644 --- a/x-pack/plugins/case/server/saved_object_types/migrations.ts +++ b/x-pack/plugins/case/server/saved_object_types/migrations.ts @@ -8,7 +8,13 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { SavedObjectUnsanitizedDoc, SavedObjectSanitizedDoc } from '../../../../../src/core/server'; -import { ConnectorTypes, CommentType, CaseType, AssociationType } from '../../common/api'; +import { + ConnectorTypes, + CommentType, + CaseType, + AssociationType, + ESConnectorFields, +} from '../../common/api'; interface UnsanitizedCaseConnector { connector_id: string; @@ -24,7 +30,7 @@ interface SanitizedCaseConnector { id: string; name: string | null; type: string | null; - fields: null; + fields: null | ESConnectorFields; }; } @@ -88,13 +94,21 @@ export const caseMigrations = { }; }, '7.12.0': ( - doc: SavedObjectUnsanitizedDoc> - ): SavedObjectSanitizedDoc => { + doc: SavedObjectUnsanitizedDoc + ): SavedObjectSanitizedDoc => { + const { fields, type } = doc.attributes.connector; return { ...doc, attributes: { ...doc.attributes, type: CaseType.individual, + connector: { + ...doc.attributes.connector, + fields: + Array.isArray(fields) && fields.length > 0 && type === ConnectorTypes.serviceNowITSM + ? [...fields, { key: 'category', value: null }, { key: 'subcategory', value: null }] + : fields, + }, }, references: doc.references || [], }; diff --git a/x-pack/test/case_api_integration/basic/tests/cases/migrations.ts b/x-pack/test/case_api_integration/basic/tests/cases/migrations.ts index e75ea0f8a89c9..e66b623138e60 100644 --- a/x-pack/test/case_api_integration/basic/tests/cases/migrations.ts +++ b/x-pack/test/case_api_integration/basic/tests/cases/migrations.ts @@ -58,7 +58,6 @@ export default function createGetTests({ getService }: FtrProviderContext) { // tests upgrading a 7.11.1 saved object to the latest version describe('7.11.1 -> latest stack version', () => { - const caseID = '2ea28c10-7855-11eb-9ca6-83ec5acb735f'; before(async () => { await esArchiver.load('cases/migrations/7.11.1'); }); @@ -68,6 +67,7 @@ export default function createGetTests({ getService }: FtrProviderContext) { }); it('adds rule info to only alert comments for 7.12', async () => { + const caseID = '2ea28c10-7855-11eb-9ca6-83ec5acb735f'; // user comment let { body } = await supertest .get(`${CASES_URL}/${caseID}/comments/34a20a00-7855-11eb-9ca6-83ec5acb735f`) @@ -84,6 +84,28 @@ export default function createGetTests({ getService }: FtrProviderContext) { expect(body).key('rule'); expect(body.rule).to.eql({ id: null, name: null }); }); + + it('adds category and subcategory to the ITSM connector', async () => { + const { body } = await supertest + .get(`${CASES_URL}/6f973440-7abd-11eb-9ca6-83ec5acb735f`) + .set('kbn-xsrf', 'true') + .send() + .expect(200); + + expect(body).key('connector'); + expect(body.connector).to.eql({ + id: '444ebab0-7abd-11eb-9ca6-83ec5acb735f', + name: 'SN', + type: '.servicenow', + fields: { + impact: '2', + severity: '2', + urgency: '2', + category: null, + subcategory: null, + }, + }); + }); }); }); } diff --git a/x-pack/test/functional/es_archives/cases/migrations/7.11.1/data.json.gz b/x-pack/test/functional/es_archives/cases/migrations/7.11.1/data.json.gz index 219f58b7e9d216faa6b20e2ea4d7e6a5a5c0a47c..efb62cba5675de208dc0af5a77b2f07566218af8 100644 GIT binary patch literal 1039 zcmV+q1n~PGiwFq7JUw6l17u-zVJ>QOZ*BnXSWR=AJP^M7S1_Cn1LD)1-pqUIC6{!1 zNS*Nrv37Wig$IeGo{ax{B>}b|xW#?rw4G^AVOP7-emsw~ewi7D$@e=j6T{3(V$P-D z2^Y1Lyoe9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