From 55f241a781ace1ae72411f4ce705b4c268bb8b9a Mon Sep 17 00:00:00 2001 From: Julia Bardi <90178898+juliaElastic@users.noreply.github.com> Date: Thu, 9 Dec 2021 15:57:10 +0100 Subject: [PATCH] [Fleet] Fix bug caused by API changes (#120886) * fix endpoint integration * added test --- x-pack/plugins/fleet/server/routes/epm/index.ts | 3 ++- x-pack/test/fleet_api_integration/apis/epm/get.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/fleet/server/routes/epm/index.ts b/x-pack/plugins/fleet/server/routes/epm/index.ts index da2e2458276084..b07bb2b1ab77bb 100644 --- a/x-pack/plugins/fleet/server/routes/epm/index.ts +++ b/x-pack/plugins/fleet/server/routes/epm/index.ts @@ -172,7 +172,8 @@ export const registerRoutes = (routers: { rbac: FleetRouter; superuser: FleetRou response ); if (resp.payload?.item) { - return response.ok({ body: { response: resp.payload.item } }); + // returning item as well here, because pkgVersion is optional in new GET endpoint, and if not specified, the router selects the deprecated route + return response.ok({ body: { item: resp.payload.item, response: resp.payload.item } }); } return resp; } 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 71a359c10c2a58..df6cbf3c4fecb6 100644 --- a/x-pack/test/fleet_api_integration/apis/epm/get.ts +++ b/x-pack/test/fleet_api_integration/apis/epm/get.ts @@ -102,5 +102,15 @@ export default function (providerContext: FtrProviderContext) { .auth(testUsers.fleet_read_only.username, testUsers.fleet_read_only.password) .expect(200); }); + + it('returns package info in item field when calling without version', async function () { + // this will install through the registry by default + await installPackage(testPkgName, testPkgVersion); + const res = await supertest.get(`/api/fleet/epm/packages/${testPkgName}`).expect(200); + const packageInfo = res.body.item; + // the uploaded version will have this description + expect(packageInfo.name).to.equal('apache'); + await uninstallPackage(testPkgName, testPkgVersion); + }); }); }