diff --git a/x-pack/test/functional/es_archives/signals/legacy_signals_index_non_default_space/data.json b/x-pack/test/functional/es_archives/signals/legacy_signals_index_non_default_space/data.json new file mode 100644 index 0000000000000..2547b46171e44 --- /dev/null +++ b/x-pack/test/functional/es_archives/signals/legacy_signals_index_non_default_space/data.json @@ -0,0 +1,12 @@ +{ + "type": "doc", + "value": { + "id": "1", + "index": ".siem-signals-another-space-legacy", + "source": { + "@timestamp": "2020-10-10T00:00:00.000Z", + "signal": {} + }, + "type": "_doc" + } + } \ No newline at end of file diff --git a/x-pack/test/functional/es_archives/signals/legacy_signals_index_non_default_space/mappings.json b/x-pack/test/functional/es_archives/signals/legacy_signals_index_non_default_space/mappings.json new file mode 100644 index 0000000000000..0dbbf1d4e833e --- /dev/null +++ b/x-pack/test/functional/es_archives/signals/legacy_signals_index_non_default_space/mappings.json @@ -0,0 +1,29 @@ +{ + "type": "index", + "value": { + "aliases": { + ".siem-signals-another-space": { + "is_write_index": false + } + }, + "index": ".siem-signals-another-space-legacy", + "mappings": { + "_meta": { + "version": 1 + }, + "properties": { + "@timestamp": { + "type": "date" + }, + "signal": { "type": "object" } + } + }, + "settings": { + "index": { + "lifecycle": { + "indexing_complete": true + } + } + } + } + } \ No newline at end of file diff --git a/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/basic_license_essentials_tier/ess_specific_index_logic/migrations/deprecations.ts b/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/basic_license_essentials_tier/ess_specific_index_logic/migrations/deprecations.ts new file mode 100644 index 0000000000000..77dcede0c0491 --- /dev/null +++ b/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/basic_license_essentials_tier/ess_specific_index_logic/migrations/deprecations.ts @@ -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 + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from 'expect'; +import type { DeprecationsDetails } from '@kbn/core/server'; + +import { + createAlertsIndex, + deleteAllAlerts, +} from '../../../../../../../../common/utils/security_solution'; + +import { FtrProviderContext } from '../../../../../../../ftr_provider_context'; + +export default ({ getService }: FtrProviderContext): void => { + const esArchiver = getService('esArchiver'); + const supertest = getService('supertest'); + const log = getService('log'); + const es = getService('es'); + + const getDeprecations = async (): Promise => { + const { body } = await supertest.get('/api/deprecations/').set('kbn-xsrf', 'true').expect(200); + return body.deprecations; + }; + + const getLegacyIndicesDeprecation = async (): Promise => { + const deprecations = await getDeprecations(); + + return deprecations.find(({ title }) => title === 'Found not migrated detection alerts'); + }; + + describe.only('@ess Alerts migration deprecations API', () => { + describe('no siem legacy indices exist', () => { + it('should return empty siem signals deprecation', async () => { + const deprecation = await getLegacyIndicesDeprecation(); + + expect(deprecation).toBeUndefined(); + }); + }); + + describe('siem legacy indices exist', () => { + beforeEach(async () => { + await esArchiver.load('x-pack/test/functional/es_archives/signals/legacy_signals_index'); + await createAlertsIndex(supertest, log); + }); + + afterEach(async () => { + await esArchiver.unload('x-pack/test/functional/es_archives/signals/legacy_signals_index'); + await deleteAllAlerts(supertest, log, es); + }); + + it('should return legacy siem signals deprecation', async () => { + const deprecation = await getLegacyIndicesDeprecation(); + + expect(deprecation?.level).toBe('warning'); + + // ensures space included in manual steps + expect(deprecation?.correctiveActions.manualSteps[1]).toContain( + 'Spaces with at least one non-migrated signals index: default.' + ); + expect(deprecation?.correctiveActions.manualSteps[2]).toContain( + 'Example of migration API calls:' + ); + expect(deprecation?.correctiveActions.manualSteps[3]).toContain( + 'GET :/api/detection_engine/signals/migration_status?from=1970-01-01T00:00:00.000Z' + ); + }); + + describe('multiple spaces', () => { + beforeEach(async () => { + await esArchiver.load( + 'x-pack/test/functional/es_archives/signals/legacy_signals_index_non_default_space' + ); + }); + + afterEach(async () => { + await esArchiver.unload( + 'x-pack/test/functional/es_archives/signals/legacy_signals_index_non_default_space' + ); + }); + + it('should return legacy siem signals deprecation with multiple spaces', async () => { + const deprecation = await getLegacyIndicesDeprecation(); + + expect(deprecation?.correctiveActions.manualSteps[1]).toContain('another-space'); + expect(deprecation?.correctiveActions.manualSteps[1]).toContain('default'); + }); + }); + }); + }); +}; diff --git a/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/basic_license_essentials_tier/ess_specific_index_logic/migrations/index.ts b/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/basic_license_essentials_tier/ess_specific_index_logic/migrations/index.ts index 2c1aed2b1387b..2266e653b2493 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/basic_license_essentials_tier/ess_specific_index_logic/migrations/index.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/basic_license_essentials_tier/ess_specific_index_logic/migrations/index.ts @@ -12,5 +12,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./delete_alerts_migrations')); loadTestFile(require.resolve('./finalize_alerts_migrations')); loadTestFile(require.resolve('./get_alerts_migration_status')); + loadTestFile(require.resolve('./deprecations')); }); }