Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { silence } from '../../common';
import {
preCreateSecurityIndexesViaSamlAuth,
runElasticsearch,
startDockerServers,
runKibanaServer,
} from '../../servers';
import { getConfigRootDir, loadServersConfig } from '../../servers/configs';
Expand Down Expand Up @@ -133,6 +134,7 @@ async function runLocalServersAndTests(
};

let shutdownEs;
let shutdownDockerServers: (() => Promise<void>) | undefined;

try {
shutdownEs = await runElasticsearch({
Expand All @@ -143,6 +145,8 @@ async function runLocalServersAndTests(
logsDir: options.logsDir,
});

shutdownDockerServers = await startDockerServers(config, log);

await runKibanaServer({
procs,
onEarlyExit,
Expand All @@ -162,8 +166,14 @@ async function runLocalServersAndTests(
try {
await procs.stop('kibana');
} finally {
if (shutdownEs) {
await shutdownEs();
try {
if (shutdownDockerServers) {
await shutdownDockerServers();
}
} finally {
if (shutdownEs) {
await shutdownEs();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { packageRegistryDocker } from '@kbn/test-docker-servers';

describe('Scout base configs', () => {
const originalEnv = process.env;

beforeEach(() => {
jest.resetModules();
process.env = { ...originalEnv };
});

afterAll(() => {
process.env = originalEnv;
});

describe('stateful base config', () => {
it('includes --xpack.fleet.registryUrl when FLEET_PACKAGE_REGISTRY_PORT is set', async () => {
process.env.FLEET_PACKAGE_REGISTRY_PORT = '6104';

const { defaultConfig } = await import('./stateful/base.config');
const serverArgs: string[] = defaultConfig.kbnTestServer.serverArgs;

expect(serverArgs).toContain('--xpack.fleet.registryUrl=http://localhost:6104');
});

it('omits --xpack.fleet.registryUrl when FLEET_PACKAGE_REGISTRY_PORT is not set', async () => {
delete process.env.FLEET_PACKAGE_REGISTRY_PORT;

const { defaultConfig } = await import('./stateful/base.config');
const serverArgs: string[] = defaultConfig.kbnTestServer.serverArgs;
const registryArgs = serverArgs.filter((arg) => arg.includes('fleet.registryUrl'));

expect(registryArgs).toHaveLength(0);
});

it('uses packageRegistryDocker from @kbn/test for dockerServers', async () => {
process.env.FLEET_PACKAGE_REGISTRY_PORT = '6104';

const { defaultConfig } = await import('./stateful/base.config');
const registryConfig = (defaultConfig.dockerServers as Record<string, any>).registry;

expect(registryConfig.image).toBe(packageRegistryDocker.image);
expect(registryConfig.portInContainer).toBe(packageRegistryDocker.portInContainer);
expect(registryConfig.waitForLogLine).toBe(packageRegistryDocker.waitForLogLine);
expect(registryConfig.preferCached).toBe(packageRegistryDocker.preferCached);
});

it('overrides waitForLogLineTimeoutMs to 6 minutes', async () => {
process.env.FLEET_PACKAGE_REGISTRY_PORT = '6104';

const { defaultConfig } = await import('./stateful/base.config');
const registryConfig = (defaultConfig.dockerServers as Record<string, any>).registry;

expect(registryConfig.waitForLogLineTimeoutMs).toBe(60 * 6 * 1000);
});
});

describe('serverless base config', () => {
it('includes --xpack.fleet.registryUrl when FLEET_PACKAGE_REGISTRY_PORT is set', async () => {
process.env.FLEET_PACKAGE_REGISTRY_PORT = '6104';

const { defaultConfig } = await import('./serverless/serverless.base.config');
const serverArgs: string[] = defaultConfig.kbnTestServer.serverArgs;

expect(serverArgs).toContain('--xpack.fleet.registryUrl=http://localhost:6104');
});

it('omits --xpack.fleet.registryUrl when FLEET_PACKAGE_REGISTRY_PORT is not set', async () => {
delete process.env.FLEET_PACKAGE_REGISTRY_PORT;

const { defaultConfig } = await import('./serverless/serverless.base.config');
const serverArgs: string[] = defaultConfig.kbnTestServer.serverArgs;
const registryArgs = serverArgs.filter((arg) => arg.includes('fleet.registryUrl'));

expect(registryArgs).toHaveLength(0);
});

it('uses packageRegistryDocker from @kbn/test for dockerServers', async () => {
process.env.FLEET_PACKAGE_REGISTRY_PORT = '6104';

const { defaultConfig } = await import('./serverless/serverless.base.config');
const registryConfig = (defaultConfig.dockerServers as Record<string, any>).registry;

expect(registryConfig.image).toBe(packageRegistryDocker.image);
expect(registryConfig.portInContainer).toBe(packageRegistryDocker.portInContainer);
expect(registryConfig.waitForLogLine).toBe(packageRegistryDocker.waitForLogLine);
expect(registryConfig.preferCached).toBe(packageRegistryDocker.preferCached);
});

it('overrides waitForLogLineTimeoutMs to 6 minutes', async () => {
process.env.FLEET_PACKAGE_REGISTRY_PORT = '6104';

const { defaultConfig } = await import('./serverless/serverless.base.config');
const registryConfig = (defaultConfig.dockerServers as Record<string, any>).registry;

expect(registryConfig.waitForLogLineTimeoutMs).toBe(60 * 6 * 1000);
});
});
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { resolve, join } from 'path';
import { resolve } from 'path';
import { format as formatUrl } from 'url';
import Fs from 'fs';

import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH, kibanaDevServiceAccount } from '@kbn/dev-utils';
import {
fleetPackageRegistryDockerImage,
defineDockerServersConfig,
dockerRegistryPort,
packageRegistryDocker,
} from '@kbn/test-docker-servers';
import { getDockerFileMountPath } from '@kbn/es';
import {
Expand All @@ -29,17 +30,6 @@ import { REPO_ROOT } from '@kbn/repo-info';
import type { ScoutServerConfig } from '../../../../../types';
import { SAML_IDP_PLUGIN_PATH, SERVERLESS_IDP_METADATA_PATH, JWKS_PATH } from '../../../constants';

const packageRegistryConfig = join(__dirname, './package_registry_config.yml');
const dockerArgs: string[] = ['-v', `${packageRegistryConfig}:/package-registry/config.yml`];

/**
* This is used by CI to set the docker registry port
* you can also define this environment variable locally when running tests which
* will spin up a local docker package registry locally for you
* if this is defined it takes precedence over the `packageRegistryOverride` variable
*/
const dockerRegistryPort: string | undefined = process.env.FLEET_PACKAGE_REGISTRY_PORT;

// Indicates whether the config is used on CI or locally.
const isRunOnCI = process.env.CI;

Expand All @@ -66,14 +56,8 @@ export const defaultConfig: ScoutServerConfig = {
servers,
dockerServers: defineDockerServersConfig({
registry: {
enabled: !!dockerRegistryPort,
image: fleetPackageRegistryDockerImage,
portInContainer: 8080,
port: dockerRegistryPort,
args: dockerArgs,
waitForLogLine: 'package manifests loaded',
...packageRegistryDocker,
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes
preferCached: true,
},
}),
esTestCluster: {
Expand Down Expand Up @@ -208,6 +192,9 @@ export const defaultConfig: ScoutServerConfig = {
`--xpack.security.uiam.ssl.certificate=${KBN_CERT_PATH}`,
`--xpack.security.uiam.ssl.key=${KBN_KEY_PATH}`,
'--xpack.security.uiam.ssl.verificationMode=none',
...(dockerRegistryPort
? [`--xpack.fleet.registryUrl=http://localhost:${dockerRegistryPort}`]
: []),
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,12 @@ import {
import { REPO_ROOT } from '@kbn/repo-info';
import {
defineDockerServersConfig,
fleetPackageRegistryDockerImage,
dockerRegistryPort,
packageRegistryDocker,
} from '@kbn/test-docker-servers';
import type { ScoutServerConfig } from '../../../../../types';
import { SAML_IDP_PLUGIN_PATH, STATEFUL_IDP_METADATA_PATH } from '../../../constants';

const packageRegistryConfig = join(__dirname, './package_registry_config.yml');
const dockerArgs: string[] = ['-v', `${packageRegistryConfig}:/package-registry/config.yml`];

/**
* This is used by CI to set the docker registry port
* you can also define this environment variable locally when running tests which
* will spin up a local docker package registry locally for you
* if this is defined it takes precedence over the `packageRegistryOverride` variable
*/
const dockerRegistryPort: string | undefined = process.env.FLEET_PACKAGE_REGISTRY_PORT;

// if config is executed on CI or locally
const isRunOnCI = process.env.CI;

Expand All @@ -65,14 +55,8 @@ export const defaultConfig: ScoutServerConfig = {
servers,
dockerServers: defineDockerServersConfig({
registry: {
enabled: !!dockerRegistryPort,
image: fleetPackageRegistryDockerImage,
portInContainer: 8080,
port: dockerRegistryPort,
args: dockerArgs,
waitForLogLine: 'package manifests loaded',
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes,
preferCached: true,
...packageRegistryDocker,
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes
},
}),
esTestCluster: {
Expand Down Expand Up @@ -205,7 +189,9 @@ export const defaultConfig: ScoutServerConfig = {
],
},
])}`,
// Agent policies are now created via Fleet API using the helper function from @kbn-scout
...(dockerRegistryPort
? [`--xpack.fleet.registryUrl=http://localhost:${dockerRegistryPort}`]
: []),
// SAML configuration
...(isRunOnCI ? [] : ['--mockIdpPlugin.enabled=true']),
// This ensures that we register the Security SAML API endpoints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { parseServerFlags, SERVER_FLAG_OPTIONS } from './flags';
export { startServers } from './start_servers';
export { runKibanaServer } from './run_kibana_server';
export { runElasticsearch } from './run_elasticsearch';
export { startDockerServers } from './run_docker_servers';
export { preCreateSecurityIndexesViaSamlAuth } from './pre_create_security_indexes';

export type { StartServerOptions } from './flags';
Loading
Loading