Skip to content

Commit

Permalink
EPMRPP-97895 || Add validation on entered URL (#4134)
Browse files Browse the repository at this point in the history
* EPMRPP-97895 || Add validation on entered URL

* EPMRPP-97895 || Code Review fix - 1

* EPMRPP-97895 || add tests

* EPMRPP-97895 || Code Review fix - 2
  • Loading branch information
BlazarQSO authored Dec 20, 2024
1 parent 68a3557 commit 73d087c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/common/utils/validation/commonValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions app/src/common/utils/validation/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}$/)]);
Expand Down
12 changes: 12 additions & 0 deletions app/src/common/utils/validation/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 protected]')).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class RallyConnectionFormFields extends Component {
</FieldElement>
<FieldElement
name="url"
validate={commonValidators.btsUrl}
validate={commonValidators.btsRallyUrl}
disabled={disabled || editAuthMode}
label={formatMessage(COMMON_BTS_MESSAGES.linkToBtsLabel)}
className={cx('fields')}
Expand Down

0 comments on commit 73d087c

Please sign in to comment.