Skip to content

Commit

Permalink
[Security Solution][Case] Migrate category & subcategory fields of Se…
Browse files Browse the repository at this point in the history
…rviceNow ITSM connector (elastic#93092)
  • Loading branch information
cnasikas authored and kibanamachine committed Mar 1, 2021
1 parent 8235656 commit 87804ac
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
22 changes: 18 additions & 4 deletions x-pack/plugins/case/server/saved_object_types/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +30,7 @@ interface SanitizedCaseConnector {
id: string;
name: string | null;
type: string | null;
fields: null;
fields: null | ESConnectorFields;
};
}

Expand Down Expand Up @@ -88,13 +94,21 @@ export const caseMigrations = {
};
},
'7.12.0': (
doc: SavedObjectUnsanitizedDoc<Record<string, unknown>>
): SavedObjectSanitizedDoc<SanitizedCaseType> => {
doc: SavedObjectUnsanitizedDoc<SanitizedCaseConnector>
): SavedObjectSanitizedDoc<SanitizedCaseType & SanitizedCaseConnector> => {
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 || [],
};
Expand Down
24 changes: 23 additions & 1 deletion x-pack/test/case_api_integration/basic/tests/cases/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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`)
Expand All @@ -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,
},
});
});
});
});
}
Binary file not shown.

0 comments on commit 87804ac

Please sign in to comment.