From 43696930d77d3bb567e445624874eab9cf363872 Mon Sep 17 00:00:00 2001 From: Aleh Zasypkin Date: Thu, 30 May 2024 10:17:50 +0300 Subject: [PATCH] [7.17] fix(tests): update built-in ES privileges to expect `remote_cluster` only starting from 8.15.0+. (#184454) (#184474) # Backport This will backport the following commits from `main` to `7.17`: - [fix(tests): update built-in ES privileges to expect `remote_cluster` only starting from 8.15.0+. (#184454)](https://github.com/elastic/kibana/pull/184454) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../routes/authorization/privileges/get_builtin.ts | 4 ++-- .../apis/security/builtin_es_privileges.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/security/server/routes/authorization/privileges/get_builtin.ts b/x-pack/plugins/security/server/routes/authorization/privileges/get_builtin.ts index a016a68d842ef..7735df166eff8 100644 --- a/x-pack/plugins/security/server/routes/authorization/privileges/get_builtin.ts +++ b/x-pack/plugins/security/server/routes/authorization/privileges/get_builtin.ts @@ -16,10 +16,10 @@ export function defineGetBuiltinPrivilegesRoutes({ router }: RouteDefinitionPara // Exclude the `none` privilege, as it doesn't make sense as an option within the Kibana UI privileges.cluster = privileges.cluster.filter((privilege) => privilege !== 'none'); - const indexPriviledges = Array.isArray(privileges.index) + const indexPrivileges = Array.isArray(privileges.index) ? privileges.index : [privileges.index]; - privileges.index = indexPriviledges.filter((privilege) => privilege !== 'none'); + privileges.index = indexPrivileges.filter((privilege) => privilege !== 'none'); return response.ok({ body: privileges }); } diff --git a/x-pack/test/api_integration/apis/security/builtin_es_privileges.ts b/x-pack/test/api_integration/apis/security/builtin_es_privileges.ts index 89587fe259683..f337a02ddaf6c 100644 --- a/x-pack/test/api_integration/apis/security/builtin_es_privileges.ts +++ b/x-pack/test/api_integration/apis/security/builtin_es_privileges.ts @@ -10,6 +10,7 @@ import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); + const esVersion = getService('esVersion'); describe('Builtin ES Privileges', () => { describe('GET /internal/security/esPrivileges/builtin', () => { @@ -24,7 +25,15 @@ export default function ({ getService }: FtrProviderContext) { const sampleOfExpectedIndexPrivileges = ['create', 'index', 'delete']; const payload = response.body; - expect(Object.keys(payload).sort()).to.eql(['cluster', 'index']); + + // The `remote_cluster` built-in privilege was introduced in 8.15.0, but these tests are also run for + // earlier stack versions (e.g., compatibility tests) where `remote_cluster` isn't available. We can get + // rid of logic once we release 9.0 and switch compatibility test from 7.x branch to 8.x. + expect(Object.keys(payload).sort()).to.eql( + esVersion.matchRange('>=8.15.0') + ? ['cluster', 'index', 'remote_cluster'] + : ['cluster', 'index'] + ); sampleOfExpectedClusterPrivileges.forEach((privilege) => expect(payload.cluster).to.contain(privilege)