Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Security Solution][Case] Migrate category & subcategory fields of ServiceNow ITSM connector (#93092) #93129

Merged
merged 1 commit into from
Mar 1, 2021
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
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.