From 7dba0d343d5c61724de9ac7f7be7c7fe3181900f Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Mon, 20 Apr 2020 12:31:25 +0300 Subject: [PATCH 1/5] Init --- .../case_api_integration/common/config.ts | 96 +++++++++++++++++++ .../common/ftr_provider_context.d.ts | 11 +++ .../case_api_integration/common/services.ts | 7 ++ .../security_and_spaces/config.ts | 14 +++ .../tests/configure/get_configure.ts | 78 +++++++++++++++ .../security_and_spaces/tests/index.ts | 16 ++++ x-pack/test/case_api_integration/utils.ts | 40 ++++++++ 7 files changed, 262 insertions(+) create mode 100644 x-pack/test/case_api_integration/common/config.ts create mode 100644 x-pack/test/case_api_integration/common/ftr_provider_context.d.ts create mode 100644 x-pack/test/case_api_integration/common/services.ts create mode 100644 x-pack/test/case_api_integration/security_and_spaces/config.ts create mode 100644 x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts create mode 100644 x-pack/test/case_api_integration/security_and_spaces/tests/index.ts create mode 100644 x-pack/test/case_api_integration/utils.ts diff --git a/x-pack/test/case_api_integration/common/config.ts b/x-pack/test/case_api_integration/common/config.ts new file mode 100644 index 0000000000000..a4f751a78edc8 --- /dev/null +++ b/x-pack/test/case_api_integration/common/config.ts @@ -0,0 +1,96 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import path from 'path'; + +import { CA_CERT_PATH } from '@kbn/dev-utils'; +import { FtrConfigProviderContext } from '@kbn/test/types/ftr'; + +import { services } from './services'; + +interface CreateTestConfigOptions { + license: string; + disabledPlugins?: string[]; + ssl?: boolean; +} + +// test.not-enabled is specifically not enabled +const enabledActionTypes = [ + '.email', + '.index', + '.pagerduty', + '.server-log', + '.servicenow', + '.slack', + '.webhook', + 'test.authorization', + 'test.failing', + 'test.index-record', + 'test.noop', + 'test.rate-limit', +]; + +export function createTestConfig(name: string, options: CreateTestConfigOptions) { + const { license = 'trial', disabledPlugins = [], ssl = false } = options; + + return async ({ readConfigFile }: FtrConfigProviderContext) => { + const xPackApiIntegrationTestsConfig = await readConfigFile( + require.resolve('../../api_integration/config.js') + ); + + const servers = { + ...xPackApiIntegrationTestsConfig.get('servers'), + elasticsearch: { + ...xPackApiIntegrationTestsConfig.get('servers.elasticsearch'), + protocol: ssl ? 'https' : 'http', + }, + }; + + return { + testFiles: [require.resolve(`../${name}/tests/`)], + servers, + services, + junit: { + reportName: 'X-Pack Case API Integration Tests', + }, + esArchiver: xPackApiIntegrationTestsConfig.get('esArchiver'), + esTestCluster: { + ...xPackApiIntegrationTestsConfig.get('esTestCluster'), + license, + ssl, + serverArgs: [ + `xpack.license.self_generated.type=${license}`, + `xpack.security.enabled=${!disabledPlugins.includes('security') && + ['trial', 'basic'].includes(license)}`, + ], + }, + kbnTestServer: { + ...xPackApiIntegrationTestsConfig.get('kbnTestServer'), + serverArgs: [ + ...xPackApiIntegrationTestsConfig.get('kbnTestServer.serverArgs'), + `--xpack.actions.whitelistedHosts=${JSON.stringify([ + 'localhost', + 'some.non.existent.com', + ])}`, + `--xpack.actions.enabledActionTypes=${JSON.stringify(enabledActionTypes)}`, + '--xpack.alerting.enabled=true', + '--xpack.eventLog.logEntries=true', + ...disabledPlugins.map(key => `--xpack.${key}.enabled=false`), + `--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'alerts')}`, + `--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'actions')}`, + `--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'task_manager')}`, + `--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'aad')}`, + ...(ssl + ? [ + `--elasticsearch.hosts=${servers.elasticsearch.protocol}://${servers.elasticsearch.hostname}:${servers.elasticsearch.port}`, + `--elasticsearch.ssl.certificateAuthorities=${CA_CERT_PATH}`, + ] + : []), + ], + }, + }; + }; +} diff --git a/x-pack/test/case_api_integration/common/ftr_provider_context.d.ts b/x-pack/test/case_api_integration/common/ftr_provider_context.d.ts new file mode 100644 index 0000000000000..e3add3748f56d --- /dev/null +++ b/x-pack/test/case_api_integration/common/ftr_provider_context.d.ts @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { GenericFtrProviderContext } from '@kbn/test/types/ftr'; + +import { services } from './services'; + +export type FtrProviderContext = GenericFtrProviderContext; diff --git a/x-pack/test/case_api_integration/common/services.ts b/x-pack/test/case_api_integration/common/services.ts new file mode 100644 index 0000000000000..a927a31469bab --- /dev/null +++ b/x-pack/test/case_api_integration/common/services.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { services } from '../../api_integration/services'; diff --git a/x-pack/test/case_api_integration/security_and_spaces/config.ts b/x-pack/test/case_api_integration/security_and_spaces/config.ts new file mode 100644 index 0000000000000..081b901c47fc3 --- /dev/null +++ b/x-pack/test/case_api_integration/security_and_spaces/config.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { createTestConfig } from '../common/config'; + +// eslint-disable-next-line import/no-default-export +export default createTestConfig('security_and_spaces', { + disabledPlugins: [], + license: 'trial', + ssl: true, +}); diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts new file mode 100644 index 0000000000000..0cc238279ccde --- /dev/null +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts @@ -0,0 +1,78 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; + +import { CASE_CONFIGURE_URL } from '../../../../../plugins/case/common/constants'; +import { + getConfiguration, + removeServerGeneratedPropertiesFromConfigure, + getConfigurationOutput, + deleteConfiguration, +} from '../../../utils'; + +// eslint-disable-next-line import/no-default-export +export default ({ getService }: FtrProviderContext): void => { + const supertest = getService('supertest'); + const es = getService('legacyEs'); + + describe('get_configure', () => { + beforeEach(async () => { + await deleteConfiguration(es); + }); + + it('should return an empty find body correctly if no configuration is loaded', async () => { + const { body } = await supertest + .get(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send() + .expect(200); + + expect(body).to.eql({}); + }); + + it('should return a configuration', async () => { + await supertest + .post(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send(getConfiguration()) + .expect(200); + + const { body } = await supertest + .get(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send() + .expect(200); + + const data = removeServerGeneratedPropertiesFromConfigure(body); + expect(data).to.eql(getConfigurationOutput()); + }); + + it('should keep only the latest configuration', async () => { + await supertest + .post(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send(getConfiguration('connector-2')) + .expect(200); + + await supertest + .post(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send(getConfiguration()) + .expect(200); + + const { body } = await supertest + .get(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send() + .expect(200); + + const data = removeServerGeneratedPropertiesFromConfigure(body); + expect(data).to.eql(getConfigurationOutput()); + }); + }); +}; diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts new file mode 100644 index 0000000000000..6506b5aa2025c --- /dev/null +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { FtrProviderContext } from '../../common/ftr_provider_context'; + +// eslint-disable-next-line import/no-default-export +export default ({ loadTestFile }: FtrProviderContext): void => { + describe('case api security and spaces enabled', function() { + this.tags('ciGroup1'); + + loadTestFile(require.resolve('./configure/get_configure')); + }); +}; diff --git a/x-pack/test/case_api_integration/utils.ts b/x-pack/test/case_api_integration/utils.ts new file mode 100644 index 0000000000000..818578d15ac89 --- /dev/null +++ b/x-pack/test/case_api_integration/utils.ts @@ -0,0 +1,40 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { CasesConfigureRequest, CasesConfigureResponse } from '../../plugins/case/common/api'; + +export const getConfiguration = (connector_id: string = 'connector-1'): CasesConfigureRequest => { + return { + connector_id, + connector_name: 'Connector 1', + closure_type: 'close-by-user', + }; +}; + +export const getConfigurationOutput = (): Partial => { + return { + ...getConfiguration(), + created_by: { email: null, full_name: null, username: 'elastic' }, + updated_by: null, + }; +}; + +export const removeServerGeneratedPropertiesFromConfigure = ( + config: Partial +): Partial => { + const { created_at, updated_at, version, ...rest } = config; + return rest; +}; + +export const deleteConfiguration = async (es: any): Promise => { + await es.deleteByQuery({ + index: '.kibana', + q: 'type:cases-configure', + waitForCompletion: true, + refresh: 'wait_for', + body: {}, + }); +}; From 9e3f9724b2fbd9114d7e497f5dba13cf7c811c15 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Tue, 21 Apr 2020 14:40:52 +0300 Subject: [PATCH 2/5] Init get_connectors --- .../{ => common/lib}/utils.ts | 33 ++++++++++++++++++- .../tests/configure/get_configure.ts | 2 +- .../tests/configure/get_connectors.ts | 27 +++++++++++++++ .../security_and_spaces/tests/index.ts | 1 + 4 files changed, 61 insertions(+), 2 deletions(-) rename x-pack/test/case_api_integration/{ => common/lib}/utils.ts (64%) create mode 100644 x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_connectors.ts diff --git a/x-pack/test/case_api_integration/utils.ts b/x-pack/test/case_api_integration/common/lib/utils.ts similarity index 64% rename from x-pack/test/case_api_integration/utils.ts rename to x-pack/test/case_api_integration/common/lib/utils.ts index 818578d15ac89..7bb544290ed59 100644 --- a/x-pack/test/case_api_integration/utils.ts +++ b/x-pack/test/case_api_integration/common/lib/utils.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { CasesConfigureRequest, CasesConfigureResponse } from '../../plugins/case/common/api'; +import { CasesConfigureRequest, CasesConfigureResponse } from '../../../../plugins/case/common/api'; export const getConfiguration = (connector_id: string = 'connector-1'): CasesConfigureRequest => { return { @@ -38,3 +38,34 @@ export const deleteConfiguration = async (es: any): Promise => { body: {}, }); }; + +export const getConnector = () => ({ + name: 'ServiceNow Connector', + actionTypeId: '.servicenow', + secrets: { + username: 'admin', + password: 'admin', + }, + config: { + apiUrl: 'localhost', + casesConfiguration: { + mapping: [ + { + source: 'title', + target: 'short_description', + actionType: 'overwrite', + }, + { + source: 'description', + target: 'description', + actionType: 'overwrite', + }, + { + source: 'comments', + target: 'comments', + actionType: 'append', + }, + ], + }, + }, +}); diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts index 0cc238279ccde..7e3b0493cc424 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts @@ -13,7 +13,7 @@ import { removeServerGeneratedPropertiesFromConfigure, getConfigurationOutput, deleteConfiguration, -} from '../../../utils'; +} from '../../../common/lib/utils'; // eslint-disable-next-line import/no-default-export export default ({ getService }: FtrProviderContext): void => { diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_connectors.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_connectors.ts new file mode 100644 index 0000000000000..836c76d500034 --- /dev/null +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_connectors.ts @@ -0,0 +1,27 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; + +import { CASE_CONFIGURE_CONNECTORS_URL } from '../../../../../plugins/case/common/constants'; + +// eslint-disable-next-line import/no-default-export +export default ({ getService }: FtrProviderContext): void => { + const supertest = getService('supertest'); + + describe('get_connectors', () => { + it('should return an empty find body correctly if no connectors are loaded', async () => { + const { body } = await supertest + .get(`${CASE_CONFIGURE_CONNECTORS_URL}/_find`) + .set('kbn-xsrf', 'true') + .send() + .expect(200); + + expect(body).to.eql([]); + }); + }); +}; diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts index 6506b5aa2025c..c0321716e4ea6 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts @@ -12,5 +12,6 @@ export default ({ loadTestFile }: FtrProviderContext): void => { this.tags('ciGroup1'); loadTestFile(require.resolve('./configure/get_configure')); + loadTestFile(require.resolve('./configure/get_connectors')); }); }; From edbd8e452de8ba9e8b6617d4bf348bb231f6d4d7 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Tue, 21 Apr 2020 14:49:39 +0300 Subject: [PATCH 3/5] Test post_configuration --- .../tests/configure/get_configure.ts | 27 ++------ .../tests/configure/post_configure.ts | 66 +++++++++++++++++++ .../security_and_spaces/tests/index.ts | 1 + 3 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 x-pack/test/case_api_integration/security_and_spaces/tests/configure/post_configure.ts diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts index 7e3b0493cc424..9d10c9a269fb7 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts @@ -25,6 +25,10 @@ export default ({ getService }: FtrProviderContext): void => { await deleteConfiguration(es); }); + after(async () => { + await deleteConfiguration(es); + }); + it('should return an empty find body correctly if no configuration is loaded', async () => { const { body } = await supertest .get(CASE_CONFIGURE_URL) @@ -51,28 +55,5 @@ export default ({ getService }: FtrProviderContext): void => { const data = removeServerGeneratedPropertiesFromConfigure(body); expect(data).to.eql(getConfigurationOutput()); }); - - it('should keep only the latest configuration', async () => { - await supertest - .post(CASE_CONFIGURE_URL) - .set('kbn-xsrf', 'true') - .send(getConfiguration('connector-2')) - .expect(200); - - await supertest - .post(CASE_CONFIGURE_URL) - .set('kbn-xsrf', 'true') - .send(getConfiguration()) - .expect(200); - - const { body } = await supertest - .get(CASE_CONFIGURE_URL) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - const data = removeServerGeneratedPropertiesFromConfigure(body); - expect(data).to.eql(getConfigurationOutput()); - }); }); }; diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/post_configure.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/post_configure.ts new file mode 100644 index 0000000000000..8cff27ac265c7 --- /dev/null +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/post_configure.ts @@ -0,0 +1,66 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; + +import { CASE_CONFIGURE_URL } from '../../../../../plugins/case/common/constants'; +import { + getConfiguration, + removeServerGeneratedPropertiesFromConfigure, + getConfigurationOutput, + deleteConfiguration, +} from '../../../common/lib/utils'; + +// eslint-disable-next-line import/no-default-export +export default ({ getService }: FtrProviderContext): void => { + const supertest = getService('supertest'); + const es = getService('legacyEs'); + + describe('post_configure', () => { + beforeEach(async () => { + await deleteConfiguration(es); + }); + + after(async () => { + await deleteConfiguration(es); + }); + + it('should create a configuration', async () => { + const { body } = await supertest + .post(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send(getConfiguration()) + .expect(200); + + const data = removeServerGeneratedPropertiesFromConfigure(body); + expect(data).to.eql(getConfigurationOutput()); + }); + + it('should keep only the latest configuration', async () => { + await supertest + .post(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send(getConfiguration('connector-2')) + .expect(200); + + await supertest + .post(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send(getConfiguration()) + .expect(200); + + const { body } = await supertest + .get(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send() + .expect(200); + + const data = removeServerGeneratedPropertiesFromConfigure(body); + expect(data).to.eql(getConfigurationOutput()); + }); + }); +}; diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts index c0321716e4ea6..84b6d5ce3ead5 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts @@ -12,6 +12,7 @@ export default ({ loadTestFile }: FtrProviderContext): void => { this.tags('ciGroup1'); loadTestFile(require.resolve('./configure/get_configure')); + loadTestFile(require.resolve('./configure/post_configure')); loadTestFile(require.resolve('./configure/get_connectors')); }); }; From 30e8e4fb65b3c84024376dc5bb71958eefb43b1a Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Tue, 21 Apr 2020 15:09:19 +0300 Subject: [PATCH 4/5] Test patch_configuration --- .../api/cases/configure/patch_configure.ts | 2 +- .../case_api_integration/common/lib/utils.ts | 4 +- .../tests/configure/get_configure.ts | 6 +- .../tests/configure/patch_configure.ts | 81 +++++++++++++++++++ .../tests/configure/post_configure.ts | 6 +- .../security_and_spaces/tests/index.ts | 1 + 6 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 x-pack/test/case_api_integration/security_and_spaces/tests/configure/patch_configure.ts diff --git a/x-pack/plugins/case/server/routes/api/cases/configure/patch_configure.ts b/x-pack/plugins/case/server/routes/api/cases/configure/patch_configure.ts index 47f7d503e32b8..29df97c5f8476 100644 --- a/x-pack/plugins/case/server/routes/api/cases/configure/patch_configure.ts +++ b/x-pack/plugins/case/server/routes/api/cases/configure/patch_configure.ts @@ -39,7 +39,7 @@ export function initPatchCaseConfigure({ caseConfigureService, caseService, rout if (myCaseConfigure.saved_objects.length === 0) { throw Boom.conflict( - 'You can not patch this configuration since you did not created first with a post' + 'You can not patch this configuration since you did not created first with a post.' ); } diff --git a/x-pack/test/case_api_integration/common/lib/utils.ts b/x-pack/test/case_api_integration/common/lib/utils.ts index 7bb544290ed59..6d0db69309b90 100644 --- a/x-pack/test/case_api_integration/common/lib/utils.ts +++ b/x-pack/test/case_api_integration/common/lib/utils.ts @@ -14,11 +14,11 @@ export const getConfiguration = (connector_id: string = 'connector-1'): CasesCon }; }; -export const getConfigurationOutput = (): Partial => { +export const getConfigurationOutput = (update = false): Partial => { return { ...getConfiguration(), created_by: { email: null, full_name: null, username: 'elastic' }, - updated_by: null, + updated_by: update ? { email: null, full_name: null, username: 'elastic' } : null, }; }; diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts index 9d10c9a269fb7..a9fc2706a6ba2 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts @@ -21,11 +21,7 @@ export default ({ getService }: FtrProviderContext): void => { const es = getService('legacyEs'); describe('get_configure', () => { - beforeEach(async () => { - await deleteConfiguration(es); - }); - - after(async () => { + afterEach(async () => { await deleteConfiguration(es); }); diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/patch_configure.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/patch_configure.ts new file mode 100644 index 0000000000000..d66baa2a2eee2 --- /dev/null +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/patch_configure.ts @@ -0,0 +1,81 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../common/ftr_provider_context'; + +import { CASE_CONFIGURE_URL } from '../../../../../plugins/case/common/constants'; +import { + getConfiguration, + removeServerGeneratedPropertiesFromConfigure, + getConfigurationOutput, + deleteConfiguration, +} from '../../../common/lib/utils'; + +// eslint-disable-next-line import/no-default-export +export default ({ getService }: FtrProviderContext): void => { + const supertest = getService('supertest'); + const es = getService('legacyEs'); + + describe('post_configure', () => { + afterEach(async () => { + await deleteConfiguration(es); + }); + + it('should patch a configuration', async () => { + const res = await supertest + .post(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send(getConfiguration()) + .expect(200); + + const { body } = await supertest + .patch(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send({ closure_type: 'close-by-pushing', version: res.body.version }) + .expect(200); + + const data = removeServerGeneratedPropertiesFromConfigure(body); + expect(data).to.eql({ ...getConfigurationOutput(true), closure_type: 'close-by-pushing' }); + }); + + it('should handle patch request when there is no configuration', async () => { + const { body } = await supertest + .patch(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send({ closure_type: 'close-by-pushing', version: 'no-version' }) + .expect(409); + + expect(body).to.eql({ + error: 'Conflict', + message: + 'You can not patch this configuration since you did not created first with a post.', + statusCode: 409, + }); + }); + + it('should handle patch request when versions are different', async () => { + await supertest + .post(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send(getConfiguration()) + .expect(200); + + const { body } = await supertest + .patch(CASE_CONFIGURE_URL) + .set('kbn-xsrf', 'true') + .send({ closure_type: 'close-by-pushing', version: 'no-version' }) + .expect(409); + + expect(body).to.eql({ + error: 'Conflict', + message: + 'This configuration has been updated. Please refresh before saving additional updates.', + statusCode: 409, + }); + }); + }); +}; diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/post_configure.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/post_configure.ts index 8cff27ac265c7..c2284492e5b77 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/post_configure.ts +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/configure/post_configure.ts @@ -21,11 +21,7 @@ export default ({ getService }: FtrProviderContext): void => { const es = getService('legacyEs'); describe('post_configure', () => { - beforeEach(async () => { - await deleteConfiguration(es); - }); - - after(async () => { + afterEach(async () => { await deleteConfiguration(es); }); diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts b/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts index 84b6d5ce3ead5..26a5bf5dc637c 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts +++ b/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts @@ -13,6 +13,7 @@ export default ({ loadTestFile }: FtrProviderContext): void => { loadTestFile(require.resolve('./configure/get_configure')); loadTestFile(require.resolve('./configure/post_configure')); + loadTestFile(require.resolve('./configure/patch_configure')); loadTestFile(require.resolve('./configure/get_connectors')); }); }; From 4717b85d35ec06de48d489adc55b21b9ce554183 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Thu, 23 Apr 2020 11:05:03 +0300 Subject: [PATCH 5/5] Rename folder --- .../{security_and_spaces => basic}/config.ts | 4 ++-- .../tests/configure/get_configure.ts | 0 .../tests/configure/get_connectors.ts | 0 .../tests/configure/patch_configure.ts | 0 .../tests/configure/post_configure.ts | 0 .../{security_and_spaces => basic}/tests/index.ts | 5 +++-- x-pack/test/case_api_integration/common/config.ts | 2 -- 7 files changed, 5 insertions(+), 6 deletions(-) rename x-pack/test/case_api_integration/{security_and_spaces => basic}/config.ts (83%) rename x-pack/test/case_api_integration/{security_and_spaces => basic}/tests/configure/get_configure.ts (100%) rename x-pack/test/case_api_integration/{security_and_spaces => basic}/tests/configure/get_connectors.ts (100%) rename x-pack/test/case_api_integration/{security_and_spaces => basic}/tests/configure/patch_configure.ts (100%) rename x-pack/test/case_api_integration/{security_and_spaces => basic}/tests/configure/post_configure.ts (100%) rename x-pack/test/case_api_integration/{security_and_spaces => basic}/tests/index.ts (86%) diff --git a/x-pack/test/case_api_integration/security_and_spaces/config.ts b/x-pack/test/case_api_integration/basic/config.ts similarity index 83% rename from x-pack/test/case_api_integration/security_and_spaces/config.ts rename to x-pack/test/case_api_integration/basic/config.ts index 081b901c47fc3..f9c248ec3d56f 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/config.ts +++ b/x-pack/test/case_api_integration/basic/config.ts @@ -7,8 +7,8 @@ import { createTestConfig } from '../common/config'; // eslint-disable-next-line import/no-default-export -export default createTestConfig('security_and_spaces', { +export default createTestConfig('basic', { disabledPlugins: [], - license: 'trial', + license: 'basic', ssl: true, }); diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts b/x-pack/test/case_api_integration/basic/tests/configure/get_configure.ts similarity index 100% rename from x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_configure.ts rename to x-pack/test/case_api_integration/basic/tests/configure/get_configure.ts diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_connectors.ts b/x-pack/test/case_api_integration/basic/tests/configure/get_connectors.ts similarity index 100% rename from x-pack/test/case_api_integration/security_and_spaces/tests/configure/get_connectors.ts rename to x-pack/test/case_api_integration/basic/tests/configure/get_connectors.ts diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/patch_configure.ts b/x-pack/test/case_api_integration/basic/tests/configure/patch_configure.ts similarity index 100% rename from x-pack/test/case_api_integration/security_and_spaces/tests/configure/patch_configure.ts rename to x-pack/test/case_api_integration/basic/tests/configure/patch_configure.ts diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/configure/post_configure.ts b/x-pack/test/case_api_integration/basic/tests/configure/post_configure.ts similarity index 100% rename from x-pack/test/case_api_integration/security_and_spaces/tests/configure/post_configure.ts rename to x-pack/test/case_api_integration/basic/tests/configure/post_configure.ts diff --git a/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts b/x-pack/test/case_api_integration/basic/tests/index.ts similarity index 86% rename from x-pack/test/case_api_integration/security_and_spaces/tests/index.ts rename to x-pack/test/case_api_integration/basic/tests/index.ts index 26a5bf5dc637c..efd5369c019d8 100644 --- a/x-pack/test/case_api_integration/security_and_spaces/tests/index.ts +++ b/x-pack/test/case_api_integration/basic/tests/index.ts @@ -8,8 +8,9 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; // eslint-disable-next-line import/no-default-export export default ({ loadTestFile }: FtrProviderContext): void => { - describe('case api security and spaces enabled', function() { - this.tags('ciGroup1'); + describe('case api basic', function() { + // Fastest ciGroup for the moment. + this.tags('ciGroup2'); loadTestFile(require.resolve('./configure/get_configure')); loadTestFile(require.resolve('./configure/post_configure')); diff --git a/x-pack/test/case_api_integration/common/config.ts b/x-pack/test/case_api_integration/common/config.ts index a4f751a78edc8..862705ab9610b 100644 --- a/x-pack/test/case_api_integration/common/config.ts +++ b/x-pack/test/case_api_integration/common/config.ts @@ -81,8 +81,6 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions) ...disabledPlugins.map(key => `--xpack.${key}.enabled=false`), `--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'alerts')}`, `--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'actions')}`, - `--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'task_manager')}`, - `--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'aad')}`, ...(ssl ? [ `--elasticsearch.hosts=${servers.elasticsearch.protocol}://${servers.elasticsearch.hostname}:${servers.elasticsearch.port}`,