Skip to content

Commit

Permalink
Merge pull request #144 from fcojfernandez/JENKINS-46346
Browse files Browse the repository at this point in the history
[JENKINS-46346] Fix failure tests
  • Loading branch information
abayer committed Sep 5, 2017
2 parents 4b223a6 + 35c61ff commit 6ee0069
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 54 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Expand Up @@ -55,11 +55,5 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-auth</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Expand Up @@ -38,7 +38,6 @@
import hudson.model.FreeStyleBuild;
import hudson.model.Item;
import hudson.model.Result;
import hudson.security.GlobalMatrixAuthorizationStrategy;
import hudson.security.Permission;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Publisher;
Expand All @@ -63,6 +62,7 @@
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;
import org.kohsuke.groovy.sandbox.impl.Checker;

public class SecureGroovyScriptTest {
Expand All @@ -77,12 +77,14 @@ public class SecureGroovyScriptTest {
*/
@Test public void basicApproval() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Jenkins.READ, "devel");

MockAuthorizationStrategy mockStrategy = new MockAuthorizationStrategy();
mockStrategy.grant(Jenkins.READ).everywhere().to("devel");
for (Permission p : Item.PERMISSIONS.getPermissions()) {
gmas.add(p, "devel");
mockStrategy.grant(p).everywhere().to("devel");
}
r.jenkins.setAuthorizationStrategy(gmas);
r.jenkins.setAuthorizationStrategy(mockStrategy);

FreeStyleProject p = r.createFreeStyleProject("p");
JenkinsRule.WebClient wc = r.createWebClient();
wc.login("devel");
Expand Down Expand Up @@ -140,13 +142,16 @@ public class SecureGroovyScriptTest {
*/
@Test public void testSandboxDefault_with_RUN_SCRIPTS_privs() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Jenkins.READ, "devel");
gmas.add(Jenkins.RUN_SCRIPTS, "devel");

MockAuthorizationStrategy mockStrategy = new MockAuthorizationStrategy();
mockStrategy.grant(Jenkins.READ).everywhere().to("devel");
mockStrategy.grant(Jenkins.RUN_SCRIPTS).everywhere().to("devel");
mockStrategy.grant(Jenkins.ADMINISTER).everywhere().to("devel");
for (Permission p : Item.PERMISSIONS.getPermissions()) {
gmas.add(p, "devel");
mockStrategy.grant(p).everywhere().to("devel");
}
r.jenkins.setAuthorizationStrategy(gmas);
r.jenkins.setAuthorizationStrategy(mockStrategy);

FreeStyleProject p = r.createFreeStyleProject("p");
JenkinsRule.WebClient wc = r.createWebClient();
wc.login("devel");
Expand Down Expand Up @@ -180,12 +185,14 @@ public class SecureGroovyScriptTest {
*/
@Test public void testSandboxDefault_without_RUN_SCRIPTS_privs() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Jenkins.READ, "devel");
for (Permission p : Item.PERMISSIONS.getPermissions()) {
gmas.add(p, "devel");

MockAuthorizationStrategy mockStrategy = new MockAuthorizationStrategy();
mockStrategy.grant(Jenkins.READ).everywhere().to("devel");
for (Permission p : Item.PERMISSIONS.getPermissions()) {
mockStrategy.grant(p).everywhere().to("devel");
}
r.jenkins.setAuthorizationStrategy(gmas);
r.jenkins.setAuthorizationStrategy(mockStrategy);

FreeStyleProject p = r.createFreeStyleProject("p");
JenkinsRule.WebClient wc = r.createWebClient();
wc.login("devel");
Expand Down Expand Up @@ -296,13 +303,14 @@ private List<File> getAllUpdatedJarFiles() throws URISyntaxException {

@Test public void testClasspathInSandbox() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Jenkins.READ, "devel");

MockAuthorizationStrategy mockStrategy = new MockAuthorizationStrategy();
mockStrategy.grant(Jenkins.READ).everywhere().to("devel");
for (Permission p : Item.PERMISSIONS.getPermissions()) {
gmas.add(p, "devel");
mockStrategy.grant(p).everywhere().to("devel");
}
r.jenkins.setAuthorizationStrategy(gmas);
r.jenkins.setAuthorizationStrategy(mockStrategy);

List<ClasspathEntry> classpath = new ArrayList<ClasspathEntry>();
for (File jarfile: getAllJarFiles()) {
classpath.add(new ClasspathEntry(jarfile.getAbsolutePath()));
Expand Down Expand Up @@ -372,13 +380,14 @@ private List<File> getAllUpdatedJarFiles() throws URISyntaxException {

@Test public void testNonapprovedClasspathInSandbox() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Jenkins.READ, "devel");

MockAuthorizationStrategy mockStrategy = new MockAuthorizationStrategy();
mockStrategy.grant(Jenkins.READ).everywhere().to("devel");
for (Permission p : Item.PERMISSIONS.getPermissions()) {
gmas.add(p, "devel");
mockStrategy.grant(p).everywhere().to("devel");
}
r.jenkins.setAuthorizationStrategy(gmas);
r.jenkins.setAuthorizationStrategy(mockStrategy);

List<ClasspathEntry> classpath = new ArrayList<ClasspathEntry>();
for (File jarfile: getAllJarFiles()) {
String path = jarfile.getAbsolutePath();
Expand Down Expand Up @@ -457,13 +466,14 @@ private List<File> getAllUpdatedJarFiles() throws URISyntaxException {

@Test public void testUpdatedClasspath() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Jenkins.READ, "devel");

MockAuthorizationStrategy mockStrategy = new MockAuthorizationStrategy();
mockStrategy.grant(Jenkins.READ).everywhere().to("devel");
for (Permission p : Item.PERMISSIONS.getPermissions()) {
gmas.add(p, "devel");
mockStrategy.grant(p).everywhere().to("devel");
}
r.jenkins.setAuthorizationStrategy(gmas);
r.jenkins.setAuthorizationStrategy(mockStrategy);

// Copy jar files to temporary directory, then overwrite them with updated jar files.
File tmpDir = tmpFolderRule.newFolder();

Expand Down Expand Up @@ -539,13 +549,14 @@ private List<File> getAllUpdatedJarFiles() throws URISyntaxException {

@Test public void testClasspathWithClassDirectory() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Jenkins.READ, "devel");

MockAuthorizationStrategy mockStrategy = new MockAuthorizationStrategy();
mockStrategy.grant(Jenkins.READ).everywhere().to("devel");
for (Permission p : Item.PERMISSIONS.getPermissions()) {
gmas.add(p, "devel");
mockStrategy.grant(p).everywhere().to("devel");
}
r.jenkins.setAuthorizationStrategy(gmas);
r.jenkins.setAuthorizationStrategy(mockStrategy);

// Copy jar files to temporary directory, then overwrite them with updated jar files.
File tmpDir = tmpFolderRule.newFolder();

Expand Down Expand Up @@ -589,13 +600,14 @@ private List<File> getAllUpdatedJarFiles() throws URISyntaxException {

@Test public void testDifferentClasspathButSameContent() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Jenkins.READ, "devel");

MockAuthorizationStrategy mockStrategy = new MockAuthorizationStrategy();
mockStrategy.grant(Jenkins.READ).everywhere().to("devel");
for (Permission p : Item.PERMISSIONS.getPermissions()) {
gmas.add(p, "devel");
mockStrategy.grant(p).everywhere().to("devel");
}
r.jenkins.setAuthorizationStrategy(gmas);
r.jenkins.setAuthorizationStrategy(mockStrategy);

final String testingDisplayName = "TESTDISPLAYNAME";

final List<File> jars = getAllJarFiles();
Expand Down Expand Up @@ -654,16 +666,18 @@ private List<File> getAllUpdatedJarFiles() throws URISyntaxException {

@Test public void testClasspathAutomaticApprove() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Jenkins.READ, "devel");
gmas.add(Jenkins.READ, "approver");
gmas.add(Jenkins.RUN_SCRIPTS, "approver");

MockAuthorizationStrategy mockStrategy = new MockAuthorizationStrategy();
mockStrategy.grant(Jenkins.READ).everywhere().to("devel");
mockStrategy.grant(Jenkins.READ).everywhere().to("approver");
mockStrategy.grant(Jenkins.RUN_SCRIPTS).everywhere().to("approver");
mockStrategy.grant(Jenkins.ADMINISTER).everywhere().to("approver");
for (Permission p : Item.PERMISSIONS.getPermissions()) {
gmas.add(p, "devel");
gmas.add(p, "approver");
mockStrategy.grant(p).everywhere().to("devel");
mockStrategy.grant(p).everywhere().to("approver");
}
r.jenkins.setAuthorizationStrategy(gmas);

r.jenkins.setAuthorizationStrategy(mockStrategy);
JenkinsRule.WebClient wcDevel = r.createWebClient();
wcDevel.login("devel");

Expand Down

0 comments on commit 6ee0069

Please sign in to comment.