Skip to content

Commit

Permalink
Add Regex PipelineScript Test
Browse files Browse the repository at this point in the history
  • Loading branch information
arthas-choi authored and MarkEWaite committed Oct 6, 2023
1 parent 6989acc commit 6a077a2
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,35 @@ public void basics() throws Exception {
});
}

@Test
public void basicsRegex() throws Exception {
story.then(step -> {
WorkflowJob p = step.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {wrap([$class: 'MaskPasswordsBuildWrapper', varMaskRegexes: [[key: 'REGEX', value: 's3cr3t']]]) {semaphore 'restarting'; echo 'printed s3cr3t oops'}}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("restarting/1", b);
});

story.then(step -> {
WorkflowJob p = step.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getLastBuild();
Set<String> expected = new HashSet<>(Arrays.asList("build.xml", "program.dat", "workflow/5.xml"));
if (!isWindows()) {
// Skip assertion on Windows, temporary files contaminate content frequently
assertEquals("TODO cannot keep it out of the closure block, but at least outside users cannot see this; withCredentials does better", expected, grep(b.getRootDir(), "s3cr3t"));

Check warning on line 149 in src/test/java/com/michelin/cio/hudson/plugins/maskpasswords/MaskPasswordsWorkflowTest.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: cannot keep it out of the closure block, but at least outside users cannot see this; withCredentials does better", expected, grep(b.getRootDir(), "s3cr3t"));
}
SemaphoreStep.success("restarting/1", null);
step.assertBuildStatusSuccess(step.waitForCompletion(b));
step.assertLogContains("printed ******** oops", b);
step.assertLogNotContains("printed s3cr3t oops", b);
expected = new HashSet<>(Arrays.asList("build.xml", "workflow/5.xml", "workflow/8.xml"));
if (!isWindows()) {
// Skip assertion on Windows, temporary files contaminate content frequently
assertEquals("in build.xml only because it was literally in program text", expected, grep(b.getRootDir(), "s3cr3t"));
}
});
}

@Test
public void noWorkspaceRequired() {
story.then(r -> {
Expand All @@ -143,6 +172,18 @@ public void noWorkspaceRequired() {
});
}

@Test
public void noWorkspaceRequiredRegex() {
story.then(r -> {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("maskPasswords(varMaskRegexes: [[key: 'REGEX', value: 's3cr3t']]) {echo 'printed s3cr3t oops'}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("printed ******** oops", b);
r.assertLogNotContains("printed s3cr3t oops", b);
});
}

// test to ensure that when the ConsoleLogFilter isn't enabled globally,
// it doesn't change the output (i.e. it respects the config setting).
// Note that per JENKINS-30777, this does not work with Pipeline jobs
Expand Down

0 comments on commit 6a077a2

Please sign in to comment.