mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* [xpack/encryptionKeys] use default keys when running from source * add tests for the config schema with different contexts * share the getConfigSchema helper * await promises returned by expect().resolves * tweak test naming * use data-driven tests * fix type error * hide platform dependent config from snapshot
This commit is contained in:
parent
c3f749f896
commit
f7a8b33723
11 changed files with 395 additions and 3 deletions
14
x-pack/plugins/encrypted_saved_objects/__snapshots__/index.test.ts.snap
generated
Normal file
14
x-pack/plugins/encrypted_saved_objects/__snapshots__/index.test.ts.snap
generated
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`config schema with context {"dist":false} produces correct config 1`] = `
|
||||
Object {
|
||||
"enabled": true,
|
||||
"encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`config schema with context {"dist":true} produces correct config 1`] = `
|
||||
Object {
|
||||
"enabled": true,
|
||||
}
|
||||
`;
|
17
x-pack/plugins/encrypted_saved_objects/index.test.ts
Normal file
17
x-pack/plugins/encrypted_saved_objects/index.test.ts
Normal file
|
@ -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 { encryptedSavedObjects } from './index';
|
||||
import { getConfigSchema } from '../../test_utils';
|
||||
|
||||
const describeWithContext = describe.each([[{ dist: false }], [{ dist: true }]]);
|
||||
|
||||
describeWithContext('config schema with context %j', context => {
|
||||
it('produces correct config', async () => {
|
||||
const schema = await getConfigSchema(encryptedSavedObjects);
|
||||
await expect(schema.validate({}, { context })).resolves.toMatchSnapshot();
|
||||
});
|
||||
});
|
|
@ -26,7 +26,13 @@ export const encryptedSavedObjects = (kibana: any) =>
|
|||
config(Joi: Root) {
|
||||
return Joi.object({
|
||||
enabled: Joi.boolean().default(true),
|
||||
encryptionKey: Joi.string().min(32),
|
||||
encryptionKey: Joi.when(Joi.ref('$dist'), {
|
||||
is: true,
|
||||
then: Joi.string().min(32),
|
||||
otherwise: Joi.string()
|
||||
.min(32)
|
||||
.default('a'.repeat(32)),
|
||||
}),
|
||||
}).default();
|
||||
},
|
||||
|
||||
|
|
239
x-pack/plugins/reporting/__snapshots__/index.test.js.snap
generated
Normal file
239
x-pack/plugins/reporting/__snapshots__/index.test.js.snap
generated
Normal file
|
@ -0,0 +1,239 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`config schema with context {"dev":false,"dist":false} produces correct config 1`] = `
|
||||
Object {
|
||||
"capture": Object {
|
||||
"browser": Object {
|
||||
"autoDownload": true,
|
||||
"chromium": Object {
|
||||
"disableSandbox": "<platform dependent>",
|
||||
"maxScreenshotDimension": 1950,
|
||||
"proxy": Object {
|
||||
"enabled": false,
|
||||
},
|
||||
},
|
||||
"type": "chromium",
|
||||
},
|
||||
"concurrency": 4,
|
||||
"loadDelay": 3000,
|
||||
"settleTime": 1000,
|
||||
"timeout": 20000,
|
||||
"viewport": Object {
|
||||
"height": 1200,
|
||||
"width": 1950,
|
||||
},
|
||||
"zoom": 2,
|
||||
},
|
||||
"csv": Object {
|
||||
"maxSizeBytes": 10485760,
|
||||
"scroll": Object {
|
||||
"duration": "30s",
|
||||
"size": 500,
|
||||
},
|
||||
},
|
||||
"enabled": true,
|
||||
"encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"index": ".reporting",
|
||||
"kibanaServer": Object {},
|
||||
"poll": Object {
|
||||
"jobCompletionNotifier": Object {
|
||||
"interval": 10000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
"jobsRefresh": Object {
|
||||
"interval": 5000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
},
|
||||
"queue": Object {
|
||||
"indexInterval": "week",
|
||||
"pollEnabled": true,
|
||||
"pollInterval": 3000,
|
||||
"pollIntervalErrorMultiplier": 10,
|
||||
"timeout": 120000,
|
||||
},
|
||||
"roles": Object {
|
||||
"allow": Array [
|
||||
"reporting_user",
|
||||
],
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`config schema with context {"dev":false,"dist":true} produces correct config 1`] = `
|
||||
Object {
|
||||
"capture": Object {
|
||||
"browser": Object {
|
||||
"autoDownload": false,
|
||||
"chromium": Object {
|
||||
"disableSandbox": "<platform dependent>",
|
||||
"maxScreenshotDimension": 1950,
|
||||
"proxy": Object {
|
||||
"enabled": false,
|
||||
},
|
||||
},
|
||||
"type": "chromium",
|
||||
},
|
||||
"concurrency": 4,
|
||||
"loadDelay": 3000,
|
||||
"settleTime": 1000,
|
||||
"timeout": 20000,
|
||||
"viewport": Object {
|
||||
"height": 1200,
|
||||
"width": 1950,
|
||||
},
|
||||
"zoom": 2,
|
||||
},
|
||||
"csv": Object {
|
||||
"maxSizeBytes": 10485760,
|
||||
"scroll": Object {
|
||||
"duration": "30s",
|
||||
"size": 500,
|
||||
},
|
||||
},
|
||||
"enabled": true,
|
||||
"index": ".reporting",
|
||||
"kibanaServer": Object {},
|
||||
"poll": Object {
|
||||
"jobCompletionNotifier": Object {
|
||||
"interval": 10000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
"jobsRefresh": Object {
|
||||
"interval": 5000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
},
|
||||
"queue": Object {
|
||||
"indexInterval": "week",
|
||||
"pollEnabled": true,
|
||||
"pollInterval": 3000,
|
||||
"pollIntervalErrorMultiplier": 10,
|
||||
"timeout": 120000,
|
||||
},
|
||||
"roles": Object {
|
||||
"allow": Array [
|
||||
"reporting_user",
|
||||
],
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`config schema with context {"dev":true,"dist":false} produces correct config 1`] = `
|
||||
Object {
|
||||
"capture": Object {
|
||||
"browser": Object {
|
||||
"autoDownload": true,
|
||||
"chromium": Object {
|
||||
"disableSandbox": "<platform dependent>",
|
||||
"maxScreenshotDimension": 1950,
|
||||
"proxy": Object {
|
||||
"enabled": false,
|
||||
},
|
||||
},
|
||||
"type": "chromium",
|
||||
},
|
||||
"concurrency": 4,
|
||||
"loadDelay": 3000,
|
||||
"settleTime": 1000,
|
||||
"timeout": 20000,
|
||||
"viewport": Object {
|
||||
"height": 1200,
|
||||
"width": 1950,
|
||||
},
|
||||
"zoom": 2,
|
||||
},
|
||||
"csv": Object {
|
||||
"maxSizeBytes": 10485760,
|
||||
"scroll": Object {
|
||||
"duration": "30s",
|
||||
"size": 500,
|
||||
},
|
||||
},
|
||||
"enabled": true,
|
||||
"encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"index": ".reporting",
|
||||
"kibanaServer": Object {},
|
||||
"poll": Object {
|
||||
"jobCompletionNotifier": Object {
|
||||
"interval": 10000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
"jobsRefresh": Object {
|
||||
"interval": 5000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
},
|
||||
"queue": Object {
|
||||
"indexInterval": "week",
|
||||
"pollEnabled": true,
|
||||
"pollInterval": 3000,
|
||||
"pollIntervalErrorMultiplier": 10,
|
||||
"timeout": 120000,
|
||||
},
|
||||
"roles": Object {
|
||||
"allow": Array [
|
||||
"reporting_user",
|
||||
],
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`config schema with context {"dev":true,"dist":true} produces correct config 1`] = `
|
||||
Object {
|
||||
"capture": Object {
|
||||
"browser": Object {
|
||||
"autoDownload": false,
|
||||
"chromium": Object {
|
||||
"disableSandbox": "<platform dependent>",
|
||||
"maxScreenshotDimension": 1950,
|
||||
"proxy": Object {
|
||||
"enabled": false,
|
||||
},
|
||||
},
|
||||
"type": "chromium",
|
||||
},
|
||||
"concurrency": 4,
|
||||
"loadDelay": 3000,
|
||||
"settleTime": 1000,
|
||||
"timeout": 20000,
|
||||
"viewport": Object {
|
||||
"height": 1200,
|
||||
"width": 1950,
|
||||
},
|
||||
"zoom": 2,
|
||||
},
|
||||
"csv": Object {
|
||||
"maxSizeBytes": 10485760,
|
||||
"scroll": Object {
|
||||
"duration": "30s",
|
||||
"size": 500,
|
||||
},
|
||||
},
|
||||
"enabled": true,
|
||||
"index": ".reporting",
|
||||
"kibanaServer": Object {},
|
||||
"poll": Object {
|
||||
"jobCompletionNotifier": Object {
|
||||
"interval": 10000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
"jobsRefresh": Object {
|
||||
"interval": 5000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
},
|
||||
"queue": Object {
|
||||
"indexInterval": "week",
|
||||
"pollEnabled": true,
|
||||
"pollInterval": 3000,
|
||||
"pollIntervalErrorMultiplier": 10,
|
||||
"timeout": 120000,
|
||||
},
|
||||
"roles": Object {
|
||||
"allow": Array [
|
||||
"reporting_user",
|
||||
],
|
||||
},
|
||||
}
|
||||
`;
|
|
@ -123,7 +123,11 @@ export const reporting = (kibana) => {
|
|||
size: Joi.number().integer().default(500)
|
||||
}).default(),
|
||||
}).default(),
|
||||
encryptionKey: Joi.string(),
|
||||
encryptionKey: Joi.when(Joi.ref('$dist'), {
|
||||
is: true,
|
||||
then: Joi.string(),
|
||||
otherwise: Joi.string().default('a'.repeat(32)),
|
||||
}),
|
||||
roles: Joi.object({
|
||||
allow: Joi.array().items(Joi.string()).default(['reporting_user']),
|
||||
}).default(),
|
||||
|
|
24
x-pack/plugins/reporting/index.test.js
Normal file
24
x-pack/plugins/reporting/index.test.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 { reporting } from './index';
|
||||
import { getConfigSchema } from '../../test_utils';
|
||||
|
||||
const describeWithContext = describe.each([
|
||||
[{ dev: false, dist: false }],
|
||||
[{ dev: true, dist: false }],
|
||||
[{ dev: false, dist: true }],
|
||||
[{ dev: true, dist: true }],
|
||||
]);
|
||||
|
||||
describeWithContext('config schema with context %j', (context) => {
|
||||
it('produces correct config', async () => {
|
||||
const schema = await getConfigSchema(reporting);
|
||||
const value = await schema.validate({}, { context });
|
||||
value.capture.browser.chromium.disableSandbox = '<platform dependent>';
|
||||
await expect(value).toMatchSnapshot();
|
||||
});
|
||||
});
|
44
x-pack/plugins/security/__snapshots__/index.test.js.snap
generated
Normal file
44
x-pack/plugins/security/__snapshots__/index.test.js.snap
generated
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`config schema with context {"dist":false} produces correct config 1`] = `
|
||||
Object {
|
||||
"audit": Object {
|
||||
"enabled": false,
|
||||
},
|
||||
"authProviders": Array [
|
||||
"basic",
|
||||
],
|
||||
"authorization": Object {
|
||||
"legacyFallback": Object {
|
||||
"enabled": true,
|
||||
},
|
||||
},
|
||||
"cookieName": "sid",
|
||||
"enabled": true,
|
||||
"encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"public": Object {},
|
||||
"secureCookies": false,
|
||||
"sessionTimeout": null,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`config schema with context {"dist":true} produces correct config 1`] = `
|
||||
Object {
|
||||
"audit": Object {
|
||||
"enabled": false,
|
||||
},
|
||||
"authProviders": Array [
|
||||
"basic",
|
||||
],
|
||||
"authorization": Object {
|
||||
"legacyFallback": Object {
|
||||
"enabled": true,
|
||||
},
|
||||
},
|
||||
"cookieName": "sid",
|
||||
"enabled": true,
|
||||
"public": Object {},
|
||||
"secureCookies": false,
|
||||
"sessionTimeout": null,
|
||||
}
|
||||
`;
|
|
@ -45,7 +45,11 @@ export const security = (kibana) => new kibana.Plugin({
|
|||
authProviders: Joi.array().items(Joi.string()).default(['basic']),
|
||||
enabled: Joi.boolean().default(true),
|
||||
cookieName: Joi.string().default('sid'),
|
||||
encryptionKey: Joi.string(),
|
||||
encryptionKey: Joi.when(Joi.ref('$dist'), {
|
||||
is: true,
|
||||
then: Joi.string(),
|
||||
otherwise: Joi.string().default('a'.repeat(32)),
|
||||
}),
|
||||
sessionTimeout: Joi.number().allow(null).default(null),
|
||||
secureCookies: Joi.boolean().default(false),
|
||||
public: Joi.object({
|
||||
|
|
22
x-pack/plugins/security/index.test.js
Normal file
22
x-pack/plugins/security/index.test.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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 { security } from './index';
|
||||
import { getConfigSchema } from '../../test_utils';
|
||||
|
||||
const describeWithContext = describe.each([
|
||||
[{ dist: false }],
|
||||
[{ dist: true }]
|
||||
]);
|
||||
|
||||
describeWithContext('config schema with context %j', (context) => {
|
||||
it('produces correct config', async () => {
|
||||
const schema = await getConfigSchema(security);
|
||||
await expect(
|
||||
schema.validate({}, { context })
|
||||
).resolves.toMatchSnapshot();
|
||||
});
|
||||
});
|
17
x-pack/test_utils/get_config_schema.ts
Normal file
17
x-pack/test_utils/get_config_schema.ts
Normal file
|
@ -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 Joi from 'joi';
|
||||
|
||||
export async function getConfigSchema(pluginProvider: any): Promise<Joi.Schema> {
|
||||
class Plugin {
|
||||
constructor(public readonly options: any) {}
|
||||
}
|
||||
|
||||
const plugin = pluginProvider({ Plugin });
|
||||
|
||||
return await plugin.options.config(Joi);
|
||||
}
|
|
@ -7,3 +7,4 @@
|
|||
export { registerTestBed } from './testbed';
|
||||
export { getRandomString, nextTick } from './lib';
|
||||
export { findTestSubject } from './find_test_subject';
|
||||
export { getConfigSchema } from './get_config_schema';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue