[SIEM][Detection Engine] Moves functional tests from legacyEs to Es and improves types (#65709)

Moves functional tests from "legacyEs" to "Es" and improves types

- [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios
This commit is contained in:
Frank Hassanabad 2020-05-07 11:18:27 -06:00 committed by GitHub
parent e029e35a5b
commit fe26a79608
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 32 additions and 23 deletions

View file

@ -13,7 +13,7 @@ import { createSignalsIndex, deleteAllAlerts, deleteSignalsIndex } from './utils
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('add_prepackaged_rules', () => {
describe('validation errors', () => {

View file

@ -25,7 +25,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('create_rules', () => {
describe('validation errors', () => {

View file

@ -23,7 +23,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('create_rules_bulk', () => {
describe('validation errors', () => {

View file

@ -23,7 +23,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('delete_rules', () => {
describe('deleting rules', () => {

View file

@ -23,7 +23,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('delete_rules_bulk', () => {
describe('deleting rules bulk using DELETE', () => {

View file

@ -21,7 +21,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('export_rules', () => {
describe('exporting rules', () => {

View file

@ -22,7 +22,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('find_rules', () => {
beforeEach(async () => {

View file

@ -19,7 +19,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('find_statuses', () => {
beforeEach(async () => {

View file

@ -16,7 +16,7 @@ import { createSignalsIndex, deleteAllAlerts, deleteSignalsIndex, getSimpleRule
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('get_prepackaged_rules_status', () => {
describe('getting prepackaged rules status', () => {

View file

@ -22,7 +22,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('import_rules', () => {
describe('importing rules without an index', () => {

View file

@ -22,7 +22,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('patch_rules', () => {
describe('patch rules', () => {

View file

@ -22,7 +22,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('patch_rules_bulk', () => {
describe('patch rules bulk', () => {

View file

@ -23,7 +23,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('read_rules', () => {
describe('reading rules', () => {

View file

@ -22,7 +22,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('update_rules', () => {
describe('update rules', () => {

View file

@ -22,7 +22,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const es = getService('legacyEs');
const es = getService('es');
describe('update_rules_bulk', () => {
describe('update rules bulk', () => {

View file

@ -4,6 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { Client } from '@elastic/elasticsearch';
import { SuperTest } from 'supertest';
import supertestAsPromised from 'supertest-as-promised';
import { OutputRuleAlertRest } from '../../../../plugins/siem/server/lib/detection_engine/types';
import { DETECTION_ENGINE_INDEX_URL } from '../../../../plugins/siem/common/constants';
@ -187,12 +190,13 @@ export const getSimpleMlRuleOutput = (ruleId = 'rule-1'): Partial<OutputRuleAler
* Remove all alerts from the .kibana index
* @param es The ElasticSearch handle
*/
export const deleteAllAlerts = async (es: any): Promise<void> => {
export const deleteAllAlerts = async (es: Client): Promise<void> => {
await es.deleteByQuery({
index: '.kibana',
q: 'type:alert',
waitForCompletion: true,
refresh: 'wait_for',
wait_for_completion: true,
refresh: true,
body: {},
});
};
@ -200,12 +204,13 @@ export const deleteAllAlerts = async (es: any): Promise<void> => {
* Remove all rules statuses from the .kibana index
* @param es The ElasticSearch handle
*/
export const deleteAllRulesStatuses = async (es: any): Promise<void> => {
export const deleteAllRulesStatuses = async (es: Client): Promise<void> => {
await es.deleteByQuery({
index: '.kibana',
q: 'type:siem-detection-engine-rule-status',
waitForCompletion: true,
refresh: 'wait_for',
wait_for_completion: true,
refresh: true,
body: {},
});
};
@ -213,7 +218,9 @@ export const deleteAllRulesStatuses = async (es: any): Promise<void> => {
* Creates the signals index for use inside of beforeEach blocks of tests
* @param supertest The supertest client library
*/
export const createSignalsIndex = async (supertest: any): Promise<void> => {
export const createSignalsIndex = async (
supertest: SuperTest<supertestAsPromised.Test>
): Promise<void> => {
await supertest
.post(DETECTION_ENGINE_INDEX_URL)
.set('kbn-xsrf', 'true')
@ -225,7 +232,9 @@ export const createSignalsIndex = async (supertest: any): Promise<void> => {
* Deletes the signals index for use inside of afterEach blocks of tests
* @param supertest The supertest client library
*/
export const deleteSignalsIndex = async (supertest: any): Promise<void> => {
export const deleteSignalsIndex = async (
supertest: SuperTest<supertestAsPromised.Test>
): Promise<void> => {
await supertest
.delete(DETECTION_ENGINE_INDEX_URL)
.set('kbn-xsrf', 'true')