Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-74018] Migrate legacy checkUrl attributes in BapSshTransfer/config.jelly #360

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,26 @@
return FormValidation.validateNonNegativeInteger(value);
}

public FormValidation doCheckSourceFiles(@QueryParameter final String configName, @QueryParameter final String sourceFiles,
public FormValidation doCheckSourceFiles(@QueryParameter final String sourceFilesConfigName, @QueryParameter final String value,

Check warning

Code scanning / Jenkins Security Scan

Stapler: Missing POST/RequirePOST annotation Warning

Potential CSRF vulnerability: If BapSshTransferDescriptor#doCheckSourceFiles connects to user-specified URLs, modifies state, or is expensive to run, it should be annotated with @POST or @RequirePOST

Check warning

Code scanning / Jenkins Security Scan

Stapler: Missing permission check Warning

Potential missing permission check in BapSshTransferDescriptor#doCheckSourceFiles
@QueryParameter final String execCommand) {
if (Util.fixEmptyAndTrim(configName) != null) {
if (Util.fixEmptyAndTrim(sourceFilesConfigName) != null) {
final BapSshPublisherPlugin.Descriptor pluginDescriptor = Jenkins.getActiveInstance().getDescriptorByType(
BapSshPublisherPlugin.Descriptor.class);
final BapSshHostConfiguration hostConfig = pluginDescriptor.getConfiguration(configName);
final BapSshHostConfiguration hostConfig = pluginDescriptor.getConfiguration(sourceFilesConfigName);
if (hostConfig == null)
return FormValidation.error(Messages.descriptor_sourceFiles_check_configNotFound(configName));
return FormValidation.error(Messages.descriptor_sourceFiles_check_configNotFound(sourceFilesConfigName));
if (hostConfig.isEffectiveDisableExec())
return FormValidation.validateRequired(sourceFiles);
return FormValidation.validateRequired(value);
}
return checkTransferSet(sourceFiles, execCommand);
return checkTransferSet(value, execCommand);
}

public FormValidation doCheckPatternSeparator(@QueryParameter final String value) {
return BPValidators.validateRegularExpression(value);
}

public FormValidation doCheckExecCommand(@QueryParameter final String sourceFiles, @QueryParameter final String execCommand) {
return checkTransferSet(sourceFiles, execCommand);
public FormValidation doCheckExecCommand(@QueryParameter final String sourceFiles, @QueryParameter final String value) {

Check warning

Code scanning / Jenkins Security Scan

Stapler: Missing permission check Warning

Potential missing permission check in BapSshTransferDescriptor#doCheckExecCommand

Check warning

Code scanning / Jenkins Security Scan

Stapler: Missing POST/RequirePOST annotation Warning

Potential CSRF vulnerability: If BapSshTransferDescriptor#doCheckExecCommand connects to user-specified URLs, modifies state, or is expensive to run, it should be annotated with @POST or @RequirePOST
return checkTransferSet(sourceFiles, value);

Check warning on line 75 in src/main/java/jenkins/plugins/publish_over_ssh/descriptor/BapSshTransferDescriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 58-75 are not covered by tests
}

private FormValidation checkTransferSet(final String sourceFiles, final String execCommand) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@

<poj:defaultMessages/>

<f:invisibleEntry>
<f:textbox clazz="ssh-transfer-source-files-config-name" field="sourceFilesConfigName"/>
</f:invisibleEntry>
<f:entry title="${m.sourceFiles()}" field="sourceFiles" help="${descriptor.getHelpFile((inPromotion and !matrixPromotion) ? 'sourceFilesForPromotion' : 'sourceFiles')}">
<f:textbox checkUrl="'${rootURL}/descriptorByName/jenkins.plugins.publish_over_ssh.BapSshTransfer/checkSourceFiles'+qs(this).nearBy('sourceFiles').nearBy('execCommand').toString()+bap_get_configName_qs(this)" default="${defaults.transfer.sourceFiles}"/>
<f:textbox default="${defaults.transfer.sourceFiles}"/>
</f:entry>

<f:entry title="${m.removePrefix()}" field="removePrefix">
Expand All @@ -41,7 +44,7 @@
</f:entry>

<f:entry title="${%execCommand}" field="execCommand">
<poj:textarea checkUrl="'${rootURL}/descriptorByName/jenkins.plugins.publish_over_ssh.BapSshTransfer/checkExecCommand'+qs(this).nearBy('sourceFiles').nearBy('execCommand').toString()" minRows="1" class="ssh-exec-control" default="${defaults.transfer.execCommand}"/>
<f:textarea class="ssh-exec-control" default="${defaults.transfer.execCommand}"/>
</f:entry>

<f:description>
Expand Down
14 changes: 13 additions & 1 deletion src/main/webapp/js/pos.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,20 @@ var sshBehave = {
bap_show_exec_controls(publisher);
}
bap_blur_inputs(publisher);
updateSourceFilesConfigName(configName);
};
}
};

Behaviour.register(sshBehave);
Behaviour.register(sshBehave);

function updateSourceFilesConfigName(configNameElement) {
const parentContainer = configNameElement.closest("div[name='publishers']");
parentContainer.querySelectorAll(".ssh-transfer-source-files-config-name").forEach(function (hiddenField) {
hiddenField.value = configNameElement.value;
});
}

Behaviour.specify(".ssh-transfer-source-files-config-name", "SshTransfer_syncSourceFileConfigName", 0, function (element) {
element.value = element.closest("div[name='publishers']").querySelector("select.ssh-config-name").value;
});