From af7db4245c63759791b077fceefb5c7b3b22f5f8 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Fri, 15 Apr 2022 14:54:55 +0300 Subject: [PATCH 1/5] Fix bug with deprecated connectors --- .../servicenow_itsm_case_fields.test.tsx | 19 +++ .../servicenow_sir_case_fields.test.tsx | 19 +++ .../connectors/servicenow/validator.test.ts | 11 ++ .../connectors/servicenow/validator.ts | 16 +- .../cases/public/components/utils.test.ts | 11 ++ .../plugins/cases/public/components/utils.ts | 8 +- .../server/client/configure/client.test.ts | 154 ++++++++++++++---- .../cases/server/client/configure/client.ts | 4 +- 8 files changed, 198 insertions(+), 44 deletions(-) diff --git a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.test.tsx b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.test.tsx index 66ff8c751c461..cfc16f1fb6e8b 100644 --- a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.test.tsx @@ -146,6 +146,25 @@ describe('ServiceNowITSM Fields', () => { expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument(); }); + it('does not show the deprecated callout when the connector is preconfigured', async () => { + render( + + ); + expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument(); + }); + + it('does not show the deprecated callout when the config of the connector is undefined', async () => { + render( + // @ts-expect-error + + ); + expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument(); + }); + it('should hide subcategory if selecting a category without subcategories', async () => { // Failed Login doesn't have defined subcategories const customFields = { diff --git a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_sir_case_fields.test.tsx b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_sir_case_fields.test.tsx index 279cab7e6f879..a2c61ac78be0b 100644 --- a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_sir_case_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_sir_case_fields.test.tsx @@ -180,6 +180,25 @@ describe('ServiceNowSIR Fields', () => { expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument(); }); + it('does not show the deprecated callout when the connector is preconfigured', async () => { + render( + + ); + expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument(); + }); + + it('does not show the deprecated callout when the config of the connector is undefined', async () => { + render( + // @ts-expect-error + + ); + expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument(); + }); + test('it should hide subcategory if selecting a category without subcategories', async () => { // Failed Login doesn't have defined subcategories const customFields = { diff --git a/x-pack/plugins/cases/public/components/connectors/servicenow/validator.test.ts b/x-pack/plugins/cases/public/components/connectors/servicenow/validator.test.ts index aa643191ac62e..d7cc424216d12 100644 --- a/x-pack/plugins/cases/public/components/connectors/servicenow/validator.test.ts +++ b/x-pack/plugins/cases/public/components/connectors/servicenow/validator.test.ts @@ -33,5 +33,16 @@ describe('ServiceNow validator', () => { expect(connectorValidator(invalidConnector)).toBeFalsy(); }); + + test('it does not returns an error message if the config of the connector is undefined', () => { + const { config, ...invalidConnector } = connector; + + // @ts-expect-error + expect(connectorValidator(invalidConnector)).toBeFalsy(); + }); + + test('it does not returns an error message if the config of the connector is preconfigured', () => { + expect(connectorValidator({ ...connector, isPreconfigured: true })).toBeFalsy(); + }); }); }); diff --git a/x-pack/plugins/cases/public/components/connectors/servicenow/validator.ts b/x-pack/plugins/cases/public/components/connectors/servicenow/validator.ts index 7d56163c48350..fed2900715527 100644 --- a/x-pack/plugins/cases/public/components/connectors/servicenow/validator.ts +++ b/x-pack/plugins/cases/public/components/connectors/servicenow/validator.ts @@ -15,10 +15,18 @@ import { CaseActionConnector } from '../../types'; export const connectorValidator = ( connector: CaseActionConnector ): ReturnType => { - const { - config: { usesTableApi }, - } = connector; - if (usesTableApi) { + /** + * It is not possible to know if a preconfigured connector + * is deprecated or not as the config property of a + * preconfigured connector is not returned by the + * actions framework + */ + + if (connector.isPreconfigured || connector.config == null) { + return; + } + + if (connector.config?.usesTableApi) { return { message: 'Deprecated connector', }; diff --git a/x-pack/plugins/cases/public/components/utils.test.ts b/x-pack/plugins/cases/public/components/utils.test.ts index 71218492dec95..278bb28b86627 100644 --- a/x-pack/plugins/cases/public/components/utils.test.ts +++ b/x-pack/plugins/cases/public/components/utils.test.ts @@ -83,5 +83,16 @@ describe('Utils', () => { }) ).toBe(true); }); + + it('returns false if the connector preconfigured', () => { + expect(isDeprecatedConnector({ ...connector, isPreconfigured: true })).toBe(false); + }); + + it('returns false if the config is undefined', () => { + expect( + // @ts-expect-error + isDeprecatedConnector({ ...connector, config: undefined }) + ).toBe(false); + }); }); }); diff --git a/x-pack/plugins/cases/public/components/utils.ts b/x-pack/plugins/cases/public/components/utils.ts index 5ff675a31ce61..34ebffb4eacb4 100644 --- a/x-pack/plugins/cases/public/components/utils.ts +++ b/x-pack/plugins/cases/public/components/utils.ts @@ -74,7 +74,13 @@ export const getConnectorIcon = ( // TODO: Remove when the applications are certified export const isDeprecatedConnector = (connector?: CaseActionConnector): boolean => { - if (connector == null) { + /** + * It is not possible to know if a preconfigured connector + * is deprecated or not as the config property of a + * preconfigured connector is not returned by the + * actions framework + */ + if (connector == null || connector.config == null || connector.isPreconfigured) { return false; } diff --git a/x-pack/plugins/cases/server/client/configure/client.test.ts b/x-pack/plugins/cases/server/client/configure/client.test.ts index fa3f2b3f987f1..671ed8df5219b 100644 --- a/x-pack/plugins/cases/server/client/configure/client.test.ts +++ b/x-pack/plugins/cases/server/client/configure/client.test.ts @@ -5,11 +5,10 @@ * 2.0. */ -import { CasesClientArgs } from '../types'; import { loggingSystemMock } from '@kbn/core/server/mocks'; -import { getConnectors } from './client'; import { actionsClientMock } from '@kbn/actions-plugin/server/mocks'; -import { ActionType } from '@kbn/actions-plugin/common/types'; +import { CasesClientArgs } from '../types'; +import { getConnectors } from './client'; describe('client', () => { describe('getConnectors', () => { @@ -18,66 +17,153 @@ describe('client', () => { const args = { actionsClient, logger } as unknown as CasesClientArgs; - const jiraType: ActionType = { - id: '.jira', - name: '1', - enabled: true, - enabledInConfig: true, - enabledInLicense: true, - minimumLicenseRequired: 'basic', - }; + const actionTypes = [ + { + id: '.jira', + name: '1', + enabled: true, + enabledInConfig: true, + enabledInLicense: true, + minimumLicenseRequired: 'basic' as const, + }, + { + id: '.servicenow', + name: '2', + enabled: true, + enabledInConfig: true, + enabledInLicense: true, + minimumLicenseRequired: 'basic' as const, + }, + { + id: '.unsupported', + name: '3', + enabled: true, + enabledInConfig: true, + enabledInLicense: true, + minimumLicenseRequired: 'basic' as const, + }, + { + id: '.swimlane', + name: 'swimlane', + enabled: true, + enabledInConfig: true, + enabledInLicense: false, + minimumLicenseRequired: 'basic' as const, + }, + ]; + + const connectors = [ + { + id: '1', + actionTypeId: '.jira', + name: '1', + config: {}, + isPreconfigured: false, + referencedByCount: 1, + }, + { + id: '2', + actionTypeId: '.servicenow', + name: '2', + config: {}, + isPreconfigured: false, + referencedByCount: 1, + }, + { + id: '3', + actionTypeId: '.unsupported', + name: '3', + config: {}, + isPreconfigured: false, + referencedByCount: 1, + }, + ]; beforeEach(() => { jest.clearAllMocks(); }); - it('removes connectors without a config field defined', async () => { - actionsClient.listTypes.mockImplementation(async () => [jiraType]); + it('remove unsupported connectors', async () => { + actionsClient.listTypes.mockImplementation(async () => actionTypes); + actionsClient.getAll.mockImplementation(async () => connectors); - actionsClient.getAll.mockImplementation(async () => [ + expect(await getConnectors(args)).toEqual([ { id: '1', actionTypeId: '.jira', name: '1', + config: {}, + isPreconfigured: false, + referencedByCount: 1, + }, + { + id: '2', + actionTypeId: '.servicenow', + name: '2', + config: {}, isPreconfigured: false, referencedByCount: 1, }, ]); - - expect(await getConnectors(args)).toEqual([]); }); - it('removes connectors that are pre configured', async () => { - actionsClient.listTypes.mockImplementation(async () => [jiraType]); - + it('returns preconfigured connectors', async () => { + actionsClient.listTypes.mockImplementation(async () => actionTypes); actionsClient.getAll.mockImplementation(async () => [ + ...connectors, + { + id: '4', + actionTypeId: '.servicenow', + name: 'sn-preconfigured', + config: {}, + isPreconfigured: true, + referencedByCount: 1, + }, + ]); + + expect(await getConnectors(args)).toEqual([ { id: '1', actionTypeId: '.jira', name: '1', config: {}, + isPreconfigured: false, + referencedByCount: 1, + }, + { + id: '2', + actionTypeId: '.servicenow', + name: '2', + config: {}, + isPreconfigured: false, + referencedByCount: 1, + }, + { + id: '4', + actionTypeId: '.servicenow', + name: 'sn-preconfigured', + config: {}, isPreconfigured: true, referencedByCount: 1, }, ]); - - expect(await getConnectors(args)).toEqual([]); }); - it('includes connectors that have a config and are not pre configured', async () => { - actionsClient.listTypes.mockImplementation(async () => [ - jiraType, + it('filter out connectors that are unsupported by the current license', async () => { + actionsClient.listTypes.mockImplementation(async () => actionTypes); + actionsClient.getAll.mockImplementation(async () => [ + ...connectors, { - id: '.servicenow', - name: '2', - enabled: true, - enabledInConfig: true, - enabledInLicense: true, - minimumLicenseRequired: 'basic', + id: '4', + actionTypeId: '.swimlane', + name: 'swimlane', + config: {}, + isPreconfigured: false, + referencedByCount: 1, }, ]); - const connectors = [ + expect(await getConnectors(args)).toEqual([ { id: '1', actionTypeId: '.jira', @@ -94,11 +180,7 @@ describe('client', () => { isPreconfigured: false, referencedByCount: 1, }, - ]; - - actionsClient.getAll.mockImplementation(async () => connectors); - - expect(await getConnectors(args)).toEqual(connectors); + ]); }); }); }); diff --git a/x-pack/plugins/cases/server/client/configure/client.ts b/x-pack/plugins/cases/server/client/configure/client.ts index c4b07019627e4..9bb6b83316264 100644 --- a/x-pack/plugins/cases/server/client/configure/client.ts +++ b/x-pack/plugins/cases/server/client/configure/client.ts @@ -223,9 +223,7 @@ function isConnectorSupported( ): boolean { return ( SUPPORTED_CONNECTORS.includes(action.actionTypeId) && - actionTypes[action.actionTypeId]?.enabledInLicense && - action.config != null && - !action.isPreconfigured + actionTypes[action.actionTypeId]?.enabledInLicense ); } From cad32cac38be5e26e223c4a21f069ceebf144312 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Tue, 19 Apr 2022 12:01:46 +0300 Subject: [PATCH 2/5] Add integration test --- .../cases_api_integration/common/config.ts | 14 ++++++- .../tests/common/configure/get_connectors.ts | 40 ++++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/x-pack/test/cases_api_integration/common/config.ts b/x-pack/test/cases_api_integration/common/config.ts index 803327cd037d3..421f2f823442e 100644 --- a/x-pack/test/cases_api_integration/common/config.ts +++ b/x-pack/test/cases_api_integration/common/config.ts @@ -20,7 +20,6 @@ interface CreateTestConfigOptions { testFiles?: string[]; } -// test.not-enabled is specifically not enabled const enabledActionTypes = [ '.email', '.index', @@ -139,6 +138,19 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions) (pluginDir) => `--plugin-path=${path.resolve(__dirname, 'fixtures', 'plugins', pluginDir)}` ), + `--xpack.actions.preconfigured=${JSON.stringify({ + 'preconfigured-servicenow': { + name: 'preconfigured-servicenow', + actionTypeId: '.servicenow', + config: { + apiUrl: 'https://example.com', + }, + secrets: { + username: 'elastic', + password: 'elastic', + }, + }, + })}`, `--server.xsrf.allowlist=${JSON.stringify(getAllExternalServiceSimulatorPaths())}`, ...(ssl ? [ diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts index 46f712ff84aa3..5209f65cf4feb 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts @@ -8,20 +8,48 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; -import { getCaseConnectors } from '../../../../common/lib/utils'; +import { + createConnector, + getCaseConnectors, + getServiceNowConnector, + getWebhookConnector, +} from '../../../../common/lib/utils'; // eslint-disable-next-line import/no-default-export export default ({ getService }: FtrProviderContext): void => { const supertest = getService('supertest'); + /** + * Preconfigured connectors are being registered here: + * x-pack/test/cases_api_integration/common/config.ts + */ describe('get_connectors', () => { - it('should return an empty find body correctly if no connectors are loaded', async () => { + it('should return only supported connectors including preconfigured connectors', async () => { + await createConnector({ supertest, req: getServiceNowConnector() }); + await createConnector({ supertest, req: getWebhookConnector() }); const connectors = await getCaseConnectors({ supertest }); - expect(connectors).to.eql([]); - }); - it.skip('filters out connectors that are not enabled in license', async () => { - // TODO: Should find a way to downgrade license to gold and upgrade back to trial + expect(connectors).to.eql([ + { + actionTypeId: '.servicenow', + id: 'preconfigured-servicenow', + isPreconfigured: true, + name: 'preconfigured-servicenow', + referencedByCount: 0, + }, + { + actionTypeId: '.servicenow', + config: { + apiUrl: 'http://some.non.existent.com', + usesTableApi: false, + }, + id: '35e75fd0-bfbe-11ec-b200-cdb35f39b10d', + isMissingSecrets: false, + isPreconfigured: false, + name: 'ServiceNow Connector', + referencedByCount: 0, + }, + ]); }); }); }; From f117f09183c385a199c46c222f88662998948fde Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Tue, 19 Apr 2022 15:59:01 +0300 Subject: [PATCH 3/5] Improve integration tests --- .../cases_api_integration/common/lib/utils.ts | 13 ++++ .../tests/basic/configure/create_connector.ts | 20 ------- .../tests/basic/configure/get_connectors.ts | 32 ++++++++++ .../security_and_spaces/tests/basic/index.ts | 1 + .../tests/common/configure/get_connectors.ts | 55 ----------------- .../security_and_spaces/tests/common/index.ts | 1 - .../tests/trial/configure/get_connectors.ts | 59 ++++++------------ .../tests/trial/configure/get_connectors.ts | 60 +++++++++++-------- 8 files changed, 99 insertions(+), 142 deletions(-) delete mode 100644 x-pack/test/cases_api_integration/security_and_spaces/tests/basic/configure/create_connector.ts create mode 100644 x-pack/test/cases_api_integration/security_and_spaces/tests/basic/configure/get_connectors.ts delete mode 100644 x-pack/test/cases_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts diff --git a/x-pack/test/cases_api_integration/common/lib/utils.ts b/x-pack/test/cases_api_integration/common/lib/utils.ts index a433f5da1d74a..322bc3567211d 100644 --- a/x-pack/test/cases_api_integration/common/lib/utils.ts +++ b/x-pack/test/cases_api_integration/common/lib/utils.ts @@ -289,6 +289,19 @@ export const getWebhookConnector = () => ({ }, }); +export const getEmailConnector = () => ({ + name: 'An email action', + connector_type_id: '.email', + config: { + service: '__json', + from: 'bob@example.com', + }, + secrets: { + user: 'bob', + password: 'supersecret', + }, +}); + interface CommonSavedObjectAttributes { id?: string | null; created_at?: string | null; diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/basic/configure/create_connector.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/basic/configure/create_connector.ts deleted file mode 100644 index fe8e311b5e4f6..0000000000000 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/basic/configure/create_connector.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { createConnector, getServiceNowConnector } from '../../../../common/lib/utils'; -import { FtrProviderContext } from '../../../../common/ftr_provider_context'; - -// eslint-disable-next-line import/no-default-export -export default function serviceNow({ getService }: FtrProviderContext) { - const supertest = getService('supertest'); - - describe('create service now action', () => { - it('should return 403 when creating a service now action', async () => { - await createConnector({ supertest, req: getServiceNowConnector(), expectedHttpCode: 403 }); - }); - }); -} diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/basic/configure/get_connectors.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/basic/configure/get_connectors.ts new file mode 100644 index 0000000000000..57854075c20fb --- /dev/null +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/basic/configure/get_connectors.ts @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; + +import { getCaseConnectors } from '../../../../common/lib/utils'; + +// eslint-disable-next-line import/no-default-export +export default ({ getService }: FtrProviderContext): void => { + const supertest = getService('supertest'); + + describe('get_connectors', () => { + /** + * A ServiceNow preconfigured connector is registered here + * x-pack/test/cases_api_integration/common/config.ts + * + * The license for this test is set to basic. ServiceNow connectors + * needs license >= platinum. The test below ensures + * that connectors without valid license are being filtered correctly + */ + it('should return an empty list of connectors', async () => { + const connectors = await getCaseConnectors({ supertest }); + + expect(connectors).to.eql([]); + }); + }); +}; diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/basic/index.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/basic/index.ts index ce2f59a115e69..b618cf5b4df68 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/basic/index.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/basic/index.ts @@ -24,6 +24,7 @@ export default ({ loadTestFile, getService }: FtrProviderContext): void => { // Basic loadTestFile(require.resolve('./cases/push_case')); + loadTestFile(require.resolve('./configure/get_connectors')); // Common loadTestFile(require.resolve('../common')); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts deleted file mode 100644 index 5209f65cf4feb..0000000000000 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; - -import { - createConnector, - getCaseConnectors, - getServiceNowConnector, - getWebhookConnector, -} from '../../../../common/lib/utils'; - -// eslint-disable-next-line import/no-default-export -export default ({ getService }: FtrProviderContext): void => { - const supertest = getService('supertest'); - - /** - * Preconfigured connectors are being registered here: - * x-pack/test/cases_api_integration/common/config.ts - */ - describe('get_connectors', () => { - it('should return only supported connectors including preconfigured connectors', async () => { - await createConnector({ supertest, req: getServiceNowConnector() }); - await createConnector({ supertest, req: getWebhookConnector() }); - const connectors = await getCaseConnectors({ supertest }); - - expect(connectors).to.eql([ - { - actionTypeId: '.servicenow', - id: 'preconfigured-servicenow', - isPreconfigured: true, - name: 'preconfigured-servicenow', - referencedByCount: 0, - }, - { - actionTypeId: '.servicenow', - config: { - apiUrl: 'http://some.non.existent.com', - usesTableApi: false, - }, - id: '35e75fd0-bfbe-11ec-b200-cdb35f39b10d', - isMissingSecrets: false, - isPreconfigured: false, - name: 'ServiceNow Connector', - referencedByCount: 0, - }, - ]); - }); - }); -}; diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/index.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/index.ts index f70c8593d3c94..25f39164f7c28 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/index.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/index.ts @@ -31,7 +31,6 @@ export default ({ loadTestFile }: FtrProviderContext): void => { loadTestFile(require.resolve('./cases/tags/get_tags')); loadTestFile(require.resolve('./user_actions/get_all_user_actions')); loadTestFile(require.resolve('./configure/get_configure')); - loadTestFile(require.resolve('./configure/get_connectors')); loadTestFile(require.resolve('./configure/patch_configure')); loadTestFile(require.resolve('./configure/post_configure')); loadTestFile(require.resolve('./metrics/get_case_metrics')); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/configure/get_connectors.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/configure/get_connectors.ts index b5a58d3af5086..91309462d98be 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/configure/get_connectors.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/configure/get_connectors.ts @@ -6,7 +6,6 @@ */ import expect from '@kbn/expect'; -import { CASE_CONFIGURE_CONNECTORS_URL } from '@kbn/cases-plugin/common/constants'; import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; import { ObjectRemover as ActionsRemover } from '../../../../../alerting_api_integration/common/lib'; @@ -16,6 +15,8 @@ import { getResilientConnector, createConnector, getServiceNowSIRConnector, + getEmailConnector, + getCaseConnectors, } from '../../../../common/lib/utils'; // eslint-disable-next-line import/no-default-export @@ -29,41 +30,10 @@ export default ({ getService }: FtrProviderContext): void => { }); it('should return the correct connectors', async () => { - const { body: snConnector } = await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'true') - .send(getServiceNowConnector()) - .expect(200); - - const { body: emailConnector } = await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'true') - .send({ - name: 'An email action', - connector_type_id: '.email', - config: { - service: '__json', - from: 'bob@example.com', - }, - secrets: { - user: 'bob', - password: 'supersecret', - }, - }) - .expect(200); - - const { body: jiraConnector } = await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'true') - .send(getJiraConnector()) - .expect(200); - - const { body: resilientConnector } = await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'true') - .send(getResilientConnector()) - .expect(200); - + const snConnector = await createConnector({ supertest, req: getServiceNowConnector() }); + const emailConnector = await createConnector({ supertest, req: getEmailConnector() }); + const jiraConnector = await createConnector({ supertest, req: getJiraConnector() }); + const resilientConnector = await createConnector({ supertest, req: getResilientConnector() }); const sir = await createConnector({ supertest, req: getServiceNowSIRConnector() }); actionsRemover.add('default', sir.id, 'action', 'actions'); @@ -72,11 +42,7 @@ export default ({ getService }: FtrProviderContext): void => { actionsRemover.add('default', jiraConnector.id, 'action', 'actions'); actionsRemover.add('default', resilientConnector.id, 'action', 'actions'); - const { body: connectors } = await supertest - .get(`${CASE_CONFIGURE_CONNECTORS_URL}/_find`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); + const connectors = await getCaseConnectors({ supertest }); expect(connectors).to.eql([ { @@ -91,6 +57,17 @@ export default ({ getService }: FtrProviderContext): void => { isMissingSecrets: false, referencedByCount: 0, }, + /** + * Preconfigured connectors are being registered here: + * x-pack/test/cases_api_integration/common/config.ts + */ + { + actionTypeId: '.servicenow', + id: 'preconfigured-servicenow', + isPreconfigured: true, + name: 'preconfigured-servicenow', + referencedByCount: 0, + }, { id: resilientConnector.id, actionTypeId: '.resilient', diff --git a/x-pack/test/cases_api_integration/spaces_only/tests/trial/configure/get_connectors.ts b/x-pack/test/cases_api_integration/spaces_only/tests/trial/configure/get_connectors.ts index 02b91c9f0b918..d91e48cff559b 100644 --- a/x-pack/test/cases_api_integration/spaces_only/tests/trial/configure/get_connectors.ts +++ b/x-pack/test/cases_api_integration/spaces_only/tests/trial/configure/get_connectors.ts @@ -18,6 +18,7 @@ import { getAuthWithSuperUser, getCaseConnectors, getActionsSpace, + getEmailConnector, } from '../../../../common/lib/utils'; // eslint-disable-next-line import/no-default-export @@ -38,32 +39,25 @@ export default ({ getService }: FtrProviderContext): void => { req: getServiceNowConnector(), auth: authSpace1, }); + const emailConnector = await createConnector({ supertest, - req: { - name: 'An email action', - connector_type_id: '.email', - config: { - service: '__json', - from: 'bob@example.com', - }, - secrets: { - user: 'bob', - password: 'supersecret', - }, - }, + req: getEmailConnector(), auth: authSpace1, }); + const jiraConnector = await createConnector({ supertest, req: getJiraConnector(), auth: authSpace1, }); + const resilientConnector = await createConnector({ supertest, req: getResilientConnector(), auth: authSpace1, }); + const sir = await createConnector({ supertest, req: getServiceNowSIRConnector(), @@ -91,6 +85,17 @@ export default ({ getService }: FtrProviderContext): void => { isMissingSecrets: false, referencedByCount: 0, }, + /** + * Preconfigured connectors are being registered here: + * x-pack/test/cases_api_integration/common/config.ts + */ + { + actionTypeId: '.servicenow', + id: 'preconfigured-servicenow', + isPreconfigured: true, + name: 'preconfigured-servicenow', + referencedByCount: 0, + }, { id: resilientConnector.id, actionTypeId: '.resilient', @@ -136,32 +141,25 @@ export default ({ getService }: FtrProviderContext): void => { req: getServiceNowConnector(), auth: authSpace1, }); + const emailConnector = await createConnector({ supertest, - req: { - name: 'An email action', - connector_type_id: '.email', - config: { - service: '__json', - from: 'bob@example.com', - }, - secrets: { - user: 'bob', - password: 'supersecret', - }, - }, + req: getEmailConnector(), auth: authSpace1, }); + const jiraConnector = await createConnector({ supertest, req: getJiraConnector(), auth: authSpace1, }); + const resilientConnector = await createConnector({ supertest, req: getResilientConnector(), auth: authSpace1, }); + const sir = await createConnector({ supertest, req: getServiceNowSIRConnector(), @@ -179,7 +177,19 @@ export default ({ getService }: FtrProviderContext): void => { auth: getAuthWithSuperUser('space2'), }); - expect(connectors).to.eql([]); + expect(connectors).to.eql([ + /** + * Preconfigured connectors are being registered here: + * x-pack/test/cases_api_integration/common/config.ts + */ + { + actionTypeId: '.servicenow', + id: 'preconfigured-servicenow', + isPreconfigured: true, + name: 'preconfigured-servicenow', + referencedByCount: 0, + }, + ]); }); }); }; From 152e4e5690f64b96c2d3f254bfae24043e84bf5e Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Tue, 19 Apr 2022 17:34:13 +0300 Subject: [PATCH 4/5] Fix grammar --- .../components/connectors/servicenow/validator.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/cases/public/components/connectors/servicenow/validator.test.ts b/x-pack/plugins/cases/public/components/connectors/servicenow/validator.test.ts index d7cc424216d12..ab21a6b5c779c 100644 --- a/x-pack/plugins/cases/public/components/connectors/servicenow/validator.test.ts +++ b/x-pack/plugins/cases/public/components/connectors/servicenow/validator.test.ts @@ -22,7 +22,7 @@ describe('ServiceNow validator', () => { expect(connectorValidator(invalidConnector)).toEqual({ message: 'Deprecated connector' }); }); - test('it does not returns an error message if the connector does not uses the table API', () => { + test('it does not return an error message if the connector does not uses the table API', () => { const invalidConnector = { ...connector, config: { @@ -34,14 +34,14 @@ describe('ServiceNow validator', () => { expect(connectorValidator(invalidConnector)).toBeFalsy(); }); - test('it does not returns an error message if the config of the connector is undefined', () => { + test('it does not return an error message if the config of the connector is undefined', () => { const { config, ...invalidConnector } = connector; // @ts-expect-error expect(connectorValidator(invalidConnector)).toBeFalsy(); }); - test('it does not returns an error message if the config of the connector is preconfigured', () => { + test('it does not return an error message if the config of the connector is preconfigured', () => { expect(connectorValidator({ ...connector, isPreconfigured: true })).toBeFalsy(); }); }); From 0576128762026c8b2190d332c7c23fc8e9958687 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Wed, 27 Apr 2022 10:57:31 +0300 Subject: [PATCH 5/5] Fix CI --- .../plugins/cases/server/client/configure/client.test.ts | 8 ++++++++ .../tests/trial/configure/get_connectors.ts | 1 + .../spaces_only/tests/trial/configure/get_connectors.ts | 2 ++ 3 files changed, 11 insertions(+) diff --git a/x-pack/plugins/cases/server/client/configure/client.test.ts b/x-pack/plugins/cases/server/client/configure/client.test.ts index 46179e5daddf9..2889f00b6d28b 100644 --- a/x-pack/plugins/cases/server/client/configure/client.test.ts +++ b/x-pack/plugins/cases/server/client/configure/client.test.ts @@ -59,6 +59,7 @@ describe('client', () => { name: '1', config: {}, isPreconfigured: false, + isDeprecated: false, referencedByCount: 1, }, { @@ -67,6 +68,7 @@ describe('client', () => { name: '2', config: {}, isPreconfigured: false, + isDeprecated: false, referencedByCount: 1, }, { @@ -75,6 +77,7 @@ describe('client', () => { name: '3', config: {}, isPreconfigured: false, + isDeprecated: false, referencedByCount: 1, }, ]; @@ -94,6 +97,7 @@ describe('client', () => { name: '1', config: {}, isPreconfigured: false, + isDeprecated: false, referencedByCount: 1, }, { @@ -118,6 +122,7 @@ describe('client', () => { name: 'sn-preconfigured', config: {}, isPreconfigured: true, + isDeprecated: false, referencedByCount: 1, }, ]); @@ -129,6 +134,7 @@ describe('client', () => { name: '1', config: {}, isPreconfigured: false, + isDeprecated: false, referencedByCount: 1, }, { @@ -137,6 +143,7 @@ describe('client', () => { name: '2', config: {}, isPreconfigured: false, + isDeprecated: false, referencedByCount: 1, }, { @@ -161,6 +168,7 @@ describe('client', () => { name: 'swimlane', config: {}, isPreconfigured: false, + isDeprecated: false, referencedByCount: 1, }, ]); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/configure/get_connectors.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/configure/get_connectors.ts index 6a297648a69d6..26df77bfbc924 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/configure/get_connectors.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/configure/get_connectors.ts @@ -66,6 +66,7 @@ export default ({ getService }: FtrProviderContext): void => { actionTypeId: '.servicenow', id: 'preconfigured-servicenow', isPreconfigured: true, + isDeprecated: false, name: 'preconfigured-servicenow', referencedByCount: 0, }, diff --git a/x-pack/test/cases_api_integration/spaces_only/tests/trial/configure/get_connectors.ts b/x-pack/test/cases_api_integration/spaces_only/tests/trial/configure/get_connectors.ts index cfce42419d0aa..c4115b5c4902d 100644 --- a/x-pack/test/cases_api_integration/spaces_only/tests/trial/configure/get_connectors.ts +++ b/x-pack/test/cases_api_integration/spaces_only/tests/trial/configure/get_connectors.ts @@ -94,6 +94,7 @@ export default ({ getService }: FtrProviderContext): void => { actionTypeId: '.servicenow', id: 'preconfigured-servicenow', isPreconfigured: true, + isDeprecated: false, name: 'preconfigured-servicenow', referencedByCount: 0, }, @@ -190,6 +191,7 @@ export default ({ getService }: FtrProviderContext): void => { actionTypeId: '.servicenow', id: 'preconfigured-servicenow', isPreconfigured: true, + isDeprecated: false, name: 'preconfigured-servicenow', referencedByCount: 0, },