Skip to content

Commit

Permalink
Merge pull request #2726 from Vlatombe/JENKINS-41511
Browse files Browse the repository at this point in the history
[JENKINS-41511] Don't try to set slaveAgentPort when it is enforced
  • Loading branch information
daniel-beck committed Jan 30, 2017
2 parents f0c9416 + d885987 commit 5f5e86d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Expand Up @@ -79,7 +79,7 @@ public int getSlaveAgentPort() {
* @since 2.24
* @return true if the slave agent port is enforced on this instance.
*/
@Restricted(DoNotUse.class) // only for index.groovy
@Restricted(NoExternalUse.class)
public boolean isSlaveAgentPortEnforced() {
return Jenkins.getInstance().isSlaveAgentPortEnforced();
}
Expand Down Expand Up @@ -114,10 +114,12 @@ public boolean configure(StaplerRequest req, JSONObject json) throws hudson.mode
j.setDisableRememberMe(security.optBoolean("disableRememberMe", false));
j.setSecurityRealm(SecurityRealm.all().newInstanceFromRadioList(security, "realm"));
j.setAuthorizationStrategy(AuthorizationStrategy.all().newInstanceFromRadioList(security, "authorization"));
try {
j.setSlaveAgentPort(new ServerTcpPort(security.getJSONObject("slaveAgentPort")).getPort());
} catch (IOException e) {
throw new hudson.model.Descriptor.FormException(e, "slaveAgentPortType");
if (!isSlaveAgentPortEnforced()) {
try {
j.setSlaveAgentPort(new ServerTcpPort(security.getJSONObject("slaveAgentPort")).getPort());
} catch (IOException e) {
throw new hudson.model.Descriptor.FormException(e, "slaveAgentPortType");
}
}
Set<String> agentProtocols = new TreeSet<>();
if (security.has("agentProtocol")) {
Expand Down
27 changes: 27 additions & 0 deletions test/src/test/groovy/jenkins/bugs/Jenkins41511Test.java
@@ -0,0 +1,27 @@
package jenkins.bugs;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import hudson.security.HudsonPrivateSecurityRealm;
import jenkins.model.Jenkins;

public class Jenkins41511Test {

@BeforeClass
public static void setUpClass() {
System.setProperty(Jenkins.class.getName()+".slaveAgentPort", "10000");
System.setProperty(Jenkins.class.getName()+".slaveAgentPortEnforce", "true");
}

@Rule
public JenkinsRule j = new JenkinsRule();

@Test
public void configRoundTrip() throws Exception {
Jenkins.getInstance().setSecurityRealm(new HudsonPrivateSecurityRealm(true, false, null));
j.submit(j.createWebClient().goTo("configureSecurity").getFormByName("config"));
}
}

0 comments on commit 5f5e86d

Please sign in to comment.