diff --git a/x-pack/plugins/fleet/server/services/setup.ts b/x-pack/plugins/fleet/server/services/setup.ts index cc4be9bab0bcc..a9af93e70f7ab 100644 --- a/x-pack/plugins/fleet/server/services/setup.ts +++ b/x-pack/plugins/fleet/server/services/setup.ts @@ -369,6 +369,7 @@ export async function ensureFleetDirectories() { try { await fs.stat(bundledPackageLocation); + logger.debug(`Bundled package directory ${bundledPackageLocation} exists`); } catch (error) { logger.warn( `Bundled package directory ${bundledPackageLocation} does not exist. All packages will be sourced from ${registryUrl}.` diff --git a/x-pack/test/fleet_api_integration/apis/agents/list.ts b/x-pack/test/fleet_api_integration/apis/agents/list.ts index 4bf7e84d70e7f..91796d5a9b9dd 100644 --- a/x-pack/test/fleet_api_integration/apis/agents/list.ts +++ b/x-pack/test/fleet_api_integration/apis/agents/list.ts @@ -17,10 +17,8 @@ export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const es = getService('es'); let elasticAgentpkgVersion: string; - // Failing: See https://github.com/elastic/kibana/issues/170690 - // Failing: See https://github.com/elastic/kibana/issues/170690 - // Failing: See https://github.com/elastic/kibana/issues/170690 - describe.skip('fleet_list_agent', () => { + + describe('fleet_list_agent', () => { before(async () => { await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/fleet/agents'); const getPkRes = await supertest @@ -159,6 +157,7 @@ export default function ({ getService }: FtrProviderContext) { dataset: 'elastic_agent.elastic_agent', }, elastic_agent: { id: 'agent1', process: 'elastic_agent' }, + component: { id: 'component1' }, system: { process: { memory: { @@ -179,6 +178,7 @@ export default function ({ getService }: FtrProviderContext) { document: { '@timestamp': new Date(now - 1 * 60 * 1000).toISOString(), elastic_agent: { id: 'agent1', process: 'elastic_agent' }, + component: { id: 'component2' }, data_stream: { namespace: 'default', type: 'metrics', diff --git a/x-pack/test/fleet_api_integration/apis/epm/get.ts b/x-pack/test/fleet_api_integration/apis/epm/get.ts index 045a6d034a0a0..7b79272bbef0b 100644 --- a/x-pack/test/fleet_api_integration/apis/epm/get.ts +++ b/x-pack/test/fleet_api_integration/apis/epm/get.ts @@ -13,6 +13,7 @@ import { FtrProviderContext } from '../../../api_integration/ftr_provider_contex import { skipIfNoDockerRegistry } from '../../helpers'; import { setupFleetAndAgents } from '../agents/services'; import { testUsers } from '../test_users'; +import { bundlePackage, removeBundledPackages } from './install_bundled'; export default function (providerContext: FtrProviderContext) { const { getService } = providerContext; @@ -22,6 +23,7 @@ export default function (providerContext: FtrProviderContext) { const testPkgName = 'apache'; const testPkgVersion = '0.1.4'; + const log = getService('log'); const uninstallPackage = async (name: string, version: string) => { await supertest.delete(`/api/fleet/epm/packages/${name}/${version}`).set('kbn-xsrf', 'xxxx'); @@ -38,8 +40,7 @@ export default function (providerContext: FtrProviderContext) { '../fixtures/direct_upload_packages/apache_0.1.4.zip' ); - // FLAKY: https://github.com/elastic/kibana/issues/163203 - describe.skip('EPM - get', () => { + describe('EPM - get', () => { skipIfNoDockerRegistry(providerContext); setupFleetAndAgents(providerContext); @@ -114,6 +115,7 @@ export default function (providerContext: FtrProviderContext) { before(async () => { await installPackage(testPkgName, testPkgVersion); await installPackage('experimental', '0.1.0'); + await bundlePackage('endpoint-8.6.1'); await installPackage('endpoint', '8.6.1'); }); after(async () => { @@ -121,6 +123,9 @@ export default function (providerContext: FtrProviderContext) { await uninstallPackage('experimental', '0.1.0'); await uninstallPackage('endpoint', '8.6.1'); }); + after(async () => { + await removeBundledPackages(log); + }); it('Allows the fetching of installed packages', async () => { const res = await supertest.get(`/api/fleet/epm/packages/installed`).expect(200); const packages = res.body.items; diff --git a/x-pack/test/fleet_api_integration/apis/epm/install_bundled.ts b/x-pack/test/fleet_api_integration/apis/epm/install_bundled.ts index 3fdb609129994..4b91e8ac88e54 100644 --- a/x-pack/test/fleet_api_integration/apis/epm/install_bundled.ts +++ b/x-pack/test/fleet_api_integration/apis/epm/install_bundled.ts @@ -9,58 +9,59 @@ import expect from '@kbn/expect'; import fs from 'fs/promises'; import path from 'path'; +import { ToolingLog } from '@kbn/tooling-log'; import { BUNDLED_PACKAGE_DIR } from '../../config.base'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { skipIfNoDockerRegistry } from '../../helpers'; import { setupFleetAndAgents } from '../agents/services'; -export default function (providerContext: FtrProviderContext) { - const { getService } = providerContext; - const supertest = getService('supertest'); - const log = getService('log'); - - const BUNDLED_PACKAGE_FIXTURES_DIR = path.join( - path.dirname(__filename), - '../fixtures/bundled_packages' +const BUNDLED_PACKAGE_FIXTURES_DIR = path.join( + path.dirname(__filename), + '../fixtures/bundled_packages' +); + +export const bundlePackage = async (name: string) => { + try { + await fs.access(BUNDLED_PACKAGE_DIR); + } catch (error) { + await fs.mkdir(BUNDLED_PACKAGE_DIR); + } + + await fs.copyFile( + path.join(BUNDLED_PACKAGE_FIXTURES_DIR, `${name}.zip`), + path.join(BUNDLED_PACKAGE_DIR, `${name}.zip`) ); +}; - const bundlePackage = async (name: string) => { - try { - await fs.access(BUNDLED_PACKAGE_DIR); - } catch (error) { - await fs.mkdir(BUNDLED_PACKAGE_DIR); - } - - await fs.copyFile( - path.join(BUNDLED_PACKAGE_FIXTURES_DIR, `${name}.zip`), - path.join(BUNDLED_PACKAGE_DIR, `${name}.zip`) - ); - }; +export const removeBundledPackages = async (log: ToolingLog) => { + try { + const files = await fs.readdir(BUNDLED_PACKAGE_DIR); - const removeBundledPackages = async () => { - try { - const files = await fs.readdir(BUNDLED_PACKAGE_DIR); + for (const file of files) { + const isFixtureFile = !!(await fs.readFile(path.join(BUNDLED_PACKAGE_FIXTURES_DIR, file))); - for (const file of files) { - const isFixtureFile = !!(await fs.readFile(path.join(BUNDLED_PACKAGE_FIXTURES_DIR, file))); - - // Only remove fixture files - leave normal bundled packages in place - if (isFixtureFile) { - await fs.unlink(path.join(BUNDLED_PACKAGE_DIR, file)); - } + // Only remove fixture files - leave normal bundled packages in place + if (isFixtureFile) { + await fs.unlink(path.join(BUNDLED_PACKAGE_DIR, file)); } - } catch (error) { - log.error('Error removing bundled packages'); - log.error(error); } - }; + } catch (error) { + log.error('Error removing bundled packages'); + log.error(error); + } +}; + +export default function (providerContext: FtrProviderContext) { + const { getService } = providerContext; + const supertest = getService('supertest'); + const log = getService('log'); describe('installing bundled packages', async () => { skipIfNoDockerRegistry(providerContext); setupFleetAndAgents(providerContext); afterEach(async () => { - await removeBundledPackages(); + await removeBundledPackages(log); }); describe('without registry', () => { diff --git a/x-pack/test/fleet_api_integration/apis/epm/install_endpoint.ts b/x-pack/test/fleet_api_integration/apis/epm/install_endpoint.ts index 892f89f7c2bb6..a4f313383f06c 100644 --- a/x-pack/test/fleet_api_integration/apis/epm/install_endpoint.ts +++ b/x-pack/test/fleet_api_integration/apis/epm/install_endpoint.ts @@ -9,14 +9,14 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { skipIfNoDockerRegistry } from '../../helpers'; import { setupFleetAndAgents } from '../agents/services'; +import { bundlePackage, removeBundledPackages } from './install_bundled'; export default function (providerContext: FtrProviderContext) { /** * There are a few features that are only currently supported for the Endpoint * package due to security concerns. */ - // Failing: See https://github.com/elastic/kibana/issues/156941 - describe.skip('Install endpoint package', () => { + describe('Install endpoint package', () => { const { getService } = providerContext; skipIfNoDockerRegistry(providerContext); setupFleetAndAgents(providerContext); @@ -25,8 +25,9 @@ export default function (providerContext: FtrProviderContext) { const dockerServers = getService('dockerServers'); const server = dockerServers.get('registry'); const es = getService('es'); + const log = getService('log'); const pkgName = 'endpoint'; - let pkgVersion: string; + const pkgVersion = '8.6.1'; const transforms = [ { @@ -39,12 +40,21 @@ export default function (providerContext: FtrProviderContext) { }, ]; + const installPackage = async (name: string, version: string) => { + await supertest + .post(`/api/fleet/epm/packages/${name}/${version}`) + .set('kbn-xsrf', 'xxxx') + .send({ force: true }); + }; + before(async () => { if (!server.enabled) return; - // The latest endpoint package is already installed by default in our FTR config, - // just get the most recent version number. - const getResp = await supertest.get(`/api/fleet/epm/packages/${pkgName}`).expect(200); - pkgVersion = getResp.body.response.version; + await bundlePackage('endpoint-8.6.1'); + await installPackage('endpoint', '8.6.1'); + }); + after(async () => { + await uninstallPackage('endpoint', '8.6.1'); + await removeBundledPackages(log); }); describe('install', () => { diff --git a/x-pack/test/fleet_api_integration/apis/epm/list.ts b/x-pack/test/fleet_api_integration/apis/epm/list.ts index e07c215e4ad9f..6bccbc37a678c 100644 --- a/x-pack/test/fleet_api_integration/apis/epm/list.ts +++ b/x-pack/test/fleet_api_integration/apis/epm/list.ts @@ -10,6 +10,7 @@ import { FtrProviderContext } from '../../../api_integration/ftr_provider_contex import { skipIfNoDockerRegistry } from '../../helpers'; import { setupFleetAndAgents } from '../agents/services'; import { testUsers } from '../test_users'; +import { bundlePackage, removeBundledPackages } from './install_bundled'; export default function (providerContext: FtrProviderContext) { const { getService } = providerContext; @@ -21,9 +22,9 @@ export default function (providerContext: FtrProviderContext) { // because `this` has to point to the Mocha context // see https://mochajs.org/#arrow-functions - // FLAKY: https://github.com/elastic/kibana/issues/167188 - describe.skip('EPM - list', async function () { + describe('EPM - list', async function () { skipIfNoDockerRegistry(providerContext); + const log = getService('log'); before(async () => { await esArchiver.load('x-pack/test/functional/es_archives/fleet/empty_fleet_server'); @@ -32,6 +33,9 @@ export default function (providerContext: FtrProviderContext) { after(async () => { await esArchiver.unload('x-pack/test/functional/es_archives/fleet/empty_fleet_server'); }); + after(async () => { + await removeBundledPackages(log); + }); describe('list api tests', async () => { it('lists all packages from the registry', async function () { @@ -47,6 +51,7 @@ export default function (providerContext: FtrProviderContext) { }); it('lists all limited packages from the registry', async function () { + await bundlePackage('endpoint-8.6.1'); const fetchLimitedPackageList = async () => { const response = await supertest .get('/api/fleet/epm/packages/limited') diff --git a/x-pack/test/fleet_api_integration/apis/fixtures/bundled_packages/endpoint-8.6.1.zip b/x-pack/test/fleet_api_integration/apis/fixtures/bundled_packages/endpoint-8.6.1.zip new file mode 100644 index 0000000000000..4c20854aee729 Binary files /dev/null and b/x-pack/test/fleet_api_integration/apis/fixtures/bundled_packages/endpoint-8.6.1.zip differ