-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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>
- Loading branch information
1 parent
44f9cbc
commit a145aa9
Showing
11 changed files
with
443 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); |
55 changes: 55 additions & 0 deletions
55
x-pack/test/case_api_integration/basic/tests/configure/get_configure.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
}); | ||
}); | ||
}; |
27 changes: 27 additions & 0 deletions
27
x-pack/test/case_api_integration/basic/tests/configure/get_connectors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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([]); | ||
}); | ||
}); | ||
}; |
81 changes: 81 additions & 0 deletions
81
x-pack/test/case_api_integration/basic/tests/configure/patch_configure.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); | ||
}); | ||
}); | ||
}; |
62 changes: 62 additions & 0 deletions
62
x-pack/test/case_api_integration/basic/tests/configure/post_configure.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 11 additions & 0 deletions
11
x-pack/test/case_api_integration/common/ftr_provider_context.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, {}>; |
Oops, something went wrong.