From 1d8974469728f084a8413ab9acfbd9b415657242 Mon Sep 17 00:00:00 2001 From: Bhavya RM Date: Mon, 21 Jun 2021 15:04:03 -0400 Subject: [PATCH] Test for role specific access to non-default space (#101653) --- .../feature_controls/spaces_security.ts | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional/apps/spaces/feature_controls/spaces_security.ts b/x-pack/test/functional/apps/spaces/feature_controls/spaces_security.ts index a91166810b6264..78207c49c9b755 100644 --- a/x-pack/test/functional/apps/spaces/feature_controls/spaces_security.ts +++ b/x-pack/test/functional/apps/spaces/feature_controls/spaces_security.ts @@ -11,16 +11,23 @@ import { FtrProviderContext } from '../../../ftr_provider_context'; export default function ({ getPageObjects, getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const security = getService('security'); - const PageObjects = getPageObjects(['common', 'settings', 'security']); + const PageObjects = getPageObjects(['common', 'settings', 'security', 'spaceSelector']); const appsMenu = getService('appsMenu'); + const spaces = getService('spaces'); const testSubjects = getService('testSubjects'); describe('security feature controls', () => { before(async () => { await esArchiver.load('x-pack/test/functional/es_archives/empty_kibana'); + await spaces.create({ + id: 'nondefaultspace', + name: 'Non-default Space', + disabledFeatures: [], + }); }); after(async () => { + await spaces.delete('nondefaultspace'); await esArchiver.unload('x-pack/test/functional/es_archives/empty_kibana'); }); @@ -44,8 +51,9 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.security.forceLogout(); await PageObjects.security.login('global_all_user', 'global_all_user-password', { - expectSpaceSelector: false, + expectSpaceSelector: true, }); + await testSubjects.click('space-card-default'); }); after(async () => { @@ -174,5 +182,56 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { await testSubjects.existOrFail('managementHome'); }); }); + + // these tests are testing role specific privilege with non default space + describe('Non default space and role specific privilege', () => { + before(async () => { + await security.role.create('nondefault_space_specific_role', { + kibana: [ + { + base: ['all'], + spaces: ['nondefaultspace'], + }, + ], + }); + + await security.user.create('nondefault_space_specific_user', { + password: 'nondefault_space_specific_role-password', + roles: ['nondefault_space_specific_role'], + full_name: 'nondefaultspace_specific_user', + }); + + await PageObjects.security.forceLogout(); + + await PageObjects.security.login( + 'nondefault_space_specific_user', + 'nondefault_space_specific_role-password', + { + expectSpaceSelector: false, + } + ); + }); + + after(async () => { + await Promise.all([ + security.role.delete('nondefault_space_specific_role'), + security.user.delete('nondefault_space_specific_user'), + PageObjects.security.forceLogout(), + ]); + }); + + it('shows management navlink', async () => { + await PageObjects.spaceSelector.expectHomePage('nondefaultspace'); + const navLinks = (await appsMenu.readLinks()).map((link) => link.text); + expect(navLinks).to.contain('Stack Management'); + }); + + it(`doesn't display spaces in the management section`, async () => { + await PageObjects.common.navigateToApp('management', { + basePath: '/s/nondefaultspace', + }); + await testSubjects.missingOrFail('spaces'); + }); + }); }); }