[7.x] [xpack/encryptionKeys] use default keys when running from source (#36452) (#36461)

* [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:
Spencer 2019-05-10 13:21:46 -07:00 committed by GitHub
parent c3f749f896
commit f7a8b33723
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 395 additions and 3 deletions

View 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,
}
`;

View 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();
});
});

View file

@ -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();
},

View 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",
],
},
}
`;

View file

@ -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(),

View 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();
});
});

View 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,
}
`;

View file

@ -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({

View 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();
});
});

View 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);
}

View file

@ -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';