Skip to content

Commit

Permalink
[Security Solution][Detection Engine] add FTR tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliidm committed Dec 17, 2024
1 parent 1988f37 commit 2bedfe2
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<DeprecationsDetails[]> => {
const { body } = await supertest.get('/api/deprecations/').set('kbn-xsrf', 'true').expect(200);
return body.deprecations;
};

const getLegacyIndicesDeprecation = async (): Promise<DeprecationsDetails | undefined> => {
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 <kibana host>:<port>/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');
});
});
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}

0 comments on commit 2bedfe2

Please sign in to comment.