From c94d7ab6a22f6ec5bdbd319edbbaa388d18e58df Mon Sep 17 00:00:00 2001 From: shlomomdahan <64103471+shlomomdahan@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:56:13 -0400 Subject: [PATCH 1/8] wip --- src/main/java/hudson/scm/SubversionSCM.java | 51 ++++++++++--------- .../SubversionSCM/ModuleLocation/config.jelly | 38 +++++++++----- .../hudson/scm/SubversionSCM/config.jelly | 12 ++++- 3 files changed, 64 insertions(+), 37 deletions(-) diff --git a/src/main/java/hudson/scm/SubversionSCM.java b/src/main/java/hudson/scm/SubversionSCM.java index db3a7ace..a20e8fd0 100755 --- a/src/main/java/hudson/scm/SubversionSCM.java +++ b/src/main/java/hudson/scm/SubversionSCM.java @@ -2352,23 +2352,25 @@ public void postCredential(String url, final UserProvidedCredential upc, PrintWr } } - /** - * @deprecated retained for API compatibility only - */ - @CheckForNull - @Deprecated - @RequirePOST - public FormValidation doCheckRemote(StaplerRequest req, @AncestorInPath AbstractProject context, @QueryParameter String value, @QueryParameter String credentialsId) { - Jenkins instance = Jenkins.getInstance(); - if (instance != null) { - ModuleLocation.DescriptorImpl d = instance.getDescriptorByType(ModuleLocation.DescriptorImpl.class); - if (d != null) { - return d.doCheckCredentialsId(req, context, value, credentialsId); - } - } - - return FormValidation.warning("Unable to check remote."); - } +// /** +// * @deprecated retained for API compatibility only +// */ +// @CheckForNull +// @Deprecated +// @RequirePOST +// public FormValidation doCheckRemote(StaplerRequest req, @AncestorInPath AbstractProject context, @QueryParameter String value, @QueryParameter String credentialsId) { +// +// System.out.println("doCheckRemote NOT QHAT WE NEED"); +// Jenkins instance = Jenkins.getInstance(); +// if (instance != null) { +// ModuleLocation.DescriptorImpl d = instance.getDescriptorByType(ModuleLocation.DescriptorImpl.class); +// if (d != null) { +// return d.doCheckCredentialsId(req, context, value, credentialsId); +// } +// } +// +// return FormValidation.warning("Unable to check remote."); +// } /** * @deprecated use {@link #checkRepositoryPath(hudson.model.Job, org.tmatesoft.svn.core.SVNURL, com.cloudbees.plugins.credentials.common.StandardCredentials)} @@ -2544,10 +2546,11 @@ public FormValidation doCheckExcludedCommitMessages(@QueryParameter String value */ @RequirePOST public FormValidation doCheckRevisionPropertiesSupported(@AncestorInPath Item context, - @QueryParameter String value, - @QueryParameter String credentialsId, - @QueryParameter String excludedRevprop) throws IOException, ServletException { - String v = Util.fixNull(value).trim(); + @QueryParameter String excludedRevprop, + @QueryParameter("remoteLocation") String remoteLocation, + @QueryParameter("credentialsId") String credentialsId + ) throws IOException, ServletException { + String v = Util.fixNull(remoteLocation).trim(); if (v.length() == 0) return FormValidation.ok(); @@ -3200,10 +3203,10 @@ public ListBoxModel fillCredentialsIdItems(@CheckForNull Item context, String re */ @RequirePOST public FormValidation doCheckRemote(/* TODO unused, delete */StaplerRequest req, @AncestorInPath Item context, - @QueryParameter String remote) { + @QueryParameter String value) { // repository URL is required - String url = Util.fixEmptyAndTrim(remote); + String url = Util.fixEmptyAndTrim(value); if (url == null) { return FormValidation.error(Messages.SubversionSCM_doCheckRemote_required()); } @@ -3228,7 +3231,7 @@ public FormValidation doCheckRemote(/* TODO unused, delete */StaplerRequest req, */ @RequirePOST public FormValidation doCheckCredentialsId(StaplerRequest req, @AncestorInPath Item context, - @QueryParameter String remote, @QueryParameter String value) { + @QueryParameter("remoteLocation") String remote, @QueryParameter String value) { // Test the connection only if we may use the credentials (cf. hudson.plugins.git.UserRemoteConfig.DescriptorImpl.doCheckUrl) if (context == null && !Jenkins.get().hasPermission(Jenkins.ADMINISTER) || diff --git a/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly b/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly index 9f197aa3..f320ed01 100644 --- a/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly +++ b/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly @@ -24,22 +24,36 @@ THE SOFTWARE. - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/hudson/scm/SubversionSCM/config.jelly b/src/main/resources/hudson/scm/SubversionSCM/config.jelly index 0f8fbf6d..468a25ad 100644 --- a/src/main/resources/hudson/scm/SubversionSCM/config.jelly +++ b/src/main/resources/hudson/scm/SubversionSCM/config.jelly @@ -56,9 +56,19 @@ THE SOFTWARE. + + + - + + + + + + + + From d3d8ef7c879a5117ec86142bfe4d444d79f8fcc3 Mon Sep 17 00:00:00 2001 From: shlomomdahan <64103471+shlomomdahan@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:43:28 -0400 Subject: [PATCH 2/8] make subversion CSP compliant / fix existing form validation --- src/main/java/hudson/scm/SubversionSCM.java | 10 +++--- .../SubversionSCM/ModuleLocation/config.jelly | 21 ------------- .../hudson/scm/SubversionSCM/config.jelly | 21 +++++++------ .../excludedRevprop-validation.js | 31 +++++++++++++++++++ 4 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js diff --git a/src/main/java/hudson/scm/SubversionSCM.java b/src/main/java/hudson/scm/SubversionSCM.java index a20e8fd0..ebb42037 100755 --- a/src/main/java/hudson/scm/SubversionSCM.java +++ b/src/main/java/hudson/scm/SubversionSCM.java @@ -54,6 +54,7 @@ import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder; import com.cloudbees.plugins.credentials.impl.CertificateCredentialsImpl; import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; +import com.sun.tools.jconsole.JConsoleContext; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -2546,15 +2547,16 @@ public FormValidation doCheckExcludedCommitMessages(@QueryParameter String value */ @RequirePOST public FormValidation doCheckRevisionPropertiesSupported(@AncestorInPath Item context, - @QueryParameter String excludedRevprop, - @QueryParameter("remoteLocation") String remoteLocation, - @QueryParameter("credentialsId") String credentialsId + @QueryParameter String value, + @QueryParameter("svn.remote.loc") String remoteLocation, + @QueryParameter("svn.remote.cred") String credentialsId ) throws IOException, ServletException { + String v = Util.fixNull(remoteLocation).trim(); if (v.length() == 0) return FormValidation.ok(); - String revprop = Util.fixNull(excludedRevprop).trim(); + String revprop = Util.fixNull(value).trim(); if (revprop.length() == 0) return FormValidation.ok(); diff --git a/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly b/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly index f320ed01..be9e97ce 100644 --- a/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly +++ b/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly @@ -25,31 +25,10 @@ THE SOFTWARE. - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/hudson/scm/SubversionSCM/config.jelly b/src/main/resources/hudson/scm/SubversionSCM/config.jelly index 468a25ad..f5b45669 100644 --- a/src/main/resources/hudson/scm/SubversionSCM/config.jelly +++ b/src/main/resources/hudson/scm/SubversionSCM/config.jelly @@ -57,17 +57,20 @@ THE SOFTWARE. - - - - - - + + + + + + + + + - - - + + + diff --git a/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js b/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js new file mode 100644 index 00000000..a5ac4b94 --- /dev/null +++ b/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js @@ -0,0 +1,31 @@ +Behaviour.specify("input[name='_.remoteLocation']", 'SubversionSCM.RemoteLocation', 0, function(element) { + element.addEventListener('blur', updateHiddenFields); +}); + +Behaviour.specify("select[name='_.credentialsId'][filldependson='remote']", 'SubversionSCM.CredentialsId', 0, function(element) { + element.addEventListener('change', updateHiddenFields); +}); + +function updateHiddenFields() { + + var remoteLocationElement = document.querySelector("input[name='_.remoteLocation']"); + var credentialsIdElement = document.querySelector("select[name='_.credentialsId'][filldependson='remote']"); + var selectedOption = credentialsIdElement.options[credentialsIdElement.selectedIndex].value; + + + var remoteHidden = document.querySelector("input[name='_.svn.remote.loc']"); + var credentialsHidden = document.querySelector("input[name='_.svn.remote.cred']"); + + if (remoteHidden) { + remoteHidden.value = remoteLocationElement.value; + } + + if (credentialsHidden) { + credentialsHidden.value = selectedOption; + } + + var revPropField = document.querySelector("input[name='_.excludedRevprop']"); + if (revPropField) { + revPropField.dispatchEvent(new Event('change')); + } +} From 1895dc4874bee9bd86aac05ebf900da31079cf63 Mon Sep 17 00:00:00 2001 From: shlomomdahan <64103471+shlomomdahan@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:09:52 -0400 Subject: [PATCH 3/8] make subversion CSP compliant / fix existing form validation --- src/main/java/hudson/scm/SubversionSCM.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/hudson/scm/SubversionSCM.java b/src/main/java/hudson/scm/SubversionSCM.java index ebb42037..80e5f923 100755 --- a/src/main/java/hudson/scm/SubversionSCM.java +++ b/src/main/java/hudson/scm/SubversionSCM.java @@ -54,7 +54,6 @@ import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder; import com.cloudbees.plugins.credentials.impl.CertificateCredentialsImpl; import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; -import com.sun.tools.jconsole.JConsoleContext; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; From cc487b934c794ee7f3416a5066a4a5efe95eff2b Mon Sep 17 00:00:00 2001 From: shlomomdahan <64103471+shlomomdahan@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:13:12 -0400 Subject: [PATCH 4/8] make subversion CSP compliant / fix existing form validation --- src/main/java/hudson/scm/SubversionSCM.java | 37 ++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/java/hudson/scm/SubversionSCM.java b/src/main/java/hudson/scm/SubversionSCM.java index 80e5f923..dda7031c 100755 --- a/src/main/java/hudson/scm/SubversionSCM.java +++ b/src/main/java/hudson/scm/SubversionSCM.java @@ -2352,25 +2352,24 @@ public void postCredential(String url, final UserProvidedCredential upc, PrintWr } } -// /** -// * @deprecated retained for API compatibility only -// */ -// @CheckForNull -// @Deprecated -// @RequirePOST -// public FormValidation doCheckRemote(StaplerRequest req, @AncestorInPath AbstractProject context, @QueryParameter String value, @QueryParameter String credentialsId) { -// -// System.out.println("doCheckRemote NOT QHAT WE NEED"); -// Jenkins instance = Jenkins.getInstance(); -// if (instance != null) { -// ModuleLocation.DescriptorImpl d = instance.getDescriptorByType(ModuleLocation.DescriptorImpl.class); -// if (d != null) { -// return d.doCheckCredentialsId(req, context, value, credentialsId); -// } -// } -// -// return FormValidation.warning("Unable to check remote."); -// } + /** + * @deprecated retained for API compatibility only + */ + @CheckForNull + @Deprecated + @RequirePOST + public FormValidation doCheckRemote(StaplerRequest req, @AncestorInPath AbstractProject context, @QueryParameter String value, @QueryParameter String credentialsId) { + + Jenkins instance = Jenkins.getInstance(); + if (instance != null) { + ModuleLocation.DescriptorImpl d = instance.getDescriptorByType(ModuleLocation.DescriptorImpl.class); + if (d != null) { + return d.doCheckCredentialsId(req, context, value, credentialsId); + } + } + + return FormValidation.warning("Unable to check remote."); + } /** * @deprecated use {@link #checkRepositoryPath(hudson.model.Job, org.tmatesoft.svn.core.SVNURL, com.cloudbees.plugins.credentials.common.StandardCredentials)} From 7fb59bda43d55afd0630ffb08767616773ec1310 Mon Sep 17 00:00:00 2001 From: shlomomdahan <64103471+shlomomdahan@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:18:55 -0400 Subject: [PATCH 5/8] address comments --- src/main/java/hudson/scm/SubversionSCM.java | 10 +++++----- .../scm/SubversionSCM/ModuleLocation/config.jelly | 5 ++--- .../resources/hudson/scm/SubversionSCM/config.jelly | 9 +++------ .../scm/SubversionSCM/excludedRevprop-validation.js | 8 ++++---- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/java/hudson/scm/SubversionSCM.java b/src/main/java/hudson/scm/SubversionSCM.java index dda7031c..f5f1d8bc 100755 --- a/src/main/java/hudson/scm/SubversionSCM.java +++ b/src/main/java/hudson/scm/SubversionSCM.java @@ -2544,10 +2544,10 @@ public FormValidation doCheckExcludedCommitMessages(@QueryParameter String value * Validates the remote server supports custom revision properties */ @RequirePOST - public FormValidation doCheckRevisionPropertiesSupported(@AncestorInPath Item context, + public FormValidation doCheckExcludedRevprop(@AncestorInPath Item context, @QueryParameter String value, - @QueryParameter("svn.remote.loc") String remoteLocation, - @QueryParameter("svn.remote.cred") String credentialsId + @QueryParameter String remoteLocation, + @QueryParameter String remoteCredentialsId ) throws IOException, ServletException { String v = Util.fixNull(remoteLocation).trim(); @@ -2564,7 +2564,7 @@ public FormValidation doCheckRevisionPropertiesSupported(@AncestorInPath Item co try { SVNURL repoURL = SVNURL.parseURIDecoded(new EnvVars(EnvVars.masterEnvVars).expand(v)); - StandardCredentials credentials = lookupCredentials(context, credentialsId, repoURL); + StandardCredentials credentials = lookupCredentials(context, remoteCredentialsId, repoURL); SVNNodeKind node = null; try { node = checkRepositoryPath(context,repoURL, credentials); @@ -3231,7 +3231,7 @@ public FormValidation doCheckRemote(/* TODO unused, delete */StaplerRequest req, */ @RequirePOST public FormValidation doCheckCredentialsId(StaplerRequest req, @AncestorInPath Item context, - @QueryParameter("remoteLocation") String remote, @QueryParameter String value) { + @QueryParameter String remote, @QueryParameter String value) { // Test the connection only if we may use the credentials (cf. hudson.plugins.git.UserRemoteConfig.DescriptorImpl.doCheckUrl) if (context == null && !Jenkins.get().hasPermission(Jenkins.ADMINISTER) || diff --git a/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly b/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly index be9e97ce..018087bf 100644 --- a/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly +++ b/src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly @@ -25,10 +25,9 @@ THE SOFTWARE. - - + + - diff --git a/src/main/resources/hudson/scm/SubversionSCM/config.jelly b/src/main/resources/hudson/scm/SubversionSCM/config.jelly index f5b45669..dd60e829 100644 --- a/src/main/resources/hudson/scm/SubversionSCM/config.jelly +++ b/src/main/resources/hudson/scm/SubversionSCM/config.jelly @@ -58,20 +58,17 @@ THE SOFTWARE. - - + - + - - + - diff --git a/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js b/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js index a5ac4b94..14b654a3 100644 --- a/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js +++ b/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js @@ -1,4 +1,4 @@ -Behaviour.specify("input[name='_.remoteLocation']", 'SubversionSCM.RemoteLocation', 0, function(element) { +Behaviour.specify("input[name='_.remote']", 'SubversionSCM.RemoteLocation', 0, function(element) { element.addEventListener('blur', updateHiddenFields); }); @@ -8,13 +8,13 @@ Behaviour.specify("select[name='_.credentialsId'][filldependson='remote']", 'Sub function updateHiddenFields() { - var remoteLocationElement = document.querySelector("input[name='_.remoteLocation']"); + var remoteLocationElement = document.querySelector("input[name='_.remote']"); var credentialsIdElement = document.querySelector("select[name='_.credentialsId'][filldependson='remote']"); var selectedOption = credentialsIdElement.options[credentialsIdElement.selectedIndex].value; - var remoteHidden = document.querySelector("input[name='_.svn.remote.loc']"); - var credentialsHidden = document.querySelector("input[name='_.svn.remote.cred']"); + var remoteHidden = document.querySelector("input[name='_.remoteLocation']"); + var credentialsHidden = document.querySelector("input[name='_.remoteCredentialsId']"); if (remoteHidden) { remoteHidden.value = remoteLocationElement.value; From a574c02d060b80843eb59727c8332e4e6722bc65 Mon Sep 17 00:00:00 2001 From: shlomomdahan <64103471+shlomomdahan@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:22:28 -0400 Subject: [PATCH 6/8] address comments --- src/main/java/hudson/scm/SubversionSCM.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/hudson/scm/SubversionSCM.java b/src/main/java/hudson/scm/SubversionSCM.java index f5f1d8bc..eca41c43 100755 --- a/src/main/java/hudson/scm/SubversionSCM.java +++ b/src/main/java/hudson/scm/SubversionSCM.java @@ -2359,7 +2359,6 @@ public void postCredential(String url, final UserProvidedCredential upc, PrintWr @Deprecated @RequirePOST public FormValidation doCheckRemote(StaplerRequest req, @AncestorInPath AbstractProject context, @QueryParameter String value, @QueryParameter String credentialsId) { - Jenkins instance = Jenkins.getInstance(); if (instance != null) { ModuleLocation.DescriptorImpl d = instance.getDescriptorByType(ModuleLocation.DescriptorImpl.class); From 2e2de5fb8897a7a8365f7581d2fe05314255cb80 Mon Sep 17 00:00:00 2001 From: shlomomdahan <64103471+shlomomdahan@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:12:44 -0400 Subject: [PATCH 7/8] simplify invisible entry --- .../resources/hudson/scm/SubversionSCM/config.jelly | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/resources/hudson/scm/SubversionSCM/config.jelly b/src/main/resources/hudson/scm/SubversionSCM/config.jelly index dd60e829..7a95ac2e 100644 --- a/src/main/resources/hudson/scm/SubversionSCM/config.jelly +++ b/src/main/resources/hudson/scm/SubversionSCM/config.jelly @@ -59,12 +59,10 @@ THE SOFTWARE. - - - - - - + + + + From 80738a0edcf9d416f153b648ba2e67fef2bfdd69 Mon Sep 17 00:00:00 2001 From: shlomomdahan <64103471+shlomomdahan@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:22:18 -0400 Subject: [PATCH 8/8] use specific class namesa to access elements --- .../resources/hudson/scm/SubversionSCM/config.jelly | 12 ++++++------ .../scm/SubversionSCM/excludedRevprop-validation.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/resources/hudson/scm/SubversionSCM/config.jelly b/src/main/resources/hudson/scm/SubversionSCM/config.jelly index 7a95ac2e..33d433c4 100644 --- a/src/main/resources/hudson/scm/SubversionSCM/config.jelly +++ b/src/main/resources/hudson/scm/SubversionSCM/config.jelly @@ -58,12 +58,12 @@ THE SOFTWARE. - - - - - - + + + + + + diff --git a/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js b/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js index 14b654a3..6142ae12 100644 --- a/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js +++ b/src/main/resources/hudson/scm/SubversionSCM/excludedRevprop-validation.js @@ -13,8 +13,8 @@ function updateHiddenFields() { var selectedOption = credentialsIdElement.options[credentialsIdElement.selectedIndex].value; - var remoteHidden = document.querySelector("input[name='_.remoteLocation']"); - var credentialsHidden = document.querySelector("input[name='_.remoteCredentialsId']"); + var remoteHidden = document.querySelector(".svn-remote-location-hidden"); + var credentialsHidden = document.querySelector(".svn-credentials-id-hidden"); if (remoteHidden) { remoteHidden.value = remoteLocationElement.value;