From 73d087c26e262828d6bee7c9d8509e16f2fff04a Mon Sep 17 00:00:00 2001 From: Iukou Siarhei <45054016+BlazarQSO@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:19:07 +0300 Subject: [PATCH] EPMRPP-97895 || Add validation on entered URL (#4134) * EPMRPP-97895 || Add validation on entered URL * EPMRPP-97895 || Code Review fix - 1 * EPMRPP-97895 || add tests * EPMRPP-97895 || Code Review fix - 2 --- app/src/common/utils/validation/commonValidators.js | 1 + app/src/common/utils/validation/validate.js | 4 ++++ app/src/common/utils/validation/validate.test.js | 12 ++++++++++++ .../rallyConnectionFormFields.jsx | 2 +- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/common/utils/validation/commonValidators.js b/app/src/common/utils/validation/commonValidators.js index 5007f30609..7d2f0ca5fc 100644 --- a/app/src/common/utils/validation/commonValidators.js +++ b/app/src/common/utils/validation/commonValidators.js @@ -37,6 +37,7 @@ export const descriptionEntity = bindMessageToValidator( ); export const btsUrl = bindMessageToValidator(validate.url, 'btsUrlHint'); +export const btsRallyUrl = bindMessageToValidator(validate.rallyUrl, 'btsUrlHint'); export const btsIntegrationName = bindMessageToValidator( validate.btsIntegrationName, 'btsIntegrationNameHint', diff --git a/app/src/common/utils/validation/validate.js b/app/src/common/utils/validation/validate.js index 0fd5d4ea90..5d13d0ef6d 100644 --- a/app/src/common/utils/validation/validate.js +++ b/app/src/common/utils/validation/validate.js @@ -29,6 +29,10 @@ import { export const required = isNotEmpty; export const isNotEmptyArray = composeValidators([isNotEmpty, minLength(1)]); export const url = composeValidators([isNotEmpty, regex(/^(ftp|http|https):\/\/[^ "]+$/)]); +export const rallyUrl = composeValidators([ + isNotEmpty, + regex(/^(https:\/\/rally1.rallydev.com\/).*/), +]); export const email = composeValidators([regex(/^[a-z0-9.+_-]+@[a-z0-9_.-]+?\.[a-z0-9]{2,}$/i)]); export const requiredEmail = composeValidators([isNotEmpty, email]); export const login = composeValidators([isNotEmpty, regex(/^[0-9a-zA-Z-_.]{1,128}$/)]); diff --git a/app/src/common/utils/validation/validate.test.js b/app/src/common/utils/validation/validate.test.js index 3ffd371a3e..7e01aaad45 100644 --- a/app/src/common/utils/validation/validate.test.js +++ b/app/src/common/utils/validation/validate.test.js @@ -54,6 +54,18 @@ describe('validate.url', () => { }); }); +describe('validate.rallyUrl', () => { + test('validation should be correct', () => { + expect(validate.rallyUrl('https://rally1.rallydev.com/8888')).toBe(true); + }); + test('Validation should not be correct', () => { + expect(validate.rallyUrl(undefined)).toBe(false); + expect(validate.rallyUrl('')).toBe(false); + expect(validate.rallyUrl(' ')).toBe(false); + expect(validate.rallyUrl('example')).toBe(false); + }); +}); + describe('validate.email', () => { test('validation should be correct', () => { expect(validate.email('email@example.com')).toBe(true); diff --git a/app/src/components/integrations/integrationProviders/rallyIntegration/rallyConnectionFormFields/rallyConnectionFormFields.jsx b/app/src/components/integrations/integrationProviders/rallyIntegration/rallyConnectionFormFields/rallyConnectionFormFields.jsx index e59bb21154..4b0b8acd93 100644 --- a/app/src/components/integrations/integrationProviders/rallyIntegration/rallyConnectionFormFields/rallyConnectionFormFields.jsx +++ b/app/src/components/integrations/integrationProviders/rallyIntegration/rallyConnectionFormFields/rallyConnectionFormFields.jsx @@ -85,7 +85,7 @@ export class RallyConnectionFormFields extends Component {