mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
# Backport This will backport the following commits from `main` to `8.6`: - [[Cases] Fix failing migration tests (#148808)](https://github.com/elastic/kibana/pull/148808) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jonathan Buttner","email":"56361221+jonathan-buttner@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-02-01T20:50:15Z","message":"[Cases] Fix failing migration tests (#148808)\n\nThis PR fixes a failing migration test. The test was likely failing\r\nbecause we're using es archiver to add saved objects to the kibana index\r\ninstead of using the kbn archiver. Since we support importing cases\r\nsaved objects I converted most of the places to use the kbn archiver. We\r\ndon't export the case configuration type so it cannot be imported so I\r\nhad to remove the integration tests and moved them to unit tests\r\ninstead.\r\n\r\nFixes: https://github.com/elastic/kibana/issues/139782\r\n\r\nFlaky test runner:\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1855\r\n🟢","sha":"6b790e7994239e3fe4ffac017772660f6402e9cb","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","Feature:Cases","backport:prev-minor","v8.7.0"],"number":148808,"url":"https://github.com/elastic/kibana/pull/148808","mergeCommit":{"message":"[Cases] Fix failing migration tests (#148808)\n\nThis PR fixes a failing migration test. The test was likely failing\r\nbecause we're using es archiver to add saved objects to the kibana index\r\ninstead of using the kbn archiver. Since we support importing cases\r\nsaved objects I converted most of the places to use the kbn archiver. We\r\ndon't export the case configuration type so it cannot be imported so I\r\nhad to remove the integration tests and moved them to unit tests\r\ninstead.\r\n\r\nFixes: https://github.com/elastic/kibana/issues/139782\r\n\r\nFlaky test runner:\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1855\r\n🟢","sha":"6b790e7994239e3fe4ffac017772660f6402e9cb"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/148808","number":148808,"mergeCommit":{"message":"[Cases] Fix failing migration tests (#148808)\n\nThis PR fixes a failing migration test. The test was likely failing\r\nbecause we're using es archiver to add saved objects to the kibana index\r\ninstead of using the kbn archiver. Since we support importing cases\r\nsaved objects I converted most of the places to use the kbn archiver. We\r\ndon't export the case configuration type so it cannot be imported so I\r\nhad to remove the integration tests and moved them to unit tests\r\ninstead.\r\n\r\nFixes: https://github.com/elastic/kibana/issues/139782\r\n\r\nFlaky test runner:\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1855\r\n🟢","sha":"6b790e7994239e3fe4ffac017772660f6402e9cb"}}]}] BACKPORT--> Co-authored-by: Jonathan Buttner <56361221+jonathan-buttner@users.noreply.github.com>
This commit is contained in:
parent
bf585d188e
commit
d9f90aaf24
9 changed files with 286 additions and 2576 deletions
|
@ -5,15 +5,17 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { SavedObjectSanitizedDoc } from '@kbn/core/server';
|
||||
import type { SavedObjectSanitizedDoc, SavedObjectUnsanitizedDoc } from '@kbn/core/server';
|
||||
import { ACTION_SAVED_OBJECT_TYPE } from '@kbn/actions-plugin/server';
|
||||
import type { CasesConfigureAttributes } from '../../../common/api';
|
||||
import { ConnectorTypes } from '../../../common/api';
|
||||
import { CASE_CONFIGURE_SAVED_OBJECT, SECURITY_SOLUTION_OWNER } from '../../../common/constants';
|
||||
import { CONNECTOR_ID_REFERENCE_NAME } from '../../common/constants';
|
||||
import { getNoneCaseConnector } from '../../common/utils';
|
||||
import type { ESCaseConnectorWithId } from '../../services/test_utils';
|
||||
import type { ESCasesConfigureAttributes } from '../../services/configure/types';
|
||||
import { configureConnectorIdMigration } from './configuration';
|
||||
import type { UnsanitizedConfigureConnector } from './configuration';
|
||||
import { createConnectorAttributeMigration, configureConnectorIdMigration } from './configuration';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const create_7_14_0_configSchema = (connector?: ESCaseConnectorWithId) => ({
|
||||
|
@ -38,7 +40,95 @@ const create_7_14_0_configSchema = (connector?: ESCaseConnectorWithId) => ({
|
|||
},
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const create_7_9_0_configSchema = (
|
||||
overrides?: object
|
||||
): SavedObjectUnsanitizedDoc<UnsanitizedConfigureConnector> => {
|
||||
return {
|
||||
attributes: {
|
||||
connector_id: 'b35c26a9-4d0d-4ffb-be85-4e9b96266204',
|
||||
connector_name: '',
|
||||
closure_type: 'close-by-user',
|
||||
created_at: '2023-01-31T22:11:49.480Z',
|
||||
created_by: {
|
||||
email: 'test@test.com',
|
||||
full_name: 'tester',
|
||||
username: 'tester_user',
|
||||
},
|
||||
updated_at: null,
|
||||
updated_by: null,
|
||||
...overrides,
|
||||
},
|
||||
id: '1',
|
||||
type: 'cases-configure',
|
||||
references: [],
|
||||
updated_at: '2023-01-31T22:00:50.003Z',
|
||||
} as SavedObjectUnsanitizedDoc<UnsanitizedConfigureConnector>;
|
||||
};
|
||||
|
||||
describe('configuration migrations', () => {
|
||||
describe('7.10.0 connector migration', () => {
|
||||
it('creates the connector field with the connector id and name nested under it', () => {
|
||||
const config = createConnectorAttributeMigration(create_7_9_0_configSchema());
|
||||
|
||||
expect(config.attributes.connector.id).toEqual('b35c26a9-4d0d-4ffb-be85-4e9b96266204');
|
||||
expect(config.attributes.connector.name).toEqual('');
|
||||
});
|
||||
|
||||
it('sets the connector.name field to the existing name', () => {
|
||||
const config = createConnectorAttributeMigration(
|
||||
create_7_9_0_configSchema({ connector_name: 'connector-name' })
|
||||
);
|
||||
|
||||
expect(config.attributes.connector.name).toEqual('connector-name');
|
||||
});
|
||||
|
||||
it('sets the connector.fields to null and connector.type to .none', () => {
|
||||
const config = createConnectorAttributeMigration(create_7_9_0_configSchema());
|
||||
|
||||
expect(config.attributes.connector).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"fields": null,
|
||||
"id": "b35c26a9-4d0d-4ffb-be85-4e9b96266204",
|
||||
"name": "",
|
||||
"type": ".none",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('does not modify the other attributes of the saved object', () => {
|
||||
const config = createConnectorAttributeMigration(create_7_9_0_configSchema());
|
||||
|
||||
const configAttributes = config as SavedObjectSanitizedDoc<CasesConfigureAttributes>;
|
||||
expect(configAttributes.attributes.created_by.email).toEqual('test@test.com');
|
||||
});
|
||||
|
||||
it('sets name and id to none when they are undefined', () => {
|
||||
const config = createConnectorAttributeMigration(
|
||||
create_7_9_0_configSchema({ connector_name: undefined, connector_id: undefined })
|
||||
);
|
||||
|
||||
expect(config.attributes.connector.id).toEqual('none');
|
||||
expect(config.attributes.connector.name).toEqual('none');
|
||||
});
|
||||
|
||||
it('removes the connector_id and connector_name fields', () => {
|
||||
const config = createConnectorAttributeMigration(
|
||||
create_7_9_0_configSchema({ connector_name: 'name', connector_id: 'id' })
|
||||
);
|
||||
|
||||
expect(config.attributes).not.toHaveProperty('connector_id');
|
||||
expect(config.attributes).not.toHaveProperty('connector_name');
|
||||
});
|
||||
|
||||
it('sets the references to an empty array when it is initially undefined', () => {
|
||||
const docWithoutRefs = { ...create_7_9_0_configSchema(), references: undefined };
|
||||
const config = createConnectorAttributeMigration(docWithoutRefs);
|
||||
|
||||
expect(config.references).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('7.15.0 connector ID migration', () => {
|
||||
it('does not create a reference when the connector ID is none', () => {
|
||||
const configureSavedObject = create_7_14_0_configSchema(getNoneCaseConnector());
|
||||
|
|
|
@ -14,7 +14,7 @@ import { addOwnerToSO } from '.';
|
|||
import { CONNECTOR_ID_REFERENCE_NAME } from '../../common/constants';
|
||||
import { transformConnectorIdToReference } from './user_actions/connector_id';
|
||||
|
||||
interface UnsanitizedConfigureConnector {
|
||||
export interface UnsanitizedConfigureConnector {
|
||||
connector_id: string;
|
||||
connector_name: string;
|
||||
}
|
||||
|
@ -28,6 +28,26 @@ interface SanitizedConfigureConnector {
|
|||
};
|
||||
}
|
||||
|
||||
export const createConnectorAttributeMigration = (
|
||||
doc: SavedObjectUnsanitizedDoc<UnsanitizedConfigureConnector>
|
||||
): SavedObjectSanitizedDoc<SanitizedConfigureConnector> => {
|
||||
const { connector_id, connector_name, ...restAttributes } = doc.attributes;
|
||||
|
||||
return {
|
||||
...doc,
|
||||
attributes: {
|
||||
...restAttributes,
|
||||
connector: {
|
||||
id: connector_id ?? 'none',
|
||||
name: connector_name ?? 'none',
|
||||
type: ConnectorTypes.none,
|
||||
fields: null,
|
||||
},
|
||||
},
|
||||
references: doc.references || [],
|
||||
};
|
||||
};
|
||||
|
||||
export const configureConnectorIdMigration = (
|
||||
doc: SavedObjectUnsanitizedDoc<{ connector?: { id: string } }>
|
||||
): SavedObjectSanitizedDoc<unknown> => {
|
||||
|
@ -50,25 +70,7 @@ export const configureConnectorIdMigration = (
|
|||
};
|
||||
|
||||
export const configureMigrations = {
|
||||
'7.10.0': (
|
||||
doc: SavedObjectUnsanitizedDoc<UnsanitizedConfigureConnector>
|
||||
): SavedObjectSanitizedDoc<SanitizedConfigureConnector> => {
|
||||
const { connector_id, connector_name, ...restAttributes } = doc.attributes;
|
||||
|
||||
return {
|
||||
...doc,
|
||||
attributes: {
|
||||
...restAttributes,
|
||||
connector: {
|
||||
id: connector_id ?? 'none',
|
||||
name: connector_name ?? 'none',
|
||||
type: ConnectorTypes.none,
|
||||
fields: null,
|
||||
},
|
||||
},
|
||||
references: doc.references || [],
|
||||
};
|
||||
},
|
||||
'7.10.0': createConnectorAttributeMigration,
|
||||
'7.14.0': (
|
||||
doc: SavedObjectUnsanitizedDoc<Record<string, unknown>>
|
||||
): SavedObjectSanitizedDoc<SanitizedCaseOwner> => {
|
||||
|
|
|
@ -28,11 +28,16 @@ export default function createGetTests({ getService }: FtrProviderContext) {
|
|||
// tests upgrading a 7.10.0 saved object to the latest version
|
||||
describe('7.10.0 -> latest stack version', () => {
|
||||
before(async () => {
|
||||
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
|
||||
await kibanaServer.importExport.load(
|
||||
'x-pack/test/functional/fixtures/kbn_archiver/cases/7.10.0/data.json'
|
||||
);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
|
||||
await kibanaServer.importExport.unload(
|
||||
'x-pack/test/functional/fixtures/kbn_archiver/cases/7.10.0/data.json'
|
||||
);
|
||||
await deleteAllCaseItems(es);
|
||||
});
|
||||
|
||||
it('migrates cases connector', async () => {
|
||||
|
|
|
@ -21,11 +21,16 @@ export default function createGetTests({ getService }: FtrProviderContext) {
|
|||
describe('migrations', () => {
|
||||
describe('7.11.0', () => {
|
||||
before(async () => {
|
||||
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
|
||||
await kibanaServer.importExport.load(
|
||||
'x-pack/test/functional/fixtures/kbn_archiver/cases/7.10.0/data.json'
|
||||
);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
|
||||
await kibanaServer.importExport.unload(
|
||||
'x-pack/test/functional/fixtures/kbn_archiver/cases/7.10.0/data.json'
|
||||
);
|
||||
await deleteAllCaseItems(es);
|
||||
});
|
||||
|
||||
it('7.11.0 migrates cases comments', async () => {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { CASE_CONFIGURE_URL, SECURITY_SOLUTION_OWNER } from '@kbn/cases-plugin/common/constants';
|
||||
import { SECURITY_SOLUTION_OWNER } from '@kbn/cases-plugin/common/constants';
|
||||
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';
|
||||
import {
|
||||
getConfiguration,
|
||||
|
@ -21,34 +21,6 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
const es = getService('es');
|
||||
|
||||
describe('migrations', () => {
|
||||
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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('7.13.2', () => {
|
||||
before(async () => {
|
||||
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.13.2');
|
||||
|
|
|
@ -23,11 +23,16 @@ export default function createGetTests({ getService }: FtrProviderContext) {
|
|||
const CASE_ID = 'e1900ac0-017f-11eb-93f8-d161651bf509';
|
||||
|
||||
before(async () => {
|
||||
await esArchiver.load('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
|
||||
await kibanaServer.importExport.load(
|
||||
'x-pack/test/functional/fixtures/kbn_archiver/cases/7.10.0/data.json'
|
||||
);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await esArchiver.unload('x-pack/test/functional/es_archives/cases/migrations/7.10.0');
|
||||
await kibanaServer.importExport.unload(
|
||||
'x-pack/test/functional/fixtures/kbn_archiver/cases/7.10.0/data.json'
|
||||
);
|
||||
await deleteAllCaseItems(es);
|
||||
});
|
||||
|
||||
it('7.10.0 migrates user actions connector', async () => {
|
||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,150 @@
|
|||
{
|
||||
"id": "e1900ac0-017f-11eb-93f8-d161651bf509",
|
||||
"attributes": {
|
||||
"closed_at": null,
|
||||
"closed_by": null,
|
||||
"connector_id": "connector-1",
|
||||
"created_at": "2020-09-28T11:43:52.158Z",
|
||||
"created_by": {
|
||||
"email": null,
|
||||
"full_name": null,
|
||||
"username": "elastic"
|
||||
},
|
||||
"description": "This is a brand new case of a bad meanie defacing data",
|
||||
"external_service": null,
|
||||
"status": "open",
|
||||
"tags": [
|
||||
"defacement"
|
||||
],
|
||||
"title": "Super Bad Security Issue",
|
||||
"updated_at": null,
|
||||
"updated_by": null
|
||||
},
|
||||
"coreMigrationVersion": "7.10.0",
|
||||
"migrationVersion": {
|
||||
"alert": "7.10.0"
|
||||
},
|
||||
"references": [
|
||||
],
|
||||
"type": "cases",
|
||||
"updated_at": "2020-09-28T11:43:52.171Z"
|
||||
}
|
||||
|
||||
{
|
||||
"id": "e22a7600-017f-11eb-93f8-d161651bf509",
|
||||
"attributes": {
|
||||
"action": "create",
|
||||
"action_at": "2020-09-28T11:43:52.158Z",
|
||||
"action_by": {
|
||||
"email": null,
|
||||
"full_name": null,
|
||||
"username": "elastic"
|
||||
},
|
||||
"action_field": [
|
||||
"description",
|
||||
"status",
|
||||
"tags",
|
||||
"title"
|
||||
],
|
||||
"new_value": "{\"description\":\"This is a brand new case of a bad meanie defacing data\",\"title\":\"Super Bad Security Issue\",\"tags\":[\"defacement\"]}",
|
||||
"old_value": null
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"id": "e1900ac0-017f-11eb-93f8-d161651bf509",
|
||||
"name": "associated-cases",
|
||||
"type": "cases"
|
||||
}
|
||||
],
|
||||
"coreMigrationVersion": "7.10.0",
|
||||
"type": "cases-user-actions",
|
||||
"updated_at": "2020-09-28T11:43:53.184Z"
|
||||
}
|
||||
|
||||
{
|
||||
"id": "a22a7600-017f-11eb-93f8-d161651bf509",
|
||||
"attributes": {
|
||||
"action": "update",
|
||||
"action_at": "2020-09-28T11:53:52.158Z",
|
||||
"action_by": {
|
||||
"email": null,
|
||||
"full_name": null,
|
||||
"username": "elastic"
|
||||
},
|
||||
"action_field": [
|
||||
"connector_id"
|
||||
],
|
||||
"new_value": "b1900ac0-017f-11eb-93f8-d161651bf509",
|
||||
"old_value": "c1900ac0-017f-11eb-93f8-d161651bf509"
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"id": "e1900ac0-017f-11eb-93f8-d161651bf509",
|
||||
"name": "associated-cases",
|
||||
"type": "cases"
|
||||
}
|
||||
],
|
||||
"coreMigrationVersion": "7.10.0",
|
||||
"type": "cases-user-actions",
|
||||
"updated_at": "2020-09-28T11:43:53.184Z"
|
||||
}
|
||||
|
||||
{
|
||||
"id": "da677740-1ac7-11eb-b5a3-25ee88122510",
|
||||
"attributes": {
|
||||
"comment": "This is a cool comment",
|
||||
"created_at": "2020-10-30T15:52:02.984Z",
|
||||
"created_by": {
|
||||
"email": null,
|
||||
"full_name": null,
|
||||
"username": "elastic"
|
||||
},
|
||||
"pushed_at": null,
|
||||
"pushed_by": null,
|
||||
"updated_at": null,
|
||||
"updated_by": null
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"id": "e1900ac0-017f-11eb-93f8-d161651bf509",
|
||||
"name": "associated-cases",
|
||||
"type": "cases"
|
||||
}
|
||||
],
|
||||
"coreMigrationVersion": "7.10.0",
|
||||
"type": "cases-comments",
|
||||
"updated_at": "2020-10-30T15:52:02.996Z"
|
||||
}
|
||||
|
||||
{
|
||||
"id": "db027ec0-1ac7-11eb-b5a3-25ee88122510",
|
||||
"attributes": {
|
||||
"action": "create",
|
||||
"action_at": "2020-10-30T15:52:02.984Z",
|
||||
"action_by": {
|
||||
"email": null,
|
||||
"full_name": null,
|
||||
"username": "elastic"
|
||||
},
|
||||
"action_field": [
|
||||
"comment"
|
||||
],
|
||||
"new_value": "This is a cool comment",
|
||||
"old_value": null
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"id": "e1900ac0-017f-11eb-93f8-d161651bf509",
|
||||
"name": "associated-cases",
|
||||
"type": "cases"
|
||||
},
|
||||
{
|
||||
"id": "da677740-1ac7-11eb-b5a3-25ee88122510",
|
||||
"name": "associated-cases-comments",
|
||||
"type": "cases-comments"
|
||||
}
|
||||
],
|
||||
"coreMigrationVersion": "7.10.0",
|
||||
"type": "cases-user-actions",
|
||||
"updated_at": "2020-10-30T15:52:04.012Z"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue