[Cases] Adding migration tests for owner field added in 7.14 (#102577)

* Adding migration tests for 7.13 to 7.14

* Adding test for connector mapping

* Comments
This commit is contained in:
Jonathan Buttner 2021-07-01 04:21:46 -04:00 committed by GitHub
parent a3c079bda6
commit 258d33c120
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 3119 additions and 67 deletions

View file

@ -7,7 +7,11 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import { CASES_URL } from '../../../../../../plugins/cases/common/constants';
import {
CASES_URL,
SECURITY_SOLUTION_OWNER,
} from '../../../../../../plugins/cases/common/constants';
import { getCase } from '../../../../common/lib/utils';
// eslint-disable-next-line import/no-default-export
export default function createGetTests({ getService }: FtrProviderContext) {
@ -107,5 +111,24 @@ export default function createGetTests({ getService }: FtrProviderContext) {
});
});
});
describe('7.13.2', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
});
it('adds the owner field', async () => {
const theCase = await getCase({
supertest,
caseId: 'e49ad6e0-cf9d-11eb-a603-13e7747d215c',
});
expect(theCase.owner).to.be(SECURITY_SOLUTION_OWNER);
});
});
});
}

View file

@ -7,7 +7,11 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import { CASES_URL } from '../../../../../../plugins/cases/common/constants';
import {
CASES_URL,
SECURITY_SOLUTION_OWNER,
} from '../../../../../../plugins/cases/common/constants';
import { getComment } from '../../../../common/lib/utils';
// eslint-disable-next-line import/no-default-export
export default function createGetTests({ getService }: FtrProviderContext) {
@ -15,23 +19,45 @@ export default function createGetTests({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
describe('migrations', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
describe('7.11.0', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
});
it('7.11.0 migrates cases comments', async () => {
const { body: comment } = await supertest
.get(
`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509/comments/da677740-1ac7-11eb-b5a3-25ee88122510`
)
.set('kbn-xsrf', 'true')
.send();
expect(comment.type).to.eql('user');
});
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
});
describe('7.13.2', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
});
it('7.11.0 migrates cases comments', async () => {
const { body: comment } = await supertest
.get(
`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509/comments/da677740-1ac7-11eb-b5a3-25ee88122510`
)
.set('kbn-xsrf', 'true')
.send();
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
});
expect(comment.type).to.eql('user');
it('adds the owner field', async () => {
const comment = await getComment({
supertest,
caseId: 'e49ad6e0-cf9d-11eb-a603-13e7747d215c',
commentId: 'ee59cdd0-cf9d-11eb-a603-13e7747d215c',
});
expect(comment.owner).to.be(SECURITY_SOLUTION_OWNER);
});
});
});
}

View file

@ -7,7 +7,11 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import { CASE_CONFIGURE_URL } from '../../../../../../plugins/cases/common/constants';
import {
CASE_CONFIGURE_URL,
SECURITY_SOLUTION_OWNER,
} from '../../../../../../plugins/cases/common/constants';
import { getConfiguration } from '../../../../common/lib/utils';
// eslint-disable-next-line import/no-default-export
export default function createGetTests({ getService }: FtrProviderContext) {
@ -15,29 +19,50 @@ export default function createGetTests({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
describe('migrations', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
describe('7.10.0', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
});
it('7.10.0 migrates configure cases connector', async () => {
const { body } = await supertest
.get(`${CASE_CONFIGURE_URL}`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);
expect(body.length).to.be(1);
expect(body[0]).key('connector');
expect(body[0]).not.key('connector_id');
expect(body[0].connector).to.eql({
id: 'connector-1',
name: 'Connector 1',
type: '.none',
fields: null,
});
});
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
});
describe('7.13.2', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
});
it('7.10.0 migrates configure cases connector', async () => {
const { body } = await supertest
.get(`${CASE_CONFIGURE_URL}`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
});
expect(body.length).to.be(1);
expect(body[0]).key('connector');
expect(body[0]).not.key('connector_id');
expect(body[0].connector).to.eql({
id: 'connector-1',
name: 'Connector 1',
type: '.none',
fields: null,
it('adds the owner field', async () => {
const configuration = await getConfiguration({
supertest,
query: { owner: SECURITY_SOLUTION_OWNER },
});
expect(configuration[0].owner).to.be(SECURITY_SOLUTION_OWNER);
});
});
});

