Skip to content

Commit

Permalink
[JENKINS-32525] - Handle null @AncestorInPath when selecting Downstre…
Browse files Browse the repository at this point in the history
…am Jobs.
  • Loading branch information
Dohbedoh committed Mar 7, 2016
1 parent 9cb52bf commit 10699e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/tasks/BuildTrigger.java
Expand Up @@ -367,6 +367,8 @@ public boolean showEvenIfUnstableOption(@CheckForNull Class<? extends AbstractPr
* Form validation method.
*/
public FormValidation doCheck(@AncestorInPath AbstractProject project, @QueryParameter String value) {
// JENKINS-32525: Check that it behaves gracefully for an unknown context
if (project == null) return FormValidation.ok();
// Require CONFIGURE permission on this project
if(!project.hasPermission(Item.CONFIGURE)) return FormValidation.ok();

Expand Down
8 changes: 7 additions & 1 deletion test/src/test/java/hudson/tasks/BuildTriggerTest.java
Expand Up @@ -222,6 +222,7 @@ public void downstreamProjectSecurity() throws Exception {
assertEquals(Collections.singletonList(downstream), upstream.getDownstreamProjects());
// Downstream projects whose existence we are not aware of will silently not be triggered:
assertDoCheck(alice, Messages.BuildTrigger_NoSuchProject(downstreamName, "upstream"), upstream, downstreamName);
assertDoCheck(alice, null, null, downstreamName);
FreeStyleBuild b = j.buildAndAssertSuccess(upstream);
j.assertLogNotContains(downstreamName, b);
j.waitUntilNoActivity();
Expand All @@ -232,6 +233,7 @@ public void downstreamProjectSecurity() throws Exception {
AuthorizationMatrixProperty amp = new AuthorizationMatrixProperty(grantedPermissions);
downstream.addProperty(amp);
assertDoCheck(alice, Messages.BuildTrigger_you_have_no_permission_to_build_(downstreamName), upstream, downstreamName);
assertDoCheck(alice, null, null, downstreamName);
b = j.buildAndAssertSuccess(upstream);
j.assertLogContains(downstreamName, b);
j.waitUntilNoActivity();
Expand All @@ -242,6 +244,7 @@ public void downstreamProjectSecurity() throws Exception {
amp = new AuthorizationMatrixProperty(grantedPermissions);
downstream.addProperty(amp);
assertDoCheck(alice, null, upstream, downstreamName);
assertDoCheck(alice, null, null, downstreamName);
b = j.buildAndAssertSuccess(upstream);
j.assertLogContains(downstreamName, b);
j.waitUntilNoActivity();
Expand All @@ -251,8 +254,9 @@ public void downstreamProjectSecurity() throws Exception {
assertNotNull(cause);
assertEquals(b, cause.getUpstreamRun());
// Now if we have configured some QIA’s but they are not active on this job, we should run as anonymous. Which would normally have no permissions:
QueueItemAuthenticatorConfiguration.get().getAuthenticators().replace(new MockQueueItemAuthenticator(Collections.<String,Authentication>emptyMap()));
QueueItemAuthenticatorConfiguration.get().getAuthenticators().replace(new MockQueueItemAuthenticator(Collections.<String, Authentication>emptyMap()));
assertDoCheck(alice, Messages.BuildTrigger_you_have_no_permission_to_build_(downstreamName), upstream, downstreamName);
assertDoCheck(alice, null, null, downstreamName);
b = j.buildAndAssertSuccess(upstream);
j.assertLogNotContains(downstreamName, b);
j.assertLogContains(Messages.BuildTrigger_warning_this_build_has_no_associated_aut(), b);
Expand All @@ -265,6 +269,7 @@ public void downstreamProjectSecurity() throws Exception {
amp = new AuthorizationMatrixProperty(grantedPermissions);
downstream.addProperty(amp);
assertDoCheck(alice, null, upstream, downstreamName);
assertDoCheck(alice, null, null, downstreamName);
b = j.buildAndAssertSuccess(upstream);
j.assertLogContains(downstreamName, b);
j.waitUntilNoActivity();
Expand All @@ -280,6 +285,7 @@ public void downstreamProjectSecurity() throws Exception {
downstream.addProperty(amp);
QueueItemAuthenticatorConfiguration.get().getAuthenticators().clear();
assertDoCheck(alice, Messages.BuildTrigger_NoSuchProject(downstreamName, "upstream"), upstream, downstreamName);
assertDoCheck(alice, null, null, downstreamName);
b = j.buildAndAssertSuccess(upstream);
j.assertLogContains(downstreamName, b);
j.assertLogContains(Messages.BuildTrigger_warning_access_control_for_builds_in_glo(), b);
Expand Down

0 comments on commit 10699e2

Please sign in to comment.