Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Synthetics] URL validation softens to allow vars usage !! #197797

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { formatLocation } from '../../../../common/utils/location_formatter';
import {
BrowserFields,
Expand Down Expand Up @@ -408,6 +409,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