mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Prior to this PR, the create and update http apis for actions returned an object with the shape `{ id: <id of relevant action> }`. This PR changes the responses to be the complete body of the action that was created / updated, not just the `id`. I believe this is the final piece of the "fix http apis for actions / alerts" issue https://github.com/elastic/kibana/issues/41828
134 lines
4.3 KiB
TypeScript
134 lines
4.3 KiB
TypeScript
/*
|
|
* 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 '../../ftr_provider_context';
|
|
|
|
export default function createActionTests({ getService }: FtrProviderContext) {
|
|
const supertest = getService('supertest');
|
|
const esArchiver = getService('esArchiver');
|
|
|
|
describe('create', () => {
|
|
after(() => esArchiver.unload('empty_kibana'));
|
|
|
|
it('should return 200 when creating an action and not return encrypted attributes', async () => {
|
|
await supertest
|
|
.post('/api/action')
|
|
.set('kbn-xsrf', 'foo')
|
|
.send({
|
|
description: 'My action',
|
|
actionTypeId: 'test.index-record',
|
|
config: {
|
|
unencrypted: `This value shouldn't get encrypted`,
|
|
},
|
|
secrets: {
|
|
encrypted: 'This value should be encrypted',
|
|
},
|
|
})
|
|
.expect(200)
|
|
.then((resp: any) => {
|
|
expect(resp.body).to.eql({
|
|
id: resp.body.id,
|
|
description: 'My action',
|
|
actionTypeId: 'test.index-record',
|
|
config: {
|
|
unencrypted: `This value shouldn't get encrypted`,
|
|
},
|
|
});
|
|
expect(typeof resp.body.id).to.be('string');
|
|
});
|
|
});
|
|
|
|
it('should return 200 when creating an action inside a space and to not be accessible from another space', async () => {
|
|
const { body: createdAction } = await supertest
|
|
.post('/s/space_1/api/action')
|
|
.set('kbn-xsrf', 'foo')
|
|
.send({
|
|
description: 'My action',
|
|
actionTypeId: 'test.index-record',
|
|
config: {
|
|
unencrypted: `This value shouldn't get encrypted`,
|
|
},
|
|
secrets: {
|
|
encrypted: 'This value should be encrypted',
|
|
},
|
|
})
|
|
.expect(200);
|
|
expect(createdAction).to.eql({
|
|
id: createdAction.id,
|
|
description: 'My action',
|
|
actionTypeId: 'test.index-record',
|
|
config: {
|
|
unencrypted: `This value shouldn't get encrypted`,
|
|
},
|
|
});
|
|
expect(typeof createdAction.id).to.be('string');
|
|
await supertest.get(`/s/space_1/api/action/${createdAction.id}`).expect(200);
|
|
await supertest.get(`/api/action/${createdAction.id}`).expect(404);
|
|
});
|
|
|
|
it(`should return 400 when action type isn't registered`, async () => {
|
|
await supertest
|
|
.post('/api/action')
|
|
.set('kbn-xsrf', 'foo')
|
|
.send({
|
|
description: 'My action',
|
|
actionTypeId: 'test.unregistered-action-type',
|
|
config: {},
|
|
})
|
|
.expect(400)
|
|
.then((resp: any) => {
|
|
expect(resp.body).to.eql({
|
|
statusCode: 400,
|
|
error: 'Bad Request',
|
|
message: 'Action type "test.unregistered-action-type" is not registered.',
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should return 400 when payload is empty and invalid', async () => {
|
|
await supertest
|
|
.post('/api/action')
|
|
.set('kbn-xsrf', 'foo')
|
|
.send({})
|
|
.expect(400)
|
|
.then((resp: any) => {
|
|
expect(resp.body).to.eql({
|
|
statusCode: 400,
|
|
error: 'Bad Request',
|
|
message:
|
|
'child "description" fails because ["description" is required]. child "actionTypeId" fails because ["actionTypeId" is required]',
|
|
validation: {
|
|
source: 'payload',
|
|
keys: ['description', 'actionTypeId'],
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
it(`should return 400 when config isn't valid`, async () => {
|
|
await supertest
|
|
.post('/api/action')
|
|
.set('kbn-xsrf', 'foo')
|
|
.send({
|
|
description: 'my description',
|
|
actionTypeId: 'test.index-record',
|
|
config: {
|
|
unencrypted: 'my unencrypted text',
|
|
},
|
|
})
|
|
.expect(400)
|
|
.then((resp: any) => {
|
|
expect(resp.body).to.eql({
|
|
statusCode: 400,
|
|
error: 'Bad Request',
|
|
message:
|
|
'error validating action type secrets: [encrypted]: expected value of type [string] but got [undefined]',
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|