2727import com .cloudbees .hudson .plugins .folder .computed .DefaultOrphanedItemStrategy ;
2828import edu .umd .cs .findbugs .annotations .NonNull ;
2929import hudson .Util ;
30+ import hudson .model .Cause ;
31+ import hudson .model .CauseAction ;
3032import hudson .model .Item ;
3133import hudson .model .Result ;
3234import hudson .model .TaskListener ;
@@ -235,6 +237,7 @@ public static void assertRevisionAction(WorkflowRun build) {
235237 assertEquals (1 , mp .getItems ().size ());
236238 }
237239
240+ @ Issue ("JENKINS-46795" )
238241 @ Test public void untrustedRevisions () throws Exception {
239242 sampleGitRepo .init ();
240243 String masterJenkinsfile = "node {checkout scm; echo readFile('file')}" ;
@@ -255,7 +258,6 @@ public static void assertRevisionAction(WorkflowRun build) {
255258 String branch = "some-other-branch-from-Norway" ;
256259 sampleGitRepo .git ("checkout" , "-b" , branch );
257260 sampleGitRepo .write ("Jenkinsfile" , "error 'ALL YOUR BUILD STEPS ARE BELONG TO US'" );
258- sampleGitRepo .write ("file" , "subsequent content" );
259261 sampleGitRepo .git ("commit" , "--all" , "--message=big evil laugh" );
260262 p = WorkflowMultiBranchProjectTest .scheduleAndFindBranchProject (mp , branch );
261263 r .waitUntilNoActivity ();
@@ -268,17 +270,42 @@ public static void assertRevisionAction(WorkflowRun build) {
268270 r .assertLogContains ("not trusting" , b );
269271 SCMBinder .IGNORE_UNTRUSTED_EDITS = true ;
270272 try {
271- b = r .buildAndAssertSuccess (p );
273+ sampleGitRepo .write ("file" , "subsequent content" );
274+ sampleGitRepo .git ("commit" , "--all" , "--message=edits" );
275+ p = WorkflowMultiBranchProjectTest .scheduleAndFindBranchProject (mp , branch );
276+ r .waitUntilNoActivity ();
277+ b = p .getLastBuild ();
278+ assertNotNull (b );
279+ assertEquals (2 , b .getNumber ());
272280 r .assertLogContains ("subsequent content" , b );
273281 r .assertLogContains ("not trusting" , b );
274282 } finally {
275283 SCMBinder .IGNORE_UNTRUSTED_EDITS = false ;
276284 }
277285 sampleGitRepo .write ("Jenkinsfile" , masterJenkinsfile );
278286 sampleGitRepo .git ("commit" , "--all" , "--message=meekly submitting" );
279- b = r .buildAndAssertSuccess (p );
287+ p = WorkflowMultiBranchProjectTest .scheduleAndFindBranchProject (mp , branch );
288+ r .waitUntilNoActivity ();
289+ b = p .getLastBuild ();
290+ assertNotNull (b );
291+ assertEquals (3 , b .getNumber ());
280292 r .assertLogContains ("subsequent content" , b );
281293 r .assertLogContains ("not trusting" , b );
294+ sampleGitRepo .write ("Jenkinsfile" , "node {checkout scm; echo readTrusted('file').toUpperCase()}" );
295+ sampleGitRepo .git ("commit" , "--all" , "--message=changes to be approved" );
296+ p = WorkflowMultiBranchProjectTest .scheduleAndFindBranchProject (mp , branch );
297+ r .waitUntilNoActivity ();
298+ b = p .getLastBuild ();
299+ assertNotNull (b );
300+ assertEquals (4 , b .getNumber ());
301+ r .assertBuildStatus (Result .FAILURE , b );
302+ r .assertLogContains (Messages .ReadTrustedStep__has_been_modified_in_an_untrusted_revis ("Jenkinsfile" ), b );
303+ r .assertLogContains ("not trusting" , b );
304+ b = p .scheduleBuild2 (0 , new CauseAction (new Cause .UserIdCause ())).get ();
305+ assertEquals (5 , b .getNumber ());
306+ r .assertBuildStatusSuccess (b );
307+ r .assertLogContains ("SUBSEQUENT CONTENT" , b );
308+ r .assertLogNotContains ("not trusting" , b );
282309 }
283310 public static class WarySource extends GitSCMSource {
284311 public WarySource (String id , String remote , String credentialsId , String includes , String excludes , boolean ignoreOnPushNotifications ) {
0 commit comments