27
27
import com .cloudbees .hudson .plugins .folder .computed .DefaultOrphanedItemStrategy ;
28
28
import edu .umd .cs .findbugs .annotations .NonNull ;
29
29
import hudson .Util ;
30
+ import hudson .model .Cause ;
31
+ import hudson .model .CauseAction ;
30
32
import hudson .model .Item ;
31
33
import hudson .model .Result ;
32
34
import hudson .model .TaskListener ;
@@ -235,6 +237,7 @@ public static void assertRevisionAction(WorkflowRun build) {
235
237
assertEquals (1 , mp .getItems ().size ());
236
238
}
237
239
240
+ @ Issue ("JENKINS-46795" )
238
241
@ Test public void untrustedRevisions () throws Exception {
239
242
sampleGitRepo .init ();
240
243
String masterJenkinsfile = "node {checkout scm; echo readFile('file')}" ;
@@ -255,7 +258,6 @@ public static void assertRevisionAction(WorkflowRun build) {
255
258
String branch = "some-other-branch-from-Norway" ;
256
259
sampleGitRepo .git ("checkout" , "-b" , branch );
257
260
sampleGitRepo .write ("Jenkinsfile" , "error 'ALL YOUR BUILD STEPS ARE BELONG TO US'" );
258
- sampleGitRepo .write ("file" , "subsequent content" );
259
261
sampleGitRepo .git ("commit" , "--all" , "--message=big evil laugh" );
260
262
p = WorkflowMultiBranchProjectTest .scheduleAndFindBranchProject (mp , branch );
261
263
r .waitUntilNoActivity ();
@@ -268,17 +270,42 @@ public static void assertRevisionAction(WorkflowRun build) {
268
270
r .assertLogContains ("not trusting" , b );
269
271
SCMBinder .IGNORE_UNTRUSTED_EDITS = true ;
270
272
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 ());
272
280
r .assertLogContains ("subsequent content" , b );
273
281
r .assertLogContains ("not trusting" , b );
274
282
} finally {
275
283
SCMBinder .IGNORE_UNTRUSTED_EDITS = false ;
276
284
}
277
285
sampleGitRepo .write ("Jenkinsfile" , masterJenkinsfile );
278
286
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 ());
280
292
r .assertLogContains ("subsequent content" , b );
281
293
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 );
282
309
}
283
310
public static class WarySource extends GitSCMSource {
284
311
public WarySource (String id , String remote , String credentialsId , String includes , String excludes , boolean ignoreOnPushNotifications ) {
0 commit comments