mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Reporting] clean up config tests (#117411)
This commit is contained in:
parent
038e77680d
commit
ea7ff2932d
3 changed files with 234 additions and 229 deletions
197
x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap
generated
Normal file
197
x-pack/plugins/reporting/server/config/__snapshots__/schema.test.ts.snap
generated
Normal file
|
@ -0,0 +1,197 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Reporting Config Schema context {"dev":false,"dist":false} produces correct config 1`] = `
|
||||
Object {
|
||||
"capture": Object {
|
||||
"browser": Object {
|
||||
"autoDownload": true,
|
||||
"chromium": Object {
|
||||
"proxy": Object {
|
||||
"enabled": false,
|
||||
},
|
||||
},
|
||||
"type": "chromium",
|
||||
},
|
||||
"loadDelay": "PT3S",
|
||||
"maxAttempts": 1,
|
||||
"networkPolicy": Object {
|
||||
"enabled": true,
|
||||
"rules": Array [
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "http:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "https:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "ws:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "wss:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "data:",
|
||||
},
|
||||
Object {
|
||||
"allow": false,
|
||||
"host": undefined,
|
||||
"protocol": undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
"timeouts": Object {
|
||||
"openUrl": "PT1M",
|
||||
"renderComplete": "PT30S",
|
||||
"waitForElements": "PT30S",
|
||||
},
|
||||
"zoom": 2,
|
||||
},
|
||||
"csv": Object {
|
||||
"checkForFormulas": true,
|
||||
"enablePanelActionDownload": true,
|
||||
"escapeFormulaValues": false,
|
||||
"maxSizeBytes": ByteSizeValue {
|
||||
"valueInBytes": 10485760,
|
||||
},
|
||||
"scroll": Object {
|
||||
"duration": "30s",
|
||||
"size": 500,
|
||||
},
|
||||
"useByteOrderMarkEncoding": false,
|
||||
},
|
||||
"enabled": true,
|
||||
"encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"kibanaServer": Object {},
|
||||
"poll": Object {
|
||||
"jobCompletionNotifier": Object {
|
||||
"interval": 10000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
"jobsRefresh": Object {
|
||||
"interval": 5000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
},
|
||||
"queue": Object {
|
||||
"indexInterval": "week",
|
||||
"pollEnabled": true,
|
||||
"pollInterval": "PT3S",
|
||||
"pollIntervalErrorMultiplier": 10,
|
||||
"timeout": "PT2M",
|
||||
},
|
||||
"roles": Object {
|
||||
"allow": Array [
|
||||
"reporting_user",
|
||||
],
|
||||
"enabled": true,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Reporting Config Schema context {"dev":false,"dist":true} produces correct config 1`] = `
|
||||
Object {
|
||||
"capture": Object {
|
||||
"browser": Object {
|
||||
"autoDownload": false,
|
||||
"chromium": Object {
|
||||
"inspect": false,
|
||||
"proxy": Object {
|
||||
"enabled": false,
|
||||
},
|
||||
},
|
||||
"type": "chromium",
|
||||
},
|
||||
"loadDelay": "PT3S",
|
||||
"maxAttempts": 3,
|
||||
"networkPolicy": Object {
|
||||
"enabled": true,
|
||||
"rules": Array [
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "http:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "https:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "ws:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "wss:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "data:",
|
||||
},
|
||||
Object {
|
||||
"allow": false,
|
||||
"host": undefined,
|
||||
"protocol": undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
"timeouts": Object {
|
||||
"openUrl": "PT1M",
|
||||
"renderComplete": "PT30S",
|
||||
"waitForElements": "PT30S",
|
||||
},
|
||||
"zoom": 2,
|
||||
},
|
||||
"csv": Object {
|
||||
"checkForFormulas": true,
|
||||
"enablePanelActionDownload": true,
|
||||
"escapeFormulaValues": false,
|
||||
"maxSizeBytes": ByteSizeValue {
|
||||
"valueInBytes": 10485760,
|
||||
},
|
||||
"scroll": Object {
|
||||
"duration": "30s",
|
||||
"size": 500,
|
||||
},
|
||||
"useByteOrderMarkEncoding": false,
|
||||
},
|
||||
"enabled": true,
|
||||
"kibanaServer": Object {},
|
||||
"poll": Object {
|
||||
"jobCompletionNotifier": Object {
|
||||
"interval": 10000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
"jobsRefresh": Object {
|
||||
"interval": 5000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
},
|
||||
"queue": Object {
|
||||
"indexInterval": "week",
|
||||
"pollEnabled": true,
|
||||
"pollInterval": "PT3S",
|
||||
"pollIntervalErrorMultiplier": 10,
|
||||
"timeout": "PT2M",
|
||||
},
|
||||
"roles": Object {
|
||||
"allow": Array [
|
||||
"reporting_user",
|
||||
],
|
||||
"enabled": true,
|
||||
},
|
||||
}
|
||||
`;
|
|
@ -43,10 +43,10 @@ describe('Reporting server createConfig$', () => {
|
|||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();
|
||||
|
||||
expect(result.encryptionKey).toMatch(/\S{32,}/); // random 32 characters
|
||||
expect(mockLogger.warn.mock.calls.length).toBe(1);
|
||||
expect(mockLogger.warn.mock.calls[0]).toMatchObject([
|
||||
'Generating a random key for xpack.reporting.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.reporting.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command.',
|
||||
]);
|
||||
expect(mockLogger.warn).toHaveBeenCalledTimes(1);
|
||||
expect(mockLogger.warn).toHaveBeenCalledWith(
|
||||
'Generating a random key for xpack.reporting.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.reporting.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command.'
|
||||
);
|
||||
});
|
||||
|
||||
it('uses the user-provided encryption key', async () => {
|
||||
|
@ -58,7 +58,7 @@ describe('Reporting server createConfig$', () => {
|
|||
const mockConfig$ = createMockConfig(mockInitContext);
|
||||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();
|
||||
expect(result.encryptionKey).toMatch('iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii');
|
||||
expect(mockLogger.warn.mock.calls.length).toBe(0);
|
||||
expect(mockLogger.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uses the user-provided encryption key, reporting kibanaServer settings to override server info', async () => {
|
||||
|
@ -103,7 +103,7 @@ describe('Reporting server createConfig$', () => {
|
|||
},
|
||||
}
|
||||
`);
|
||||
expect(mockLogger.warn.mock.calls.length).toBe(0);
|
||||
expect(mockLogger.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uses user-provided disableSandbox: false', async () => {
|
||||
|
@ -117,7 +117,7 @@ describe('Reporting server createConfig$', () => {
|
|||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();
|
||||
|
||||
expect(result.capture.browser.chromium).toMatchObject({ disableSandbox: false });
|
||||
expect(mockLogger.warn.mock.calls.length).toBe(0);
|
||||
expect(mockLogger.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uses user-provided disableSandbox: true', async () => {
|
||||
|
@ -131,7 +131,7 @@ describe('Reporting server createConfig$', () => {
|
|||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();
|
||||
|
||||
expect(result.capture.browser.chromium).toMatchObject({ disableSandbox: true });
|
||||
expect(mockLogger.warn.mock.calls.length).toBe(0);
|
||||
expect(mockLogger.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('provides a default for disableSandbox', async () => {
|
||||
|
@ -144,18 +144,12 @@ describe('Reporting server createConfig$', () => {
|
|||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();
|
||||
|
||||
expect(result.capture.browser.chromium).toMatchObject({ disableSandbox: expect.any(Boolean) });
|
||||
expect(mockLogger.warn.mock.calls.length).toBe(0);
|
||||
expect(mockLogger.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
for (const hostname of [
|
||||
'0',
|
||||
'0.0',
|
||||
'0.0.0',
|
||||
'0.0.0.0',
|
||||
'0000:0000:0000:0000:0000:0000:0000:0000',
|
||||
'::',
|
||||
]) {
|
||||
it(`apply failover logic when hostname is given as ${hostname}`, async () => {
|
||||
it.each(['0', '0.0', '0.0.0', '0.0.0.0', '0000:0000:0000:0000:0000:0000:0000:0000', '::'])(
|
||||
`apply failover logic when hostname is given as "%s"`,
|
||||
async (hostname) => {
|
||||
mockInitContext = coreMock.createPluginInitializerContext(
|
||||
createMockConfigSchema({
|
||||
encryptionKey: 'aaaaaaaaaaaaabbbbbbbbbbbbaaaaaaaaa',
|
||||
|
@ -167,7 +161,7 @@ describe('Reporting server createConfig$', () => {
|
|||
},
|
||||
})
|
||||
);
|
||||
mockCoreSetup.http.getServerInfo = jest.fn().mockImplementation(
|
||||
mockCoreSetup.http.getServerInfo = jest.fn(
|
||||
(): HttpServerInfo => ({
|
||||
name: 'cool server',
|
||||
hostname,
|
||||
|
@ -177,12 +171,16 @@ describe('Reporting server createConfig$', () => {
|
|||
);
|
||||
|
||||
const mockConfig$ = createMockConfig(mockInitContext);
|
||||
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();
|
||||
expect(result.kibanaServer).toMatchObject({
|
||||
hostname: 'localhost',
|
||||
port: 5601,
|
||||
protocol: 'http',
|
||||
});
|
||||
});
|
||||
}
|
||||
await expect(
|
||||
createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise()
|
||||
).resolves.toHaveProperty(
|
||||
'kibanaServer',
|
||||
expect.objectContaining({
|
||||
hostname: 'localhost',
|
||||
port: 5601,
|
||||
protocol: 'http',
|
||||
})
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -9,203 +9,11 @@ import { ConfigSchema } from './schema';
|
|||
|
||||
describe('Reporting Config Schema', () => {
|
||||
it(`context {"dev":false,"dist":false} produces correct config`, () => {
|
||||
expect(ConfigSchema.validate({}, { dev: false, dist: false })).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"capture": Object {
|
||||
"browser": Object {
|
||||
"autoDownload": true,
|
||||
"chromium": Object {
|
||||
"proxy": Object {
|
||||
"enabled": false,
|
||||
},
|
||||
},
|
||||
"type": "chromium",
|
||||
},
|
||||
"loadDelay": "PT3S",
|
||||
"maxAttempts": 1,
|
||||
"networkPolicy": Object {
|
||||
"enabled": true,
|
||||
"rules": Array [
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "http:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "https:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "ws:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "wss:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "data:",
|
||||
},
|
||||
Object {
|
||||
"allow": false,
|
||||
"host": undefined,
|
||||
"protocol": undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
"timeouts": Object {
|
||||
"openUrl": "PT1M",
|
||||
"renderComplete": "PT30S",
|
||||
"waitForElements": "PT30S",
|
||||
},
|
||||
"zoom": 2,
|
||||
},
|
||||
"csv": Object {
|
||||
"checkForFormulas": true,
|
||||
"enablePanelActionDownload": true,
|
||||
"escapeFormulaValues": false,
|
||||
"maxSizeBytes": ByteSizeValue {
|
||||
"valueInBytes": 10485760,
|
||||
},
|
||||
"scroll": Object {
|
||||
"duration": "30s",
|
||||
"size": 500,
|
||||
},
|
||||
"useByteOrderMarkEncoding": false,
|
||||
},
|
||||
"enabled": true,
|
||||
"encryptionKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"kibanaServer": Object {},
|
||||
"poll": Object {
|
||||
"jobCompletionNotifier": Object {
|
||||
"interval": 10000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
"jobsRefresh": Object {
|
||||
"interval": 5000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
},
|
||||
"queue": Object {
|
||||
"indexInterval": "week",
|
||||
"pollEnabled": true,
|
||||
"pollInterval": "PT3S",
|
||||
"pollIntervalErrorMultiplier": 10,
|
||||
"timeout": "PT2M",
|
||||
},
|
||||
"roles": Object {
|
||||
"allow": Array [
|
||||
"reporting_user",
|
||||
],
|
||||
"enabled": true,
|
||||
},
|
||||
}
|
||||
`);
|
||||
expect(ConfigSchema.validate({}, { dev: false, dist: false })).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it(`context {"dev":false,"dist":true} produces correct config`, () => {
|
||||
expect(ConfigSchema.validate({}, { dev: false, dist: true })).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"capture": Object {
|
||||
"browser": Object {
|
||||
"autoDownload": false,
|
||||
"chromium": Object {
|
||||
"inspect": false,
|
||||
"proxy": Object {
|
||||
"enabled": false,
|
||||
},
|
||||
},
|
||||
"type": "chromium",
|
||||
},
|
||||
"loadDelay": "PT3S",
|
||||
"maxAttempts": 3,
|
||||
"networkPolicy": Object {
|
||||
"enabled": true,
|
||||
"rules": Array [
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "http:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "https:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "ws:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "wss:",
|
||||
},
|
||||
Object {
|
||||
"allow": true,
|
||||
"host": undefined,
|
||||
"protocol": "data:",
|
||||
},
|
||||
Object {
|
||||
"allow": false,
|
||||
"host": undefined,
|
||||
"protocol": undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
"timeouts": Object {
|
||||
"openUrl": "PT1M",
|
||||
"renderComplete": "PT30S",
|
||||
"waitForElements": "PT30S",
|
||||
},
|
||||
"zoom": 2,
|
||||
},
|
||||
"csv": Object {
|
||||
"checkForFormulas": true,
|
||||
"enablePanelActionDownload": true,
|
||||
"escapeFormulaValues": false,
|
||||
"maxSizeBytes": ByteSizeValue {
|
||||
"valueInBytes": 10485760,
|
||||
},
|
||||
"scroll": Object {
|
||||
"duration": "30s",
|
||||
"size": 500,
|
||||
},
|
||||
"useByteOrderMarkEncoding": false,
|
||||
},
|
||||
"enabled": true,
|
||||
"kibanaServer": Object {},
|
||||
"poll": Object {
|
||||
"jobCompletionNotifier": Object {
|
||||
"interval": 10000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
"jobsRefresh": Object {
|
||||
"interval": 5000,
|
||||
"intervalErrorMultiplier": 5,
|
||||
},
|
||||
},
|
||||
"queue": Object {
|
||||
"indexInterval": "week",
|
||||
"pollEnabled": true,
|
||||
"pollInterval": "PT3S",
|
||||
"pollIntervalErrorMultiplier": 10,
|
||||
"timeout": "PT2M",
|
||||
},
|
||||
"roles": Object {
|
||||
"allow": Array [
|
||||
"reporting_user",
|
||||
],
|
||||
"enabled": true,
|
||||
},
|
||||
}
|
||||
`);
|
||||
expect(ConfigSchema.validate({}, { dev: false, dist: true })).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('allows Duration values for certain keys', () => {
|
||||
|
@ -288,18 +96,20 @@ describe('Reporting Config Schema', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
for (const address of ['0', '0.0', '0.0.0']) {
|
||||
it(`fails to validate "kibanaServer.hostname" with an invalid hostname: "${address}"`, () => {
|
||||
it.each(['0', '0.0', '0.0.0'])(
|
||||
`fails to validate "kibanaServer.hostname" with an invalid hostname: "%s"`,
|
||||
(address) => {
|
||||
expect(() =>
|
||||
ConfigSchema.validate({
|
||||
kibanaServer: { hostname: address },
|
||||
})
|
||||
).toThrowError(`[kibanaServer.hostname]: value must be a valid hostname (see RFC 1123).`);
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
for (const address of ['0.0.0.0', '0000:0000:0000:0000:0000:0000:0000:0000', '::']) {
|
||||
it(`fails to validate "kibanaServer.hostname" hostname as zero: "${address}"`, () => {
|
||||
it.each(['0.0.0.0', '0000:0000:0000:0000:0000:0000:0000:0000', '::'])(
|
||||
`fails to validate "kibanaServer.hostname" hostname as zero: "%s"`,
|
||||
(address) => {
|
||||
expect(() =>
|
||||
ConfigSchema.validate({
|
||||
kibanaServer: { hostname: address },
|
||||
|
@ -307,6 +117,6 @@ describe('Reporting Config Schema', () => {
|
|||
).toThrowError(
|
||||
`[kibanaServer.hostname]: cannot use '0.0.0.0' as Kibana host name, consider using the default (localhost) instead`
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue