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
16 changes: 8 additions & 8 deletions x-pack/plugins/cases/server/client/cases/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const resolve = async (
}

const {
saved_object: savedObject,
saved_object: resolvedSavedObject,
...resolveData
}: SavedObjectsResolveResponse<CaseAttributes> = await caseService.getResolveCase({
unsecuredSavedObjectsClient,
Expand All @@ -262,8 +262,8 @@ export const resolve = async (
operation: Operations.resolveCase,
entities: [
{
id: savedObject.id,
owner: savedObject.attributes.owner,
id: resolvedSavedObject.id,
owner: resolvedSavedObject.attributes.owner,
},
],
});
Expand All @@ -272,7 +272,7 @@ export const resolve = async (
if (ENABLE_CASE_CONNECTOR) {
const subCasesForCaseId = await caseService.findSubCasesByCaseId({
unsecuredSavedObjectsClient,
ids: [id],
ids: [resolvedSavedObject.id],
});
subCaseIds = subCasesForCaseId.saved_objects.map((so) => so.id);
}
Expand All @@ -281,15 +281,15 @@ export const resolve = async (
return CaseResolveResponseRt.encode({
...resolveData,
case: flattenCaseSavedObject({
savedObject,
savedObject: resolvedSavedObject,
subCaseIds,
}),
});
}

const theComments = await caseService.getAllCaseComments({
unsecuredSavedObjectsClient,
id,
id: resolvedSavedObject.id,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of an alias match the request's id and the resolvedSavedObject.id will be different. We'll want to use the resolvedSavedObject.id instead since that'll be pointing to the changed id.

options: {
sortField: 'created_at',
sortOrder: 'asc',
Expand All @@ -300,11 +300,11 @@ export const resolve = async (
return CaseResolveResponseRt.encode({
...resolveData,
case: flattenCaseSavedObject({
savedObject,
savedObject: resolvedSavedObject,
subCaseIds,
comments: theComments.saved_objects,
totalComment: theComments.total,
totalAlerts: countAlertsForID({ comments: theComments, id }),
totalAlerts: countAlertsForID({ comments: theComments, id: resolvedSavedObject.id }),
}),
});
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/saved_object_types/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const createCaseSavedObjectType = (
): SavedObjectsType => ({
name: CASE_SAVED_OBJECT,
hidden: true,
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: {
properties: {
closed_at: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/saved_object_types/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const createCaseCommentSavedObjectType = ({
}): SavedObjectsType => ({
name: CASE_COMMENT_SAVED_OBJECT,
hidden: true,
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: {
properties: {
associationType: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/saved_object_types/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { configureMigrations } from './migrations';
export const caseConfigureSavedObjectType: SavedObjectsType = {
name: CASE_CONFIGURE_SAVED_OBJECT,
hidden: true,
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: {
properties: {
created_at: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { connectorMappingsMigrations } from './migrations';
export const caseConnectorMappingsSavedObjectType: SavedObjectsType = {
name: CASE_CONNECTOR_MAPPINGS_SAVED_OBJECT,
hidden: true,
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: {
properties: {
mappings: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/saved_object_types/sub_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { subCasesMigrations } from './migrations';
export const subCaseSavedObjectType: SavedObjectsType = {
name: SUB_CASE_SAVED_OBJECT,
hidden: true,
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: {
properties: {
closed_at: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { userActionsMigrations } from './migrations';
export const caseUserActionSavedObjectType: SavedObjectsType = {
name: CASE_USER_ACTION_SAVED_OBJECT,
hidden: true,
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: {
properties: {
action_field: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const noteSavedObjectMappings: SavedObjectsType['mappings'] = {
export const noteType: SavedObjectsType = {
name: noteSavedObjectType,
hidden: false,
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: noteSavedObjectMappings,
migrations: notesMigrations,
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const pinnedEventSavedObjectMappings: SavedObjectsType['mappings'] = {
export const pinnedEventType: SavedObjectsType = {
name: pinnedEventSavedObjectType,
hidden: false,
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: pinnedEventSavedObjectMappings,
migrations: pinnedEventsMigrations,
};
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ export const timelineSavedObjectMappings: SavedObjectsType['mappings'] = {
export const timelineType: SavedObjectsType = {
name: timelineSavedObjectType,
hidden: false,
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
mappings: timelineSavedObjectMappings,
migrations: timelinesMigrations,
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,79 @@ export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const es = getService('es');

describe('8.0 id migration', () => {
const resolveWithSpaceApi = '/s/awesome-space/api/timeline/resolve';

before(async () => {
await esArchiver.load(
'x-pack/test/functional/es_archives/security_solution/timelines/7.15.0_space'
);
});

after(async () => {
await esArchiver.unload(
'x-pack/test/functional/es_archives/security_solution/timelines/7.15.0_space'
);
});

describe('resolve', () => {
it('should return an aliasMatch outcome', async () => {
const resp = await supertest
.get(resolveWithSpaceApi)
.query({ id: '1e2e9850-25f8-11ec-a981-b77847c6ef30' });

expect(resp.body.data.outcome).to.be('aliasMatch');
expect(resp.body.data.alias_target_id).to.not.be(undefined);
expect(resp.body.data.timeline.title).to.be('An awesome timeline');
});

describe('notes', () => {
it('should return the notes with the correct eventId', async () => {
const resp = await supertest
.get(resolveWithSpaceApi)
.query({ id: '1e2e9850-25f8-11ec-a981-b77847c6ef30' });

expect(resp.body.data.timeline.notes[0].eventId).to.be('StU_UXwBAowmaxx6YdiS');
});

it('should return notes with the timelineId matching the resolved timeline id', async () => {
const resp = await supertest
.get(resolveWithSpaceApi)
.query({ id: '1e2e9850-25f8-11ec-a981-b77847c6ef30' });

expect(resp.body.data.timeline.notes[0].timelineId).to.be(
resp.body.data.timeline.savedObjectId
);
expect(resp.body.data.timeline.notes[1].timelineId).to.be(
resp.body.data.timeline.savedObjectId
);
});
});

describe('pinned events', () => {
it('should pinned events with eventId', async () => {
const resp = await supertest
.get(resolveWithSpaceApi)
.query({ id: '1e2e9850-25f8-11ec-a981-b77847c6ef30' });

expect(resp.body.data.timeline.pinnedEventsSaveObject[0].eventId).to.be(
'StU_UXwBAowmaxx6YdiS'
);
});

it('should return pinned events with the timelineId matching request id', async () => {
const resp = await supertest
.get(resolveWithSpaceApi)
.query({ id: '1e2e9850-25f8-11ec-a981-b77847c6ef30' });

expect(resp.body.data.timeline.pinnedEventsSaveObject[0].timelineId).to.be(
resp.body.data.timeline.savedObjectId
);
});
});
});
});

describe('7.16.0', () => {
before(async () => {
await esArchiver.load(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
SECURITY_SOLUTION_OWNER,
} from '../../../../../../plugins/cases/common/constants';
import { getCase, getCaseSavedObjectsFromES, resolveCase } from '../../../../common/lib/utils';
import { superUser } from '../../../../common/lib/authentication/users';
import { AttributesTypeUser } from '../../../../../../plugins/cases/common';

// eslint-disable-next-line import/no-default-export
export default function createGetTests({ getService }: FtrProviderContext) {
Expand Down Expand Up @@ -278,5 +280,58 @@ export default function createGetTests({ getService }: FtrProviderContext) {
});
});
});

describe('8.0 id migration', () => {
describe('awesome space', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.16.0_space');
});

after(async () => {
await esArchiver.unload(
'x-pack/test/functional/es_archives/cases/migrations/7.16.0_space'
);
});

describe('resolve', () => {
const auth = { user: superUser, space: 'awesome-space' };

it('should return aliasMatch outcome', async () => {
const { outcome } = await resolveCase({
supertest,
caseId: 'a97a13b0-22f3-11ec-9f3b-fbc97859d7ed',
auth,
});

expect(outcome).to.be('aliasMatch');
});

it('should preserve the same case info', async () => {
const { case: theCase } = await resolveCase({
supertest,
caseId: 'a97a13b0-22f3-11ec-9f3b-fbc97859d7ed',
auth,
});

expect(theCase.title).to.be('Case name');
expect(theCase.description).to.be('a description');
expect(theCase.owner).to.be(SECURITY_SOLUTION_OWNER);
});

it('should preserve the comment', async () => {
const { case: theCase } = await resolveCase({
supertest,
caseId: 'a97a13b0-22f3-11ec-9f3b-fbc97859d7ed',
auth,
includeComments: true,
});

const comment = theCase.comments![0] as AttributesTypeUser;
expect(comment.comment).to.be('a comment');
expect(comment.owner).to.be(SECURITY_SOLUTION_OWNER);
});
});
});
});
});
}
Binary file not shown.
Loading