Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions x-pack/test/functional/apps/api_keys/api_keys_helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { Client } from '@elastic/elasticsearch';
import { ToolingLog } from '@kbn/dev-utils';

export default async function clearAllApiKeys(esClient: Client, logger: ToolingLog) {
const existingKeys = await esClient.security.queryApiKeys();
if (existingKeys.count > 0) {
await Promise.all(
// The type for key is not available yet. Using any for the time being.
existingKeys.api_keys.map(async (key: any) => {
esClient.security.invalidateApiKey({ ids: [key.id] });
})
);
} else {
logger.debug('No API keys to delete.');
}
}
13 changes: 9 additions & 4 deletions x-pack/test/functional/apps/api_keys/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
*/

import expect from '@kbn/expect';
import clearAllApiKeys from './api_keys_helpers';
import { FtrProviderContext } from '../../ftr_provider_context';

export default ({ getPageObjects, getService }: FtrProviderContext) => {
const es = getService('es');
const pageObjects = getPageObjects(['common', 'apiKeys']);
const log = getService('log');
const security = getService('security');
Expand All @@ -18,6 +20,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

describe('Home page', function () {
before(async () => {
await clearAllApiKeys(es, log);
await security.testUser.setRoles(['kibana_admin']);
await pageObjects.common.navigateToApp('apiKeys');
});
Expand All @@ -39,8 +42,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

describe('creates API key', function () {
before(async () => {
await security.testUser.setRoles(['kibana_admin']);
await security.testUser.setRoles(['test_api_keys']);
await security.testUser.setRoles(['kibana_admin', 'test_api_keys']);
await pageObjects.common.navigateToApp('apiKeys');

// Delete any API keys created outside of these tests
Expand All @@ -51,6 +53,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await pageObjects.apiKeys.deleteAllApiKeyOneByOne();
});

after(async () => {
await clearAllApiKeys(es, log);
});

it('when submitting form, close dialog and displays new api key', async () => {
const apiKeyName = 'Happy API Key';
await pageObjects.apiKeys.clickOnPromptCreateApiKey();
Expand Down Expand Up @@ -95,8 +101,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

describe('deletes API key(s)', function () {
before(async () => {
await security.testUser.setRoles(['kibana_admin']);
await security.testUser.setRoles(['test_api_keys']);
await security.testUser.setRoles(['kibana_admin', 'test_api_keys']);
await pageObjects.common.navigateToApp('apiKeys');
});

Expand Down