Skip to content

Commit 0e467d3

Browse files
s1mahantyShrikha .Shrikha .
authored
FORMS-16007 : rest endpoint url validation, to not allow relative url (#1505)
* restendpoint url validation * cypress test and incorporating the review comments * updating the fieldDescription * removing the updatefieldDescription logic --------- Co-authored-by: Shrikha . <smahanty@shrikhas-mbp.corp.adobe.com> Co-authored-by: Shrikha . <smahanty@Shrikhas-MacBook-Pro.local>
1 parent b20dcba commit 0e467d3

File tree

2 files changed

+41
-3
lines changed
  • ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v1/container/clientlibs/editor/js
  • ui.tests/test-module/specs

2 files changed

+41
-3
lines changed

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v1/container/clientlibs/editor/js/editDialog.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,18 @@
378378
if(restEndPointSource.length == 0 || isPostUrlSelected){
379379
Utils.showComponent(restEndPointUrlTextBox, 'div');
380380
Utils.hideComponent(restEndpointConfigPath, 'div');
381+
restEndPointUrlTextBox?.setAttribute("data-rest-endpoint-url-validation", "");
381382
} else {
382383
Utils.showComponent(restEndpointConfigPath, 'div');
383384
Utils.hideComponent(restEndPointUrlTextBox, 'div');
385+
restEndPointUrlTextBox?.removeAttribute("data-rest-endpoint-url-validation");
384386
}
385387
} else {
386388
Utils.hideComponent(restEndPointSource, 'div');
387389
Utils.hideComponent(restEndPointUrlTextBox, 'div');
388390
Utils.hideComponent(restEndpointConfigPath, 'div');
389391
restEndPointSource.parent('div').parent('div').hide();
392+
restEndPointUrlTextBox?.removeAttribute("data-rest-endpoint-url-validation");
390393
}
391394
}
392395

@@ -421,6 +424,7 @@
421424
$(document).off('change' + REST_ENDPOINT).on('change' + REST_ENDPOINT, restCheckBox, function(){
422425
showPostUrlTextField(dialog);
423426
});
427+
registerRestEndpointUrlValidator();
424428
}
425429
}
426430

@@ -489,6 +493,22 @@
489493
}
490494
});
491495

496+
function registerRestEndpointUrlValidator() {
497+
$(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
498+
selector: "[data-rest-endpoint-url-validation]",
499+
validate: (el) => {
500+
const url = el.value;
501+
// Regex to validate absolute URLs starting with http:// or https:// only
502+
const absoluteUrlPattern = /^https?:\/\/.+$/i;
503+
if (!absoluteUrlPattern.test(url)) {
504+
return Granite.I18n.getMessage(
505+
"Please enter the absolute path of the REST endpoint."
506+
);
507+
}
508+
}
509+
});
510+
}
511+
492512
Utils.initializeEditDialog(EDIT_DIALOG_FORM)(handleAsyncSubmissionAndThankYouOption, handleSubmitAction,
493513
registerSubmitActionSubDialogClientLibs, registerRestEndPointDialogClientlibs, registerFDMDialogClientlibs, registerEmailDialogClientlibs, initialiseDataModel, registerAutoSaveDialogAction);
494514

ui.tests/test-module/specs/formcontainer.cy.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,18 @@ describe('Page/Form Authoring', function () {
7676
cy.get("coral-numberinput[name='./fd:autoSaveInterval']").should("exist");
7777
}
7878

79-
79+
const checkValidatorFunctioning = function(formContainerEditPathSelector) {
80+
cy.openEditableToolbar(sitesSelectors.overlays.overlay.component + formContainerEditPathSelector);
81+
cy.invokeEditableAction("[data-action='CONFIGURE']");
82+
cy.get('.cmp-adaptiveform-container__editdialog').contains('Submission').click({force:true});
83+
cy.get(".cmp-adaptiveform-container__submitaction").children('button[is="coral-button"][aria-haspopup="listbox"]').first().click({force: true});
84+
cy.get('coral-selectlist-item[value="fd/af/components/guidesubmittype/restendpoint"]').should('be.visible').click();
85+
cy.get("[name='./restEndpointPostUrl']").scrollIntoView().clear({force: true}).type("invalid-url", {force: true});
86+
cy.get('.coral-Form-errorlabel').should('contain.text', "Please enter the absolute path of the REST endpoint.");
87+
cy.get("[name='./restEndpointPostUrl']").clear({force: true}).type("http://localhost:4502/some/endpoint", {force: true});
88+
cy.get('.coral-Form-errorlabel').should('not.exist');
89+
cy.get('.cq-dialog-submit').click();
90+
};
8091

8192
const checkAndSaveSubmitAction = function(formContainerEditPathSelector) {
8293
// click configure action on adaptive form container component
@@ -107,11 +118,11 @@ describe('Page/Form Authoring', function () {
107118
cy.get("[name='./restEndpointConfigPath']").should("exist").should("be.visible");
108119
cy.get("coral-radio[name='./restEndPointSource'][value='posturl']").first().click();
109120
cy.get("[name='./restEndpointPostUrl']").should("exist").should("be.visible");
121+
cy.get("[name='./restEndpointPostUrl']").should("exist").clear().type("http://localhost:4502/some/endpoint");
110122
cy.get("[name='./restEndpointConfigPath']").should("exist").should("not.be.visible");
111123
}
112-
cy.get("[name='./restEndpointPostUrl']").should("exist").type("http://localhost:4502/some/endpoint");
113-
114124
//save the configuration
125+
cy.get("[name='./restEndpointPostUrl']").scrollIntoView().should("exist").clear().type("http://localhost:4502/some/endpoint");
115126
cy.get('.cq-dialog-submit').click();
116127
};
117128

@@ -243,6 +254,9 @@ describe('Page/Form Authoring', function () {
243254
}
244255
});
245256

257+
it('check validator functioning for REST endpoint URL', function() {
258+
checkValidatorFunctioning(formContainerEditPathSelector);
259+
});
246260
});
247261

248262
// commenting once we support adaptive form container in sites editor, uncomment this test
@@ -296,6 +310,10 @@ describe('Page/Form Authoring', function () {
296310
checkEditDialog(formContainerEditPathSelector);
297311
cy.get(sitesSelectors.confirmDialog.actions.first).click();
298312
})
313+
314+
it('check validator functioning for REST endpoint URL', function() {
315+
checkValidatorFunctioning(formContainerEditPathSelector);
316+
});
299317
});
300318

301319
context("Render Forms in Disabled mode", function () {

0 commit comments

Comments
 (0)