Skip to content

Commit

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

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Synthetics] URL validation softens to allow vars usage !!
(#197797)](#197797)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-25T14:33:26Z","message":"[Synthetics]
URL validation softens to allow vars usage !! (#197797)\n\n##
Summary\r\n\r\nURL validation softens to allow vars usage !!\r\n\r\nFor
example \r\n\r\n` should urls: \"${url}\" interpolate --params
'{\"url\":
\"my-url\"}'`","sha":"3b05b6a7a83df7ff8b929dbbb60c639cc11101d8","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-major","ci:project-deploy-observability","Team:obs-ux-management"],"title":"[Synthetics]
URL validation softens to allow vars usage
!!","number":197797,"url":"https://github.com/elastic/kibana/pull/197797","mergeCommit":{"message":"[Synthetics]
URL validation softens to allow vars usage !! (#197797)\n\n##
Summary\r\n\r\nURL validation softens to allow vars usage !!\r\n\r\nFor
example \r\n\r\n` should urls: \"${url}\" interpolate --params
'{\"url\":
\"my-url\"}'`","sha":"3b05b6a7a83df7ff8b929dbbb60c639cc11101d8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197797","number":197797,"mergeCommit":{"message":"[Synthetics]
URL validation softens to allow vars usage !! (#197797)\n\n##
Summary\r\n\r\nURL validation softens to allow vars usage !!\r\n\r\nFor
example \r\n\r\n` should urls: \"${url}\" interpolate --params
'{\"url\":
\"my-url\"}'`","sha":"3b05b6a7a83df7ff8b929dbbb60c639cc11101d8"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <[email protected]>
Co-authored-by: Maryam Saeidi <[email protected]>
  • Loading branch information
3 people authored Nov 5, 2024
1 parent ebe7a2c commit fe73a24
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 { 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

0 comments on commit fe73a24

Please sign in to comment.