Skip to content
Closed
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 @@ -929,14 +929,17 @@ public JSONObject sendHTTPCall(String urlString, String requestType, AbstractBui
this.failBuild(new Exception("No remote host is defined for this job."), listener);
return null;
}

HttpURLConnection connection = null;

JSONObject responseObject = null;

URL buildUrl = new URL(urlString);
connection = (HttpURLConnection) buildUrl.openConnection();

if(remoteServer.hasCrumbSupport() && requestType.equals("POST")){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to use renamed 'getHasCrumbSupport' method.

String crumbUrl=remoteServer.getAddress()+"/crumbIssuer/api/json";
JSONObject crumb = sendHTTPCall(crumbUrl, "GET", build, listener);
connection.addRequestProperty(crumb.getString("crumbRequestField"),crumb.getString("crumb"));
}
// if there is a username + apiToken defined for this remote host, then use it
String usernameTokenConcat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ public class RemoteJenkinsServer extends AbstractDescribableImpl<RemoteJenkinsSe
private final URL address;
private final String displayName;
private final boolean hasBuildTokenRootSupport;
private final boolean hasCrumbSupport;
private final String username;
private final String apiToken;

private CopyOnWriteList<Auth> auth = new CopyOnWriteList<Auth>();

@DataBoundConstructor
public RemoteJenkinsServer(String address, String displayName, boolean hasBuildTokenRootSupport, JSONObject auth)
public RemoteJenkinsServer(String address, String displayName, boolean hasBuildTokenRootSupport, boolean hasCrumbSupport, JSONObject auth)
throws MalformedURLException {

this.address = new URL(address);
this.displayName = displayName.trim();
this.hasBuildTokenRootSupport = hasBuildTokenRootSupport;
this.hasCrumbSupport = hasCrumbSupport;

// Holding on to both of these variables for legacy purposes. The seemingly 'dirty' getters for these properties
// are for the same reason.
Expand Down Expand Up @@ -78,6 +80,10 @@ public boolean getHasBuildTokenRootSupport() {
return this.hasBuildTokenRootSupport;
}

public boolean hasCrumbSupport() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be renamed to 'getHasCrumbSupport', otherwise the config page will not pick up the current value.

return hasCrumbSupport;
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<f:checkbox />
</f:entry>

<f:entry title="Enable 'crumb issuer enabled' support" field="hasCrumbSupport">
<f:checkbox />
</f:entry>

<!-- <f:optionalBlock title="Add authentication credentials" field="needsAuthentication"> -->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.ParameterizedRemoteTrigger;

import hudson.model.FreeStyleProject;
import hudson.security.csrf.DefaultCrumbIssuer;
import net.sf.json.JSONObject;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -21,7 +22,34 @@ public void testRemoteBuild() throws Exception {

String remoteUrl = jenkinsRule.getURL().toString();
RemoteJenkinsServer remoteJenkinsServer =
new RemoteJenkinsServer(remoteUrl, "JENKINS", false, auth);
new RemoteJenkinsServer(remoteUrl, "JENKINS", false, false, auth);
RemoteBuildConfiguration.DescriptorImpl descriptor =
jenkinsRule.jenkins.getDescriptorByType(RemoteBuildConfiguration.DescriptorImpl.class);
descriptor.setRemoteSites(remoteJenkinsServer);

FreeStyleProject remoteProject = jenkinsRule.createFreeStyleProject();

FreeStyleProject project = jenkinsRule.createFreeStyleProject();
RemoteBuildConfiguration remoteBuildConfiguration = new RemoteBuildConfiguration(
remoteJenkinsServer.getDisplayName(), false, remoteProject.getFullName(), "",
"", true, null, null, false, true, 1);
project.getBuildersList().add(remoteBuildConfiguration);

jenkinsRule.buildAndAssertSuccess(project);
}

@Test
public void testRemoteBuildWithCrumb() throws Exception {
jenkinsRule.jenkins.setCrumbIssuer(new DefaultCrumbIssuer(true));

JSONObject authenticationMode = new JSONObject();
authenticationMode.put("value", "none");
JSONObject auth = new JSONObject();
auth.put("authenticationMode", authenticationMode);

String remoteUrl = jenkinsRule.getURL().toString();
RemoteJenkinsServer remoteJenkinsServer =
new RemoteJenkinsServer(remoteUrl, "JENKINS", false, true, auth);
RemoteBuildConfiguration.DescriptorImpl descriptor =
jenkinsRule.jenkins.getDescriptorByType(RemoteBuildConfiguration.DescriptorImpl.class);
descriptor.setRemoteSites(remoteJenkinsServer);
Expand Down