Skip to content
Permalink
Browse files

[FIXED JENKINS-43279] Make sure Cloud.PROVISION is properly initialized

(cherry picked from commit d35dfcb)
  • Loading branch information...
olivergondza committed Apr 6, 2017
1 parent 6bcd968 commit 6f44ff7dee22e277cdfb94494c1b23e0c676ebbf
@@ -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;
@@ -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());
}
@@ -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) {
@@ -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.
You can’t perform that action at this time.