Skip to content

Commit

Permalink
Add spaces only tests for alerting and actions (#43616) (#43702)
Browse files Browse the repository at this point in the history
* Add spaces only tests

* Rename some tests to make more sense in spaces only context

* Modify test suite titles

* Apply changes from master

* Loop only one scenario for now

* Reduce amount of tests spaces_only runs

* Fix failing test

* Remove looping in spaces only tests
  • Loading branch information
mikecote authored Aug 21, 2019
1 parent 1a45a65 commit 4540c55
Show file tree
Hide file tree
Showing 25 changed files with 1,494 additions and 1 deletion.
1 change: 1 addition & 0 deletions x-pack/scripts/functional_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require('@kbn/test').runTestsCli([
require.resolve('../test/functional/config.js'),
require.resolve('../test/api_integration/config_security_basic.js'),
require.resolve('../test/api_integration/config.js'),
require.resolve('../test/alerting_api_integration/spaces_only/config.ts'),
require.resolve('../test/alerting_api_integration/security_and_spaces/config.ts'),
require.resolve('../test/plugin_api_integration/config.js'),
require.resolve('../test/kerberos_api_integration/config'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function alertingApiIntegrationTests({
const spacesService: SpacesService = getService('spaces');
const esArchiver = getService('esArchiver');

describe('alerting api integration', function() {
describe('alerting api integration security and spaces enabled', function() {
this.tags('ciGroup8');

before(async () => {
Expand Down
10 changes: 10 additions & 0 deletions x-pack/test/alerting_api_integration/spaces_only/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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('spaces_only', { disabledPlugins: ['security'], license: 'basic' });
17 changes: 17 additions & 0 deletions x-pack/test/alerting_api_integration/spaces_only/scenarios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 { Space } from '../common/types';

const Space1: Space = {
id: 'space1',
name: 'Space 1',
disabledFeatures: [],
};

export const Spaces = {
space1: Space1,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* 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';

const ES_TEST_INDEX_NAME = 'functional-test-actions-index';

// eslint-disable-next-line import/no-default-export
export default function indexTest({ getService }: FtrProviderContext) {
const es = getService('es');
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');

describe('index action', () => {
after(() => esArchiver.unload('empty_kibana'));
beforeEach(() => clearTestIndex(es));

let createdActionID: string;
let createdActionIDWithIndex: string;

it('should be created successfully', async () => {
// create action with no config
const { body: createdAction } = await supertest
.post('/api/action')
.set('kbn-xsrf', 'foo')
.send({
description: 'An index action',
actionTypeId: '.index',
config: {},
secrets: {},
})
.expect(200);

expect(createdAction).to.eql({
id: createdAction.id,
description: 'An index action',
actionTypeId: '.index',
config: {
index: null,
},
});
createdActionID = createdAction.id;
expect(typeof createdActionID).to.be('string');

const { body: fetchedAction } = await supertest
.get(`/api/action/${createdActionID}`)
.expect(200);

expect(fetchedAction).to.eql({
id: fetchedAction.id,
description: 'An index action',
actionTypeId: '.index',
config: { index: null },
});

// create action with index config
const { body: createdActionWithIndex } = await supertest
.post('/api/action')
.set('kbn-xsrf', 'foo')
.send({
description: 'An index action with index config',
actionTypeId: '.index',
config: {
index: ES_TEST_INDEX_NAME,
},
})
.expect(200);

expect(createdActionWithIndex).to.eql({
id: createdActionWithIndex.id,
description: 'An index action with index config',
actionTypeId: '.index',
config: {
index: ES_TEST_INDEX_NAME,
},
});
createdActionIDWithIndex = createdActionWithIndex.id;
expect(typeof createdActionIDWithIndex).to.be('string');

const { body: fetchedActionWithIndex } = await supertest
.get(`/api/action/${createdActionIDWithIndex}`)
.expect(200);

expect(fetchedActionWithIndex).to.eql({
id: fetchedActionWithIndex.id,
description: 'An index action with index config',
actionTypeId: '.index',
config: {
index: ES_TEST_INDEX_NAME,
},
});
});

it('should execute successly when expected for a single body', async () => {
const { body: result } = await supertest
.post(`/api/action/${createdActionID}/_execute`)
.set('kbn-xsrf', 'foo')
.send({
params: {
index: ES_TEST_INDEX_NAME,
documents: [{ testing: [1, 2, 3] }],
refresh: true,
},
})
.expect(200);
expect(result.status).to.eql('ok');

const items = await getTestIndexItems(es);
expect(items.length).to.eql(1);
expect(items[0]._source).to.eql({ testing: [1, 2, 3] });
});
});
}

async function clearTestIndex(es: any) {
return await es.indices.delete({
index: ES_TEST_INDEX_NAME,
ignoreUnavailable: true,
});
}

async function getTestIndexItems(es: any) {
const result = await es.search({
index: ES_TEST_INDEX_NAME,
});

return result.hits.hits;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 { Spaces } from '../../scenarios';
import { getUrlPrefix, ObjectRemover } from '../../../common/lib';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

// eslint-disable-next-line import/no-default-export
export default function createActionTests({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

describe('create', () => {
const objectRemover = new ObjectRemover(supertest);

after(() => objectRemover.removeAll());

it('should handle create action request appropriately', async () => {
const response = await supertest
.post(`${getUrlPrefix(Spaces.space1.id)}/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(response.statusCode).to.eql(200);
expect(response.body).to.eql({
id: response.body.id,
description: 'My action',
actionTypeId: 'test.index-record',
config: {
unencrypted: `This value shouldn't get encrypted`,
},
});
expect(typeof response.body.id).to.be('string');
objectRemover.add(Spaces.space1.id, response.body.id, 'action');
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 { Spaces } from '../../scenarios';
import { getUrlPrefix, ObjectRemover } from '../../../common/lib';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

// eslint-disable-next-line import/no-default-export
export default function deleteActionTests({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

describe('delete', () => {
const objectRemover = new ObjectRemover(supertest);

after(() => objectRemover.removeAll());

it('should handle delete action request appropriately', async () => {
const { body: createdAction } = await supertest
.post(`${getUrlPrefix(Spaces.space1.id)}/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);

await supertest
.delete(`${getUrlPrefix(Spaces.space1.id)}/api/action/${createdAction.id}`)
.set('kbn-xsrf', 'foo')
.expect(204, '');
});

it(`should handle delete request appropriately when action doesn't exist`, async () => {
await supertest
.delete(`${getUrlPrefix(Spaces.space1.id)}/api/action/2`)
.set('kbn-xsrf', 'foo')
.expect(404, {
statusCode: 404,
error: 'Not Found',
message: 'Saved object [action/2] not found',
});
});
});
}
Loading

0 comments on commit 4540c55

Please sign in to comment.