[SIEM][CASE] Api Integration Tests: Configuration (#63948)
* Init * Init get_connectors * Test post_configuration * Test patch_configuration * Rename folder Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
44f9cbcb60
commit
a145aa9d5e
11 changed files with 443 additions and 1 deletions
|
@ -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.'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
14
x-pack/test/case_api_integration/basic/config.ts
Normal file
14
x-pack/test/case_api_integration/basic/config.ts
Normal file
|
@ -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('basic', {
|
||||
disabledPlugins: [],
|
||||
license: 'basic',
|
||||
ssl: true,
|
||||
});
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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('get_configure', () => {
|
||||
afterEach(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());
|
||||
});
|
||||
});
|
||||
};
|
|
@ -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([]);
|
||||
});
|
||||
});
|
||||
};
|
|
@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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 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());
|
||||
});
|
||||
});
|
||||
};
|
20
x-pack/test/case_api_integration/basic/tests/index.ts
Normal file
20
x-pack/test/case_api_integration/basic/tests/index.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* 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 basic', function() {
|
||||
// Fastest ciGroup for the moment.
|
||||
this.tags('ciGroup2');
|
||||
|
||||
loadTestFile(require.resolve('./configure/get_configure'));
|
||||
loadTestFile(require.resolve('./configure/post_configure'));
|
||||
loadTestFile(require.resolve('./configure/patch_configure'));
|
||||
loadTestFile(require.resolve('./configure/get_connectors'));
|
||||
});
|
||||
};
|
94
x-pack/test/case_api_integration/common/config.ts
Normal file
94
x-pack/test/case_api_integration/common/config.ts
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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')}`,
|
||||
...(ssl
|
||||
? [
|
||||
`--elasticsearch.hosts=${servers.elasticsearch.protocol}://${servers.elasticsearch.hostname}:${servers.elasticsearch.port}`,
|
||||
`--elasticsearch.ssl.certificateAuthorities=${CA_CERT_PATH}`,
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
11
x-pack/test/case_api_integration/common/ftr_provider_context.d.ts
vendored
Normal file
11
x-pack/test/case_api_integration/common/ftr_provider_context.d.ts
vendored
Normal file
|
@ -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<typeof services, {}>;
|
71
x-pack/test/case_api_integration/common/lib/utils.ts
Normal file
71
x-pack/test/case_api_integration/common/lib/utils.ts
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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 = (update = false): Partial<CasesConfigureResponse> => {
|
||||
return {
|
||||
...getConfiguration(),
|
||||
created_by: { email: null, full_name: null, username: 'elastic' },
|
||||
updated_by: update ? { email: null, full_name: null, username: 'elastic' } : null,
|
||||
};
|
||||
};
|
||||
|
||||
export const removeServerGeneratedPropertiesFromConfigure = (
|
||||
config: Partial<CasesConfigureResponse>
|
||||
): Partial<CasesConfigureResponse> => {
|
||||
const { created_at, updated_at, version, ...rest } = config;
|
||||
return rest;
|
||||
};
|
||||
|
||||
export const deleteConfiguration = async (es: any): Promise<void> => {
|
||||
await es.deleteByQuery({
|
||||
index: '.kibana',
|
||||
q: 'type:cases-configure',
|
||||
waitForCompletion: true,
|
||||
refresh: 'wait_for',
|
||||
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',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
7
x-pack/test/case_api_integration/common/services.ts
Normal file
7
x-pack/test/case_api_integration/common/services.ts
Normal file
|
@ -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';
|
Loading…
Reference in a new issue