Skip to content

Commit

Permalink
[FIXED JENKINS-43279] Make sure Cloud.PROVISION is properly initialized
Browse files Browse the repository at this point in the history
(cherry picked from commit d35dfcb)
  • Loading branch information
olivergondza committed May 2, 2017
1 parent 6bcd968 commit 6f44ff7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/Computer.java
Expand Up @@ -29,6 +29,7 @@
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher.ProcStarter;
import hudson.slaves.Cloud;
import jenkins.util.SystemProperties;
import hudson.Util;
import hudson.cli.declarative.CLIMethod;
Expand Down Expand Up @@ -1733,5 +1734,10 @@ public long getWhen() {
public static final Permission CONNECT = new Permission(PERMISSIONS,"Connect", Messages._Computer_ConnectPermission_Description(), DISCONNECT, PermissionScope.COMPUTER);
public static final Permission BUILD = new Permission(PERMISSIONS, "Build", Messages._Computer_BuildPermission_Description(), Permission.WRITE, PermissionScope.COMPUTER);

// This permission was historically scoped to this class albeit declared in Cloud. While deserializing, Jenkins loads
// the scope class to make sure the permission is initialized and registered. since Cloud class is used rather seldom,
// it might appear the permission does not exist. Referencing the permission from here to make sure it gets loaded.
private static final @Deprecated Permission CLOUD_PROVISION = Cloud.PROVISION;

private static final Logger LOGGER = Logger.getLogger(Computer.class.getName());
}
Expand Up @@ -7,11 +7,17 @@
import hudson.security.SidACL;
import jenkins.model.Jenkins;
import org.acegisecurity.acls.sid.Sid;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.WithoutJenkins;

public class CloudTest {

@Test
@Rule public JenkinsRule j = new JenkinsRule();

@Test @WithoutJenkins @Issue("JENKINS-37616")
public void provisionPermissionShouldBeIndependentFromAdminister() throws Exception {
SidACL acl = new SidACL() {
@Override protected Boolean hasPermission(Sid p, Permission permission) {
Expand All @@ -23,4 +29,11 @@ public void provisionPermissionShouldBeIndependentFromAdminister() throws Except
assertFalse(acl.hasPermission(Jenkins.ANONYMOUS, Jenkins.ADMINISTER));
assertEquals(Cloud.PROVISION, Computer.PERMISSIONS.find("Provision"));
}

@Test @Issue("JENKINS-37616")
public void ensureProvisionPermissionIsLoadable() throws Exception {
// Name introduced by JENKINS-37616
Permission p = Permission.fromId("hudson.model.Computer.Provision");
assertEquals("Provision", p.name);
}
}

0 comments on commit 6f44ff7

Please sign in to comment.