From 2fab2041c47c93e509e54c663a0095e4e6408eaf Mon Sep 17 00:00:00 2001 From: Julia Bardi <90178898+juliaElastic@users.noreply.github.com> Date: Wed, 17 Aug 2022 16:49:28 +0200 Subject: [PATCH] fixed bug with comparing upgrade version with snapshot kibana version (#139007) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../routes/agent/upgrade_handler.test.ts | 26 +++++++++++++++++++ .../server/routes/agent/upgrade_handler.ts | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/fleet/server/routes/agent/upgrade_handler.test.ts diff --git a/x-pack/plugins/fleet/server/routes/agent/upgrade_handler.test.ts b/x-pack/plugins/fleet/server/routes/agent/upgrade_handler.test.ts new file mode 100644 index 0000000000000..5eafcf1a94104 --- /dev/null +++ b/x-pack/plugins/fleet/server/routes/agent/upgrade_handler.test.ts @@ -0,0 +1,26 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { checkKibanaVersion } from './upgrade_handler'; + +describe('upgrade handler', () => { + describe('checkKibanaVersion', () => { + it('should not throw if upgrade version is equal to kibana version', () => { + expect(() => checkKibanaVersion('8.4.0', '8.4.0')).not.toThrowError(); + }); + + it('should throw if upgrade version is higher than kibana version', () => { + expect(() => checkKibanaVersion('8.5.0', '8.4.0')).toThrowError( + 'cannot upgrade agent to 8.5.0 because it is higher than the installed kibana version 8.4.0' + ); + }); + + it('should not throw if upgrade version is equal to kibana version with snapshot', () => { + expect(() => checkKibanaVersion('8.4.0', '8.4.0-SNAPSHOT')).not.toThrowError(); + }); + }); +}); diff --git a/x-pack/plugins/fleet/server/routes/agent/upgrade_handler.ts b/x-pack/plugins/fleet/server/routes/agent/upgrade_handler.ts index 024158b5b8785..d75e3ad07d9b8 100644 --- a/x-pack/plugins/fleet/server/routes/agent/upgrade_handler.ts +++ b/x-pack/plugins/fleet/server/routes/agent/upgrade_handler.ts @@ -160,7 +160,7 @@ export const checkKibanaVersion = (version: string, kibanaVersion: string) => { if (!versionToUpgradeNumber) throw new Error(`version to upgrade ${versionToUpgradeNumber} is not valid`); - if (semverGt(version, kibanaVersion)) + if (semverGt(versionToUpgradeNumber, kibanaVersionNumber)) throw new Error( `cannot upgrade agent to ${versionToUpgradeNumber} because it is higher than the installed kibana version ${kibanaVersionNumber}` );