Skip to content

Commit

Permalink
update functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamieh committed Jan 26, 2021
1 parent 7b61956 commit ec3bc7d
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 97 deletions.
17 changes: 0 additions & 17 deletions packages/kbn-dev-utils/src/kbn_client/kbn_client_ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ToolingLog } from '../tooling_log';
import { KbnClientRequester, uriencode } from './kbn_client_requester';

export type UiSettingValues = Record<string, string | number | boolean>;

interface UiSettingsApiResponse {
settings: {
[key: string]: {
Expand All @@ -21,10 +20,6 @@ interface UiSettingsApiResponse {
};
}

interface UiSettingsWithRegisteredApiResponse<V> extends UiSettingsApiResponse {
registered: Record<string, V>;
}

export class KbnClientUiSettings {
constructor(
private readonly log: ToolingLog,
Expand Down Expand Up @@ -84,18 +79,6 @@ export class KbnClientUiSettings {
});
}

/**
* Returns all registered kibana settings
*/
async getAllRegistered<T = unknown>() {
const { data } = await this.requester.request<UiSettingsWithRegisteredApiResponse<T>>({
path: '/api/kibana/settings?_allRegistered=true',
method: 'GET',
});

return data.registered;
}

/**
* Add fields to the config doc (like setting timezone and defaultIndex)
*/
Expand Down
13 changes: 1 addition & 12 deletions src/core/server/ui_settings/routes/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,17 @@
* Public License, v 1.
*/

import { schema } from '@kbn/config-schema';
import { IRouter } from '../../http';
import { SavedObjectsErrorHelpers } from '../../saved_objects';

export function registerGetRoute(router: IRouter) {
router.get(
{
path: '/api/kibana/settings',
validate: {
query: schema.object({
_allRegistered: schema.maybe(schema.boolean()),
}),
},
},
{ path: '/api/kibana/settings', validate: false },
async (context, request, response) => {
try {
const { _allRegistered } = request.query;
const uiSettingsClient = context.core.uiSettings.client;

return response.ok({
body: {
registered: _allRegistered ? uiSettingsClient.getRegistered() : undefined,
settings: await uiSettingsClient.getUserProvided(),
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ export const stackManagementSchema: MakeSchemaFrom<UsageStats> = {
'securitySolution:rulesTableRefresh': { type: 'text' },
'apm:enableSignificantTerms': { type: 'boolean' },
'apm:enableServiceOverview': { type: 'boolean' },
'apm:enableCorrelations': { type: 'boolean' },
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface UsageStats {
'securitySolution:rulesTableRefresh': string;
'apm:enableSignificantTerms': boolean;
'apm:enableServiceOverview': boolean;
'apm:enableCorrelations': boolean;
'visualize:enableLabs': boolean;
'visualization:heatmap:maxBuckets': number;
'visualization:colorMapping': string;
Expand Down
1 change: 0 additions & 1 deletion test/api_integration/apis/telemetry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
export default function ({ loadTestFile }) {
describe('Telemetry', () => {
loadTestFile(require.resolve('./telemetry_local'));
loadTestFile(require.resolve('./ui_settings'));
loadTestFile(require.resolve('./opt_in'));
loadTestFile(require.resolve('./telemetry_optin_notice_seen'));
});
Expand Down
1 change: 0 additions & 1 deletion x-pack/test/api_integration/apis/telemetry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default function ({ loadTestFile }) {
describe('Telemetry', () => {
loadTestFile(require.resolve('./telemetry'));
loadTestFile(require.resolve('./telemetry_local'));
loadTestFile(require.resolve('./management_collection'));
loadTestFile(require.resolve('./opt_in'));
loadTestFile(require.resolve('./telemetry_optin_notice_seen'));
});
Expand Down

This file was deleted.

5 changes: 4 additions & 1 deletion x-pack/test/usage_collection/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
return {
...xpackFunctionalConfig.getAll(),
// list paths to the files that contain your plugins tests
testFiles: [resolve(__dirname, './test_suites/application_usage')],
testFiles: [
resolve(__dirname, './test_suites/application_usage'),
resolve(__dirname, './test_suites/stack_management_usage'),
],

services,
pageObjects,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "StackManagementUsageTest",
"version": "1.0.0",
"kibanaVersion": "kibana",
"configPath": ["xpack", "StackManagementUsageTest"],
"requiredPlugins": [],
"server": false,
"ui": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { StackManagementUsageTest } from './plugin';

export function plugin() {
return new StackManagementUsageTest();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { Plugin, CoreSetup, CoreStart } from 'kibana/public';
import './types';

export class StackManagementUsageTest implements Plugin {
public setup(core: CoreSetup) {}

public start(core: CoreStart) {
const allUiSettings = core.uiSettings.getAll();
window.__registeredUiSettings__ = allUiSettings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { IUiSettingsClient } from 'src/core/public';
export {}; // Hack to declare this file as a module so TS allows us to extend the Global Window interface

declare global {
interface Window {
__registeredUiSettings__: ReturnType<IUiSettingsClient['getAll']>;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./target",
"skipLibCheck": true
},
"include": [
"public/**/*.ts",
"public/**/*.tsx",
],
"exclude": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import _ from 'lodash';
import { FtrProviderContext } from '../../ftr_provider_context';
import { stackManagementSchema } from '../../../../../src/plugins/kibana_usage_collection/server/collectors/management/schema';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('Stack Management', function () {
this.tags('ciGroup1');
const { common } = getPageObjects(['common']);
const browser = getService('browser');

let registeredSettings: Record<string, any>;

before(async () => {
await common.navigateToApp('home'); // Navigate to Home to make sure all the appIds are loaded
registeredSettings = await browser.execute(() => window.__registeredUiSettings__);
});

it('registers all UI Settings in the UsageStats interface', () => {
const unreportedUISettings = Object.keys(registeredSettings)
.filter((key) => key !== 'buildNum')
.filter((key) => typeof _.get(stackManagementSchema, key) === 'undefined');

expect(unreportedUISettings).to.eql([]);
});

it('registers all sensitive UI settings as boolean type', async () => {
const sensitiveSettings = Object.entries(registeredSettings)
.filter(([, config]) => config.sensitive)
.map(([key]) => key);

const nonBooleanSensitiveProps = sensitiveSettings
.map((key) => ({ key, ..._.get(stackManagementSchema, key) }))
.filter((keyDescriptor) => keyDescriptor.type !== 'boolean');

expect(nonBooleanSensitiveProps).to.eql([]);
});
});
}

0 comments on commit ec3bc7d

Please sign in to comment.