forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Reporting] Update some runtime validations (elastic#53975)
* [Reporting] Update some runtime validations * fix unit test * i18n * make warning logging of encryptionKey possible * update snapshot * revert unrelated config change
- Loading branch information
Showing
8 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
x-pack/legacy/plugins/reporting/server/lib/validate/__tests__/validate_server_host.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 sinon from 'sinon'; | ||
import { ServerFacade } from '../../../../types'; | ||
import { validateServerHost } from '../validate_server_host'; | ||
|
||
const configKey = 'xpack.reporting.kibanaServer.hostname'; | ||
|
||
describe('Reporting: Validate server host setting', () => { | ||
it(`should log a warning and set ${configKey} if server.host is "0"`, () => { | ||
const getStub = sinon.stub(); | ||
getStub.withArgs('server.host').returns('0'); | ||
getStub.withArgs(configKey).returns(undefined); | ||
const config = { | ||
get: getStub, | ||
set: sinon.stub(), | ||
}; | ||
|
||
expect(() => | ||
validateServerHost(({ config: () => config } as unknown) as ServerFacade) | ||
).to.throwError(); | ||
|
||
sinon.assert.calledWith(config.set, configKey); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
x-pack/legacy/plugins/reporting/server/lib/validate/validate_server_host.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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 { ServerFacade } from '../../../types'; | ||
|
||
const configKey = 'xpack.reporting.kibanaServer.hostname'; | ||
|
||
export function validateServerHost(serverFacade: ServerFacade) { | ||
const config = serverFacade.config(); | ||
|
||
const serverHost = config.get('server.host'); | ||
const reportingKibanaHostName = config.get(configKey); | ||
|
||
if (!reportingKibanaHostName && serverHost === '0') { | ||
// @ts-ignore: No set() method on KibanaConfig, just get() and has() | ||
config.set(configKey, '0.0.0.0'); // update config in memory to allow Reporting to work | ||
|
||
throw new Error( | ||
`Found 'server.host: "0"' in settings. This is incompatible with Reporting. ` + | ||
`To enable Reporting to work, '${configKey}: 0.0.0.0' is being automatically to the configuration. ` + | ||
`You can change to 'server.host: 0.0.0.0' or add '${configKey}: 0.0.0.0' in kibana.yml to prevent this message.` | ||
); | ||
} | ||
} |