Skip to content

Commit

Permalink
[ResponseOps][Alerting] xpack.actions.proxyUrl is not validated as a …
Browse files Browse the repository at this point in the history
…URL at startup (#141970)

* Adding validation

* Removing error
  • Loading branch information
doakalexi authored Sep 28, 2022
1 parent 0b4a942 commit a47918d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions x-pack/plugins/actions/server/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ describe('config validation', () => {
`);
});

test('validates proxyUrl', () => {
const proxyUrl = 'https://test.com';
const badProxyUrl = 'bad url';
let validated: ActionsConfig;

validated = configSchema.validate({ proxyUrl });
expect(validated.proxyUrl).toEqual(proxyUrl);
expect(getValidatedConfig(mockLogger, validated).proxyUrl).toEqual(proxyUrl);
expect(mockLogger.warn.mock.calls).toMatchInlineSnapshot(`Array []`);

validated = configSchema.validate({ proxyUrl: badProxyUrl });
expect(validated.proxyUrl).toEqual(badProxyUrl);
expect(getValidatedConfig(mockLogger, validated).proxyUrl).toEqual(badProxyUrl);
expect(mockLogger.warn.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"The confguration xpack.actions.proxyUrl: bad url is invalid.",
],
]
`);
});

// Most of the customHostSettings tests are in ./lib/custom_host_settings.test.ts
// but this one seemed more relevant for this test suite, since url is the one
// required property.
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/actions/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ export type ActionsConfig = TypeOf<typeof configSchema>;
export function getValidatedConfig(logger: Logger, originalConfig: ActionsConfig): ActionsConfig {
const proxyBypassHosts = originalConfig.proxyBypassHosts;
const proxyOnlyHosts = originalConfig.proxyOnlyHosts;
const proxyUrl = originalConfig.proxyUrl;

if (proxyUrl) {
try {
new URL(proxyUrl);
} catch (err) {
logger.warn(`The confguration xpack.actions.proxyUrl: ${proxyUrl} is invalid.`);
}
}

if (proxyBypassHosts && proxyOnlyHosts) {
logger.warn(
Expand Down

0 comments on commit a47918d

Please sign in to comment.