TestingHeading
diff --git a/x-pack/plugins/uptime/public/pages/page_header.tsx b/x-pack/plugins/uptime/public/pages/page_header.tsx
index d2e1f9036a24a..3b228afe904f4 100644
--- a/x-pack/plugins/uptime/public/pages/page_header.tsx
+++ b/x-pack/plugins/uptime/public/pages/page_header.tsx
@@ -18,6 +18,7 @@ interface PageHeaderProps {
extraLinks?: boolean;
datePicker?: boolean;
}
+
const SETTINGS_LINK_TEXT = i18n.translate('xpack.uptime.page_header.settingsLink', {
defaultMessage: 'Settings',
});
@@ -38,6 +39,10 @@ const StyledPicker = styled(EuiFlexItem)`
}
`;
+const H1Text = styled.h1`
+ white-space: nowrap;
+`;
+
export const PageHeader = React.memo(
({ headingText, extraLinks = false, datePicker = true }: PageHeaderProps) => {
const DatePickerComponent = () =>
@@ -73,7 +78,7 @@ export const PageHeader = React.memo(
>
- {headingText}
+ {headingText}
{extraLinkComponents}
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_monitor_locations.ts b/x-pack/plugins/uptime/server/lib/requests/get_monitor_locations.ts
index c8d3ca043edc5..17d79002e6f7d 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_monitor_locations.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_monitor_locations.ts
@@ -32,7 +32,7 @@ export const getMonitorLocations: UMElasticsearchQueryFn<
bool: {
filter: [
{
- match: {
+ term: {
'monitor.id': monitorId,
},
},
@@ -70,6 +70,18 @@ export const getMonitorLocations: UMElasticsearchQueryFn<
_source: ['monitor', 'summary', 'observer', '@timestamp'],
},
},
+ down_history: {
+ sum: {
+ field: 'summary.down',
+ missing: 0,
+ },
+ },
+ up_history: {
+ sum: {
+ field: 'summary.up',
+ missing: 0,
+ },
+ },
},
},
},
@@ -99,10 +111,17 @@ export const getMonitorLocations: UMElasticsearchQueryFn<
}
};
+ let totalUps = 0;
+ let totalDowns = 0;
+
const monLocs: MonitorLocation[] = [];
- locations.forEach((loc: any) => {
- const mostRecentLocation = loc.most_recent.hits.hits[0]._source;
+ locations.forEach(({ most_recent: mostRecent, up_history, down_history }: any) => {
+ const mostRecentLocation = mostRecent.hits.hits[0]._source;
+ totalUps += up_history.value;
+ totalDowns += down_history.value;
const location: MonitorLocation = {
+ up_history: up_history.value ?? 0,
+ down_history: down_history.value ?? 0,
summary: mostRecentLocation?.summary,
geo: getGeo(mostRecentLocation?.observer?.geo),
timestamp: mostRecentLocation['@timestamp'],
@@ -113,5 +132,7 @@ export const getMonitorLocations: UMElasticsearchQueryFn<
return {
monitorId,
locations: monLocs,
+ up_history: totalUps,
+ down_history: totalDowns,
};
};
diff --git a/x-pack/test/accessibility/apps/uptime.ts b/x-pack/test/accessibility/apps/uptime.ts
index dccce4ba1b0b1..ebd120fa0feea 100644
--- a/x-pack/test/accessibility/apps/uptime.ts
+++ b/x-pack/test/accessibility/apps/uptime.ts
@@ -65,7 +65,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
it('detail page', async () => {
await uptimeService.navigation.goToMonitor(A11Y_TEST_MONITOR_ID);
- await uptimeService.monitor.locationMapIsRendered();
+ await uptimeService.monitor.displayOverallAvailability('0.00 %');
await a11y.testAppSnapshot();
});
diff --git a/x-pack/test/functional/apps/uptime/locations.ts b/x-pack/test/functional/apps/uptime/locations.ts
index 27c42a365ec74..8aefca6a70195 100644
--- a/x-pack/test/functional/apps/uptime/locations.ts
+++ b/x-pack/test/functional/apps/uptime/locations.ts
@@ -11,41 +11,58 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default ({ getPageObjects, getService }: FtrProviderContext) => {
const { uptime: uptimePage } = getPageObjects(['uptime']);
const uptime = getService('uptime');
+ const es = getService('legacyEs');
const monitor = () => uptime.monitor;
+ const MONITOR_ID = 'location-testing-id';
+
+ const LessAvailMonitor = 'less-availability-monitor';
+
+ const addMonitorWithNoLocation = async () => {
+ /**
+ * This mogrify function will strip the documents of their location
+ * data (but preserve their location name), which is necessary for
+ * this test to work as desired.
+ * @param d current document
+ */
+ const mogrifyNoLocation = (d: any) => {
+ if (d.observer?.geo?.location) {
+ d.observer.geo.location = undefined;
+ }
+ return d;
+ };
+ await makeChecksWithStatus(es, MONITOR_ID, 5, 2, 10000, {}, 'up', mogrifyNoLocation);
+ };
+
+ const addLessAvailMonitor = async () => {
+ await makeChecksWithStatus(es, LessAvailMonitor, 5, 2, 10000, {}, 'up');
+ await makeChecksWithStatus(es, LessAvailMonitor, 5, 2, 10000, {}, 'down');
+ };
describe('Observer location', () => {
const start = moment().subtract('15', 'm').toISOString();
const end = moment().toISOString();
- const MONITOR_ID = 'location-testing-id';
+ before(async () => {
+ await addMonitorWithNoLocation();
+ await addLessAvailMonitor();
+ await uptime.navigation.goToUptime();
+ await uptimePage.goToRoot(true);
+ });
beforeEach(async () => {
- /**
- * This mogrify function will strip the documents of their location
- * data (but preserve their location name), which is necessary for
- * this test to work as desired.
- * @param d current document
- */
- const mogrifyNoLocation = (d: any) => {
- if (d.observer?.geo?.location) {
- d.observer.geo.location = undefined;
- }
- return d;
- };
- await makeChecksWithStatus(
- getService('legacyEs'),
- MONITOR_ID,
- 5,
- 2,
- 10000,
- {},
- 'up',
- mogrifyNoLocation
- );
- await uptime.navigation.goToUptime();
+ await addMonitorWithNoLocation();
+ await addLessAvailMonitor();
+ if (!(await uptime.navigation.isOnDetailsPage()))
+ await uptimePage.loadDataAndGoToMonitorPage(start, end, MONITOR_ID);
+ });
+
+ it('displays the overall availability', async () => {
+ await monitor().displayOverallAvailability('100.00 %');
+ });
- await uptimePage.loadDataAndGoToMonitorPage(start, end, MONITOR_ID);
+ it('can change the view to map', async () => {
+ await monitor().toggleToMapView();
});
it('renders the location panel and canvas', async () => {
@@ -55,5 +72,11 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
it('renders the location missing popover when monitor has location name, but no geo data', async () => {
await monitor().locationMissingExists();
});
+
+ it('displays less monitor availability', async () => {
+ await uptime.navigation.goToHomeViaBreadCrumb();
+ await uptimePage.loadDataAndGoToMonitorPage(start, end, LessAvailMonitor);
+ await monitor().displayOverallAvailability('50.00 %');
+ });
});
};
diff --git a/x-pack/test/functional/services/uptime/common.ts b/x-pack/test/functional/services/uptime/common.ts
index b5be1e29a0e8c..5f544b5e46010 100644
--- a/x-pack/test/functional/services/uptime/common.ts
+++ b/x-pack/test/functional/services/uptime/common.ts
@@ -58,13 +58,13 @@ export function UptimeCommonProvider({ getService }: FtrProviderContext) {
'[data-test-subj="xpack.uptime.filterBar.filterStatusUp"]'
);
if (await upFilter.elementHasClass('euiFilterButton-hasActiveFilters')) {
- this.setStatusFilterUp();
+ await this.setStatusFilterUp();
}
const downFilter = await find.byCssSelector(
'[data-test-subj="xpack.uptime.filterBar.filterStatusDown"]'
);
if (await downFilter.elementHasClass('euiFilterButton-hasActiveFilters')) {
- this.setStatusFilterDown();
+ await this.setStatusFilterDown();
}
},
async selectFilterItem(filterType: string, option: string) {
diff --git a/x-pack/test/functional/services/uptime/monitor.ts b/x-pack/test/functional/services/uptime/monitor.ts
index 3137711698ba4..593950fbb7619 100644
--- a/x-pack/test/functional/services/uptime/monitor.ts
+++ b/x-pack/test/functional/services/uptime/monitor.ts
@@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import expect from '@kbn/expect/expect.js';
import { FtrProviderContext } from '../../ftr_provider_context';
export function UptimeMonitorProvider({ getService }: FtrProviderContext) {
@@ -17,6 +18,13 @@ export function UptimeMonitorProvider({ getService }: FtrProviderContext) {
timeout: 3000,
});
},
+ async displayOverallAvailability(availabilityVal: string) {
+ return retry.tryForTime(60 * 1000, async () => {
+ await testSubjects.existOrFail('uptimeOverallAvailability');
+ const availability = await testSubjects.getVisibleText('uptimeOverallAvailability');
+ expect(availability).to.be(availabilityVal);
+ });
+ },
async locationMapIsRendered() {
return retry.tryForTime(15000, async () => {
await testSubjects.existOrFail('xpack.uptime.locationMap.embeddedPanel', {
@@ -45,5 +53,8 @@ export function UptimeMonitorProvider({ getService }: FtrProviderContext) {
);
});
},
+ async toggleToMapView() {
+ await testSubjects.click('uptimeMonitorToggleMapBtn');
+ },
};
}
diff --git a/x-pack/test/functional/services/uptime/navigation.ts b/x-pack/test/functional/services/uptime/navigation.ts
index 7c5a4632f8627..f8e0c0cff41f4 100644
--- a/x-pack/test/functional/services/uptime/navigation.ts
+++ b/x-pack/test/functional/services/uptime/navigation.ts
@@ -56,6 +56,7 @@ export function UptimeNavigationProvider({ getService, getPageObjects }: FtrProv
},
goToMonitor: async (monitorId: string) => {
+ // only go to monitor page if not already there
if (!(await testSubjects.exists('uptimeMonitorPage', { timeout: 0 }))) {
await testSubjects.click(`monitor-page-link-${monitorId}`);
await testSubjects.existOrFail('uptimeMonitorPage', {
@@ -80,5 +81,13 @@ export function UptimeNavigationProvider({ getService, getPageObjects }: FtrProv
await PageObjects.timePicker.setAbsoluteRange(dateStart, dateEnd);
await this.goToMonitor(monitorId);
},
+
+ async isOnDetailsPage() {
+ return await testSubjects.exists('uptimeMonitorPage', { timeout: 0 });
+ },
+
+ async goToHomeViaBreadCrumb() {
+ await testSubjects.click('breadcrumb first');
+ },
};
}
From 9c881447270926c5fb63153c392871cd22eb908a Mon Sep 17 00:00:00 2001
From: Lisa Cawley
Date: Tue, 16 Jun 2020 09:30:02 -0700
Subject: [PATCH 04/41] [DOCS] Adds classification to data frame analytics
overview (#69068)
---
docs/user/ml/index.asciidoc | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/docs/user/ml/index.asciidoc b/docs/user/ml/index.asciidoc
index f82bb0a406511..1bc74ce87de08 100644
--- a/docs/user/ml/index.asciidoc
+++ b/docs/user/ml/index.asciidoc
@@ -87,12 +87,14 @@ and {ml-docs}/xpack-ml.html[{ml-cap} {anomaly-detect}].
[[xpack-ml-dfanalytics]]
== {dfanalytics-cap}
+experimental[]
+
The Elastic {ml} {dfanalytics} feature enables you to analyze your data using
-{oldetection} and {regression} algorithms and generate new indices that contain
-the results alongside your source data.
+{classification}, {oldetection}, and {regression} algorithms and generate new
+indices that contain the results alongside your source data.
If you have a license that includes the {ml-features}, you can create
-{oldetection} {dfanalytics-jobs} and view their results on the *Analytics* page
+{dfanalytics-jobs} and view their results on the *Analytics* page
in {kib}. For example:
[role="screenshot"]
From fb97d91789faf2c7fe9771a832876e4c38020492 Mon Sep 17 00:00:00 2001
From: patrykkopycinski
Date: Tue, 16 Jun 2020 18:44:34 +0200
Subject: [PATCH 05/41] Bump react-redux (#69182)
---
package.json | 4 ++--
x-pack/package.json | 4 ++--
yarn.lock | 17 ++++++++---------
3 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/package.json b/package.json
index b886e6ae0f5d3..85eba40c6251a 100644
--- a/package.json
+++ b/package.json
@@ -243,7 +243,7 @@
"react-input-range": "^1.3.0",
"react-markdown": "^4.3.1",
"react-monaco-editor": "~0.27.0",
- "react-redux": "^7.1.3",
+ "react-redux": "^7.2.0",
"react-resize-detector": "^4.2.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
@@ -375,7 +375,7 @@
"@types/react": "^16.9.36",
"@types/react-dom": "^16.9.8",
"@types/react-grid-layout": "^0.16.7",
- "@types/react-redux": "^7.1.7",
+ "@types/react-redux": "^7.1.9",
"@types/react-resize-detector": "^4.0.1",
"@types/react-router": "^5.1.3",
"@types/react-router-dom": "^5.1.3",
diff --git a/x-pack/package.json b/x-pack/package.json
index c582cc8be9bbd..e24d75cc0d968 100644
--- a/x-pack/package.json
+++ b/x-pack/package.json
@@ -98,7 +98,7 @@
"@types/react": "^16.9.36",
"@types/react-beautiful-dnd": "^12.1.1",
"@types/react-dom": "^16.9.8",
- "@types/react-redux": "^7.1.7",
+ "@types/react-redux": "^7.1.9",
"@types/react-router-dom": "^5.1.3",
"@types/react-sticky": "^6.0.3",
"@types/react-test-renderer": "^16.9.1",
@@ -322,7 +322,7 @@
"react-markdown": "^4.3.1",
"react-moment-proptypes": "^1.7.0",
"react-portal": "^3.2.0",
- "react-redux": "^7.1.3",
+ "react-redux": "^7.2.0",
"react-reverse-portal": "^1.0.4",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
diff --git a/yarn.lock b/yarn.lock
index 0188957073965..e43cb2997e531 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5550,10 +5550,10 @@
"@types/prop-types" "*"
"@types/react" "*"
-"@types/react-redux@^7.1.7":
- version "7.1.7"
- resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.7.tgz#12a0c529aba660696947384a059c5c6e08185c7a"
- integrity sha512-U+WrzeFfI83+evZE2dkZ/oF/1vjIYgqrb5dGgedkqVV8HEfDFujNgWCwHL89TDuWKb47U0nTBT6PLGq4IIogWg==
+"@types/react-redux@^7.1.9":
+ version "7.1.9"
+ resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.9.tgz#280c13565c9f13ceb727ec21e767abe0e9b4aec3"
+ integrity sha512-mpC0jqxhP4mhmOl3P4ipRsgTgbNofMRXJb08Ms6gekViLj61v1hOZEKWDCyWsdONr6EjEA6ZHXC446wdywDe0w==
dependencies:
"@types/hoist-non-react-statics" "^3.3.0"
"@types/react" "*"
@@ -25452,14 +25452,13 @@ react-redux@^5.1.2:
react-is "^16.6.0"
react-lifecycles-compat "^3.0.0"
-react-redux@^7.1.0, react-redux@^7.1.1, react-redux@^7.1.3:
- version "7.1.3"
- resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.1.3.tgz#717a3d7bbe3a1b2d535c94885ce04cdc5a33fc79"
- integrity sha512-uI1wca+ECG9RoVkWQFF4jDMqmaw0/qnvaSvOoL/GA4dNxf6LoV8sUAcNDvE5NWKs4hFpn0t6wswNQnY3f7HT3w==
+react-redux@^7.1.0, react-redux@^7.1.1, react-redux@^7.2.0:
+ version "7.2.0"
+ resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.0.tgz#f970f62192b3981642fec46fd0db18a074fe879d"
+ integrity sha512-EvCAZYGfOLqwV7gh849xy9/pt55rJXPwmYvI4lilPM5rUT/1NxuuN59ipdBksRVSvz0KInbPnp4IfoXJXCqiDA==
dependencies:
"@babel/runtime" "^7.5.5"
hoist-non-react-statics "^3.3.0"
- invariant "^2.2.4"
loose-envify "^1.4.0"
prop-types "^15.7.2"
react-is "^16.9.0"
From 62f25506d384fc0c430486fa97c9a5c98e597264 Mon Sep 17 00:00:00 2001
From: Spencer
Date: Tue, 16 Jun 2020 09:54:41 -0700
Subject: [PATCH 06/41] [kbn/es] only make one attempt in tests to avoid
timeout (#69197)
Co-authored-by: spalger
Co-authored-by: Elastic Machine
---
packages/kbn-es/src/utils/native_realm.js | 30 ++++++++++---------
.../kbn-es/src/utils/native_realm.test.js | 10 +++----
2 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/packages/kbn-es/src/utils/native_realm.js b/packages/kbn-es/src/utils/native_realm.js
index 573944a8cc6d0..5075cfb965c08 100644
--- a/packages/kbn-es/src/utils/native_realm.js
+++ b/packages/kbn-es/src/utils/native_realm.js
@@ -37,13 +37,8 @@ exports.NativeRealm = class NativeRealm {
this._log = log;
}
- async setPassword(username, password = this._elasticPassword, { attempt = 1 } = {}) {
- await this._autoRetry(async () => {
- this._log.info(
- (attempt > 1 ? `attempt ${attempt}: ` : '') +
- `setting ${chalk.bold(username)} password to ${chalk.bold(password)}`
- );
-
+ async setPassword(username, password = this._elasticPassword, retryOpts = {}) {
+ await this._autoRetry(retryOpts, async () => {
try {
await this._client.security.changePassword({
username,
@@ -83,8 +78,8 @@ exports.NativeRealm = class NativeRealm {
);
}
- async getReservedUsers() {
- return await this._autoRetry(async () => {
+ async getReservedUsers(retryOpts = {}) {
+ return await this._autoRetry(retryOpts, async () => {
const resp = await this._client.security.getUser();
const usernames = Object.keys(resp.body).filter(
(user) => resp.body[user].metadata._reserved === true
@@ -98,9 +93,9 @@ exports.NativeRealm = class NativeRealm {
});
}
- async isSecurityEnabled() {
+ async isSecurityEnabled(retryOpts = {}) {
try {
- return await this._autoRetry(async () => {
+ return await this._autoRetry(retryOpts, async () => {
const {
body: { features },
} = await this._client.xpack.info({ categories: 'features' });
@@ -115,18 +110,25 @@ exports.NativeRealm = class NativeRealm {
}
}
- async _autoRetry(fn, attempt = 1) {
+ async _autoRetry(opts, fn) {
+ const { attempt = 1, maxAttempts = 3 } = opts;
+
try {
return await fn(attempt);
} catch (error) {
- if (attempt >= 3) {
+ if (attempt >= maxAttempts) {
throw error;
}
const sec = 1.5 * attempt;
this._log.warning(`assuming ES isn't initialized completely, trying again in ${sec} seconds`);
await new Promise((resolve) => setTimeout(resolve, sec * 1000));
- return await this._autoRetry(fn, attempt + 1);
+
+ const nextOpts = {
+ ...opts,
+ attempt: attempt + 1,
+ };
+ return await this._autoRetry(nextOpts, fn);
}
}
};
diff --git a/packages/kbn-es/src/utils/native_realm.test.js b/packages/kbn-es/src/utils/native_realm.test.js
index 54732f7136fcc..cd124c97dfdd4 100644
--- a/packages/kbn-es/src/utils/native_realm.test.js
+++ b/packages/kbn-es/src/utils/native_realm.test.js
@@ -85,7 +85,7 @@ describe('isSecurityEnabled', () => {
throw error;
});
- expect(await nativeRealm.isSecurityEnabled()).toBe(false);
+ expect(await nativeRealm.isSecurityEnabled({ maxAttempts: 1 })).toBe(false);
});
test('rejects if unexpected error is thrown', async () => {
@@ -97,9 +97,9 @@ describe('isSecurityEnabled', () => {
throw error;
});
- await expect(nativeRealm.isSecurityEnabled()).rejects.toThrowErrorMatchingInlineSnapshot(
- `"ResponseError"`
- );
+ await expect(
+ nativeRealm.isSecurityEnabled({ maxAttempts: 1 })
+ ).rejects.toThrowErrorMatchingInlineSnapshot(`"ResponseError"`);
});
});
@@ -226,7 +226,7 @@ describe('setPassword', () => {
});
await expect(
- nativeRealm.setPassword('kibana_system', 'foo')
+ nativeRealm.setPassword('kibana_system', 'foo', { maxAttempts: 1 })
).rejects.toThrowErrorMatchingInlineSnapshot(`"SomeError"`);
});
});
From 3de93501c6df2007312e22dc872135e039f1ff0d Mon Sep 17 00:00:00 2001
From: Larry Gregory
Date: Tue, 16 Jun 2020 12:55:18 -0400
Subject: [PATCH 07/41] Resolve security cloud test failures (#68935)
Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
Co-authored-by: Elastic Machine
---
.../functional/page_objects/security_page.ts | 173 ++++++++----------
1 file changed, 72 insertions(+), 101 deletions(-)
diff --git a/x-pack/test/functional/page_objects/security_page.ts b/x-pack/test/functional/page_objects/security_page.ts
index 57f62ab33e39a..395e41a91f53a 100644
--- a/x-pack/test/functional/page_objects/security_page.ts
+++ b/x-pack/test/functional/page_objects/security_page.ts
@@ -16,6 +16,7 @@ export function SecurityPageProvider({ getService, getPageObjects }: FtrProvider
const testSubjects = getService('testSubjects');
const esArchiver = getService('esArchiver');
const userMenu = getService('userMenu');
+ const comboBox = getService('comboBox');
const PageObjects = getPageObjects(['common', 'header', 'settings', 'home', 'error']);
interface LoginOptions {
@@ -273,11 +274,7 @@ export function SecurityPageProvider({ getService, getPageObjects }: FtrProvider
async addIndexToRole(index: string) {
log.debug(`Adding index ${index} to role`);
- const indexInput = await retry.try(() =>
- find.byCssSelector('[data-test-subj="indicesInput0"] input')
- );
- await indexInput.type(index);
- await indexInput.type('\n');
+ await comboBox.setCustom('indicesInput0', index);
}
async addPrivilegeToRole(privilege: string) {
@@ -400,104 +397,78 @@ export function SecurityPageProvider({ getService, getPageObjects }: FtrProvider
}
}
- addRole(roleName: string, roleObj: Role) {
+ async addRole(roleName: string, roleObj: Role) {
const self = this;
- return (
- this.clickNewRole()
- .then(function () {
- // We have to use non-test-subject selectors because this markup is generated by ui-select.
- log.debug('roleObj.indices[0].names = ' + roleObj.elasticsearch.indices[0].names);
- return testSubjects.append('roleFormNameInput', roleName);
- })
- .then(function () {
- return find.setValue(
- '[data-test-subj="indicesInput0"] input',
- roleObj.elasticsearch.indices[0].names + '\n'
- );
- })
- .then(function () {
- return testSubjects.click('restrictDocumentsQuery0');
- })
- .then(function () {
- if (roleObj.elasticsearch.indices[0].query) {
- return testSubjects.setValue('queryInput0', roleObj.elasticsearch.indices[0].query);
- }
- })
-
- // KibanaPrivilege
- .then(async () => {
- const globalPrivileges = (roleObj.kibana as any).global;
- if (globalPrivileges) {
- for (const privilegeName of globalPrivileges) {
- const button = await testSubjects.find('addSpacePrivilegeButton');
- await button.click();
-
- const spaceSelector = await testSubjects.find('spaceSelectorComboBox');
- await spaceSelector.click();
-
- const globalSpaceOption = await find.byCssSelector(`#spaceOption_\\*`);
- await globalSpaceOption.click();
-
- const basePrivilegeSelector = await testSubjects.find('basePrivilegeComboBox');
- await basePrivilegeSelector.click();
-
- const privilegeOption = await find.byCssSelector(`#basePrivilege_${privilegeName}`);
- await privilegeOption.click();
-
- const createPrivilegeButton = await testSubjects.find('createSpacePrivilegeButton');
- await createPrivilegeButton.click();
- }
- }
- })
-
- .then(function () {
- function addPrivilege(privileges: string[]) {
- return privileges.reduce(function (promise: Promise, privilegeName: string) {
- // We have to use non-test-subject selectors because this markup is generated by ui-select.
- return promise
- .then(() => self.addPrivilegeToRole(privilegeName))
- .then(() => PageObjects.common.sleep(250));
- }, Promise.resolve());
- }
- return addPrivilege(roleObj.elasticsearch.indices[0].privileges);
- })
- // clicking the Granted fields and removing the asterix
- .then(async function () {
- function addGrantedField(field: string[]) {
- return field.reduce(function (promise: Promise, fieldName: string) {
- return promise
- .then(function () {
- return find.setValue('[data-test-subj="fieldInput0"] input', fieldName + '\n');
- })
- .then(function () {
- return PageObjects.common.sleep(1000);
- });
- }, Promise.resolve());
- }
-
- if (roleObj.elasticsearch.indices[0].field_security) {
- // Toggle FLS switch
- await testSubjects.click('restrictFieldsQuery0');
-
- // have to remove the '*'
- return find
- .clickByCssSelector(
- 'div[data-test-subj="fieldInput0"] [title="Remove * from selection in this group"] svg.euiIcon'
- )
- .then(function () {
- return addGrantedField(roleObj.elasticsearch.indices[0].field_security!.grant!);
- });
- }
- }) // clicking save button
- .then(async () => {
- log.debug('click save button');
- await testSubjects.click('roleFormSaveButton');
- })
- .then(function () {
- return PageObjects.common.sleep(5000);
- })
- );
+ await this.clickNewRole();
+
+ // We have to use non-test-subject selectors because this markup is generated by ui-select.
+ log.debug('roleObj.indices[0].names = ' + roleObj.elasticsearch.indices[0].names);
+ await testSubjects.append('roleFormNameInput', roleName);
+
+ for (const indexName of roleObj.elasticsearch.indices[0].names) {
+ await comboBox.setCustom('indicesInput0', indexName);
+ }
+
+ if (roleObj.elasticsearch.indices[0].query) {
+ await testSubjects.click('restrictDocumentsQuery0');
+ await testSubjects.setValue('queryInput0', roleObj.elasticsearch.indices[0].query);
+ }
+
+ const globalPrivileges = (roleObj.kibana as any).global;
+ if (globalPrivileges) {
+ for (const privilegeName of globalPrivileges) {
+ await testSubjects.click('addSpacePrivilegeButton');
+
+ await testSubjects.click('spaceSelectorComboBox');
+
+ const globalSpaceOption = await find.byCssSelector(`#spaceOption_\\*`);
+ await globalSpaceOption.click();
+
+ await testSubjects.click('basePrivilegeComboBox');
+
+ const privilegeOption = await find.byCssSelector(`#basePrivilege_${privilegeName}`);
+ await privilegeOption.click();
+
+ await testSubjects.click('createSpacePrivilegeButton');
+ }
+ }
+
+ function addPrivilege(privileges: string[]) {
+ return privileges.reduce(function (promise: Promise, privilegeName: string) {
+ return promise
+ .then(() => self.addPrivilegeToRole(privilegeName))
+ .then(() => PageObjects.common.sleep(250));
+ }, Promise.resolve());
+ }
+
+ await addPrivilege(roleObj.elasticsearch.indices[0].privileges);
+
+ async function addGrantedField(fields: string[]) {
+ for (const entry of fields) {
+ await comboBox.setCustom('fieldInput0', entry);
+ }
+ }
+
+ // clicking the Granted fields and removing the asterix
+ if (roleObj.elasticsearch.indices[0].field_security) {
+ // Toggle FLS switch
+ await testSubjects.click('restrictFieldsQuery0');
+
+ // have to remove the '*'
+ await find.clickByCssSelector(
+ 'div[data-test-subj="fieldInput0"] [title="Remove * from selection in this group"] svg.euiIcon'
+ );
+
+ await addGrantedField(roleObj.elasticsearch.indices[0].field_security!.grant!);
+ }
+
+ log.debug('click save button');
+ await testSubjects.click('roleFormSaveButton');
+
+ // Signifies that the role management page redirected back to the role grid page,
+ // and successfully refreshed the grid
+ await testSubjects.existOrFail('roleRow');
}
async selectRole(role: string) {
From d5785a0d6d91f6dd110ea2d2cb69e6c3bfded427 Mon Sep 17 00:00:00 2001
From: Frank Hassanabad
Date: Tue, 16 Jun 2020 12:02:40 -0600
Subject: [PATCH 08/41] SIEM] Moves validation up to the common section
## Summary
Moves validation up to the common section so it can be used by others in common for API boundary validation.
---
.../update_exception_list_item_schema.test.ts | 2 +-
.../exception_list_item_schema.test.ts | 2 +-
.../plugins/lists/common/siem_common_deps.ts | 2 ++
.../create_exception_list_item_route.ts | 8 ++---
.../routes/create_exception_list_route.ts | 8 ++---
.../server/routes/create_list_index_route.ts | 3 +-
.../server/routes/create_list_item_route.ts | 8 ++---
.../lists/server/routes/create_list_route.ts | 8 ++---
.../delete_exception_list_item_route.ts | 8 ++---
.../routes/delete_exception_list_route.ts | 8 ++---
.../server/routes/delete_list_index_route.ts | 3 +-
.../server/routes/delete_list_item_route.ts | 8 ++---
.../lists/server/routes/delete_list_route.ts | 8 ++---
.../routes/find_exception_list_item_route.ts | 8 ++---
.../routes/find_exception_list_route.ts | 8 ++---
.../server/routes/find_list_item_route.ts | 8 ++---
.../lists/server/routes/find_list_route.ts | 8 ++---
.../server/routes/import_list_item_route.ts | 8 ++---
.../server/routes/patch_list_item_route.ts | 8 ++---
.../lists/server/routes/patch_list_route.ts | 8 ++---
.../routes/read_exception_list_item_route.ts | 8 ++---
.../routes/read_exception_list_route.ts | 8 ++---
.../server/routes/read_list_index_route.ts | 3 +-
.../server/routes/read_list_item_route.ts | 8 ++---
.../lists/server/routes/read_list_route.ts | 8 ++---
.../update_exception_list_item_route.ts | 8 ++---
.../routes/update_exception_list_route.ts | 8 ++---
.../server/routes/update_list_item_route.ts | 8 ++---
.../lists/server/routes/update_list_route.ts | 8 ++---
.../plugins/lists/server/siem_server_deps.ts | 1 -
.../security_solution/common/validate.test.ts | 34 +++++++++++++++++++
.../security_solution/common/validate.ts | 25 ++++++++++++++
.../plugins/security_solution/server/index.ts | 1 -
.../rules/add_prepackaged_rules_route.ts | 2 +-
.../routes/rules/create_rules_bulk_route.ts | 3 +-
.../routes/rules/delete_rules_bulk_route.ts | 3 +-
.../get_prepackaged_rules_status_route.ts | 2 +-
.../routes/rules/import_rules_route.ts | 2 +-
.../routes/rules/patch_rules_bulk_route.ts | 3 +-
.../routes/rules/update_rules_bulk_route.ts | 3 +-
.../routes/rules/validate.test.ts | 23 -------------
.../detection_engine/routes/rules/validate.ts | 15 +-------
.../timeline/routes/import_timelines_route.ts | 2 +-
43 files changed, 128 insertions(+), 190 deletions(-)
create mode 100644 x-pack/plugins/security_solution/common/validate.test.ts
create mode 100644 x-pack/plugins/security_solution/common/validate.ts
diff --git a/x-pack/plugins/lists/common/schemas/request/update_exception_list_item_schema.test.ts b/x-pack/plugins/lists/common/schemas/request/update_exception_list_item_schema.test.ts
index 38541e205598b..69702a5e8a4f9 100644
--- a/x-pack/plugins/lists/common/schemas/request/update_exception_list_item_schema.test.ts
+++ b/x-pack/plugins/lists/common/schemas/request/update_exception_list_item_schema.test.ts
@@ -147,7 +147,7 @@ describe('update_exception_list_item_schema', () => {
// TODO: Is it expected behavior for it not to auto-generate a uui or throw
// error if item_id is not passed in?
- xtest('it should accept an undefined for "item_id" and auto generate a uuid', () => {
+ test.skip('it should accept an undefined for "item_id" and auto generate a uuid', () => {
const inputPayload = getUpdateExceptionListItemSchemaMock();
delete inputPayload.item_id;
const decoded = updateExceptionListItemSchema.decode(inputPayload);
diff --git a/x-pack/plugins/lists/common/schemas/response/exception_list_item_schema.test.ts b/x-pack/plugins/lists/common/schemas/response/exception_list_item_schema.test.ts
index b9d142fbccbee..ff900104251b7 100644
--- a/x-pack/plugins/lists/common/schemas/response/exception_list_item_schema.test.ts
+++ b/x-pack/plugins/lists/common/schemas/response/exception_list_item_schema.test.ts
@@ -101,7 +101,7 @@ describe('exception_list_item_schema', () => {
// TODO: Should this throw an error? "namespace_type" gets auto-populated
// with default "single", is that desired behavior?
- xtest('it should NOT accept an undefined for "namespace_type"', () => {
+ test.skip('it should NOT accept an undefined for "namespace_type"', () => {
const payload = getExceptionListItemSchemaMock();
delete payload.namespace_type;
const decoded = exceptionListItemSchema.decode(payload);
diff --git a/x-pack/plugins/lists/common/siem_common_deps.ts b/x-pack/plugins/lists/common/siem_common_deps.ts
index 3759305987f79..b1bb7d8aace36 100644
--- a/x-pack/plugins/lists/common/siem_common_deps.ts
+++ b/x-pack/plugins/lists/common/siem_common_deps.ts
@@ -9,3 +9,5 @@ export { DefaultUuid } from '../../security_solution/common/detection_engine/sch
export { DefaultStringArray } from '../../security_solution/common/detection_engine/schemas/types/default_string_array';
export { exactCheck } from '../../security_solution/common/exact_check';
export { getPaths, foldLeftRight } from '../../security_solution/common/test_utils';
+export { validate } from '../../security_solution/common/validate';
+export { formatErrors } from '../../security_solution/common/format_errors';
diff --git a/x-pack/plugins/lists/server/routes/create_exception_list_item_route.ts b/x-pack/plugins/lists/server/routes/create_exception_list_item_route.ts
index 2cafd435e0853..375d25c6fa5f8 100644
--- a/x-pack/plugins/lists/server/routes/create_exception_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/create_exception_list_item_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import {
CreateExceptionListItemSchemaDecoded,
createExceptionListItemSchema,
diff --git a/x-pack/plugins/lists/server/routes/create_exception_list_route.ts b/x-pack/plugins/lists/server/routes/create_exception_list_route.ts
index 9be6b72dcd255..bd29a65c9450a 100644
--- a/x-pack/plugins/lists/server/routes/create_exception_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/create_exception_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { EXCEPTION_LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import {
CreateExceptionListSchemaDecoded,
createExceptionListSchema,
diff --git a/x-pack/plugins/lists/server/routes/create_list_index_route.ts b/x-pack/plugins/lists/server/routes/create_list_index_route.ts
index 1c893fb757c5d..5ec2b36da61b0 100644
--- a/x-pack/plugins/lists/server/routes/create_list_index_route.ts
+++ b/x-pack/plugins/lists/server/routes/create_list_index_route.ts
@@ -6,7 +6,8 @@
import { IRouter } from 'kibana/server';
-import { buildSiemResponse, transformError, validate } from '../siem_server_deps';
+import { buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { LIST_INDEX } from '../../common/constants';
import { acknowledgeSchema } from '../../common/schemas';
diff --git a/x-pack/plugins/lists/server/routes/create_list_item_route.ts b/x-pack/plugins/lists/server/routes/create_list_item_route.ts
index 68622e98cbc52..2e1b7fa07221f 100644
--- a/x-pack/plugins/lists/server/routes/create_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/create_list_item_route.ts
@@ -7,13 +7,9 @@
import { IRouter } from 'kibana/server';
import { LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
import { createListItemSchema, listItemSchema } from '../../common/schemas';
+import { validate } from '../../common/siem_common_deps';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/create_list_route.ts b/x-pack/plugins/lists/server/routes/create_list_route.ts
index 0f3c404c53cfd..9872bbfa09e23 100644
--- a/x-pack/plugins/lists/server/routes/create_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/create_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { createListSchema, listSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/delete_exception_list_item_route.ts b/x-pack/plugins/lists/server/routes/delete_exception_list_item_route.ts
index 2c91fe3c28681..f363252dada50 100644
--- a/x-pack/plugins/lists/server/routes/delete_exception_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/delete_exception_list_item_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import {
DeleteExceptionListItemSchemaDecoded,
deleteExceptionListItemSchema,
diff --git a/x-pack/plugins/lists/server/routes/delete_exception_list_route.ts b/x-pack/plugins/lists/server/routes/delete_exception_list_route.ts
index b4c67c0ab1418..b1bf705dcc5f6 100644
--- a/x-pack/plugins/lists/server/routes/delete_exception_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/delete_exception_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { EXCEPTION_LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import {
DeleteExceptionListSchemaDecoded,
deleteExceptionListSchema,
diff --git a/x-pack/plugins/lists/server/routes/delete_list_index_route.ts b/x-pack/plugins/lists/server/routes/delete_list_index_route.ts
index 424c3f45aac40..cb2e16b3602a7 100644
--- a/x-pack/plugins/lists/server/routes/delete_list_index_route.ts
+++ b/x-pack/plugins/lists/server/routes/delete_list_index_route.ts
@@ -7,7 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_INDEX } from '../../common/constants';
-import { buildSiemResponse, transformError, validate } from '../siem_server_deps';
+import { buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { acknowledgeSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/delete_list_item_route.ts b/x-pack/plugins/lists/server/routes/delete_list_item_route.ts
index 82dfe8a4f29d0..510be764cefba 100644
--- a/x-pack/plugins/lists/server/routes/delete_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/delete_list_item_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { deleteListItemSchema, listItemArraySchema, listItemSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/delete_list_route.ts b/x-pack/plugins/lists/server/routes/delete_list_route.ts
index e89355b7689c5..600e4b00c29ca 100644
--- a/x-pack/plugins/lists/server/routes/delete_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/delete_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { deleteListSchema, listSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/find_exception_list_item_route.ts b/x-pack/plugins/lists/server/routes/find_exception_list_item_route.ts
index 1820ffdeadb88..a6c2a18bb8c8a 100644
--- a/x-pack/plugins/lists/server/routes/find_exception_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/find_exception_list_item_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import {
FindExceptionListItemSchemaDecoded,
findExceptionListItemSchema,
diff --git a/x-pack/plugins/lists/server/routes/find_exception_list_route.ts b/x-pack/plugins/lists/server/routes/find_exception_list_route.ts
index 3181deda8b91d..97e1de834cd37 100644
--- a/x-pack/plugins/lists/server/routes/find_exception_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/find_exception_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { EXCEPTION_LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import {
FindExceptionListSchemaDecoded,
findExceptionListSchema,
diff --git a/x-pack/plugins/lists/server/routes/find_list_item_route.ts b/x-pack/plugins/lists/server/routes/find_list_item_route.ts
index 37b5fe44b919c..1ccb948d0ad21 100644
--- a/x-pack/plugins/lists/server/routes/find_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/find_list_item_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { findListItemSchema, foundListItemSchema } from '../../common/schemas';
import { decodeCursor } from '../services/utils';
diff --git a/x-pack/plugins/lists/server/routes/find_list_route.ts b/x-pack/plugins/lists/server/routes/find_list_route.ts
index 04b33e3d67075..2fa43c6368b5c 100644
--- a/x-pack/plugins/lists/server/routes/find_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/find_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { findListSchema, foundListSchema } from '../../common/schemas';
import { decodeCursor } from '../services/utils';
diff --git a/x-pack/plugins/lists/server/routes/import_list_item_route.ts b/x-pack/plugins/lists/server/routes/import_list_item_route.ts
index c951c9b337131..67f345c2c6c1d 100644
--- a/x-pack/plugins/lists/server/routes/import_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/import_list_item_route.ts
@@ -9,12 +9,8 @@ import { Readable } from 'stream';
import { IRouter } from 'kibana/server';
import { LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { importListItemQuerySchema, importListItemSchema, listSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/patch_list_item_route.ts b/x-pack/plugins/lists/server/routes/patch_list_item_route.ts
index e18fd0618b133..f706559dffdbd 100644
--- a/x-pack/plugins/lists/server/routes/patch_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/patch_list_item_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { listItemSchema, patchListItemSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/patch_list_route.ts b/x-pack/plugins/lists/server/routes/patch_list_route.ts
index 9d3fa4db8ccd0..3a0d8714a14cd 100644
--- a/x-pack/plugins/lists/server/routes/patch_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/patch_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { listSchema, patchListSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/read_exception_list_item_route.ts b/x-pack/plugins/lists/server/routes/read_exception_list_item_route.ts
index 083d4d7a0d479..c4e969b27fcf4 100644
--- a/x-pack/plugins/lists/server/routes/read_exception_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/read_exception_list_item_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import {
ReadExceptionListItemSchemaDecoded,
exceptionListItemSchema,
diff --git a/x-pack/plugins/lists/server/routes/read_exception_list_route.ts b/x-pack/plugins/lists/server/routes/read_exception_list_route.ts
index c295f045b38c2..6cb91c10aea55 100644
--- a/x-pack/plugins/lists/server/routes/read_exception_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/read_exception_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { EXCEPTION_LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import {
ReadExceptionListSchemaDecoded,
exceptionListSchema,
diff --git a/x-pack/plugins/lists/server/routes/read_list_index_route.ts b/x-pack/plugins/lists/server/routes/read_list_index_route.ts
index 21f539d97fc74..4664bed3e7a8b 100644
--- a/x-pack/plugins/lists/server/routes/read_list_index_route.ts
+++ b/x-pack/plugins/lists/server/routes/read_list_index_route.ts
@@ -7,7 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_INDEX } from '../../common/constants';
-import { buildSiemResponse, transformError, validate } from '../siem_server_deps';
+import { buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { listItemIndexExistSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/read_list_item_route.ts b/x-pack/plugins/lists/server/routes/read_list_item_route.ts
index 10c7f781f554c..24011d3b50d27 100644
--- a/x-pack/plugins/lists/server/routes/read_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/read_list_item_route.ts
@@ -7,13 +7,9 @@
import { IRouter } from 'kibana/server';
import { LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
import { listItemArraySchema, listItemSchema, readListItemSchema } from '../../common/schemas';
+import { validate } from '../../common/siem_common_deps';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/read_list_route.ts b/x-pack/plugins/lists/server/routes/read_list_route.ts
index c30eadfca0b65..34924b70fd4df 100644
--- a/x-pack/plugins/lists/server/routes/read_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/read_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { listSchema, readListSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/update_exception_list_item_route.ts b/x-pack/plugins/lists/server/routes/update_exception_list_item_route.ts
index 73392c326056e..0ec33b7651982 100644
--- a/x-pack/plugins/lists/server/routes/update_exception_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/update_exception_list_item_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import {
UpdateExceptionListItemSchemaDecoded,
exceptionListItemSchema,
diff --git a/x-pack/plugins/lists/server/routes/update_exception_list_route.ts b/x-pack/plugins/lists/server/routes/update_exception_list_route.ts
index fe45d403c040f..cff78614d05ba 100644
--- a/x-pack/plugins/lists/server/routes/update_exception_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/update_exception_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { EXCEPTION_LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import {
UpdateExceptionListSchemaDecoded,
exceptionListSchema,
diff --git a/x-pack/plugins/lists/server/routes/update_list_item_route.ts b/x-pack/plugins/lists/server/routes/update_list_item_route.ts
index 494d57b93b8e4..3e231e319104b 100644
--- a/x-pack/plugins/lists/server/routes/update_list_item_route.ts
+++ b/x-pack/plugins/lists/server/routes/update_list_item_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_ITEM_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { listItemSchema, updateListItemSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/routes/update_list_route.ts b/x-pack/plugins/lists/server/routes/update_list_route.ts
index 6ace61e46a780..a6d9f8329c7c8 100644
--- a/x-pack/plugins/lists/server/routes/update_list_route.ts
+++ b/x-pack/plugins/lists/server/routes/update_list_route.ts
@@ -7,12 +7,8 @@
import { IRouter } from 'kibana/server';
import { LIST_URL } from '../../common/constants';
-import {
- buildRouteValidation,
- buildSiemResponse,
- transformError,
- validate,
-} from '../siem_server_deps';
+import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
+import { validate } from '../../common/siem_common_deps';
import { listSchema, updateListSchema } from '../../common/schemas';
import { getListClient } from '.';
diff --git a/x-pack/plugins/lists/server/siem_server_deps.ts b/x-pack/plugins/lists/server/siem_server_deps.ts
index df4b07fc46322..87a623c7a1892 100644
--- a/x-pack/plugins/lists/server/siem_server_deps.ts
+++ b/x-pack/plugins/lists/server/siem_server_deps.ts
@@ -17,5 +17,4 @@ export {
createBootstrapIndex,
getIndexExists,
buildRouteValidation,
- validate,
} from '../../security_solution/server';
diff --git a/x-pack/plugins/security_solution/common/validate.test.ts b/x-pack/plugins/security_solution/common/validate.test.ts
new file mode 100644
index 0000000000000..032f6d9590168
--- /dev/null
+++ b/x-pack/plugins/security_solution/common/validate.test.ts
@@ -0,0 +1,34 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import * as t from 'io-ts';
+
+import { validate } from './validate';
+
+describe('validate', () => {
+ test('it should do a validation correctly', () => {
+ const schema = t.exact(t.type({ a: t.number }));
+ const payload = { a: 1 };
+ const [validated, errors] = validate(payload, schema);
+
+ expect(validated).toEqual(payload);
+ expect(errors).toEqual(null);
+ });
+
+ test('it should do an in-validation correctly', () => {
+ const schema = t.exact(t.type({ a: t.number }));
+ const payload = { a: 'some other value' };
+ const [validated, errors] = validate(payload, schema);
+
+ expect(validated).toEqual(null);
+ expect(errors).toEqual('Invalid value "some other value" supplied to "a"');
+ });
+});
diff --git a/x-pack/plugins/security_solution/common/validate.ts b/x-pack/plugins/security_solution/common/validate.ts
new file mode 100644
index 0000000000000..db9e286e2ebc2
--- /dev/null
+++ b/x-pack/plugins/security_solution/common/validate.ts
@@ -0,0 +1,25 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { fold } from 'fp-ts/lib/Either';
+import { pipe } from 'fp-ts/lib/pipeable';
+import * as t from 'io-ts';
+import { exactCheck } from './exact_check';
+import { formatErrors } from './format_errors';
+
+export const validate = (
+ obj: object,
+ schema: T
+): [t.TypeOf | null, string | null] => {
+ const decoded = schema.decode(obj);
+ const checked = exactCheck(obj, decoded);
+ const left = (errors: t.Errors): [T | null, string | null] => [
+ null,
+ formatErrors(errors).join(','),
+ ];
+ const right = (output: T): [T | null, string | null] => [output, null];
+ return pipe(checked, fold(left, right));
+};
diff --git a/x-pack/plugins/security_solution/server/index.ts b/x-pack/plugins/security_solution/server/index.ts
index 586b9dec2f4ab..8a77137c20c11 100644
--- a/x-pack/plugins/security_solution/server/index.ts
+++ b/x-pack/plugins/security_solution/server/index.ts
@@ -27,5 +27,4 @@ export { getPolicyExists } from './lib/detection_engine/index/get_policy_exists'
export { createBootstrapIndex } from './lib/detection_engine/index/create_bootstrap_index';
export { getIndexExists } from './lib/detection_engine/index/get_index_exists';
export { buildRouteValidation } from './utils/build_validation/route_validation';
-export { validate } from './lib/detection_engine/routes/rules/validate';
export { transformError, buildSiemResponse } from './lib/detection_engine/routes/utils';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts
index 39eea16c6290a..9878521c49322 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts
@@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { validate } from '../../../../../common/validate';
import {
PrePackagedRulesSchema,
prePackagedRulesSchema,
@@ -18,7 +19,6 @@ import { updatePrepackagedRules } from '../../rules/update_prepacked_rules';
import { getRulesToInstall } from '../../rules/get_rules_to_install';
import { getRulesToUpdate } from '../../rules/get_rules_to_update';
import { getExistingPrepackagedRules } from '../../rules/get_existing_prepackaged_rules';
-import { validate } from './validate';
export const addPrepackedRulesRoute = (router: IRouter) => {
router.put(
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.ts
index 7af58adca7529..92a7ea17e7eaf 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.ts
@@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { validate } from '../../../../../common/validate';
import { createRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/create_rules_type_dependents';
import { RuleAlertAction } from '../../../../../common/detection_engine/types';
import {
@@ -19,7 +20,7 @@ import { throwHttpError } from '../../../machine_learning/validation';
import { createRules } from '../../rules/create_rules';
import { readRules } from '../../rules/read_rules';
import { getDuplicates } from './utils';
-import { transformValidateBulkError, validate } from './validate';
+import { transformValidateBulkError } from './validate';
import { getIndexExists } from '../../index/get_index_exists';
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.ts
index 12f908ce7e8b5..99bf16aadc815 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.ts
@@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { validate } from '../../../../../common/validate';
import { queryRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/query_rules_type_dependents';
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation';
import {
@@ -14,7 +15,7 @@ import { rulesBulkSchema } from '../../../../../common/detection_engine/schemas/
import { IRouter, RouteConfig, RequestHandler } from '../../../../../../../../src/core/server';
import { DETECTION_ENGINE_RULES_URL } from '../../../../../common/constants';
import { getIdBulkError } from './utils';
-import { transformValidateBulkError, validate } from './validate';
+import { transformValidateBulkError } from './validate';
import { transformBulkError, buildSiemResponse, createBulkErrorObject } from '../utils';
import { deleteRules } from '../../rules/delete_rules';
import { deleteNotifications } from '../../notifications/delete_notifications';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/get_prepackaged_rules_status_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/get_prepackaged_rules_status_route.ts
index c3f4695a20461..bc199ee132e96 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/get_prepackaged_rules_status_route.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/get_prepackaged_rules_status_route.ts
@@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { validate } from '../../../../../common/validate';
import {
PrePackagedRulesStatusSchema,
prePackagedRulesStatusSchema,
@@ -16,7 +17,6 @@ import { getRulesToInstall } from '../../rules/get_rules_to_install';
import { getRulesToUpdate } from '../../rules/get_rules_to_update';
import { findRules } from '../../rules/find_rules';
import { getExistingPrepackagedRules } from '../../rules/get_existing_prepackaged_rules';
-import { validate } from './validate';
export const getPrepackagedRulesStatusRoute = (router: IRouter) => {
router.get(
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts
index c8b61414608a9..a277f97ccf9f0 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts
@@ -7,6 +7,7 @@
import { chunk } from 'lodash/fp';
import { extname } from 'path';
+import { validate } from '../../../../../common/validate';
import {
importRulesQuerySchema,
ImportRulesQuerySchemaDecoded,
@@ -39,7 +40,6 @@ import {
} from '../utils';
import { patchRules } from '../../rules/patch_rules';
import { getTupleDuplicateErrorsAndUniqueRules } from './utils';
-import { validate } from './validate';
import { createRulesStreamFromNdJson } from '../../rules/create_rules_stream_from_ndjson';
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation';
import { HapiReadableStream } from '../../rules/types';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts
index 16f491547a9e6..b2a9fdd103a68 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts
@@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { validate } from '../../../../../common/validate';
import { RuleAlertAction } from '../../../../../common/detection_engine/types';
import {
patchRulesBulkSchema,
@@ -18,7 +19,7 @@ import { buildMlAuthz } from '../../../machine_learning/authz';
import { throwHttpError } from '../../../machine_learning/validation';
import { transformBulkError, buildSiemResponse } from '../utils';
import { getIdBulkError } from './utils';
-import { transformValidateBulkError, validate } from './validate';
+import { transformValidateBulkError } from './validate';
import { patchRules } from '../../rules/patch_rules';
import { updateRulesNotifications } from '../../rules/update_rules_notifications';
import { ruleStatusSavedObjectsClientFactory } from '../../signals/rule_status_saved_objects_client';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_bulk_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_bulk_route.ts
index 3ca4a28dd93ee..1e6815a357154 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_bulk_route.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_bulk_route.ts
@@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { validate } from '../../../../../common/validate';
import { updateRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/update_rules_type_dependents';
import { RuleAlertAction } from '../../../../../common/detection_engine/types';
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation';
@@ -18,7 +19,7 @@ import { SetupPlugins } from '../../../../plugin';
import { buildMlAuthz } from '../../../machine_learning/authz';
import { throwHttpError } from '../../../machine_learning/validation';
import { getIdBulkError } from './utils';
-import { transformValidateBulkError, validate } from './validate';
+import { transformValidateBulkError } from './validate';
import { transformBulkError, buildSiemResponse, createBulkErrorObject } from '../utils';
import { updateRules } from '../../rules/update_rules';
import { updateRulesNotifications } from '../../rules/update_rules_notifications';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.test.ts
index 07b891e2bf021..1f5442e23d884 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.test.ts
@@ -4,10 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import * as t from 'io-ts';
-
import {
- validate,
transformValidate,
transformValidateFindAlerts,
transformValidateBulkError,
@@ -121,26 +118,6 @@ describe('validate', () => {
unSetFeatureFlagsForTestsOnly();
});
- describe('validate', () => {
- test('it should do a validation correctly', () => {
- const schema = t.exact(t.type({ a: t.number }));
- const payload = { a: 1 };
- const [validated, errors] = validate(payload, schema);
-
- expect(validated).toEqual(payload);
- expect(errors).toEqual(null);
- });
-
- test('it should do an in-validation correctly', () => {
- const schema = t.exact(t.type({ a: t.number }));
- const payload = { a: 'some other value' };
- const [validated, errors] = validate(payload, schema);
-
- expect(validated).toEqual(null);
- expect(errors).toEqual('Invalid value "some other value" supplied to "a"');
- });
- });
-
describe('transformValidate', () => {
test('it should do a validation correctly of a partial alert', () => {
const ruleAlert = getResult();
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.ts
index 7b0bf5997d12f..983382b28ab38 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.ts
@@ -9,6 +9,7 @@ import { fold } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import * as t from 'io-ts';
+import { validate } from '../../../../../common/validate';
import { findRulesSchema } from '../../../../../common/detection_engine/schemas/response/find_rules_schema';
import {
RulesSchema,
@@ -113,17 +114,3 @@ export const transformValidateBulkError = (
});
}
};
-
-export const validate = (
- obj: object,
- schema: T
-): [t.TypeOf | null, string | null] => {
- const decoded = schema.decode(obj);
- const checked = exactCheck(obj, decoded);
- const left = (errors: t.Errors): [T | null, string | null] => [
- null,
- formatErrors(errors).join(','),
- ];
- const right = (output: T): [T | null, string | null] => [output, null];
- return pipe(checked, fold(left, right));
-};
diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/import_timelines_route.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/import_timelines_route.ts
index 0f9e97cfc2106..5080142f22b15 100644
--- a/x-pack/plugins/security_solution/server/lib/timeline/routes/import_timelines_route.ts
+++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/import_timelines_route.ts
@@ -7,6 +7,7 @@
import { extname } from 'path';
import { chunk, omit } from 'lodash/fp';
+import { validate } from '../../../../common/validate';
import { importRulesSchema } from '../../../../common/detection_engine/schemas/response/import_rules_schema';
import { createPromiseFromStreams } from '../../../../../../../src/legacy/utils';
import { IRouter } from '../../../../../../../src/core/server';
@@ -17,7 +18,6 @@ import { SetupPlugins } from '../../../plugin';
import { ConfigType } from '../../../config';
import { buildRouteValidation } from '../../../utils/build_validation/route_validation';
-import { validate } from '../../detection_engine/routes/rules/validate';
import {
buildSiemResponse,
createBulkErrorObject,
From 9f7620b84dd0707666b6c2d20e3c98b1d0d8eb03 Mon Sep 17 00:00:00 2001
From: Dmitry Lemeshko
Date: Tue, 16 Jun 2020 20:15:01 +0200
Subject: [PATCH 09/41] [QA] Code coverage: fix flaky tests (#69272)
* skip test
* [page_objects/common_page] update closing toast
---
test/functional/apps/dashboard/dashboard_filter_bar.js | 2 ++
test/functional/page_objects/common_page.ts | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/test/functional/apps/dashboard/dashboard_filter_bar.js b/test/functional/apps/dashboard/dashboard_filter_bar.js
index c931e6763f483..f9b0d0a370c06 100644
--- a/test/functional/apps/dashboard/dashboard_filter_bar.js
+++ b/test/functional/apps/dashboard/dashboard_filter_bar.js
@@ -170,6 +170,8 @@ export default function ({ getService, getPageObjects }) {
});
describe('saved search filtering', function () {
+ // https://github.com/elastic/kibana/issues/47286#issuecomment-644687577
+ this.tags('skipCoverage');
before(async () => {
await filterBar.ensureFieldEditorModalIsClosed();
await PageObjects.dashboard.gotoDashboardLandingPage();
diff --git a/test/functional/page_objects/common_page.ts b/test/functional/page_objects/common_page.ts
index fe5694efc35da..d08e88ecf47ea 100644
--- a/test/functional/page_objects/common_page.ts
+++ b/test/functional/page_objects/common_page.ts
@@ -409,7 +409,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
async closeToastIfExists() {
const toastShown = await find.existsByCssSelector('.euiToast');
if (toastShown) {
- await this.closeToast();
+ await find.clickByCssSelector('.euiToast__closeButton');
}
}
From efbb4ccc31f314f51b2f10663a5635cbed78e148 Mon Sep 17 00:00:00 2001
From: Melissa Alvarez
Date: Tue, 16 Jun 2020 14:29:11 -0400
Subject: [PATCH 10/41] use navigateToUrl instead of window location (#69167)
---
.../back_to_list_panel/back_to_list_panel.tsx | 57 +++++++++++--------
.../analytics_list/action_clone.tsx | 18 ++++--
.../source_selection/source_selection.tsx | 18 ++++--
3 files changed, 59 insertions(+), 34 deletions(-)
diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/back_to_list_panel/back_to_list_panel.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/back_to_list_panel/back_to_list_panel.tsx
index e437d27372a3e..b6b335afa53f5 100644
--- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/back_to_list_panel/back_to_list_panel.tsx
+++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/back_to_list_panel/back_to_list_panel.tsx
@@ -7,29 +7,38 @@
import React, { FC, Fragment } from 'react';
import { EuiCard, EuiHorizontalRule, EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
+import { useMlKibana } from '../../../../../contexts/kibana';
-function redirectToAnalyticsManagementPage() {
- window.location.href = '#/data_frame_analytics?';
-}
+export const BackToListPanel: FC = () => {
+ const {
+ services: {
+ application: { navigateToUrl },
+ },
+ } = useMlKibana();
-export const BackToListPanel: FC = () => (
-
-
- }
- title={i18n.translate('xpack.ml.dataframe.analytics.create.analyticsListCardTitle', {
- defaultMessage: 'Data Frame Analytics',
- })}
- description={i18n.translate(
- 'xpack.ml.dataframe.analytics.create.analyticsListCardDescription',
- {
- defaultMessage: 'Return to the analytics management page.',
- }
- )}
- onClick={redirectToAnalyticsManagementPage}
- data-test-subj="analyticsWizardCardManagement"
- />
-
-);
+ const redirectToAnalyticsManagementPage = async () => {
+ await navigateToUrl('#/data_frame_analytics?');
+ };
+
+ return (
+
+
+ }
+ title={i18n.translate('xpack.ml.dataframe.analytics.create.analyticsListCardTitle', {
+ defaultMessage: 'Data Frame Analytics',
+ })}
+ description={i18n.translate(
+ 'xpack.ml.dataframe.analytics.create.analyticsListCardDescription',
+ {
+ defaultMessage: 'Return to the analytics management page.',
+ }
+ )}
+ onClick={redirectToAnalyticsManagementPage}
+ data-test-subj="analyticsWizardCardManagement"
+ />
+
+ );
+};
diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/action_clone.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/action_clone.tsx
index e8b1cd1a5696a..df7dce7217fd4 100644
--- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/action_clone.tsx
+++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/action_clone.tsx
@@ -360,7 +360,14 @@ export const CloneAction: FC = ({ createAnalyticsForm, item })
defaultMessage: 'Clone job',
});
- const { notifications, savedObjects } = useMlKibana().services;
+ const {
+ services: {
+ application: { navigateToUrl },
+ notifications: { toasts },
+ savedObjects,
+ },
+ } = useMlKibana();
+
const savedObjectsClient = savedObjects.client;
const onClick = async () => {
@@ -385,7 +392,6 @@ export const CloneAction: FC = ({ createAnalyticsForm, item })
sourceIndexId = ip.id;
}
} catch (e) {
- const { toasts } = notifications;
const error = extractErrorMessage(e);
toasts.addDanger(
@@ -401,9 +407,11 @@ export const CloneAction: FC = ({ createAnalyticsForm, item })
}
if (sourceIndexId) {
- window.location.href = `ml#/data_frame_analytics/new_job?index=${encodeURIComponent(
- sourceIndexId
- )}&jobId=${item.config.id}`;
+ await navigateToUrl(
+ `ml#/data_frame_analytics/new_job?index=${encodeURIComponent(sourceIndexId)}&jobId=${
+ item.config.id
+ }`
+ );
}
};
diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx
index d20afe93d2b9d..b03a58a02309d 100644
--- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx
+++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx
@@ -26,12 +26,20 @@ interface Props {
}
export const SourceSelection: FC = ({ onClose }) => {
- const { uiSettings, savedObjects } = useMlKibana().services;
+ const {
+ services: {
+ application: { navigateToUrl },
+ savedObjects,
+ uiSettings,
+ },
+ } = useMlKibana();
- const onSearchSelected = (id: string, type: string) => {
- window.location.href = `ml#/data_frame_analytics/new_job?${
- type === 'index-pattern' ? 'index' : 'savedSearchId'
- }=${encodeURIComponent(id)}`;
+ const onSearchSelected = async (id: string, type: string) => {
+ await navigateToUrl(
+ `ml#/data_frame_analytics/new_job?${
+ type === 'index-pattern' ? 'index' : 'savedSearchId'
+ }=${encodeURIComponent(id)}`
+ );
};
return (
From db1df7bed03f624dca78630830b9bb0395666b20 Mon Sep 17 00:00:00 2001
From: Spencer
Date: Tue, 16 Jun 2020 12:57:34 -0700
Subject: [PATCH 11/41] [kbn/optimizer] fix windows compatibility (#69304)
Co-authored-by: spalger
---
.../src/optimizer/observe_worker.ts | 66 +++++++++++++++----
.../src/worker/entry_point_creator.ts | 10 ++-
.../kbn-optimizer/src/worker/run_worker.ts | 38 +++++++++--
.../src/worker/webpack.config.ts | 14 ++--
4 files changed, 102 insertions(+), 26 deletions(-)
diff --git a/packages/kbn-optimizer/src/optimizer/observe_worker.ts b/packages/kbn-optimizer/src/optimizer/observe_worker.ts
index 4527052fa821a..fef3efc13a516 100644
--- a/packages/kbn-optimizer/src/optimizer/observe_worker.ts
+++ b/packages/kbn-optimizer/src/optimizer/observe_worker.ts
@@ -22,7 +22,7 @@ import { inspect } from 'util';
import execa from 'execa';
import * as Rx from 'rxjs';
-import { map, takeUntil } from 'rxjs/operators';
+import { map, takeUntil, first, ignoreElements } from 'rxjs/operators';
import { isWorkerMsg, WorkerConfig, WorkerMsg, Bundle, BundleRefs } from '../common';
@@ -68,19 +68,11 @@ if (inspectFlagIndex !== -1) {
function usingWorkerProc(
config: OptimizerConfig,
- workerConfig: WorkerConfig,
- bundles: Bundle[],
fn: (proc: execa.ExecaChildProcess) => Rx.Observable
) {
return Rx.using(
(): ProcResource => {
- const args = [
- JSON.stringify(workerConfig),
- JSON.stringify(bundles.map((b) => b.toSpec())),
- BundleRefs.fromBundles(config.bundles).toSpecJson(),
- ];
-
- const proc = execa.node(require.resolve('../worker/run_worker'), args, {
+ const proc = execa.node(require.resolve('../worker/run_worker'), [], {
nodeOptions: [
...(inspectFlag && config.inspectWorkers
? [`${inspectFlag}=${inspectPortCounter++}`]
@@ -129,6 +121,51 @@ function observeStdio$(stream: Readable, name: WorkerStdio['stream']) {
);
}
+/**
+ * We used to pass configuration to the worker as JSON encoded arguments, but they
+ * grew too large for argv, especially on Windows, so we had to move to an async init
+ * where we send the args over IPC. To keep the logic simple we basically mock the
+ * argv behavior and don't use complicated messages or anything so that state can
+ * be initialized in the worker before most of the code is run.
+ */
+function initWorker(
+ proc: execa.ExecaChildProcess,
+ config: OptimizerConfig,
+ workerConfig: WorkerConfig,
+ bundles: Bundle[]
+) {
+ const msg$ = Rx.fromEvent<[unknown]>(proc, 'message').pipe(
+ // validate the initialization messages from the process
+ map(([msg]) => {
+ if (typeof msg === 'string') {
+ switch (msg) {
+ case 'init':
+ return 'init' as const;
+ case 'ready':
+ return 'ready' as const;
+ }
+ }
+
+ throw new Error(`unexpected message from worker while initializing: [${inspect(msg)}]`);
+ })
+ );
+
+ return Rx.concat(
+ msg$.pipe(first((msg) => msg === 'init')),
+ Rx.defer(() => {
+ proc.send({
+ args: [
+ JSON.stringify(workerConfig),
+ JSON.stringify(bundles.map((b) => b.toSpec())),
+ BundleRefs.fromBundles(config.bundles).toSpecJson(),
+ ],
+ });
+ return [];
+ }),
+ msg$.pipe(first((msg) => msg === 'ready'))
+ ).pipe(ignoreElements());
+}
+
/**
* Start a worker process with the specified `workerConfig` and
* `bundles` and return an observable of the events related to
@@ -140,10 +177,11 @@ export function observeWorker(
workerConfig: WorkerConfig,
bundles: Bundle[]
): Rx.Observable {
- return usingWorkerProc(config, workerConfig, bundles, (proc) => {
- let lastMsg: WorkerMsg;
+ return usingWorkerProc(config, (proc) => {
+ const init$ = initWorker(proc, config, workerConfig, bundles);
- return Rx.merge(
+ let lastMsg: WorkerMsg;
+ const worker$: Rx.Observable = Rx.merge(
Rx.of({
type: 'worker started',
bundles,
@@ -201,5 +239,7 @@ export function observeWorker(
)
)
);
+
+ return Rx.concat(init$, worker$);
});
}
diff --git a/packages/kbn-optimizer/src/worker/entry_point_creator.ts b/packages/kbn-optimizer/src/worker/entry_point_creator.ts
index a613e3e8925a4..f8f41b2e13422 100644
--- a/packages/kbn-optimizer/src/worker/entry_point_creator.ts
+++ b/packages/kbn-optimizer/src/worker/entry_point_creator.ts
@@ -17,9 +17,13 @@
* under the License.
*/
-module.exports = function ({ entries }: { entries: Array<{ importId: string; relPath: string }> }) {
- const lines = entries.map(({ importId, relPath }) => [
- `__kbnBundles__.define('${importId}', __webpack_require__, require.resolve('./${relPath}'))`,
+module.exports = function ({
+ entries,
+}: {
+ entries: Array<{ importId: string; requirePath: string }>;
+}) {
+ const lines = entries.map(({ importId, requirePath }) => [
+ `__kbnBundles__.define('${importId}', __webpack_require__, require.resolve('${requirePath}'))`,
]);
return {
diff --git a/packages/kbn-optimizer/src/worker/run_worker.ts b/packages/kbn-optimizer/src/worker/run_worker.ts
index 178637d39ab00..781cf83624a1e 100644
--- a/packages/kbn-optimizer/src/worker/run_worker.ts
+++ b/packages/kbn-optimizer/src/worker/run_worker.ts
@@ -17,7 +17,10 @@
* under the License.
*/
+import { inspect } from 'util';
+
import * as Rx from 'rxjs';
+import { take, mergeMap } from 'rxjs/operators';
import {
parseBundles,
@@ -80,15 +83,38 @@ setInterval(() => {
}
}, 1000).unref();
+function assertInitMsg(msg: unknown): asserts msg is { args: string[] } {
+ if (typeof msg !== 'object' || !msg) {
+ throw new Error(`expected init message to be an object: ${inspect(msg)}`);
+ }
+
+ const { args } = msg as Record;
+ if (!args || !Array.isArray(args) || !args.every((a) => typeof a === 'string')) {
+ throw new Error(
+ `expected init message to have an 'args' property that's an array of strings: ${inspect(msg)}`
+ );
+ }
+}
+
Rx.defer(() => {
- const workerConfig = parseWorkerConfig(process.argv[2]);
- const bundles = parseBundles(process.argv[3]);
- const bundleRefs = BundleRefs.parseSpec(process.argv[4]);
+ process.send!('init');
+
+ return Rx.fromEvent<[unknown]>(process as any, 'message').pipe(
+ take(1),
+ mergeMap(([msg]) => {
+ assertInitMsg(msg);
+ process.send!('ready');
+
+ const workerConfig = parseWorkerConfig(msg.args[0]);
+ const bundles = parseBundles(msg.args[1]);
+ const bundleRefs = BundleRefs.parseSpec(msg.args[2]);
- // set BROWSERSLIST_ENV so that style/babel loaders see it before running compilers
- process.env.BROWSERSLIST_ENV = workerConfig.browserslistEnv;
+ // set BROWSERSLIST_ENV so that style/babel loaders see it before running compilers
+ process.env.BROWSERSLIST_ENV = workerConfig.browserslistEnv;
- return runCompilers(workerConfig, bundles, bundleRefs);
+ return runCompilers(workerConfig, bundles, bundleRefs);
+ })
+ );
}).subscribe(
(msg) => {
send(msg);
diff --git a/packages/kbn-optimizer/src/worker/webpack.config.ts b/packages/kbn-optimizer/src/worker/webpack.config.ts
index e361b186c30e0..11f5544cd9274 100644
--- a/packages/kbn-optimizer/src/worker/webpack.config.ts
+++ b/packages/kbn-optimizer/src/worker/webpack.config.ts
@@ -100,10 +100,16 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:
entries: bundle.publicDirNames.map((name) => {
const absolute = Path.resolve(bundle.contextDir, name);
const newContext = Path.dirname(ENTRY_CREATOR);
- return {
- importId: `${bundle.type}/${bundle.id}/${name}`,
- relPath: Path.relative(newContext, absolute),
- };
+ const importId = `${bundle.type}/${bundle.id}/${name}`;
+
+ // relative path from context of the ENTRY_CREATOR, with linux path separators
+ let requirePath = Path.relative(newContext, absolute).split('\\').join('/');
+ if (!requirePath.startsWith('.')) {
+ // ensure requirePath is identified by node as relative
+ requirePath = `./${requirePath}`;
+ }
+
+ return { importId, requirePath };
}),
},
},
From ade4c8dded247e4d29b9eb5b9baa934e214aa676 Mon Sep 17 00:00:00 2001
From: Lukas Olson
Date: Tue, 16 Jun 2020 13:20:52 -0700
Subject: [PATCH 12/41] [Search service] Refactor the way server-side search
strategies are registered (#68452)
* [search] Refactor the way search strategies are registered/retrieved on the server
* Fix types and tests and update docs
* Fix failing test
* Fix build of example plugin
* Fix functional test
* Make server strategies sync
Co-authored-by: Liza K
---
...in-plugins-data-server.irequesttypesmap.md | 2 +
...n-plugins-data-server.iresponsetypesmap.md | 2 +
...bana-plugin-plugins-data-server.isearch.md | 2 +-
...lugin-plugins-data-server.isearchcancel.md | 2 +-
...gins-data-server.isearchcontext.config_.md | 11 --
...plugins-data-server.isearchcontext.core.md | 11 --
...ugin-plugins-data-server.isearchcontext.md | 19 ---
...ugin-plugins-data-server.isearchoptions.md | 2 +-
...ugins-data-server.isearchoptions.signal.md | 2 +
...plugin-plugins-data-server.isearchsetup.md | 18 +++
...ver.isearchsetup.registersearchstrategy.md | 13 ++
...a-server.isearchstart.getsearchstrategy.md | 13 ++
...plugin-plugins-data-server.isearchstart.md | 18 +++
...gins-data-server.isearchstrategy.cancel.md | 11 ++
...gin-plugins-data-server.isearchstrategy.md | 21 ++++
...gins-data-server.isearchstrategy.search.md | 11 ++
.../kibana-plugin-plugins-data-server.md | 10 +-
...plugin-plugins-data-server.plugin.setup.md | 8 +-
...plugin-plugins-data-server.plugin.start.md | 6 +-
...-plugin-plugins-data-server.pluginstart.md | 1 +
...-plugins-data-server.pluginstart.search.md | 11 ++
...ins-data-server.tsearchstrategyprovider.md | 13 --
...ugin-plugins-data-server.tstrategytypes.md | 19 +++
.../server/async_demo_search_strategy.ts | 50 ++++----
.../server/demo_search_strategy.ts | 8 +-
examples/demo_search/server/index.ts | 5 +-
examples/demo_search/server/plugin.ts | 15 +--
.../search_explorer/public/search_api.tsx | 13 --
.../mocks.ts} | 13 +-
src/plugins/data/server/index.ts | 6 +-
.../{search/i_search_context.ts => mocks.ts} | 24 +++-
src/plugins/data/server/plugin.ts | 11 +-
.../data/server/search/create_api.test.ts | 71 -----------
src/plugins/data/server/search/create_api.ts | 58 ---------
.../es_search/es_search_strategy.test.ts | 55 +++------
.../search/es_search/es_search_strategy.ts | 22 ++--
src/plugins/data/server/search/i_search.ts | 55 ---------
.../data/server/search/i_search_setup.ts | 40 -------
.../data/server/search/i_search_strategy.ts | 67 -----------
src/plugins/data/server/search/index.ts | 14 +--
src/plugins/data/server/search/mocks.ts | 18 +--
src/plugins/data/server/search/routes.test.ts | 67 ++++-------
src/plugins/data/server/search/routes.ts | 19 ++-
.../data/server/search/search_service.test.ts | 19 +--
.../data/server/search/search_service.ts | 92 +++++----------
.../data/server/search/strategy_types.ts | 39 ------
src/plugins/data/server/search/types.ts | 111 ++++++++++++++++++
src/plugins/data/server/server.api.md | 75 +++++++-----
.../core_plugins/legacy_plugins.ts | 2 +-
x-pack/plugins/data_enhanced/server/plugin.ts | 5 +-
.../server/search/es_search_strategy.test.ts | 69 +++--------
.../server/search/es_search_strategy.ts | 24 ++--
52 files changed, 552 insertions(+), 741 deletions(-)
delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.config_.md
delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.core.md
delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.md
create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md
create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md
create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md
create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md
create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.cancel.md
create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.md
create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.search.md
create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.pluginstart.search.md
delete mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tsearchstrategyprovider.md
create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tstrategytypes.md
rename src/plugins/data/server/{search/i_route_handler_search_context.ts => field_formats/mocks.ts} (80%)
rename src/plugins/data/server/{search/i_search_context.ts => mocks.ts} (60%)
delete mode 100644 src/plugins/data/server/search/create_api.test.ts
delete mode 100644 src/plugins/data/server/search/create_api.ts
delete mode 100644 src/plugins/data/server/search/i_search.ts
delete mode 100644 src/plugins/data/server/search/i_search_setup.ts
delete mode 100644 src/plugins/data/server/search/i_search_strategy.ts
delete mode 100644 src/plugins/data/server/search/strategy_types.ts
create mode 100644 src/plugins/data/server/search/types.ts
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.md
index a9bb8f1eb9d6d..3f5e4ba0f7799 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.irequesttypesmap.md
@@ -4,6 +4,8 @@
## IRequestTypesMap interface
+The map of search strategy IDs to the corresponding request type definitions.
+
Signature:
```typescript
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.md
index fe5fa0a5d3a33..629ab4347eda8 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iresponsetypesmap.md
@@ -4,6 +4,8 @@
## IResponseTypesMap interface
+The map of search strategy IDs to the corresponding response type definitions.
+
Signature:
```typescript
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearch.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearch.md
index 6e037f5161b53..96991579c1716 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearch.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearch.md
@@ -7,5 +7,5 @@
Signature:
```typescript
-export declare type ISearch = (request: IRequestTypesMap[T], options?: ISearchOptions) => Promise;
+export declare type ISearch = (context: RequestHandlerContext, request: IRequestTypesMap[T], options?: ISearchOptions) => Promise;
```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcancel.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcancel.md
index 99c30515e8da6..b5a687d1b19d8 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcancel.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcancel.md
@@ -7,5 +7,5 @@
Signature:
```typescript
-export declare type ISearchCancel = (id: string) => Promise;
+export declare type ISearchCancel = (context: RequestHandlerContext, id: string) => Promise;
```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.config_.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.config_.md
deleted file mode 100644
index 364d44dba758a..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.config_.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchContext](./kibana-plugin-plugins-data-server.isearchcontext.md) > [config$](./kibana-plugin-plugins-data-server.isearchcontext.config_.md)
-
-## ISearchContext.config$ property
-
-Signature:
-
-```typescript
-config$: Observable;
-```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.core.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.core.md
deleted file mode 100644
index 9d571c25d94bd..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.core.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchContext](./kibana-plugin-plugins-data-server.isearchcontext.md) > [core](./kibana-plugin-plugins-data-server.isearchcontext.core.md)
-
-## ISearchContext.core property
-
-Signature:
-
-```typescript
-core: CoreSetup;
-```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.md
deleted file mode 100644
index 1c3c5ec78f894..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchcontext.md
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchContext](./kibana-plugin-plugins-data-server.isearchcontext.md)
-
-## ISearchContext interface
-
-Signature:
-
-```typescript
-export interface ISearchContext
-```
-
-## Properties
-
-| Property | Type | Description |
-| --- | --- | --- |
-| [config$](./kibana-plugin-plugins-data-server.isearchcontext.config_.md) | Observable<SharedGlobalConfig>
| |
-| [core](./kibana-plugin-plugins-data-server.isearchcontext.core.md) | CoreSetup
| |
-
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md
index 0319048f4418b..49412fc42d3b5 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.md
@@ -14,5 +14,5 @@ export interface ISearchOptions
| Property | Type | Description |
| --- | --- | --- |
-| [signal](./kibana-plugin-plugins-data-server.isearchoptions.signal.md) | AbortSignal
| |
+| [signal](./kibana-plugin-plugins-data-server.isearchoptions.signal.md) | AbortSignal
| An AbortSignal
that allows the caller of search
to abort a search request. |
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.signal.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.signal.md
index 7da5c182b2e0f..948dfd66da7a0 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.signal.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchoptions.signal.md
@@ -4,6 +4,8 @@
## ISearchOptions.signal property
+An `AbortSignal` that allows the caller of `search` to abort a search request.
+
Signature:
```typescript
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md
new file mode 100644
index 0000000000000..93e253b2e98a3
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md
@@ -0,0 +1,18 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchSetup](./kibana-plugin-plugins-data-server.isearchsetup.md)
+
+## ISearchSetup interface
+
+Signature:
+
+```typescript
+export interface ISearchSetup
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [registerSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md) | TRegisterSearchStrategy
| Extension point exposed for other plugins to register their own search strategies. |
+
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md
new file mode 100644
index 0000000000000..c06b8b00806bf
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchSetup](./kibana-plugin-plugins-data-server.isearchsetup.md) > [registerSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md)
+
+## ISearchSetup.registerSearchStrategy property
+
+Extension point exposed for other plugins to register their own search strategies.
+
+Signature:
+
+```typescript
+registerSearchStrategy: TRegisterSearchStrategy;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md
new file mode 100644
index 0000000000000..0ba4bf578d6cc
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchStart](./kibana-plugin-plugins-data-server.isearchstart.md) > [getSearchStrategy](./kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md)
+
+## ISearchStart.getSearchStrategy property
+
+Get other registered search strategies. For example, if a new strategy needs to use the already-registered ES search strategy, it can use this function to accomplish that.
+
+Signature:
+
+```typescript
+getSearchStrategy: TGetSearchStrategy;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md
new file mode 100644
index 0000000000000..abe72396f61e1
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md
@@ -0,0 +1,18 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchStart](./kibana-plugin-plugins-data-server.isearchstart.md)
+
+## ISearchStart interface
+
+Signature:
+
+```typescript
+export interface ISearchStart
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [getSearchStrategy](./kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md) | TGetSearchStrategy
| Get other registered search strategies. For example, if a new strategy needs to use the already-registered ES search strategy, it can use this function to accomplish that. |
+
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.cancel.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.cancel.md
new file mode 100644
index 0000000000000..c1e0c3d9f2330
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.cancel.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchStrategy](./kibana-plugin-plugins-data-server.isearchstrategy.md) > [cancel](./kibana-plugin-plugins-data-server.isearchstrategy.cancel.md)
+
+## ISearchStrategy.cancel property
+
+Signature:
+
+```typescript
+cancel?: ISearchCancel;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.md
new file mode 100644
index 0000000000000..167c6ab6e5a16
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.md
@@ -0,0 +1,21 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchStrategy](./kibana-plugin-plugins-data-server.isearchstrategy.md)
+
+## ISearchStrategy interface
+
+Search strategy interface contains a search method that takes in a request and returns a promise that resolves to a response.
+
+Signature:
+
+```typescript
+export interface ISearchStrategy
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [cancel](./kibana-plugin-plugins-data-server.isearchstrategy.cancel.md) | ISearchCancel<T>
| |
+| [search](./kibana-plugin-plugins-data-server.isearchstrategy.search.md) | ISearch<T>
| |
+
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.search.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.search.md
new file mode 100644
index 0000000000000..34a17ca87807a
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstrategy.search.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchStrategy](./kibana-plugin-plugins-data-server.isearchstrategy.md) > [search](./kibana-plugin-plugins-data-server.isearchstrategy.search.md)
+
+## ISearchStrategy.search property
+
+Signature:
+
+```typescript
+search: ISearch;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md
index 0efbe8ed4ed64..f492ba2843a69 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md
@@ -39,10 +39,12 @@
| [IIndexPattern](./kibana-plugin-plugins-data-server.iindexpattern.md) | |
| [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) | Use data plugin interface instead |
| [IndexPatternFieldDescriptor](./kibana-plugin-plugins-data-server.indexpatternfielddescriptor.md) | |
-| [IRequestTypesMap](./kibana-plugin-plugins-data-server.irequesttypesmap.md) | |
-| [IResponseTypesMap](./kibana-plugin-plugins-data-server.iresponsetypesmap.md) | |
-| [ISearchContext](./kibana-plugin-plugins-data-server.isearchcontext.md) | |
+| [IRequestTypesMap](./kibana-plugin-plugins-data-server.irequesttypesmap.md) | The map of search strategy IDs to the corresponding request type definitions. |
+| [IResponseTypesMap](./kibana-plugin-plugins-data-server.iresponsetypesmap.md) | The map of search strategy IDs to the corresponding response type definitions. |
| [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) | |
+| [ISearchSetup](./kibana-plugin-plugins-data-server.isearchsetup.md) | |
+| [ISearchStart](./kibana-plugin-plugins-data-server.isearchstart.md) | |
+| [ISearchStrategy](./kibana-plugin-plugins-data-server.isearchstrategy.md) | Search strategy interface contains a search method that takes in a request and returns a promise that resolves to a response. |
| [KueryNode](./kibana-plugin-plugins-data-server.kuerynode.md) | |
| [PluginSetup](./kibana-plugin-plugins-data-server.pluginsetup.md) | |
| [PluginStart](./kibana-plugin-plugins-data-server.pluginstart.md) | |
@@ -73,5 +75,5 @@
| [ISearch](./kibana-plugin-plugins-data-server.isearch.md) | |
| [ISearchCancel](./kibana-plugin-plugins-data-server.isearchcancel.md) | |
| [ParsedInterval](./kibana-plugin-plugins-data-server.parsedinterval.md) | |
-| [TSearchStrategyProvider](./kibana-plugin-plugins-data-server.tsearchstrategyprovider.md) | Search strategy provider creates an instance of a search strategy with the request handler context bound to it. This way every search strategy can use whatever information they require from the request context. |
+| [TStrategyTypes](./kibana-plugin-plugins-data-server.tstrategytypes.md) | Contains all known strategy type identifiers that will be used to map to request and response shapes. Plugins that wish to add their own custom search strategies should extend this type via:const MY\_STRATEGY = 'MY\_STRATEGY';declare module 'src/plugins/search/server' { export interface IRequestTypesMap { \[MY\_STRATEGY\]: IMySearchRequest; }export interface IResponseTypesMap { \[MY\_STRATEGY\]: IMySearchResponse } } |
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md
index bd617990a00a2..13c69d6bf7548 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md
@@ -7,11 +7,11 @@
Signature:
```typescript
-setup(core: CoreSetup, { usageCollection }: DataPluginSetupDependencies): {
+setup(core: CoreSetup