Skip to content

Commit

Permalink
unit test to reproduce JENKINS-13502 and confirm fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeloof committed Feb 28, 2013
1 parent 5d38d40 commit dbc212e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -763,7 +763,7 @@ public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOE
/**
* Reflect the submission of the pseudo 'upstream build trigger'.
*/
private void convertUpstreamBuildTrigger(Set<AbstractProject> upstream) throws IOException {
protected void convertUpstreamBuildTrigger(Set<AbstractProject> upstream) throws IOException {

SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM);
try {
Expand Down
46 changes: 45 additions & 1 deletion test/src/test/java/hudson/model/AbstractProjectTest.java
Expand Up @@ -27,7 +27,8 @@
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.security.GlobalMatrixAuthorizationStrategy;
import hudson.security.*;
import hudson.tasks.BuildTrigger;
import hudson.tasks.Shell;
import hudson.scm.NullSCM;
import hudson.Launcher;
Expand All @@ -38,13 +39,21 @@
import hudson.util.StreamTaskListener;
import hudson.util.OneShotEvent;
import java.io.IOException;

import jenkins.model.Jenkins;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.MemoryAssert;
import org.jvnet.hudson.test.recipes.PresetData;
import org.jvnet.hudson.test.recipes.PresetData.DataSet;

import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;
import org.apache.commons.io.FileUtils;
import java.lang.ref.WeakReference;
Expand Down Expand Up @@ -285,4 +294,39 @@ public void testGetBuildAfterGC() throws Exception {
MemoryAssert.assertGC(new WeakReference(job.getLastBuild()));
assertTrue(job.getLastBuild() != null);
}

@Bug(13502)
public void testHandleBuildTrigger() throws Exception {
Project u = createFreeStyleProject("u"),
d = createFreeStyleProject("d"),
e = createFreeStyleProject("e");

u.addPublisher(new BuildTrigger("d", Result.SUCCESS));

jenkins.setSecurityRealm(createDummySecurityRealm());
ProjectMatrixAuthorizationStrategy authorizations = new ProjectMatrixAuthorizationStrategy();
jenkins.setAuthorizationStrategy(authorizations);

authorizations.add(Jenkins.ADMINISTER, "admin");
authorizations.add(Jenkins.READ, "user");

// user can READ u and CONFIGURE e
Map<Permission, Set<String>> permissions = new HashMap<Permission, Set<String>>();
permissions.put(Job.READ, Collections.singleton("user"));
u.addProperty(new AuthorizationMatrixProperty(permissions));

permissions = new HashMap<Permission, Set<String>>();
permissions.put(Job.CONFIGURE, Collections.singleton("user"));
e.addProperty(new AuthorizationMatrixProperty(permissions));

User user = User.get("user");
SecurityContext sc = ACL.impersonate(user.impersonate());
try {
e.convertUpstreamBuildTrigger(Collections.<AbstractProject>emptySet());
} finally {
SecurityContextHolder.setContext(sc);
}

assertEquals(1, u.getPublishersList().size());
}
}

0 comments on commit dbc212e

Please sign in to comment.