From 784972738d05463e9e736feedcb25cd26eae3d71 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Mon, 26 Oct 2020 12:54:01 -0700 Subject: [PATCH 1/3] Fixed migration issue for case specific actions, by extending email action migrator checks --- .../server/saved_objects/migrations.test.ts | 12 +++++- .../server/saved_objects/migrations.ts | 3 ++ .../spaces_only/tests/actions/migrations.ts | 41 +++++++++++-------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/actions/server/saved_objects/migrations.test.ts b/x-pack/plugins/actions/server/saved_objects/migrations.test.ts index 1fa5889e77cb04..4583242a772183 100644 --- a/x-pack/plugins/actions/server/saved_objects/migrations.test.ts +++ b/x-pack/plugins/actions/server/saved_objects/migrations.test.ts @@ -24,7 +24,11 @@ describe('7.10.0', () => { test('add hasAuth config property for .email actions', () => { const migration710 = getMigrations(encryptedSavedObjectsSetup)['7.10.0']; const action = getMockDataForEmail({}); - expect(migration710(action, context)).toMatchObject({ + const migratedAction = migration710(action, context); + expect(migratedAction.attributes.config).toMatchObject({ + hasAuth: true, + }); + expect(migratedAction).toMatchObject({ ...action, attributes: { ...action.attributes, @@ -38,7 +42,11 @@ describe('7.10.0', () => { test('rename cases configuration object', () => { const migration710 = getMigrations(encryptedSavedObjectsSetup)['7.10.0']; const action = getMockData({}); - expect(migration710(action, context)).toMatchObject({ + const migratedAction = migration710(action, context); + expect(migratedAction.attributes.config).toMatchObject({ + incidentConfiguration: { mapping: [] }, + }); + expect(migratedAction).toMatchObject({ ...action, attributes: { ...action.attributes, diff --git a/x-pack/plugins/actions/server/saved_objects/migrations.ts b/x-pack/plugins/actions/server/saved_objects/migrations.ts index 993beef8d9b2bd..35d30accecedb5 100644 --- a/x-pack/plugins/actions/server/saved_objects/migrations.ts +++ b/x-pack/plugins/actions/server/saved_objects/migrations.ts @@ -70,6 +70,9 @@ function renameCasesConfigurationObject( const addHasAuthConfigurationObject = ( doc: SavedObjectUnsanitizedDoc ): SavedObjectUnsanitizedDoc => { + if (doc.attributes.actionTypeId !== '.email') { + return doc; + } const hasAuth = !!doc.attributes.secrets.user || !!doc.attributes.secrets.password; return { ...doc, diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/actions/migrations.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/actions/migrations.ts index 1dd88832e38b7c..3304834ae8b401 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/actions/migrations.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/actions/migrations.ts @@ -30,24 +30,29 @@ export default function createGetTests({ getService }: FtrProviderContext) { expect(response.status).to.eql(200); expect(response.body.config).key('incidentConfiguration'); expect(response.body.config).not.key('casesConfiguration'); - expect(response.body.config.incidentConfiguration).to.eql({ - mapping: [ - { - actionType: 'overwrite', - source: 'title', - target: 'summary', - }, - { - actionType: 'overwrite', - source: 'description', - target: 'description', - }, - { - actionType: 'append', - source: 'comments', - target: 'comments', - }, - ], + expect(response.body.config).to.eql({ + apiUrl: + 'http://elastic:changeme@localhost:5620/api/_actions-FTS-external-service-simulators/jira', + casesConfiguration: { + mapping: [ + { + actionType: 'overwrite', + source: 'title', + target: 'summary', + }, + { + actionType: 'overwrite', + source: 'description', + target: 'description', + }, + { + actionType: 'append', + source: 'comments', + target: 'comments', + }, + ], + }, + projectKey: 'CK', }); }); }); From 18408bd666bc22e4577e8e3a9269677f4c85433f Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Mon, 26 Oct 2020 13:15:11 -0700 Subject: [PATCH 2/3] Fixed e2e test --- .../spaces_only/tests/actions/migrations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/actions/migrations.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/actions/migrations.ts index 3304834ae8b401..5992bb54c81fd7 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/actions/migrations.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/actions/migrations.ts @@ -33,7 +33,7 @@ export default function createGetTests({ getService }: FtrProviderContext) { expect(response.body.config).to.eql({ apiUrl: 'http://elastic:changeme@localhost:5620/api/_actions-FTS-external-service-simulators/jira', - casesConfiguration: { + incidentConfiguration: { mapping: [ { actionType: 'overwrite', From 28e028b59f9b5cda863db4ef80102c95fe139b0f Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Mon, 26 Oct 2020 14:40:44 -0700 Subject: [PATCH 3/3] fixed due to comments --- .../actions/server/saved_objects/migrations.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/actions/server/saved_objects/migrations.test.ts b/x-pack/plugins/actions/server/saved_objects/migrations.test.ts index 4583242a772183..947d84fcfc638f 100644 --- a/x-pack/plugins/actions/server/saved_objects/migrations.test.ts +++ b/x-pack/plugins/actions/server/saved_objects/migrations.test.ts @@ -25,10 +25,10 @@ describe('7.10.0', () => { const migration710 = getMigrations(encryptedSavedObjectsSetup)['7.10.0']; const action = getMockDataForEmail({}); const migratedAction = migration710(action, context); - expect(migratedAction.attributes.config).toMatchObject({ + expect(migratedAction.attributes.config).toEqual({ hasAuth: true, }); - expect(migratedAction).toMatchObject({ + expect(migratedAction).toEqual({ ...action, attributes: { ...action.attributes, @@ -43,10 +43,10 @@ describe('7.10.0', () => { const migration710 = getMigrations(encryptedSavedObjectsSetup)['7.10.0']; const action = getMockData({}); const migratedAction = migration710(action, context); - expect(migratedAction.attributes.config).toMatchObject({ + expect(migratedAction.attributes.config).toEqual({ incidentConfiguration: { mapping: [] }, }); - expect(migratedAction).toMatchObject({ + expect(migratedAction).toEqual({ ...action, attributes: { ...action.attributes,