From c4df77e6047b6414692e7380c51dd95625ecbefd Mon Sep 17 00:00:00 2001 From: Rashmi Kulkarni Date: Thu, 26 Mar 2020 13:08:20 -0700 Subject: [PATCH] configurable test users for xpack -homepage tests. (#60808) * configurable test users for xpack * removed exclusive tests * added data-test-subj for the access denied page * updated the JEST snapshot, cleaned up the test * changes to the test_api_keys role * more changes to consolidate the page object function Co-authored-by: Elastic Machine --- .../api_keys_grid_page.test.tsx.snap | 5 ++++- .../permission_denied/permission_denied.tsx | 2 +- .../test/functional/apps/api_keys/home_page.ts | 17 +++++++++++++++-- x-pack/test/functional/config.js | 15 +++++++++++++++ .../functional/page_objects/api_keys_page.ts | 7 ++++++- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/__snapshots__/api_keys_grid_page.test.tsx.snap b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/__snapshots__/api_keys_grid_page.test.tsx.snap index ceb0fe751c2c7..6d1e0054078bd 100644 --- a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/__snapshots__/api_keys_grid_page.test.tsx.snap +++ b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/__snapshots__/api_keys_grid_page.test.tsx.snap @@ -135,7 +135,9 @@ exports[`APIKeysGridPage renders permission denied if user does not have require } iconType="securityApp" title={ -

+

( +

{ const pageObjects = getPageObjects(['common', 'apiKeys']); const log = getService('log'); + const security = getService('security'); describe('Home page', function() { this.tags('smoke'); before(async () => { + await security.testUser.setRoles(['kibana_admin']); await pageObjects.common.navigateToApp('apiKeys'); }); + after(async () => { + await security.testUser.restoreDefaults(); + }); + + // https://www.elastic.co/guide/en/kibana/7.6/api-keys.html#api-keys-security-privileges + it('Shows required privileges ', async () => { + log.debug('Checking for required privileges method section header'); + const message = await pageObjects.apiKeys.apiKeysPermissionDeniedMessage(); + expect(message).to.be('You need permission to manage API keys'); + }); + it('Loads the app', async () => { + await security.testUser.setRoles(['test_api_keys']); log.debug('Checking for section header'); - const headerText = await (await pageObjects.apiKeys.noAPIKeysHeading()).getVisibleText(); + const headerText = await pageObjects.apiKeys.noAPIKeysHeading(); expect(headerText).to.be('No API keys'); - const goToConsoleButton = await pageObjects.apiKeys.getGoToConsoleButton(); expect(await goToConsoleButton.isDisplayed()).to.be(true); }); diff --git a/x-pack/test/functional/config.js b/x-pack/test/functional/config.js index 1586908d8b5ef..cff555feace18 100644 --- a/x-pack/test/functional/config.js +++ b/x-pack/test/functional/config.js @@ -233,6 +233,21 @@ export default async function({ readConfigFile }) { }, kibana: [], }, + + //Kibana feature privilege isn't specific to advancedSetting. It can be anything. https://github.com/elastic/kibana/issues/35965 + test_api_keys: { + elasticsearch: { + cluster: ['manage_security', 'manage_api_key'], + }, + kibana: [ + { + feature: { + advancedSettings: ['read'], + }, + spaces: ['default'], + }, + ], + }, }, defaultRoles: ['superuser'], }, diff --git a/x-pack/test/functional/page_objects/api_keys_page.ts b/x-pack/test/functional/page_objects/api_keys_page.ts index 1ff70a0c1ee02..17f4df74921bc 100644 --- a/x-pack/test/functional/page_objects/api_keys_page.ts +++ b/x-pack/test/functional/page_objects/api_keys_page.ts @@ -11,10 +11,15 @@ export function ApiKeysPageProvider({ getService }: FtrProviderContext) { return { async noAPIKeysHeading() { - return await testSubjects.find('noApiKeysHeader'); + return await testSubjects.getVisibleText('noApiKeysHeader'); }, + async getGoToConsoleButton() { return await testSubjects.find('goToConsoleButton'); }, + + async apiKeysPermissionDeniedMessage() { + return await testSubjects.getVisibleText('apiKeysPermissionDeniedMessage'); + }, }; }