View file

@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import { SECURITY_SOLUTION_OWNER } from '../../../../../../plugins/cases/common/constants';
import { getConnectorMappingsFromES } from '../../../../common/lib/utils';
// eslint-disable-next-line import/no-default-export
export default function createGetTests({ getService }: FtrProviderContext) {
const es = getService('es');
const esArchiver = getService('esArchiver');
describe('migrations', () => {
describe('7.13.2', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
});
it('adds the owner field', async () => {
// We don't get the owner field back from the mappings when we retrieve the configuration so the only way to
// check that the migration worked is by checking the saved object stored in Elasticsearch directly
const mappings = await getConnectorMappingsFromES({ es });
expect(mappings.body.hits.hits.length).to.be(1);
expect(mappings.body.hits.hits[0]._source?.['cases-connector-mappings'].owner).to.eql(
SECURITY_SOLUTION_OWNER
);
});
});
});
}

View file

@ -12,7 +12,9 @@ export default ({ loadTestFile }: FtrProviderContext): void => {
describe('Common migrations', function () {
// Migrations
loadTestFile(require.resolve('./cases/migrations'));
loadTestFile(require.resolve('./comments/migrations'));
loadTestFile(require.resolve('./configure/migrations'));
loadTestFile(require.resolve('./user_actions/migrations'));
loadTestFile(require.resolve('./connectors/migrations'));
});
};

View file

@ -7,7 +7,11 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
import { CASES_URL } from '../../../../../../plugins/cases/common/constants';
import {
CASES_URL,
SECURITY_SOLUTION_OWNER,
} from '../../../../../../plugins/cases/common/constants';
import { getCaseUserActions } from '../../../../common/lib/utils';
// eslint-disable-next-line import/no-default-export
export default function createGetTests({ getService }: FtrProviderContext) {
@ -15,38 +19,62 @@ export default function createGetTests({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
describe('migrations', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
});
it('7.10.0 migrates user actions connector', async () => {
const { body } = await supertest
.get(`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509/user_actions`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);
const connectorUserAction = body[1];
const oldValue = JSON.parse(connectorUserAction.old_value);
const newValue = JSON.parse(connectorUserAction.new_value);
expect(connectorUserAction.action_field.length).eql(1);
expect(connectorUserAction.action_field[0]).eql('connector');
expect(oldValue).to.eql({
id: 'c1900ac0-017f-11eb-93f8-d161651bf509',
name: 'none',
type: '.none',
fields: null,
describe('7.10.0', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
});
expect(newValue).to.eql({
id: 'b1900ac0-017f-11eb-93f8-d161651bf509',
name: 'none',
type: '.none',
fields: null,
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
});
it('7.10.0 migrates user actions connector', async () => {
const { body } = await supertest
.get(`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509/user_actions`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);
const connectorUserAction = body[1];
const oldValue = JSON.parse(connectorUserAction.old_value);
const newValue = JSON.parse(connectorUserAction.new_value);
expect(connectorUserAction.action_field.length).eql(1);
expect(connectorUserAction.action_field[0]).eql('connector');
expect(oldValue).to.eql({
id: 'c1900ac0-017f-11eb-93f8-d161651bf509',
name: 'none',
type: '.none',
fields: null,
});
expect(newValue).to.eql({
id: 'b1900ac0-017f-11eb-93f8-d161651bf509',
name: 'none',
type: '.none',
fields: null,
});
});
});
describe('7.13.2', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
});
it('adds the owner field', async () => {
const userActions = await getCaseUserActions({
supertest,
caseID: 'e49ad6e0-cf9d-11eb-a603-13e7747d215c',
});
expect(userActions.length).to.not.be(0);
for (const action of userActions) {
expect(action.owner).to.be(SECURITY_SOLUTION_OWNER);
}
});
});
});

File diff suppressed because it is too large Load diff