Skip to content

Commit

Permalink
[Synthetics] URL validation softens to allow vars usage !! (elastic#1…
Browse files Browse the repository at this point in the history
…97797)

## Summary

URL validation softens to allow vars usage !!

For example

` should urls: "${url}" interpolate --params '{"url": "my-url"}'`

(cherry picked from commit 3b05b6a)

# Conflicts:
#	x-pack/plugins/observability_solution/synthetics/server/synthetics_service/project_monitor/normalizers/common_fields.ts
  • Loading branch information
shahzad31 committed Oct 25, 2024
1 parent db772d0 commit 375f998
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ describe('isValidUrl', () => {
it('returns true for valid URL', () => {
expect(isValidURL('https://elastic.co')).toBeTruthy();
});

it('returns skips validation vars', () => {
expect(isValidURL('${urlParam}')).toBeTruthy();
});

it('returns skips validation vars with http', () => {
expect(isValidURL('http://${urlParam}')).toBeTruthy();
});
});

describe('getUrlsField', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { omit, uniqBy } from 'lodash';
import { i18n } from '@kbn/i18n';
import { isValidNamespace } from '@kbn/fleet-plugin/common';
import { hasNoParams } from '../../formatters/formatting_utils';
import { PrivateLocationAttributes } from '../../../runtime_types/private_locations';
import { formatLocation } from '../../../../common/utils/location_formatter';
import {
Expand Down Expand Up @@ -407,6 +408,10 @@ export const getOptionalListField = (value?: string[] | string): string[] => {
* @returns `true` if `new URL` does not throw an error, `false` otherwise
*/
export const isValidURL = (url: string): boolean => {
if (!hasNoParams(url)) {
// this is done to avoid parsing urls with variables
return true;
}
try {
new URL(url);
return true;
Expand Down

0 comments on commit 375f998

Please sign in to comment.