[ES] Handle non-semver-compliant versions (#172093)

This commit is contained in:
Alejandro Fernández Haro 2023-11-28 21:36:23 +01:00 committed by GitHub
parent 8e36ba77f6
commit a77c4c0b69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View file

@ -42,6 +42,12 @@ describe('mapNodesVersionCompatibility', () => {
return { nodes: { 'node-without-http': { version, ip: 'ip' } } } as any;
}
it('returns isCompatible=false with a single node with non-SemVer-compliant version', async () => {
const nodesInfo = createNodes('615c621a8416c444941dc97b142a0122d5c878d0');
const result = await mapNodesVersionCompatibility(nodesInfo, KIBANA_VERSION, false);
expect(result.isCompatible).toBe(false);
});
it('returns isCompatible=true with a single node that matches', async () => {
const nodesInfo = createNodes('5.1.0');
const result = await mapNodesVersionCompatibility(nodesInfo, KIBANA_VERSION, false);

View file

@ -22,6 +22,12 @@ describe('plugins/elasticsearch', () => {
it('when majors are equal, but ES minor is less than Kibana minor', () => {
expect(esVersionCompatibleWithKibana('1.0.0', '1.1.0')).toBe(false);
});
it('ES is not SemVer-compliant', () => {
expect(
esVersionCompatibleWithKibana('615c621a8416c444941dc97b142a0122d5c878d0', '1.1.0')
).toBe(false);
});
});
describe('returns true', () => {

View file

@ -14,6 +14,10 @@ import semver, { coerce } from 'semver';
* 2. Older versions of ES won't work with newer versions of Kibana.
*/
export function esVersionCompatibleWithKibana(esVersion: string, kibanaVersion: string) {
if (!semver.valid(esVersion)) {
return false;
}
const esVersionNumbers = {
major: semver.major(esVersion),
minor: semver.minor(esVersion),