improve type safety for integration test helpers (#98731)
* convert functional_tests/lib into TS * convert ES cluster factory into TS * fix exports from kbn-test * fix core test_helpers * remove legacy ES client usage in ui_settings tests * remove unnecessary ts-expect-errors comments * initialize DEFAULT_SETTINGS_WITH_CORE_PLUGINS lazily to prevent failure when imported outside of FTR context * throw an exception on invalid process.env.TEST_ES_PORT
This commit is contained in:
parent
05e2ab4df1
commit
33eecc2979
|
@ -7,10 +7,10 @@
|
|||
*/
|
||||
|
||||
import { kibanaPackageJson as pkg } from '@kbn/dev-utils';
|
||||
import url, { format as formatUrl } from 'url';
|
||||
import Url from 'url';
|
||||
import { adminTestUser } from '../kbn';
|
||||
|
||||
export const esTestConfig = new (class EsTestConfig {
|
||||
class EsTestConfig {
|
||||
getVersion() {
|
||||
return process.env.TEST_ES_BRANCH || pkg.version;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ export const esTestConfig = new (class EsTestConfig {
|
|||
}
|
||||
|
||||
getUrl() {
|
||||
return formatUrl(this.getUrlParts());
|
||||
return Url.format(this.getUrlParts());
|
||||
}
|
||||
|
||||
getBuildFrom() {
|
||||
|
@ -34,14 +34,19 @@ export const esTestConfig = new (class EsTestConfig {
|
|||
getUrlParts() {
|
||||
// Allow setting one complete TEST_ES_URL for Es like https://elastic:changeme@myCloudInstance:9200
|
||||
if (process.env.TEST_ES_URL) {
|
||||
const testEsUrl = url.parse(process.env.TEST_ES_URL);
|
||||
const testEsUrl = Url.parse(process.env.TEST_ES_URL);
|
||||
if (!testEsUrl.port) {
|
||||
throw new Error(
|
||||
`process.env.TEST_ES_URL must contain port. given: ${process.env.TEST_ES_URL}`
|
||||
);
|
||||
}
|
||||
return {
|
||||
// have to remove the ":" off protocol
|
||||
protocol: testEsUrl.protocol.slice(0, -1),
|
||||
protocol: testEsUrl.protocol?.slice(0, -1),
|
||||
hostname: testEsUrl.hostname,
|
||||
port: parseInt(testEsUrl.port, 10),
|
||||
username: testEsUrl.auth.split(':')[0],
|
||||
password: testEsUrl.auth.split(':')[1],
|
||||
username: testEsUrl.auth?.split(':')[0],
|
||||
password: testEsUrl.auth?.split(':')[1],
|
||||
auth: testEsUrl.auth,
|
||||
};
|
||||
}
|
||||
|
@ -49,15 +54,25 @@ export const esTestConfig = new (class EsTestConfig {
|
|||
const username = process.env.TEST_ES_USERNAME || adminTestUser.username;
|
||||
const password = process.env.TEST_ES_PASSWORD || adminTestUser.password;
|
||||
|
||||
const port = process.env.TEST_ES_PORT ? parseInt(process.env.TEST_ES_PORT, 10) : 9220;
|
||||
|
||||
if (Number.isNaN(port)) {
|
||||
throw new Error(
|
||||
`process.env.TEST_ES_PORT must contain a valid port. given: ${process.env.TEST_ES_PORT}`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
// Allow setting any individual component(s) of the URL,
|
||||
// or use default values (username and password from ../kbn/users.js)
|
||||
protocol: process.env.TEST_ES_PROTOCOL || 'http',
|
||||
hostname: process.env.TEST_ES_HOSTNAME || 'localhost',
|
||||
port: parseInt(process.env.TEST_ES_PORT, 10) || 9220,
|
||||
port,
|
||||
auth: `${username}:${password}`,
|
||||
username: username,
|
||||
password: password,
|
||||
username,
|
||||
password,
|
||||
};
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
export const esTestConfig = new EsTestConfig();
|
|
@ -6,5 +6,5 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
export { createLegacyEsTestCluster } from './legacy_es_test_cluster.js';
|
||||
export { createTestEsCluster } from './test_es_cluster';
|
||||
export { esTestConfig } from './es_test_config';
|
|
@ -6,25 +6,49 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { resolve } from 'path';
|
||||
import Path from 'path';
|
||||
import { format } from 'url';
|
||||
import { get, toPath } from 'lodash';
|
||||
import del from 'del';
|
||||
// @ts-expect-error in js
|
||||
import { Cluster } from '@kbn/es';
|
||||
import { Client } from '@elastic/elasticsearch';
|
||||
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
|
||||
import type { ToolingLog } from '@kbn/dev-utils';
|
||||
import { CI_PARALLEL_PROCESS_PREFIX } from '../ci_parallel_process_prefix';
|
||||
import { esTestConfig } from './es_test_config';
|
||||
import { Client } from '@elastic/elasticsearch';
|
||||
|
||||
import { KIBANA_ROOT } from '../';
|
||||
const path = require('path');
|
||||
const del = require('del');
|
||||
|
||||
export function createLegacyEsTestCluster(options = {}) {
|
||||
interface TestClusterFactoryOptions {
|
||||
port?: number;
|
||||
password?: string;
|
||||
license?: 'basic' | 'trial'; // | 'oss'
|
||||
basePath?: string;
|
||||
esFrom?: string;
|
||||
/**
|
||||
* Path to data archive snapshot to run Elasticsearch with.
|
||||
* To prepare the the snapshot:
|
||||
* - run Elasticsearch server
|
||||
* - index necessary data
|
||||
* - stop Elasticsearch server
|
||||
* - go to Elasticsearch folder: cd .es/${ELASTICSEARCH_VERSION}
|
||||
* - archive data folder: zip -r my_archive.zip data
|
||||
* */
|
||||
dataArchive?: string;
|
||||
esArgs?: string[];
|
||||
esEnvVars?: Record<string, any>;
|
||||
clusterName?: string;
|
||||
log: ToolingLog;
|
||||
ssl?: boolean;
|
||||
}
|
||||
|
||||
export function createTestEsCluster(options: TestClusterFactoryOptions) {
|
||||
const {
|
||||
port = esTestConfig.getPort(),
|
||||
password = 'changeme',
|
||||
license = 'basic',
|
||||
log,
|
||||
basePath = resolve(KIBANA_ROOT, '.es'),
|
||||
basePath = Path.resolve(KIBANA_ROOT, '.es'),
|
||||
esFrom = esTestConfig.getBuildFrom(),
|
||||
dataArchive,
|
||||
esArgs: customEsArgs = [],
|
||||
|
@ -45,8 +69,8 @@ export function createLegacyEsTestCluster(options = {}) {
|
|||
|
||||
const config = {
|
||||
version: esTestConfig.getVersion(),
|
||||
installPath: resolve(basePath, clusterName),
|
||||
sourcePath: resolve(KIBANA_ROOT, '../elasticsearch'),
|
||||
installPath: Path.resolve(basePath, clusterName),
|
||||
sourcePath: Path.resolve(KIBANA_ROOT, '../elasticsearch'),
|
||||
password,
|
||||
license,
|
||||
basePath,
|
||||
|
@ -70,7 +94,7 @@ export function createLegacyEsTestCluster(options = {}) {
|
|||
installPath = (await cluster.installSource(config)).installPath;
|
||||
} else if (esFrom === 'snapshot') {
|
||||
installPath = (await cluster.installSnapshot(config)).installPath;
|
||||
} else if (path.isAbsolute(esFrom)) {
|
||||
} else if (Path.isAbsolute(esFrom)) {
|
||||
installPath = esFrom;
|
||||
} else {
|
||||
throw new Error(`unknown option esFrom "${esFrom}"`);
|
||||
|
@ -101,16 +125,12 @@ export function createLegacyEsTestCluster(options = {}) {
|
|||
/**
|
||||
* Returns an ES Client to the configured cluster
|
||||
*/
|
||||
getClient() {
|
||||
getClient(): KibanaClient {
|
||||
return new Client({
|
||||
node: this.getUrl(),
|
||||
});
|
||||
}
|
||||
|
||||
getCallCluster() {
|
||||
return createCallCluster(this.getClient());
|
||||
}
|
||||
|
||||
getUrl() {
|
||||
const parts = esTestConfig.getUrlParts();
|
||||
parts.port = port;
|
||||
|
@ -119,22 +139,3 @@ export function createLegacyEsTestCluster(options = {}) {
|
|||
}
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a callCluster function that properly executes methods on an
|
||||
* elasticsearch-js client
|
||||
*
|
||||
* @param {elasticsearch.Client} esClient
|
||||
* @return {Function}
|
||||
*/
|
||||
function createCallCluster(esClient) {
|
||||
return function callCluster(method, params) {
|
||||
const path = toPath(method);
|
||||
const contextPath = path.slice(0, -1);
|
||||
|
||||
const action = get(esClient, path);
|
||||
const context = contextPath.length ? get(esClient, contextPath) : esClient;
|
||||
|
||||
return action.call(context, params);
|
||||
};
|
||||
}
|
|
@ -9,14 +9,25 @@
|
|||
import fs from 'fs';
|
||||
import util from 'util';
|
||||
import { format as formatUrl } from 'url';
|
||||
|
||||
import request from 'request';
|
||||
import { delay } from 'bluebird';
|
||||
import type { ToolingLog } from '@kbn/dev-utils';
|
||||
|
||||
export const DEFAULT_SUPERUSER_PASS = 'changeme';
|
||||
|
||||
const readFile = util.promisify(fs.readFile);
|
||||
|
||||
function delay(delayMs: number) {
|
||||
return new Promise((res) => setTimeout(res, delayMs));
|
||||
}
|
||||
|
||||
interface UpdateCredentialsOptions {
|
||||
port: number;
|
||||
auth: string;
|
||||
username: string;
|
||||
password: string;
|
||||
retries?: number;
|
||||
protocol: string;
|
||||
caCert?: Buffer | string;
|
||||
}
|
||||
async function updateCredentials({
|
||||
port,
|
||||
auth,
|
||||
|
@ -25,27 +36,28 @@ async function updateCredentials({
|
|||
retries = 10,
|
||||
protocol,
|
||||
caCert,
|
||||
}) {
|
||||
const result = await new Promise((resolve, reject) =>
|
||||
request(
|
||||
{
|
||||
method: 'PUT',
|
||||
uri: formatUrl({
|
||||
protocol: `${protocol}:`,
|
||||
auth,
|
||||
hostname: 'localhost',
|
||||
port,
|
||||
pathname: `/_security/user/${username}/_password`,
|
||||
}),
|
||||
json: true,
|
||||
body: { password },
|
||||
ca: caCert,
|
||||
},
|
||||
(err, httpResponse, body) => {
|
||||
if (err) return reject(err);
|
||||
resolve({ httpResponse, body });
|
||||
}
|
||||
)
|
||||
}: UpdateCredentialsOptions): Promise<void> {
|
||||
const result = await new Promise<{ body: any; httpResponse: request.Response }>(
|
||||
(resolve, reject) =>
|
||||
request(
|
||||
{
|
||||
method: 'PUT',
|
||||
uri: formatUrl({
|
||||
protocol: `${protocol}:`,
|
||||
auth,
|
||||
hostname: 'localhost',
|
||||
port,
|
||||
pathname: `/_security/user/${username}/_password`,
|
||||
}),
|
||||
json: true,
|
||||
body: { password },
|
||||
ca: caCert,
|
||||
},
|
||||
(err, httpResponse, body) => {
|
||||
if (err) return reject(err);
|
||||
resolve({ httpResponse, body });
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
const { body, httpResponse } = result;
|
||||
|
@ -71,11 +83,25 @@ async function updateCredentials({
|
|||
throw new Error(`${statusCode} response, expected 200 -- ${JSON.stringify(body)}`);
|
||||
}
|
||||
|
||||
export async function setupUsers({ log, esPort, updates, protocol = 'http', caPath }) {
|
||||
interface SetupUsersOptions {
|
||||
log: ToolingLog;
|
||||
esPort: number;
|
||||
updates: Array<{ username: string; password: string; roles?: string[] }>;
|
||||
protocol?: string;
|
||||
caPath?: string;
|
||||
}
|
||||
|
||||
export async function setupUsers({
|
||||
log,
|
||||
esPort,
|
||||
updates,
|
||||
protocol = 'http',
|
||||
caPath,
|
||||
}: SetupUsersOptions): Promise<void> {
|
||||
// track the current credentials for the `elastic` user as
|
||||
// they will likely change as we apply updates
|
||||
let auth = `elastic:${DEFAULT_SUPERUSER_PASS}`;
|
||||
const caCert = caPath && (await readFile(caPath));
|
||||
const caCert = caPath ? await readFile(caPath) : undefined;
|
||||
|
||||
for (const { username, password, roles } of updates) {
|
||||
// If working with a built-in user, just change the password
|
||||
|
@ -95,6 +121,16 @@ export async function setupUsers({ log, esPort, updates, protocol = 'http', caPa
|
|||
}
|
||||
}
|
||||
|
||||
interface InserUserOptions {
|
||||
port: number;
|
||||
auth: string;
|
||||
username: string;
|
||||
password: string;
|
||||
roles?: string[];
|
||||
retries?: number;
|
||||
protocol: string;
|
||||
caCert?: Buffer | string;
|
||||
}
|
||||
async function insertUser({
|
||||
port,
|
||||
auth,
|
||||
|
@ -104,27 +140,28 @@ async function insertUser({
|
|||
retries = 10,
|
||||
protocol,
|
||||
caCert,
|
||||
}) {
|
||||
const result = await new Promise((resolve, reject) =>
|
||||
request(
|
||||
{
|
||||
method: 'POST',
|
||||
uri: formatUrl({
|
||||
protocol: `${protocol}:`,
|
||||
auth,
|
||||
hostname: 'localhost',
|
||||
port,
|
||||
pathname: `/_security/user/${username}`,
|
||||
}),
|
||||
json: true,
|
||||
body: { password, roles },
|
||||
ca: caCert,
|
||||
},
|
||||
(err, httpResponse, body) => {
|
||||
if (err) return reject(err);
|
||||
resolve({ httpResponse, body });
|
||||
}
|
||||
)
|
||||
}: InserUserOptions): Promise<void> {
|
||||
const result = await new Promise<{ body: any; httpResponse: request.Response }>(
|
||||
(resolve, reject) =>
|
||||
request(
|
||||
{
|
||||
method: 'POST',
|
||||
uri: formatUrl({
|
||||
protocol: `${protocol}:`,
|
||||
auth,
|
||||
hostname: 'localhost',
|
||||
port,
|
||||
pathname: `/_security/user/${username}`,
|
||||
}),
|
||||
json: true,
|
||||
body: { password, roles },
|
||||
ca: caCert,
|
||||
},
|
||||
(err, httpResponse, body) => {
|
||||
if (err) return reject(err);
|
||||
resolve({ httpResponse, body });
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
const { body, httpResponse } = result;
|
|
@ -11,7 +11,7 @@ import { resolve, relative } from 'path';
|
|||
|
||||
// resolve() treats relative paths as relative to process.cwd(),
|
||||
// so to return a relative path we use relative()
|
||||
function resolveRelative(path) {
|
||||
function resolveRelative(path: string) {
|
||||
return relative(process.cwd(), resolve(path));
|
||||
}
|
||||
|
|
@ -7,12 +7,24 @@
|
|||
*/
|
||||
|
||||
import { resolve } from 'path';
|
||||
import type { ToolingLog } from '@kbn/dev-utils';
|
||||
import { KIBANA_ROOT } from './paths';
|
||||
import { createLegacyEsTestCluster } from '../../legacy_es';
|
||||
import type { Config } from '../../functional_test_runner/';
|
||||
import { createTestEsCluster } from '../../es';
|
||||
|
||||
import { setupUsers, DEFAULT_SUPERUSER_PASS } from './auth';
|
||||
|
||||
export async function runElasticsearch({ config, options }) {
|
||||
interface RunElasticsearchOptions {
|
||||
log: ToolingLog;
|
||||
esFrom: string;
|
||||
}
|
||||
export async function runElasticsearch({
|
||||
config,
|
||||
options,
|
||||
}: {
|
||||
config: Config;
|
||||
options: RunElasticsearchOptions;
|
||||
}) {
|
||||
const { log, esFrom } = options;
|
||||
const ssl = config.get('esTestCluster.ssl');
|
||||
const license = config.get('esTestCluster.license');
|
||||
|
@ -20,7 +32,7 @@ export async function runElasticsearch({ config, options }) {
|
|||
const esEnvVars = config.get('esTestCluster.serverEnvVars');
|
||||
const isSecurityEnabled = esArgs.includes('xpack.security.enabled=true');
|
||||
|
||||
const cluster = createLegacyEsTestCluster({
|
||||
const cluster = createTestEsCluster({
|
||||
port: config.get('servers.elasticsearch.port'),
|
||||
password: isSecurityEnabled
|
||||
? DEFAULT_SUPERUSER_PASS
|
||||
|
@ -50,7 +62,7 @@ export async function runElasticsearch({ config, options }) {
|
|||
return cluster;
|
||||
}
|
||||
|
||||
function getRelativeCertificateAuthorityPath(esConfig = []) {
|
||||
function getRelativeCertificateAuthorityPath(esConfig: string[] = []) {
|
||||
const caConfig = esConfig.find(
|
||||
(config) => config.indexOf('--elasticsearch.ssl.certificateAuthorities') === 0
|
||||
);
|
|
@ -18,24 +18,17 @@ import {
|
|||
// @internal
|
||||
export { runTestsCli, processRunTestsCliOptions, startServersCli, processStartServersCliOptions };
|
||||
|
||||
// @ts-ignore not typed yet
|
||||
// @ts-expect-error not typed yet
|
||||
// @internal
|
||||
export { runTests, startServers } from './functional_tests/tasks';
|
||||
|
||||
// @ts-ignore not typed yet
|
||||
// @internal
|
||||
export { KIBANA_ROOT } from './functional_tests/lib/paths';
|
||||
|
||||
// @ts-ignore not typed yet
|
||||
// @internal
|
||||
export { esTestConfig, createLegacyEsTestCluster } from './legacy_es';
|
||||
export { esTestConfig, createTestEsCluster } from './es';
|
||||
|
||||
// @ts-ignore not typed yet
|
||||
// @internal
|
||||
export { kbnTestConfig, kibanaServerTestUser, kibanaTestUser, adminTestUser } from './kbn';
|
||||
|
||||
// @ts-ignore not typed yet
|
||||
// @internal
|
||||
export { setupUsers, DEFAULT_SUPERUSER_PASS } from './functional_tests/lib/auth';
|
||||
|
||||
export { readConfigFile } from './functional_test_runner/lib/config/read_config_file';
|
||||
|
|
|
@ -12,13 +12,13 @@ export const docExistsSuite = (savedObjectsIndex: string) => () => {
|
|||
async function setup(options: { initialSettings?: Record<string, any> } = {}) {
|
||||
const { initialSettings } = options;
|
||||
|
||||
const { uiSettings, callCluster, supertest } = getServices();
|
||||
const { uiSettings, esClient, supertest } = getServices();
|
||||
|
||||
// delete the kibana index to ensure we start fresh
|
||||
await callCluster('deleteByQuery', {
|
||||
await esClient.deleteByQuery({
|
||||
index: savedObjectsIndex,
|
||||
conflicts: 'proceed',
|
||||
body: {
|
||||
conflicts: 'proceed',
|
||||
query: { match_all: {} },
|
||||
},
|
||||
refresh: true,
|
||||
|
|
|
@ -11,10 +11,10 @@ import { getServices, chance } from './lib';
|
|||
export const docMissingSuite = (savedObjectsIndex: string) => () => {
|
||||
// ensure the kibana index has no documents
|
||||
beforeEach(async () => {
|
||||
const { callCluster } = getServices();
|
||||
const { esClient } = getServices();
|
||||
|
||||
// delete all docs from kibana index to ensure savedConfig is not found
|
||||
await callCluster('deleteByQuery', {
|
||||
await esClient.deleteByQuery({
|
||||
index: savedObjectsIndex,
|
||||
body: {
|
||||
query: { match_all: {} },
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
*/
|
||||
|
||||
import type supertest from 'supertest';
|
||||
import { SavedObjectsClientContract, IUiSettingsClient } from 'src/core/server';
|
||||
import type { SavedObjectsClientContract, IUiSettingsClient } from 'src/core/server';
|
||||
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
|
||||
|
||||
import {
|
||||
createTestServers,
|
||||
|
@ -17,7 +18,6 @@ import {
|
|||
HttpMethod,
|
||||
getSupertest,
|
||||
} from '../../../../test_helpers/kbn_server';
|
||||
import { LegacyAPICaller } from '../../../elasticsearch/';
|
||||
import { httpServerMock } from '../../../http/http_server.mocks';
|
||||
|
||||
let servers: TestUtils;
|
||||
|
@ -26,7 +26,7 @@ let kbn: TestKibanaUtils;
|
|||
|
||||
interface AllServices {
|
||||
savedObjectsClient: SavedObjectsClientContract;
|
||||
callCluster: LegacyAPICaller;
|
||||
esClient: KibanaClient;
|
||||
uiSettings: IUiSettingsClient;
|
||||
supertest: (method: HttpMethod, path: string) => supertest.Test;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ export function getServices() {
|
|||
return services;
|
||||
}
|
||||
|
||||
const callCluster = esServer.es.getCallCluster();
|
||||
const esClient = esServer.es.getClient();
|
||||
|
||||
const savedObjectsClient = kbn.coreStart.savedObjects.getScopedClient(
|
||||
httpServerMock.createKibanaRequest()
|
||||
|
@ -65,7 +65,7 @@ export function getServices() {
|
|||
|
||||
services = {
|
||||
supertest: (method: HttpMethod, path: string) => getSupertest(kbn.root, method, path),
|
||||
callCluster,
|
||||
esClient,
|
||||
savedObjectsClient,
|
||||
uiSettings,
|
||||
};
|
||||
|
|
|
@ -6,31 +6,22 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
|
||||
import { ToolingLog, REPO_ROOT } from '@kbn/dev-utils';
|
||||
import {
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
createLegacyEsTestCluster,
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
createTestEsCluster,
|
||||
DEFAULT_SUPERUSER_PASS,
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
esTestConfig,
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
kbnTestConfig,
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
kibanaServerTestUser,
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
kibanaTestUser,
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
setupUsers,
|
||||
} from '@kbn/test';
|
||||
import { defaultsDeep, get } from 'lodash';
|
||||
import { defaultsDeep } from 'lodash';
|
||||
import { resolve } from 'path';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import supertest from 'supertest';
|
||||
|
||||
import { InternalCoreSetup, InternalCoreStart } from '../server/internal_types';
|
||||
import { LegacyAPICaller } from '../server/elasticsearch';
|
||||
import { CliArgs, Env } from '../server/config';
|
||||
import { Root } from '../server/root';
|
||||
|
||||
|
@ -49,15 +40,6 @@ const DEFAULTS_SETTINGS = {
|
|||
migrations: { skip: false },
|
||||
};
|
||||
|
||||
const DEFAULT_SETTINGS_WITH_CORE_PLUGINS = {
|
||||
plugins: { scanDirs: [resolve(__dirname, '../../legacy/core_plugins')] },
|
||||
elasticsearch: {
|
||||
hosts: [esTestConfig.getUrl()],
|
||||
username: kibanaServerTestUser.username,
|
||||
password: kibanaServerTestUser.password,
|
||||
},
|
||||
};
|
||||
|
||||
export function createRootWithSettings(
|
||||
settings: Record<string, any>,
|
||||
cliArgs: Partial<CliArgs> = {}
|
||||
|
@ -118,6 +100,15 @@ export function createRoot(settings = {}, cliArgs: Partial<CliArgs> = {}) {
|
|||
* @returns {Root}
|
||||
*/
|
||||
export function createRootWithCorePlugins(settings = {}, cliArgs: Partial<CliArgs> = {}) {
|
||||
const DEFAULT_SETTINGS_WITH_CORE_PLUGINS = {
|
||||
plugins: { scanDirs: [resolve(__dirname, '../../legacy/core_plugins')] },
|
||||
elasticsearch: {
|
||||
hosts: [esTestConfig.getUrl()],
|
||||
username: kibanaServerTestUser.username,
|
||||
password: kibanaServerTestUser.password,
|
||||
},
|
||||
};
|
||||
|
||||
return createRootWithSettings(
|
||||
defaultsDeep({}, settings, DEFAULT_SETTINGS_WITH_CORE_PLUGINS),
|
||||
cliArgs
|
||||
|
@ -135,19 +126,9 @@ export const request: Record<
|
|||
put: (root, path) => getSupertest(root, 'put', path),
|
||||
};
|
||||
|
||||
export interface TestElasticsearchServer {
|
||||
getStartTimeout: () => number;
|
||||
start: (esArgs: string[], esEnvVars: Record<string, string>) => Promise<void>;
|
||||
stop: () => Promise<void>;
|
||||
cleanup: () => Promise<void>;
|
||||
getClient: () => KibanaClient;
|
||||
getCallCluster: () => LegacyAPICaller;
|
||||
getUrl: () => string;
|
||||
}
|
||||
|
||||
export interface TestElasticsearchUtils {
|
||||
stop: () => Promise<void>;
|
||||
es: TestElasticsearchServer;
|
||||
es: ReturnType<typeof createTestEsCluster>;
|
||||
hosts: string[];
|
||||
username: string;
|
||||
password: string;
|
||||
|
@ -204,8 +185,8 @@ export function createTestServers({
|
|||
if (!adjustTimeout) {
|
||||
throw new Error('adjustTimeout is required in order to avoid flaky tests');
|
||||
}
|
||||
const license = get(settings, 'es.license', 'basic');
|
||||
const usersToBeAdded = get(settings, 'users', []);
|
||||
const license = settings.es?.license ?? 'basic';
|
||||
const usersToBeAdded = settings.users ?? [];
|
||||
if (usersToBeAdded.length > 0) {
|
||||
if (license !== 'trial') {
|
||||
throw new Error(
|
||||
|
@ -223,8 +204,8 @@ export function createTestServers({
|
|||
log.info('starting elasticsearch');
|
||||
log.indent(4);
|
||||
|
||||
const es = createLegacyEsTestCluster(
|
||||
defaultsDeep({}, get(settings, 'es', {}), {
|
||||
const es = createTestEsCluster(
|
||||
defaultsDeep({}, settings.es ?? {}, {
|
||||
log,
|
||||
license,
|
||||
password: license === 'trial' ? DEFAULT_SUPERUSER_PASS : undefined,
|
||||
|
@ -236,11 +217,11 @@ export function createTestServers({
|
|||
// Add time for KBN and adding users
|
||||
adjustTimeout(es.getStartTimeout() + 100000);
|
||||
|
||||
const kbnSettings: any = get(settings, 'kbn', {});
|
||||
const kbnSettings = settings.kbn ?? {};
|
||||
|
||||
return {
|
||||
startES: async () => {
|
||||
await es.start(get(settings, 'es.esArgs', []));
|
||||
await es.start();
|
||||
|
||||
if (['gold', 'trial'].includes(license)) {
|
||||
await setupUsers({
|
||||
|
@ -249,9 +230,9 @@ export function createTestServers({
|
|||
updates: [
|
||||
...usersToBeAdded,
|
||||
// user elastic
|
||||
esTestConfig.getUrlParts(),
|
||||
esTestConfig.getUrlParts() as { username: string; password: string },
|
||||
// user kibana
|
||||
kbnTestConfig.getUrlParts(),
|
||||
kbnTestConfig.getUrlParts() as { username: string; password: string },
|
||||
],
|
||||
});
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { adminTestUser } from '@kbn/test';
|
||||
import { FtrProviderContext } from '../ftr_provider_context';
|
||||
import { AuthenticatedUser, Role } from '../../../plugins/security/common/model';
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import Url from 'url';
|
||||
import Path from 'path';
|
||||
import type { FtrConfigProviderContext } from '@kbn/test/types/ftr';
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { kbnTestConfig } from '@kbn/test';
|
||||
import { pageObjects } from '../functional/page_objects';
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import Hapi from '@hapi/hapi';
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { kbnTestConfig } from '@kbn/test';
|
||||
import { take } from 'rxjs/operators';
|
||||
import Url from 'url';
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
import expect from '@kbn/expect';
|
||||
import request, { Cookie } from 'request';
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { adminTestUser } from '@kbn/test';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import expect from '@kbn/expect';
|
||||
import request, { Cookie } from 'request';
|
||||
import { delay } from 'bluebird';
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { adminTestUser } from '@kbn/test';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
import {
|
||||
|
|
|
@ -9,7 +9,6 @@ import expect from '@kbn/expect';
|
|||
import request, { Cookie } from 'request';
|
||||
import url from 'url';
|
||||
import { delay } from 'bluebird';
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { adminTestUser } from '@kbn/test';
|
||||
import { getStateAndNonce } from '../../../fixtures/oidc/oidc_tools';
|
||||
import { FtrProviderContext } from '../../../ftr_provider_context';
|
||||
|
|
|
@ -11,7 +11,6 @@ import { delay } from 'bluebird';
|
|||
import { readFileSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import { CA_CERT_PATH } from '@kbn/dev-utils';
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { adminTestUser } from '@kbn/test';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import url from 'url';
|
|||
import { delay } from 'bluebird';
|
||||
import expect from '@kbn/expect';
|
||||
import request, { Cookie } from 'request';
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { adminTestUser } from '@kbn/test';
|
||||
import {
|
||||
getLogoutRequest,
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import request, { Cookie } from 'request';
|
||||
import { delay } from 'bluebird';
|
||||
import expect from '@kbn/expect';
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { adminTestUser } from '@kbn/test';
|
||||
import type { AuthenticationProvider } from '../../../../plugins/security/common/model';
|
||||
import { getSAMLRequestId, getSAMLResponse } from '../../fixtures/saml/saml_tools';
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
import request, { Cookie } from 'request';
|
||||
import expect from '@kbn/expect';
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { adminTestUser } from '@kbn/test';
|
||||
import type { AuthenticationProvider } from '../../../../plugins/security/common/model';
|
||||
import { getSAMLRequestId, getSAMLResponse } from '../../fixtures/saml/saml_tools';
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import request, { Cookie } from 'request';
|
||||
import { delay } from 'bluebird';
|
||||
import expect from '@kbn/expect';
|
||||
// @ts-expect-error https://github.com/elastic/kibana/issues/95679
|
||||
import { adminTestUser } from '@kbn/test';
|
||||
import type { AuthenticationProvider } from '../../../../plugins/security/common/model';
|
||||
import { getSAMLRequestId, getSAMLResponse } from '../../fixtures/saml/saml_tools';
|
||||
|
|
Loading…
Reference in a new issue